meilleurs coms ig

This commit is contained in:
2025-03-03 22:34:46 +01:00
parent d029589c21
commit 2fbe4a6052
13 changed files with 56 additions and 78 deletions

View File

@@ -11,23 +11,19 @@
Bag::Bag(const std::shared_ptr<PiecesList>& piecesList) :
piecesList(piecesList) {
// initialize bags
this->currentBag = this->piecesList->getSelectedPieces();
this->nextBag.clear();
// prepare first piece
this->prepareNext();
}
void Bag::jumpToNextBag() {
// if the bag is empty switch to the next bag
if (this->currentBag.empty()) {
if (this->currentBag.size() < this->nextBag.size()) {
std::swap(this->currentBag, this->nextBag);
}
// get the already used pieces back to the current bag
for (const std::pair<int, int>& pieceIndex : this->nextBag) {
this->currentBag.emplace_back(pieceIndex);
this->currentBag.push_back(pieceIndex);
}
this->nextBag.clear();
}
@@ -37,27 +33,21 @@ Piece Bag::lookNext() {
}
Piece Bag::getNext() {
// get the piece to return
std::pair<int, int> nextIndex = this->next;
// prepare the piece even after the next
this->prepareNext();
// return the next piece
return this->piecesList->getPiece(nextIndex);
}
void Bag::prepareNext() {
// if the bag is empty switch to the next bag
if (this->currentBag.empty()) {
std::swap(this->currentBag, this->nextBag);
}
// pick a random piece from the current bag
int indexIndex = std::rand() % this->currentBag.size();
this->next = this->currentBag.at(indexIndex);
// move the piece over to the next bag
this->nextBag.push_back(this->next);
this->currentBag.erase(this->currentBag.begin() + indexIndex);
}

View File

@@ -20,7 +20,6 @@ Board::Board(int width, int height) :
}
void Board::changeBlock(const Position& position, Block block) {
// if the block is out of bounds we discard it
if (position.x < 0 || position.x >= this->width || position.y < 0) return;
// resize the grid if needed
@@ -62,7 +61,7 @@ int Board::clearRows() {
if (lineIsFull) {
this->grid.erase(this->grid.begin() + j);
if(this->grid.size() < height) {
if(this->grid.size() < this->height) {
this->grid.push_back(this->emptyRow);
}
clearedLines++;
@@ -74,7 +73,7 @@ int Board::clearRows() {
void Board::clearBoard() {
this->grid.clear();
for (int j = 0; j < height; j++) {
for (int j = 0; j < this->height; j++) {
this->grid.push_back(this->emptyRow);
}
}

View File

@@ -230,17 +230,14 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
return;
}
}
// update remembered actions for next frame
this->heldActions = playerActions;
if ((!this->started) || this->leftARETime > 0) {
for (Action action : playerActions) {
this->initialActions.insert(action);
}
}
this->heldActions = playerActions;
if (this->leftARETime > 0) {
if (playerActions.contains(MOVE_LEFT)) {
this->heldDAS = std::min(-1, this->heldDAS - 1);
}

View File

@@ -8,6 +8,7 @@
#include <vector>
#include <set>
#include <memory>
#include <utility>
#include <cstdlib>
@@ -150,7 +151,6 @@ 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->activePieceOverlaps(safePositions, shift)) {
@@ -220,7 +220,6 @@ bool GameBoard::hold(Rotation initialRotation) {
this->heldPiece->defaultRotation();
// this piece has done nothing yet
this->isLastMoveKick = false;
return true;
@@ -232,8 +231,6 @@ bool GameBoard::spawnNextPiece() {
this->nextQueue.erase(this->nextQueue.begin());
this->goToSpawnPosition();
// this piece has done nothing yet
this->isLastMoveKick = false;
return this->activePieceInWall();

View File

@@ -12,7 +12,6 @@ GameParameters::GameParameters(Gamemode gamemode, const Player& controls) :
}
void GameParameters::reset() {
// initialize lines and level
this->clearedLines = 0;
switch (this->gamemode) {
// lowest gravity
@@ -26,17 +25,14 @@ void GameParameters::reset() {
default : this->level = 1;
}
// initialize stats
this->updateStats();
}
void GameParameters::clearLines(int lineNumber) {
// update lines and level
switch (this->gamemode) {
// modes where level increases
case MARATHON :
case MASTER : {
// update cleared lines
int previousLines = this->clearedLines;
this->clearedLines += lineNumber;

View File

@@ -10,9 +10,8 @@
Menu::Menu() {
this->piecesList = std::make_shared<PiecesList>(PiecesList());
// default board size
this->boardHeight = 20;
this->boardWidth = 10;
this->boardWidth = DEFAULT_BOARD_WIDTH;
this->boardHeight = DEFAULT_BOARD_HEIGHT;
}
Game Menu::startGame(Gamemode gamemode) const {

View File

@@ -4,7 +4,9 @@
#include "Player.h"
#include "Game.h"
static const int FRAMES_PER_SECOND = 60; // the number of frames per second, all the values in the game were choosen with this number in mind
static const int FRAMES_PER_SECOND = 60; // the number of frames per second, all the values in the game were choosen with this number in mind
static const int DEFAULT_BOARD_WIDTH = 10; // the default width of the board when starting the menu
static const int DEFAULT_BOARD_HEIGHT = 20; // the default height of the board when starting the menu
/**

View File

@@ -1,12 +1,5 @@
#include "Player.h"
static const int DAS_MIN_VALUE = 0; // 0ms
static const int DAS_MAX_VALUE = 30; // 500ms
static const int ARR_MIN_VALUE = 0; // 0ms
static const int ARR_MAX_VALUE = 30; // 500ms
static const int SDR_MIN_VALUE = 0; // 0ms
static const int SDR_MAX_VALUE = 6; // 100ms
Player::Player() {
// default settings

View File

@@ -1,5 +1,12 @@
#pragma once
static const int DAS_MIN_VALUE = 0; // the minimal selectable DAS value, equals to 0ms
static const int DAS_MAX_VALUE = 30; // the maximal selectable DAS value, equals to 500ms
static const int ARR_MIN_VALUE = 0; // the minimal selectable ARR value, equals to 0ms
static const int ARR_MAX_VALUE = 30; // the maximal selectable ARR value, equals to 500ms
static const int SDR_MIN_VALUE = 0; // the minimal selectable SDR value, equals to 0ms
static const int SDR_MAX_VALUE = 6; // the maximal selectable SDR value, equals to 100ms
/**
* The controls of a player