diff --git a/doc/class_diagramm_core.png b/doc/class_diagramm_core.png index 1e9e8e7..89b7726 100644 Binary files a/doc/class_diagramm_core.png and b/doc/class_diagramm_core.png differ diff --git a/doc/class_diagramm_pieces.png b/doc/class_diagramm_pieces.png index a965a8c..a4ccf14 100644 Binary files a/doc/class_diagramm_pieces.png and b/doc/class_diagramm_pieces.png differ diff --git a/src/Core/Bag.cpp b/src/Core/Bag.cpp index 5c8d92e..f7edb6e 100644 --- a/src/Core/Bag.cpp +++ b/src/Core/Bag.cpp @@ -8,7 +8,7 @@ #include -Bag::Bag(std::shared_ptr piecesList) : +Bag::Bag(const std::shared_ptr& piecesList) : piecesList(piecesList) { // initialize bags diff --git a/src/Core/Bag.h b/src/Core/Bag.h index d780bbc..9a6b76f 100644 --- a/src/Core/Bag.h +++ b/src/Core/Bag.h @@ -23,7 +23,7 @@ class Bag { /** * Creates a new bag with the pieces currently selected in the piece list */ - Bag(std::shared_ptr piecesList); + Bag(const std::shared_ptr& piecesList); /** * Ignores the remaining pieces in the current bag and startd fresh from a new bag diff --git a/src/Core/GameBoard.cpp b/src/Core/GameBoard.cpp index 37af858..e32a5b2 100644 --- a/src/Core/GameBoard.cpp +++ b/src/Core/GameBoard.cpp @@ -38,7 +38,7 @@ void GameBoard::initialize() { } bool GameBoard::moveLeft() { - if (this->isActivePieceInWall(Position{-1, 0})) { + if (this->activePieceInWall(Position{-1, 0})) { return false; } else { @@ -49,7 +49,7 @@ bool GameBoard::moveLeft() { } bool GameBoard::moveRight() { - if (this->isActivePieceInWall(Position{1, 0})) { + if (this->activePieceInWall(Position{1, 0})) { return false; } else { @@ -60,7 +60,7 @@ bool GameBoard::moveRight() { } bool GameBoard::moveDown() { - if (this->isActivePieceInWall(Position{0, -1})) { + if (this->activePieceInWall(Position{0, -1})) { return false; } else { @@ -75,7 +75,7 @@ bool GameBoard::rotate(Rotation rotation) { this->rotate(rotation); // before trying to kick, check if the piece can rotate without kicking - if (!this->isActivePieceInWall()) { + if (!this->activePieceInWall()) { this->isLastMoveKick = false; return true; } @@ -123,11 +123,11 @@ bool GameBoard::tryKicking(bool testingBottom, const std::set& safePos // check right before right arbitrarly, we don't decide this with rotations since it would still be arbitrary with 180° rotations if (overlapsRight) { Position shift{+i, j}; - if (!this->activePieceOverlapsOnePosition(safePositions, shift)) { + if (!this->activePieceOverlaps(safePositions, shift)) { overlapsLeft = false; } else { - if (!this->isActivePieceInWall(shift)) { + if (!this->activePieceInWall(shift)) { this->activePiecePosition += shift; return true; } @@ -137,11 +137,11 @@ bool GameBoard::tryKicking(bool testingBottom, const std::set& safePos // do the same on the left side if (overlapsLeft) { Position shift{-i, j}; - if (!this->activePieceOverlapsOnePosition(safePositions, shift)) { + if (!this->activePieceOverlaps(safePositions, shift)) { overlapsLeft = false; } else { - if (!this->isActivePieceInWall(shift)) { + if (!this->activePieceInWall(shift)) { this->activePiecePosition += shift; return true; } @@ -181,11 +181,11 @@ bool GameBoard::hold(Rotation initialRotation) { this->rotate(initialRotation); // if the piece can't spawn, abort initial rotation - if (this->isActivePieceInWall()) { + if (this->activePieceInWall()) { this->activePiece = std::make_shared(stored); // if the piece still can't spawn, abort holding - if (this->isActivePieceInWall()) { + if (this->activePieceInWall()) { if (isFirstTimeHolding) { this->activePiece = nullptr; } @@ -219,16 +219,16 @@ bool GameBoard::spawnNextPiece() { // this piece has done nothing yet this->isLastMoveKick = false; - return !this->isActivePieceInWall(); + return !this->activePieceInWall(); } bool GameBoard::touchesGround() { - return this->isActivePieceInWall(Position{0, -1}); + return this->activePieceInWall(Position{0, -1}); } LineClear GameBoard::lockPiece() { - bool isLockedInPlace = (this->isActivePieceInWall(Position{0, 1}) && this->isActivePieceInWall(Position{1, 0}) - && this->isActivePieceInWall(Position{-1, 0}) && this->isActivePieceInWall(Position{0, -1})); + bool isLockedInPlace = (this->activePieceInWall(Position{0, 1}) && this->activePieceInWall(Position{1, 0}) + && this->activePieceInWall(Position{-1, 0}) && this->activePieceInWall(Position{0, -1})); for (Position position : this->activePiece->getPositions()) { this->board.changeBlock(position + this->activePiecePosition, this->activePiece->getBlockType()); @@ -268,14 +268,14 @@ std::vector GameBoard::getNextPieces() const { return this->nextQueue; } -bool GameBoard::isActivePieceInWall(const Position& shift) const { +bool GameBoard::activePieceInWall(const Position& shift) const { for (Position position : this->activePiece->getPositions()) { if (this->board.getBlock(position + this->activePiecePosition + shift) != NOTHING) return true; } return false; } -bool GameBoard::activePieceOverlapsOnePosition(const std::set& safePositions, const Position& shift) const { +bool GameBoard::activePieceOverlaps(const std::set& safePositions, const Position& shift) const { for (Position position : this->activePiece->getPositions()) { if (safePositions.contains(position + this->activePiecePosition + shift)) return true; } diff --git a/src/Core/GameBoard.h b/src/Core/GameBoard.h index 7ce5fd8..68e8137 100644 --- a/src/Core/GameBoard.h +++ b/src/Core/GameBoard.h @@ -132,13 +132,13 @@ class GameBoard { * Checks if one of the active piece's positions touches a wall in the board * @return If the active piece is in a wall */ - bool isActivePieceInWall(const Position& shift = Position{0, 0}) const; + bool activePieceInWall(const Position& shift = Position{0, 0}) const; /** * Check if one of the active piece's positions shifted by a specified position would overlap with a set of positions * @return If the shifted active piece overlaps with one of the position */ - bool activePieceOverlapsOnePosition(const std::set& safePositions, const Position& shift = Position{0, 0}) const; + bool activePieceOverlaps(const std::set& safePositions, const Position& shift = Position{0, 0}) const; /** * Sets the active piece to its spawn position diff --git a/src/Core/Menu.h b/src/Core/Menu.h index 41331bc..5268a7e 100644 --- a/src/Core/Menu.h +++ b/src/Core/Menu.h @@ -14,8 +14,8 @@ class Menu { private: PiecesList piecesList; // the list of pieces in the game Player playerControls; // the controls of the player - int boardHeight; // the height of the board for the next game int boardWidth; // the width of the board for the next game + int boardHeight; // the height of the board for the next game public: /** diff --git a/src/Core/PiecesList.cpp b/src/Core/PiecesList.cpp index 4e639d3..58474df 100644 --- a/src/Core/PiecesList.cpp +++ b/src/Core/PiecesList.cpp @@ -101,7 +101,7 @@ std::vector> PiecesList::getSelectedPieces() const { return this->selectedPieces; } -Piece PiecesList::getPiece(std::pair pieceIndex) const { +Piece PiecesList::getPiece(const std::pair& pieceIndex) const { return this->loadedPieces.at(pieceIndex.first).at(pieceIndex.second); } diff --git a/src/Core/PiecesList.h b/src/Core/PiecesList.h index bd524e8..5f26216 100644 --- a/src/Core/PiecesList.h +++ b/src/Core/PiecesList.h @@ -84,7 +84,7 @@ class PiecesList { /** * @return The piece corresponding to the specified index */ - Piece getPiece(std::pair pieceIndex) const; + Piece getPiece(const std::pair& pieceIndex) const; private: /** diff --git a/src/Core/main.cpp b/src/TextUI/main.cpp similarity index 99% rename from src/Core/main.cpp rename to src/TextUI/main.cpp index cf36506..ba933d2 100644 --- a/src/Core/main.cpp +++ b/src/TextUI/main.cpp @@ -1,4 +1,4 @@ -#include "Menu.h" +#include "../Core/Menu.h" #include "../Pieces/Generator.h" #include "../Pieces/PiecesFiles.h" @@ -24,6 +24,8 @@ int main(int argc, char** argv) { Game game = menu.startGame(SPRINT); game.start(); + loadFromFilesForOneSize(13); + return 0; } diff --git a/xmake.lua b/xmake.lua index d858933..0f205d8 100644 --- a/xmake.lua +++ b/xmake.lua @@ -5,6 +5,7 @@ target("main") set_rundir(".") add_files("./src/Pieces/*.cpp") add_files("./src/Core/*.cpp") + add_files("./src/TextUI/*.cpp") set_optimize("fastest")