Game Development Reference
In-Depth Information
Controlling difficulty with a level class
We've shown you a couple different ways to create difficulty levels in a game already in this topic,
and with Color Drop, we will expand on these ideas even further. A simple DifficultyLevel
class follows. We will create an array of these classes in ColorDrop to represent explicit difficulty
levels that will ramp up when a level is completed.
Each DifficultyLevel contains three properties:
allowedColors : This array holds all the possible colors of blocks that can occur on any
given level.
startPlays : This is the number of plays the player is awarded at the beginning of the
level. When plays run out, the game is over
scoreThreshold : The score must be reached on a level to advance to the next level. This
score must be reached before the number of plays equals zero.
The DifficultyLevel class accepts all of these parameters in the constructor and sets the
appropriate variables.
package com.efg.games.colordrop
{
public class DifficultyLevel {
public var allowedColors:Array;
public var startPlays:Number;
public var scoreThreshold:Number;
public function DifficultyLevel(allowedColors:Array, startPlays:Number,
scoreThreshold:Number)
{
this.allowedColors = allowedColors;
this.startPlays = startPlays;
this.scoreThreshold = scoreThreshold;
}
}
}
Creating the GameStates class
GameStates is a class we will use to hold the static const values we will use in Color Drop to
control the flow of the game. These values are the local states for the ColorDrop state machine.
We will be creating a state machine local to this game that is used along with the state machine in
Main , and these states (as well as the state machine) will be explained in full a bit later. For now,
it is good to know that we will be making extensive use of these values very soon.
package com.efg.games.colordrop
{
public class GameStates {
public static const STATE_INITIALIZING:int = 10;
Search WWH ::




Custom Search