Puyo-Puyo design document

Source: Internet
Author: User

Puyo-Puyo design documentOriginal requirement: Purpose: ---------- the goal of this exercise is to develop a Java or C/C ++ version of Puyo-Puyo, a variation of the Tetris game. rules of game: --------------- * spheres come down from the top of the game board in pairs. A player can rotate them on their way down. * spheres come in 4 different colors: red, blue, green, and yellow * linking four spheres of the same color (horizontally, vertical Ly or both (as in Tetris) removes them from the game board, allowing any sphere remaining to drop and fill the vacated space. this may lead to several possible "chain combos" if additional colors match. * The Game Board can be any size you want (we recommend 6x12) l note that the pair of spheres are not linked to each other. if one sphere is blocked because there is something underneath, the other One will continue falling (with no player control over it) until it reaches something.: Thought: When I first got the question, I felt that this game had been played before, but the rules were not the same, so I had a better understanding of the game effect. (It makes sense to first play games.) recently, we are studying the Russian square algorithm, So we naturally associate the two in our hearts. Here are the comparison results: 1. the Tetris is a monochrome (color of course), which basically represents a two-dimensional array. The values of each element in the array are 0 and 1, indicating whether there are squares. This is the same in general, but it only takes a few more values to represent different colors. 0, NO, 1, Red, 2, Blue, 3, green, 4, yellow. 2. There are seven different building blocks in Tetris, and this is much simpler. There is only one pair of balls. 3. Mobile and collision detection are almost the same. That is, the ball is not connected. This should be considered separately. 4. Eliminate algorithms. Square is a whole line, which is well implemented in the algorithm. This requires a search, and there will also be a situation of disconnection, which should be a difficult point of this game. But it takes a lot of time to think about algorithms. 5. The failure conditions are the same. Is to check whether there is something in the first line ....... Implementation: for the first time, it was all self-designed, so I don't know how the development process is. I hope experienced people can give me some advice: What is a game? This problem seems to me complicated in the past, but since I learned the compilation principles last semester, I have a concept (although I have learned nothing, thanks to God.) the game is a finite state machine! First think about the several different states of the game, and what conditions can be met between various States to switch between them. Although I didn't think about the problem from this perspective at the beginning, I will definitely do it next time. However, this game does not need a state machine. I only set three states. It seems a bit redundant. However, I found that after the state machine is used, it is logically clear and easier to write. If necessary, you can use Visio to draw a State Conversion Diagram first. From the implementation process, I did this: Game background data representation (to put it bluntly, a two-dimensional array) -- à Implementation of the drawing part (that is, to draw an array) ----> fall ball generation algorithm ----> game failure determination --- à Fall Ball Moving algorithm (here I am not aware of the circumstances that cannot be controlled when a single ball falls, thanks to the "I" reminder. Note: "I" is not my own, but a person whose ID is "I -_-!) -- À fall ball rotation algorithm -- à game operation implementation -- à elimination algorithm -- à Lian Xiao implementation (this is actually nothing, just call the previously written method in a certain order) I added the points most, adjusted several bugs, and added the game pause. Is that all done? I am just doing a demo, not a real game, so it is not implemented in many aspects, which will be mentioned later. Detailed description of each part: 1. A pair of balls are generated each time when the falling ball is generated. This pair of balls has the following attributes: The color of the two balls. Initially, the random values are taken in the direction of two balls. There are two types of water and vertical. The number of horizontal balls is initially obtained. This is also a situation where a single ball falls. Coordinates of two balls. Take the left ball as the standard, and the following balls as the standard. What is the standard for a single ball? Are you still asking ?! Private method: whether the ball can be moved left, whether it can be shifted right, (whether it can be moved down) the external method of the ball: Left shift, right shift, rotation, two balls of color are exchanged from horizontal rotation to vertical rotation, and vice versa.
      R           G  
R G G   G R R  
Move down, if it can fall back to true drop, this is simple, direct while (move down () {} to deal with the painting (this varies according to the graphics system implementation) here we will discuss the two States in different directions and numbers. 2. I admit that I did not learn much about the data structure and the algorithm was poor enough, but I finally came up with it. The efficiency may be poor, but the CPU usage was very small during the game, then, J sets a color to copy the array, because when searching, the flag must be set to traverse the entire two-dimensional array in sequence. If the ball is the same as the given color, then, add it to a list and set its value to 0 (that is, colorless, which is equivalent to deleting it to prevent it from being searched later) for each element in the list, search for the color ball adjacent to it and add it to the list. After the list traversal is completed, all adjacent balls are found to determine whether the number is greater than or equal to 4. If yes, it is removed from the original array. (Points are calculated from here) Clear the list and continue traversing the two-dimensional array according to the above process, so that each elimination will copy one group of parts, and then traverse the page four times in four different colors... (If you have better algorithms, please let me know. Thank you !) 3. After the first elimination, the player may have to continue dropping the ball (because the following is empty !) Continue dropping algorithm: scans from bottom to top. If the current coordinate is empty and the current coordinate is not empty, the values corresponding to the two coordinates are exchanged. In this way, the overall location is one. The animation of falling gradually appears when every clock cycle falls. (Cool is much more than a drop !) Is there anything to add? Should it be enough? Think about the code.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.