Commit 364531a8 authored by Terence Martin's avatar Terence Martin

Switch to removing gray bricks when no moves left

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.
parent c0cd298d
......@@ -4213,6 +4213,32 @@ var nurdz;
}
}
};
/**
* Scan through the maze (left to right, bottom to top) looking for the
* first gray brick entity that has not already been told to vanish
* and tell it to.
*
* If there are no such bricks, this does nothing. This is currently
* rather brute force; it might be better to sort the live entity list
* somehow or do a random selection, but that gets tricky when we have
* run out the list of bricks.
*/
Maze.prototype.removeNextGrayBrick = function () {
for (var row = game.MAZE_HEIGHT - 2; row >= 0; row--) {
for (var col = 1; col < game.MAZE_WIDTH - 1; col++) {
// Get the cell as a brick (it may not be).
var cell = this._contents.getCellAt(col, row);
// If it is a gray brick that is not already hidden, call
// the vanish method.
if (cell != null && cell.name == "brick" &&
cell.brickType == game.BrickType.BRICK_GRAY &&
cell.isHidden == false) {
cell.vanish();
return;
}
}
}
};
/**
* This is called every frame update (tick tells us how many times this
* has happened) to allow us to update ourselves.
......@@ -4251,6 +4277,7 @@ var nurdz;
// indicates that we're done removing them now.
if (this.reapHiddenEntitiesFromPool(this._grayBricks) > 0 &&
this._grayBricks.liveEntities.length == 0) {
console.log("DEBUG: All gray bricks have fully vanished");
}
// If there is a dropping ball and it's time to drop it, take a step
// now.
......@@ -4487,6 +4514,12 @@ var nurdz;
(function (nurdz) {
var game;
(function (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.
*/
var ROUND_BRICK_VANISH_TIME = 2;
/**
* This scene represents the game screen, where the game will actually be
* played.
......@@ -4974,7 +5007,7 @@ var nurdz;
if (this._maze.contents.hasPlayableComputerBall())
this.state = game.GameState.COMPUTER_TURN;
else
this.state = game.GameState.FINAL_BALL_DROP;
this.state = game.GameState.REMOVE_GRAY_BRICKS;
}
break;
// It is becoming the computer's turn; check to see if there is
......@@ -4990,8 +5023,15 @@ var nurdz;
if (this._maze.contents.hasPlayableHumanBall())
this.state = game.GameState.PLAYER_TURN;
else
this.state = game.GameState.FINAL_BALL_DROP;
this.state = game.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 game.GameState.REMOVE_GRAY_BRICKS:
if (this._state.timerTrigger(ROUND_BRICK_VANISH_TIME))
this._maze.removeNextGrayBrick();
break;
}
};
return GameScene;
......
......@@ -768,6 +768,38 @@ module nurdz.game
}
}
/**
* Scan through the maze (left to right, bottom to top) looking for the
* first gray brick entity that has not already been told to vanish
* and tell it to.
*
* If there are no such bricks, this does nothing. This is currently
* rather brute force; it might be better to sort the live entity list
* somehow or do a random selection, but that gets tricky when we have
* run out the list of bricks.
*/
removeNextGrayBrick () : void
{
for (let row = MAZE_HEIGHT - 2 ; row >= 0 ; row--)
{
for (let col = 1 ; col < MAZE_WIDTH - 1 ; col++)
{
// Get the cell as a brick (it may not be).
let cell = <Brick> this._contents.getCellAt (col, row);
// If it is a gray brick that is not already hidden, call
// the vanish method.
if (cell != null && cell.name == "brick" &&
cell.brickType == BrickType.BRICK_GRAY &&
cell.isHidden == false)
{
cell.vanish ();
return;
}
}
}
}
/**
* This is called every frame update (tick tells us how many times this
* has happened) to allow us to update ourselves.
......@@ -812,8 +844,7 @@ module nurdz.game
if (this.reapHiddenEntitiesFromPool (this._grayBricks) > 0 &&
this._grayBricks.liveEntities.length == 0)
{
// TODO: This should set a state
// this._grayBricksRemoved = true;
console.log("DEBUG: All gray bricks have fully vanished");
}
// If there is a dropping ball and it's time to drop it, take a step
......
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.
......@@ -600,7 +607,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 +625,16 @@ 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;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment