màj diagrammes

This commit is contained in:
2025-03-01 23:15:58 +01:00
parent f525c00662
commit 857f90d646
11 changed files with 27 additions and 24 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 161 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 52 KiB

View File

@@ -8,7 +8,7 @@
#include <cstdlib>
Bag::Bag(std::shared_ptr<PiecesList> piecesList) :
Bag::Bag(const std::shared_ptr<PiecesList>& piecesList) :
piecesList(piecesList) {
// initialize bags

View File

@@ -23,7 +23,7 @@ class Bag {
/**
* Creates a new bag with the pieces currently selected in the piece list
*/
Bag(std::shared_ptr<PiecesList> piecesList);
Bag(const std::shared_ptr<PiecesList>& piecesList);
/**
* Ignores the remaining pieces in the current bag and startd fresh from a new bag

View File

@@ -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<Position>& 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<Position>& 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<Piece>(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<Piece> 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<Position>& safePositions, const Position& shift) const {
bool GameBoard::activePieceOverlaps(const std::set<Position>& safePositions, const Position& shift) const {
for (Position position : this->activePiece->getPositions()) {
if (safePositions.contains(position + this->activePiecePosition + shift)) return true;
}

View File

@@ -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<Position>& safePositions, const Position& shift = Position{0, 0}) const;
bool activePieceOverlaps(const std::set<Position>& safePositions, const Position& shift = Position{0, 0}) const;
/**
* Sets the active piece to its spawn position

View File

@@ -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:
/**

View File

@@ -101,7 +101,7 @@ std::vector<std::pair<int, int>> PiecesList::getSelectedPieces() const {
return this->selectedPieces;
}
Piece PiecesList::getPiece(std::pair<int, int> pieceIndex) const {
Piece PiecesList::getPiece(const std::pair<int, int>& pieceIndex) const {
return this->loadedPieces.at(pieceIndex.first).at(pieceIndex.second);
}

View File

@@ -84,7 +84,7 @@ class PiecesList {
/**
* @return The piece corresponding to the specified index
*/
Piece getPiece(std::pair<int, int> pieceIndex) const;
Piece getPiece(const std::pair<int, int>& pieceIndex) const;
private:
/**

View File

@@ -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;
}

View File

@@ -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")