Game Development Reference
In-Depth Information
Creating AI difficulty with a class
If you recall from the last chapter, we created a
DifficultyLevel
class. We are going to create a
new version of that class for Dice Battle. However, as well as describing the colors that will be on
each level, we also need to describe the AI of the computer player for each level.
Since this class has no functions, we will simply describe the properties and how they relate to
the Dice Battle game:
allowedColors
: This is an array of
Die.DIE_COLOR_xxx
color values that will be valid for
this level. There are only three different color values for this game.
enemyLife
: This is the value for the hit points for this enemy. When all the enemy hit
points are knocked off, the player wins the level.
aiBonus
: This is a percentage bonus that this enemy receives when we decide which
move the computer should make. This bonus is what helps make the AI ramp up on
each successive level.
minValue
: This is the minimum value of a move the computer player will make, if
possible. This helps ramp up the difficulty on each successive level.
enemyTile
: This is the in the tile sheet that will be displayed on the screen for this level.
Here is the full code for the
DifficultyLevel
class:
package com.efg.games.dicebattle
{
public class DifficultyLevel
{
public var allowedColors:Array;
public var enemyLife:Number;
public var aiBonus:Number;
public var minValue:Number;
public var enemyTile:Number
public function DifficultyLevel(allowedColors:Array, enemyLife: Number,
enemyTile:Number, aiBonus:Number, minValue:Number) {
this.allowedColors = allowedColors;
this.enemyLife = enemyLife;
this.aiBonus = aiBonus;
this.enemyTile = enemyTile;
this.minValue = minValue;
}
}
}
Creating the Die class
The
Die
class is nearly identical to the
Block
class from Color Drop. In the spirit of the
second game
theory
and the importance of iteration we have tried to emphasize in this topic so far, we are going
to use
Block
as the basis for the
Die
class. We will now highlight differences to
Block
that we have
made to support the fact that we are playing with dice and not simple colored blocks.