...
 
Commits (5)
  • Terence Martin's avatar
    Remove Maze handling of removing gray bricks · beb4c0db
    Terence Martin authored
    The code in the Maze entity that tries to determine for itself if it
    should remove all gray bricks has been removed. Now no gray brick
    removal happens at all.
    beb4c0db
  • Terence Martin's avatar
    Clarify the usage of currently defined states · c0cd298d
    Terence Martin authored
    Now that we have a better idea of the exact flow that we're going for,
    update the documentation comments for how all the states are used.
    c0cd298d
  • Terence Martin's avatar
    Switch to removing gray bricks when no moves left · 364531a8
    Terence Martin authored
    Now instead of swapping to the final ball drop state, we swap to the
    state in which we remove all gray bricks. We handle this state by
    using the state timer to slowly remove all of the gray bricks (telling
    them to vanish).
    
    Currently the code that reaps vanishing bricks is just spewing a
    console log every time it knows all of the gray bricks are gone.
    364531a8
  • Terence Martin's avatar
    Swap to final ball drop state when bricks gone · 1f9e5ca8
    Terence Martin authored
    Now the maze will invoke a method on the listener to tell it that all
    of the gray bricks have vanished out of the maze and have been reaped.
    
    The Game state uses this to transition into the final ball drop state,
    so that it can start the final ball drop of the round.
    1f9e5ca8
  • Terence Martin's avatar
    Put final ball drop under the control of states · 4b351244
    Terence Martin authored
    This puts the final ball drop into the control of the state machine;
    when we are in the final ball drop state, we select a ball and drop
    it, and then return to this state once the ball is done.
    
    There is currently a bug in this in which sometimes during the final
    ball drop a ball (that is blocked?) starts dropping, but the flag that
    says that it is done moving is not set.
    4b351244
This diff is collapsed.
......@@ -13,61 +13,76 @@ module nurdz.game
NO_STATE,
/**
* There is a maze currently being generated; no players are visible
* and no interactions with the maze are allowed.
* This state is set while the maze is undergoing generation. The Maze
* entity doing the generation will inform the registered event listener
* when the generation is completed, at which point it will switch away
* from this state.
*/
MAZE_GENERATION,
/**
* It is going to be the human players turn, but first we have to check
* and see if it's even possible for them to make a play at the moment.
* We want it to be the human player's turn. In this state we check to
* see if the human (or computer) can take a turn. If yes, the
* appropriate player state is swapped to. Otherwise we skip to the
* state where we start removing gray bricks.
*/
CHECK_VALID_PLAY_PLAYER,
/**
* The human player can take a turn now. Their controls work and they
* can attempt to push a ball.
* We have determined that the player has at least one play to make, so
* they can take a turn now. In this state, the controls available to
* the player to make a move are enabled.
*/
PLAYER_TURN,
/**
* It is going to be the computer players turn, but first we have to
* check and see if it's even possible for them to make a play at the
* moment.
* We want it to be the computer player's turn. In this state we check
* to see if the computer (or human) can take a turn. If yes, the
* appropriate player state is swapped to. Otherwise we skip to the
* state where we start removing gray bricks.
*/
CHECK_VALID_PLAY_COMPUTER,
/**
* The computer has selected its move and is now in the process of
* taking it. This covers moving to the ball, turning, and pushing.
* The computer is taking its turn now. This state encompasses the
* entirety of the computer taking it's turn, from selecting the move to
* arriving at the correct position and pushing the ball. The update()
* method in the Player entity is used to control this entire process.
*/
COMPUTER_TURN,
/**
* A ball is currently dropping through the maze. This can be either due
* to the player pushing the ball, the AI pushing a ball, or the end of
* round.
* Either the human player or the AI has pushed a ball. This state
* remains in effect until the ball has finished moving, in which case
* the handling code will either cycle to the state for the next player
* to take their turn or to the state where we start the end of round
* proceedings. round.
*/
BALL_DROPPING,
/**
* All of the balls have been pushed (or are blocked) so it is time to
* remove all of the gray bricks from the maze.
* All of the possible plays have been made. In this state we are
* removing all of the gray bricks that are in the maze by vanishing
* them away. Once that is done we transition to the state where we
* start dropping the final balls.
*/
REMOVE_GRAY_BRICKS,
/**
* All of the gray bricks have been removed, so we are now in the
* process of finding all balls that can still drop and dropping them.
* We remain in this state until all balls have been dropped, and then
* we either cycle back to the generation state for the next round or to
* the game over state.
*/
FINAL_BALL_DROP,
/**
* All gray bricks have been removed and all of the final ball drops
* have finished, so everything is done now.
* All of the gray bricks have been removed, all of the final ball drops
* have finished, and we have no more rounds to play; the game is just
* over now.
*/
GAME_OVER,
}
/**
......
This diff is collapsed.
module nurdz.game
{
/**
* When we are in the state that we're removing gray bricks from the maze,
* this is the delay (in ticks) for telling the next brick when it should
* start to vanish.
*/
const ROUND_BRICK_VANISH_TIME = 2;
/**
* This scene represents the game screen, where the game will actually be
* played.
......@@ -514,6 +521,12 @@ module nurdz.game
this.state = GameState.CHECK_VALID_PLAY_PLAYER;
break;
// If we were doing the final ball drop before, go back there
// now.
case GameState.FINAL_BALL_DROP:
this.state = GameState.FINAL_BALL_DROP;
break;
// If we get here, we don't know.
default:
console.log ("DEBUG: Do not know how to get to the next state from here");
......@@ -521,6 +534,18 @@ module nurdz.game
}
}
/**
* The Maze is telling us that it is now empty of gray bricks because it
* has just reaped the last fully hidden gray brick.
*
* This triggers the start of the final ball drop.
*/
grayBrickRemovalComplete () : void
{
// Swap states to the final ball drop
this.state = GameState.FINAL_BALL_DROP;
}
/**
* This gets triggered every time our state machine gets put into a new
* state.
......@@ -600,7 +625,7 @@ module nurdz.game
if (this._maze.contents.hasPlayableComputerBall ())
this.state = GameState.COMPUTER_TURN;
else
this.state = GameState.FINAL_BALL_DROP;
this.state = GameState.REMOVE_GRAY_BRICKS;
}
break;
......@@ -618,8 +643,28 @@ module nurdz.game
if (this._maze.contents.hasPlayableHumanBall ())
this.state = GameState.PLAYER_TURN;
else
this.state = GameState.FINAL_BALL_DROP;
this.state = GameState.REMOVE_GRAY_BRICKS;
}
break;
// When we are in the remove gray bricks state, use the state
// timer to remove a brick every so often.
case GameState.REMOVE_GRAY_BRICKS:
if (this._state.timerTrigger (ROUND_BRICK_VANISH_TIME))
this._maze.removeNextGrayBrick ();
break;
// We are dropping the final balls through the maze now. Select
// one and drop it; if there are none left to drop, set the
// state to the game over state.
//
// When a ball is successfully started dropping using this
// method the state is changed to the dropping ball state
// automatically.
case GameState.FINAL_BALL_DROP:
if (this._maze.dropNextFinalBall () == false)
this.state = GameState.GAME_OVER;
break;
}
}
}
......