Game Development Reference
In-Depth Information
dispatchEvent(new CustomEventScoreBoardUpdate(
CustomEventScoreBoardUpdate.UPDATE_TEXT, Main.SCORE_BOARD_TURN, String(turn)));
gameState = GameStates.STATE_START_REPLACING;
break;
After new dice are replaced, we look at whose turn it is at that moment. If it is
TURN_PLAYER
, we
simply listen for mouse input by setting the
gameState
to
GameStates.STATE_WAITING_FOR_INPUT
.
If it is the
TURN_COMPUTER
, we need to create an AI move, an AI move is created by setting
the
gameState
to
GameStates.STATE_START_AI
. We then set the
gameState
to
GameStates.STATE_FALL_DICE_WAIT
to wait for the replaced dice to fall into place. We did the
same thing in Color Drop.
case GameStates.STATE_START_REPLACING:
replaceDice();
if (turn == TURN_PLAYER) {
nextGameState = GameStates.STATE_WAITING_FOR_INPUT;
} else {
nextGameState = GameStates.STATE_START_AI;
}
gameState = GameStates.STATE_FALL_DICE_WAIT;
break;
case GameStates.STATE_WAITING_FOR_INPUT:
break;
The next new
gameState
is
GameStates.STATE_START_AI
. This state essentially creates the move
for the computer player. To create the computer move, we call
createAIMove
.
case GameStates.STATE_START_AI:
createAIMove();
framesToWait = 15;
framesWaited = 0;
nextGameState = GameStates.STATE_REMOVE_CLICKED_DICE;
gameState = GameStates.STATE_WAIT;
break;
case GameStates.STATE_REMOVE_CLICKED_DICE:
removeClickedDice();
gameState= GameStates.STATE_CHECK_FOR_END;
break;
Checking for the end (of a level or the game) is a bit more complicated now, as shown in the
following code. Since now we do not know if the game or level is over until the player or computer
has completed a turn, we need to do both checks right here in the
GameStates.
STATE_CHECK_FOR_END
state. The rest of the states remain essentially unchanged from Color Drop.
case GameStates.STATE_CHECK_FOR_END:
if (checkforEndLevel()) {
nextGameState = GameStates.STATE_END_LEVEL;
fadeDice();
gameState = GameStates.STATE_FADE_DICE_WAIT;
} else if (checkForEndGame() ) {
nextGameState = GameStates.STATE_END_GAME;
makeDiceFall()
gameState = GameStates.STATE_FALL_DICE_WAIT;
} else {
gameState= GameStates.STATE_CHANGE_TURN;
}