Small order
Open Pandora's magic box-this is a seriesArticleThese articles do not really tell Pandora MM's story about opening the Magic Box. These are technical articles. They are to use real cases to describe the design process of software systems. The real case used in this article is the lottery system in the web game project. The lottery system is relatively independent and involves a few technical terms, so it is easy for readers to understand. However, even so, this article is still a little difficult, just to explain the game scheme may need a lot of text. I assume that you, as a reader, have been engaged in Web Game Development for at least one or two years and have a certain understanding of the architecture of the game server, understand the basic content of Message Processing Layer msghandler, business layer bizservice, Io layer, and multithreading, and understand UML. There won't be too many details in the articleCode, Some sample code may be displayed in later sections. We mainly discuss how software systems are designed?
I prefer to restore my technical problems to my daily life, which makes it easy for people to understand and make correct judgments. In fact, technology is like this. technology comes from life and is more abstract than life ...... Therefore, I am not very familiar with using many technical terms or abbreviations to arm myself. Easy to understand. This will be a series of articles about methodology.
Before getting started
How to solve the problem is not important. What is important?
Before proceeding, let's take a brief look at the target system we will discuss: Pandora magic box system. It is because of the name of this system that the title of this article is available. In fact, the software design process is like opening Pandora magic box, full of many unknown.
Pandora magic box system is a lottery system in the game (more popular: kaibao box ). However, unlike the general lottery system, the lottery system is started on a regular basis, and the number of prizes is limited, and this number is still public. For example, if there are 10 prizes in Pandora Box, these 10 prizes will be viewed by all players. At this time, a player draws one prize and you will see nine remaining prizes in the Magic Box.
If one of the 10 prizes is a super prize, what will happen? That is, for everyone, the chance of this super prize is 10%. Just now, the unlucky guy has drawn a prize that is not a grand prize, and the chance of the grand prize to appear has increased to 11.11%. If another unlucky guy pulls another prize that is not a grand prize, the chance of a Super Grand Prize increases to 12.5% ......
Over time, everyone will see a higher chance of a grand prize. In the end, there will be a person born to win the grand prize, all the prizes in one breath. This kind of behavior is called "circle ".
The rules will be detailed later.
Pandora's magic box system can also be seen as an in-game activity system, which can only be enabled within the same period of time (this is the game planning rule !). The activated Magic Box activity is not just available. Instead, you need to calculate the average level of players on the server, and then start the corresponding Magic Box activity based on the level segment of the average level. If the text is written here, I am afraid it will not be able to proceed. I 'd like to explain the problem with graphics. See Figure 1:
(Figure 1) Level Section
The triangle in the figure represents the level segment.
Figure 1 shows the concept of a level segment in the Pandora magic box system. For example, when the average player level on the server is 10, the magic box system can only be 0 ~ 20. When the average player level on the server is 30, the magic box system will enter the next level segment, ranging from 21 ~ 40.
I have already explained the concept of the level section above, and I will probably have an impression on it. We have to continue with this article. The Pandora magic box is under the level section, and there can be many magic boxes. As shown in Figure 2:
(Figure 2) Pandora Magic Box
The square in the figure represents Pandora magic box.
There is Pandora magic box under the level section, and we now know it. Pandora magic box is enabled in sequence, and only one magic box can be opened in each round! When the prize in box 1 is exhausted, you can enable box 2. Only after the prize in Magic Box 2 is drawn can the Magic Box 3 be started. What if the prize in box 3 is exhausted? The system randomly selects one from the boxes 1, 2, and 3 to continue the next round of activity. As shown in figure 3:
(Figure 3) 4th round Lottery
A magic box will be randomly selected from the Magic Box 1, 2, 3
Figure 3 shows the lucky draw in the 1st round. What about the 5th round? The 5th round lottery is the same as the 4th round lottery. That is to say, the system is ordered at the beginning, and then it becomes random. The system enters the next stage when the average player level of the entire server reaches 21 or above. In the next stage, the system changes from orderly to disordered. After each round of Lottery, the system takes a short break and starts the next round.
Finally, let's talk about it. Each box contains many prizes, as shown in figure 4:
(Figure 4) prize in the Magic Box
The hexagonal star in the figure represents the prize in the Magic Box.
Note: In Figure 4, I used the aggregate link in the UML class diagram to show the fact that there are multiple prizes in a magic box. UML is not limited to UML.We have learned about the general content. Next, let's have a complete time trip ......
[Time;
Average player level on the server: 6;
Today, the Pandora box system opened Box 1, which contains 10 prizes.
Players enthusiastically participated in the lucky draw;
[Time;
Average player level on the server: 9;
Today, the Pandora box system opened box 2, which contains 20 intermediate prizes.
Players also enthusiastically participated in the lucky draw;
[Time;
Average player level on the server: grade 13;
Today, the Pandora box system opened Box 3, which contains 30 high-level prizes.
Players are still enthusiastic about participating in the lucky draw;
[Time;
Average player level on the server: grade 17;
Today, the Pandora magic box system randomly opened a magic box, which contains 20 intermediate prizes.
Players are still enthusiastic about participating in the lucky draw;
[Time;
Average player level on the server: level 22;
Today, Pandora's magic box system enters the second stage and starts the second stage of magic box 1.
There are 40 more advanced prizes in the Magic Box.
Everyone participated in the lucky draw;
Now, the Pandora magic box system has been clearly introduced. The text above may be boring, but I will try my best to ensure a simple and easy style. A lot of what we have mentioned earlier are the Pandora Box activities built into the system. In addition, game operations will also start custom Pandora Box activities. There is no difference between the Pandora Box launched by the Operation and the Pandora Box launched by the system. However,When the operation starts Pandora Magic Box activity, the activities that come with the system must be suspended and must be saved on site. After the operation activities are completed, resume the on-site operation. As shown in figure 5:
(Figure 5) Operation of the Magic Box
Before the operation of the Magic Box activity, you need to save the on-site activity of the system magic box.
This operation requirement is indeed troublesome. It is mainly because it is necessary to save and restore the site. So far, all the planning and operation requirements have basically been completed. If you haven't read it clearly, you can go back and read it carefully. In fact, the above text is a bit about the demand analysis process. In this process, we found several important business concepts in the Pandora magic box system.
Before starting the design, let's clarify what the problem is to be solved )? This is critical. That is, a common foundation needs to be established during the discussion.This is why I first introduced the entire system at the beginning of the article. Many technical design documents have a fatal defect, that is, from the beginning to the end are emphasizing how to do it )? This is not easy to read. Technical Design Documents are actually "Telling Stories". Since they are telling stories, we should follow the following guidelines: What? --> Why? --> how) in this order. Of course, it can also be: what is --> how to do --> Why. No matter what the order is, what is the problem at the beginning? When you are clear about what the problem is, what else's going on in your mind.
Drawing and analyzing important concepts in the system. Human brain's ability to accept text is far inferior to that of graphics. You can draw more pictures when drawing, and you can develop the right brain for drawing.ProgramThe good news is that logical thinking and imagination are exercised. Some problems need imagination to solve ...... A key capability of programmers is to visualize abstract problems and then abstract specific problems. This is a bit from positive to negative, and then to negative.
This article describes what Pandora's magic box system looks like, and the design analysis has been started in the Process of introduction. Currently, the analysis scope is "business model (or domain model. Business Model Analysis splits the target system into "Business Objects" and "business actions )". This may be a bit abstract, for example. For example, to develop an ATM system, the "Business Objects" are bank cards and cash. The "Business Behaviors" are deposits and withdrawals ).
Do you still remember this: program = Data Structure +Algorithm. Isn't "Data Structure" A "Business Object? Isn't "algorithm" a "business behavior? At this moment, does it resonate?
Through this article, we can obtain a class diagram, as shown in Figure 6:
(Figure 6) class chart
Obtain a class chart based on the business model.
This is our first design result ......