diff --git a/includes/Playfield.hpp b/includes/Playfield.hpp index 820fd94..3b1013a 100644 --- a/includes/Playfield.hpp +++ b/includes/Playfield.hpp @@ -13,6 +13,7 @@ class Playfield : private boost::noncopyable { void draw(); void store_tetromino(Tetromino *tetromino); + bool is_gameover(); Matrix &matrix() { return matrix_; }; diff --git a/src/Playfield.cc b/src/Playfield.cc index 40fe186..cea097a 100644 --- a/src/Playfield.cc +++ b/src/Playfield.cc @@ -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--) { diff --git a/src/Tetris.cc b/src/Tetris.cc index f486bf0..06c33ba 100644 --- a/src/Tetris.cc +++ b/src/Tetris.cc @@ -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();