Game Development Reference
In-Depth Information
Here is the traced output aiVal when the algorithm is complete (with a label added for
illustration):
Chosen dieSet:1
This output means this is the move the computer will make is at dieSets[1] , which has a value of
10. This means we are going to knock 10 points from the player's hit points:
tempDie = dieSets[aiVal][1];
The rest of createAIMove does the simulation of the computer actually making a move. You will
notice that some of this code looks familiar. This is because it is essentially the same as when the
player makes a move. The main difference is that we subtract from, and report to ScoreBoard ,
playerLife instead of computerLife . We also play a different sound and call that lazy function in
the Die class makeDieClickedComputer .
clickedDiceArray = findLikeColoredDice(tempDie);
for (var cd:int =0; cd< clickedDiceArray.length; cd++) {
clickedDiceArray[cd].makeDieClickedComputer();
}
playerLife -= dieSets[aiVal][0];
dispatchEvent( new CustomEventSound(CustomEventSound.PLAY_SOUND,Main.SOUND_HIT,
false,1,0,1));
dispatchEvent(new CustomEventScoreBoardUpdate(
CustomEventScoreBoardUpdate.UPDATE_TEXT,Main.SCORE_BOARD_PLAYER_LIFE,
String(playerLife)));
}
Figure 9-7 shows how the screen appears when the computers makes a move. Notice the red
boxes that highlight the dice the computer has chosen. That comes from the call
clickedDiceArray[cd].makeDiceClickedComputer .
Figure 9-7. The computer chosen move
Search WWH ::




Custom Search