diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 4 | ||||
-rw-r--r-- | src/piece.cpp | 8 | ||||
-rw-r--r-- | src/piece.h | 3 |
3 files changed, 12 insertions, 3 deletions
diff --git a/src/game.cpp b/src/game.cpp index 7d42f57..10231e7 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -7,7 +7,7 @@ GameState::GameState(Renderer* renderer, float scale_): timeCounterAdvance_ {1000}, timeLevelUp_ {20000}, renderer_ {renderer}, - piece_ {Piece::PieceType::LINE, 4}, + piece_ {4}, blockTexture_ {renderer_->renderer()} { renderer->setScale(scale_, scale_); @@ -140,7 +140,7 @@ void GameState::newPiece(){ // Clear the filled lines clearLines(); - piece_.restartTo( Piece::PieceType::LINE, 4); + piece_ = Piece( 4 ); piece_.initIterator(); while ( p = piece_.nextAbsBlockPos() ){ // Set the piece values as set diff --git a/src/piece.cpp b/src/piece.cpp index d686a32..05dab12 100644 --- a/src/piece.cpp +++ b/src/piece.cpp @@ -1,4 +1,12 @@ #include "piece.h" +#include<cstdlib> + +Piece::Piece(int xpos){ + + int divisor = static_cast<int>(Piece::PieceType::L); + auto type = static_cast<Piece::PieceType>(rand() % divisor); + restartTo(type, xpos); +} Piece::Piece(Piece::PieceType type, int xpos){ restartTo(type, xpos); diff --git a/src/piece.h b/src/piece.h index 1c3e820..01a9ac8 100644 --- a/src/piece.h +++ b/src/piece.h @@ -12,13 +12,14 @@ class Piece { public: enum class PieceType{ - LINE, + LINE = 0, BLOCK, S, T, L }; + Piece(int xpos); Piece(PieceType type, int xpos); Point getPosition(); |