Game Development Reference
In-Depth Information
super(ts, [tile], 0);
}
}
}
Adding the GameStates class
To support a computer AI player, we need to create some new game states for Dice Battle. In
Chapter 9, for Color Drop, we introduced the idea of a game state machine: a substate machine
used inside the game class independent of the one in Main . We created the states as a separate
class so that they would be easier to manage and identify within the code of ColorDrop . We are
going to utilize these concepts again for Dice Battle. However, for Dice Battle, we need to expand
that state machine we created for Color Drop with two additional states specific to Dice Battle's
functionality for playing against the computer.
The two states we need are STATE_CHANGE_TURN , where we decided whose turn to accept input for
(player or computer), and STATE_START_AI , where we start the process of creating a computer
move. The rest of the new states are really just name changes from Color Drop. Instead of BLOCK ,
we use the word DICE , but these are essentially the same states that we discussed in detail in
Chapter 8 for Color Drop.
package com.efg.games.dicebattle
{
public class GameStates {
public static const STATE_INITIALIZING:int = 10;
public static const STATE_CHANGE_TURN:int = 20;
public static const STATE_START_REPLACING:int = 30;
public static const STATE_START_AI:int = 40;
public static const STATE_WAITING_FOR_INPUT:int = 60;
public static const STATE_REMOVE_CLICKED_DICE:int = 70;
public static const STATE_CHECK_FOR_END:int = 80;
public static const STATE_FADE_DICE_WAIT:int = 90;
public static const STATE_FALL_DICE_WAIT:int = 100;
public static const STATE_END_GAME:int = 110;
public static const STATE_END_LEVEL:int = 120;
public static const STATE_WAIT:int = 130;
}
}
Setting up the game in Game.as
Now we will start looking at the Game class to see what kinds of changes we will have to make to
iterate it from Color Drop to Dice Battle. The first place that we need to make changes is in the
class properties and the constructor. We will now step through the first part of Game.as ,
highlighting the major changes along the way.
The class starts exactly like the ColorDrop.as In fact, it's not until we get to the specific code that
defines how the board is going to look that we get to any real changes. We will have far fewer Die
Search WWH ::




Custom Search