pbivens67 said:
how do get better at developing data structures?
pbivens67 said:
is this code better?
Your code uses random numbers to paint the fields of the level. That means that if you paint the level to the screen now, and one second later you do it again, most fields of the level will be different the second time (and the third time, and the fourth time and the …).
In a normal game, you will paint the entire screen several times a second. That means your current code will cause that all fields in the level constantly change, even faster than the player can see. For example, it's impossible to plan a path through the level because the fields change faster than a player can walk from one tile to the next.
EDIT: If you wan to see this for yourself, setup a game loop that repeatedly paints the tiles until you close the application (or press a key, or something else).
To fix, you need to always paint the same fields of the level at the same spot. This means you need to remember what field to paint at every tile in the level. To do that, you need to store what field needs to be drawn in a data structure, for example a 2-dimensionsal array. (You may want to start with a 1-dimensional array at first. The level will then be a single row wide, but it allows you to first deal with storing and using the tile information, and worry about more rows in a level at another time.)
The code should be split in an initialization step that creates the array and fills it with values for the fields (ie what tile to paint at each spot in the level). Once initialization is done, your paint code must use the data stored in the array to paint the fields of the level.