O'Reilly logo

Developing Mobile Games with Moai SDK by Francisco Tufro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Gameplay

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.

Initialization

  1. Add a call at the bottom of the Game:initialize () method to an auxiliary function.
      self:restartGamePlay ()
  2. Add the auxiliary function as well.
    function Game:restartGamePlay ()
      self.distributionGrid= MOAIGrid.new ()
      self.distributionGrid:setSize (GRID_COLS, GRID_ROWS)
    1. 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 = { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required