It is not surprising that there are dozens of rows of variable definitions in the game logic class. This is especially true for J2EE. To save memory space, many people leave the object-oriented feature to squeeze the Code together. The general situation is that my code drowned !! So I pay attention to this point when designing the structure, and always try to save the Code a little more scalability. It is not difficult to think about it. Just think about it carefully and you can find something that can be optimized. A variable is an example.
Most people are more accustomed to a property and a variable. For example, assume that you want to indicate the attributes of a character. You may do this:
Int life;
Int magic;
Int money;
Int attack power;
Int defensive power;
X axis of the int character;
Y axis of the int character
The row where the int character is located.
Column where the int character is located
Current action of the int character
The current direction of the int character.
.....
This is just a part. I believe it is difficult to name so many variables, especially those with poor English skills. We can see that using arrays is the best way. There are at least two advantages: 1. All variables are defined as a single line of int fairy [], and the variables are cleaned up, or even a bit of object taste, when you want to write the code related to this character, you will try fair [] without thinking about it.
2. scalability. This is easy to ignore. When a character has new attributes, you can use the fair [x + 1] lattice to indicate that the character is not affected at all, the premise is that the data types must be consistent.
An example of an Array application is a map. Assume that the first reaction of most people to make an rpg map is to use a two-dimensional array to represent map [rows] [columns]. It seems reasonable, but the problem may be that I want something on the map to work.
In this case, several variables must be added: 1. The currently displayed image; 2. How long will the image be switched.
This is only the most common case and there are more problems. We cannot define variables for every moving place, which is not worth the candle. For this reason, the 3D array now displays the following map representation:
Int map [row] [column] [attribute];
Map [] [] [0] indicates the image category