Skip to content

Commit

Permalink
Fix(Tetris): Check if the game is over.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeandudey committed Aug 7, 2015
1 parent e80ce33 commit cbcb86c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions includes/Playfield.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Playfield : private boost::noncopyable {
void draw();

void store_tetromino(Tetromino *tetromino);
bool is_gameover();

Matrix<int> &matrix() { return matrix_; };

Expand Down
7 changes: 7 additions & 0 deletions src/Playfield.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ void Playfield::store_tetromino(Tetromino *tetromino)
}
}

bool Playfield::is_gameover()
{
for (int x = 0; x < matrix_.width(); x++)
if (matrix_(x, 0) == 1)
return true;
}

void Playfield::delete_line(int line)
{
for (int y = line; y > 0; y--) {
Expand Down
3 changes: 3 additions & 0 deletions src/Tetris.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ void Tetris::update()
} else {
playfield_.store_tetromino(current_tetromino_.get());

if (playfield_.is_gameover())
running_ = false;

playfield_.update();

current_tetromino_ = TetrominoFactory::random_tetromino();
Expand Down

0 comments on commit cbcb86c

Please sign in to comment.