mis en place la PR de simon sur les couleurs

This commit is contained in:
2025-02-28 18:42:04 +01:00
parent f0f391ade6
commit 26f501f7e8
29 changed files with 713 additions and 665 deletions

View File

@@ -5,7 +5,7 @@
#include "Bag.h"
#include "LineClear.h"
#include <Vector>
#include <vector>
#include <memory>
@@ -14,15 +14,15 @@
*/
class GameBoard {
private:
Board board; // the board in which pieces moves, (0, 0) is downleft
Bag generator; // the piece generator
Board board; // the board in which pieces moves, (0, 0) is downleft
Bag generator; // the piece generator
std::shared_ptr<Piece> activePiece; // the piece currently in the board
Cell activePiecePosition; // the position of the piece currently in the board
std::shared_ptr<Piece> heldPiece; // a piece being holded
int nextQueueLength; // the number of next pieces seeable at a time
std::vector<Piece> nextQueue; // the list of the next pieces to spawn in the board
bool isLastMoveKick; // wheter the last action the piece did was kicking
Position activePiecePosition; // the position of the piece currently in the board
std::shared_ptr<Piece> heldPiece; // a piece being holded
int nextQueueLength; // the number of next pieces seeable at a time
std::vector<Piece> nextQueue; // the list of the next pieces to spawn in the board
bool isLastMoveKick; // wheter the last action the piece did was kicking
public:
/**
* Creates a new board, generator, and next queue
@@ -30,88 +30,98 @@ class GameBoard {
GameBoard(int boardWidth, int boardHeight, const std::vector<Piece>& bag, int nextQueueLength);
/**
* Try moving the piece one cell to the left, and returns wheter it was sucessfull
* Tries moving the piece one position to the left
* @return If it suceeded
*/
bool moveLeft();
/**
* Try moving the piece one cell to the right, and returns wheter it was sucessfull
* Tries moving the piece one position to the right
* @return If it suceeded
*/
bool moveRight();
/**
* Try moving the piece one cell down, and returns wheter it was sucessfull
* Tries moving the piece one position down
* @return If it suceeded
*/
bool moveDown();
/**
* Try rotating the piece and kicking it if necessary, and returns wheter it was sucessfull
* Tries rotating the piece and kicking it if necessary
* @return If it suceeded
*/
bool rotate(Rotation rotation);
private:
/**
* Try kicking the piece, testing position either above or below the piece's initial position
* Tries kicking the piece, testing position either above or below the piece's initial position
* @return If it suceeded
*/
bool tryKicking(bool testingBottom, const std::set<Cell>& safeCells);
bool tryKicking(bool testingBottom, const std::set<Position>& safePositions);
public:
/**
* Try holding the active piece or swapping it if one was already stocked, while trying to apply an initial rotation to the newly spawned piece,
* and returns wheter it was sucessfull
* Tries holding the active piece or swapping it if one was already stocked, while trying to apply an initial rotation to the newly spawned piece
* @return If it suceeded
*/
bool hold(Rotation initialRotation = NONE);
/**
* Spawns the next piece from the queue, and returns wheter it spawns in a wall
* Spawns the next piece from the queue
* @return If it spawned in a wall
*/
bool spawnNextPiece();
/**
* Returns wheter the active piece is touching walls directly below it
* Checks is the active piece as a wall directly below one of its position
* @return If it touches a ground
*/
bool touchesGround();
/**
* Lock the active piece into the board and returns the resulting line clear
* Locks the active piece into the board and clears lines if needed
* @return The resulting line clear
*/
LineClear lockPiece();
/**
* Returns a copy of the board
* @return A copy of the board
*/
Board getBoard() const;
/**
* Returns a copy of the active piece
* @return A copy of the active piece
*/
Piece getActivePiece() const;
/**
* Returns a copy of the position of the active piece
* @return A copy of the position of the active piece
*/
Cell getActivePiecePosition() const;
Position getActivePiecePosition() const;
/**
* Returns a copy of the held piece
* @return A copy of the held piece
*/
Piece getHeldPiece() const;
/**
* Returns a copy of the next piece queue
* @return A copy of the next piece queue
*/
std::vector<Piece> getNextPieces() const;
private:
/**
* Returns wheter the translated active piece is in a wall
* 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 Cell& shift = Cell{0, 0}) const;
bool isActivePieceInWall(const Position& shift = Position{0, 0}) const;
/**
* Returns wheter the translated active piece overlaps with at least one of the cells
* 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 activePieceOverlapsOneCell(const std::set<Cell>& safeCells, const Cell& shift = Cell{0, 0}) const;
bool activePieceOverlapsOnePosition(const std::set<Position>& safePositions, const Position& shift = Position{0, 0}) const;
/**
* Sets the active piece to its spawn position
@@ -121,6 +131,7 @@ class GameBoard {
public:
/**
* Stream output operator, adds the board, the hold box and the next queue
* @return A reference to the output stream
*/
friend std::ostream& operator<<(std::ostream& os, const GameBoard& gameboard);
};