Now let's take a look at what we need in order to implement the gameplay. First of all, we need to create all of the structures (and initialize them) for the game state. We'll be using another grid, this time to store a randomized distribution of numbers.
Add a call at the bottom of the
Game:initialize ()
method to an auxiliary function.self:restartGamePlay ()
Add the auxiliary function as well.
function Game:restartGamePlay () self.distributionGrid = MOAIGrid.new () self.distributionGrid:setSize (GRID_COLS, GRID_ROWS)
First, we create a grid that will hold the distribution of our colors. This grid also has a dimension of 5 x 4. Note that we don't need to set the tile size now as this grid won't be rendered.
local tiles = { 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11 }
This table is just a temporary array of tiles; as you see, we start from
2
(1
is the back tile, remember?) and repeat each number twice. These numbers represent the color...