stats in-game

This commit is contained in:
2025-03-28 21:00:46 +01:00
parent be071bd606
commit 0f026635f6
11 changed files with 164 additions and 39 deletions

View File

@@ -9,8 +9,8 @@
#include <memory>
static const int SUBPX_PER_ROW = 60; // the number of position the active piece can take "between" two rows
static const int SOFT_DROP_SCORE = 1; // the score gained by line soft dropped
static const int HARD_DROP_SCORE = 2; // the score gained by line hard dropped
static const int LOCK_DELAY_SCORE = 1; // the score gained when the piece locks due to lock delay
static const int HARD_DROP_SCORE = 10; // the score gained when the piece locks due to an hard drop
static const int LINE_CLEAR_BASE_SCORE = 100; // the score value of clearing a single line
static const int B2B_SCORE_MULTIPLIER = 2; // by how much havaing B2B on multiplies the score of the line clear
static const int B2B_MIN_LINE_NUMBER = 4; // the minimum number of lines needed to be cleared at once to gain B2B (without a spin)
@@ -140,16 +140,14 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
// SDR=0 -> instant drop
if (appliedSDR == 0) {
while (this->board.moveDown()) {
this->score += SOFT_DROP_SCORE;
}
while (this->board.moveDown());
}
// SDR>1 -> move down by specified amount
else {
this->subVerticalPosition += (SUBPX_PER_ROW / appliedSDR);
while (this->subVerticalPosition >= SUBPX_PER_ROW) {
this->board.moveDown();
this->subVerticalPosition -= SUBPX_PER_ROW;
this->score += (this->board.moveDown() * SOFT_DROP_SCORE);
}
}
}
@@ -157,11 +155,10 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
/* HARD DROP */
// needs to be done last because we can enter ARE period afterwards
if (this->initialActions.contains(HARD_DROP) || (playerActions.contains(HARD_DROP) && (!this->heldActions.contains(HARD_DROP)))) {
while (this->board.moveDown()) {
this->score += HARD_DROP_SCORE;
}
while (this->board.moveDown());
this->lockPiece();
pieceJustLocked = true;
this->score += HARD_DROP_SCORE;
}
// no need to apply gravity and lock delay if the piece was hard dropped
else {
@@ -192,6 +189,7 @@ void Game::nextFrame(const std::set<Action>& playerActions) {
if ((this->totalLockDelay > this->parameters.getLockDelay()) || (this->totalForcedLockDelay > this->parameters.getForcedLockDelay())) {
this->lockPiece();
pieceJustLocked = true;
this->score += LOCK_DELAY_SCORE;
}
}
@@ -290,7 +288,7 @@ void Game::rotatePiece(Rotation rotation) {
void Game::lockPiece() {
LineClear clear = this->board.lockPiece();
this->parameters.clearLines(clear.lines);
this->parameters.lockedPiece(clear);
bool B2BConditionsAreMet = ((clear.lines > B2B_MIN_LINE_NUMBER) || clear.isSpin || clear.isMiniSpin);
if (clear.lines > 0) {
@@ -330,6 +328,10 @@ int Game::getClearedLines() const {
return this->parameters.getClearedLines();
}
int Game::getGrade() const {
return this->parameters.getGrade();
}
int Game::getLevel() const {
return this->parameters.getLevel();
}

View File

@@ -101,6 +101,11 @@ class Game {
*/
int getClearedLines() const;
/**
* @return The current grade
*/
int getGrade() const;
/**
* @return The number of frames passed since the start of the game
*/

View File

@@ -13,6 +13,8 @@ GameParameters::GameParameters(Gamemode gamemode, const Player& controls) :
void GameParameters::reset() {
this->clearedLines = 0;
this->grade = 0;
switch (this->gamemode) {
// lowest gravity
case SPRINT : {this->level = 1; break;}
@@ -30,13 +32,13 @@ void GameParameters::reset() {
this->updateStats();
}
void GameParameters::clearLines(int lineNumber) {
void GameParameters::lockedPiece(const LineClear& lineClear) {
switch (this->gamemode) {
// modes where level increases
case MARATHON :
case MASTER : {
int previousLines = this->clearedLines;
this->clearedLines += lineNumber;
this->clearedLines += lineClear.lines;
// level increments every 10 lines, stats only changes on level up
if (previousLines / 10 < this->clearedLines / 10) {
@@ -46,7 +48,11 @@ void GameParameters::clearLines(int lineNumber) {
break;
}
// other modes
default : this->clearedLines += lineNumber;
default : this->clearedLines += lineClear.lines;
}
if (!((lineClear.lines == 0) && ((this->grade % 100) == 99))) {
this->grade += (1 + lineClear.lines);
}
}
@@ -210,6 +216,10 @@ int GameParameters::getLevel() const {
return this->level;
}
int GameParameters::getGrade() const {
return this->grade;
}
int GameParameters::getNextQueueLength() const {
return this->nextQueueLength;
}

View File

@@ -2,6 +2,7 @@
#include "Gamemode.h"
#include "Player.h"
#include "LineClear.h"
/**
@@ -14,6 +15,7 @@ class GameParameters {
Player controls; // the player's controls
int clearedLines; // the number of cleared lines
int level; // the current level
int grade; // the current amount of points
int nextQueueLength; // the number of pieces visibles in the next queue
bool boneBlocks; // wheter all blocks are bone blocks
int gravity; // the gravity at which pieces drop
@@ -39,7 +41,7 @@ class GameParameters {
/**
* Counts the newly cleared lines and update level and stats if needed
*/
void clearLines(int lineNumber);
void lockedPiece(const LineClear& lineClear);
/**
* Checks if the game ended based on the current states and time passed, accorind to the gamemode
@@ -63,6 +65,11 @@ class GameParameters {
* @return The current level
*/
int getLevel() const;
/**
* @return The current grade
*/
int getGrade() const;
/**
* @return The length of the next queue

View File

@@ -1,5 +1,7 @@
#pragma once
#include <string>
/**
* Every gamemode supported by the game
@@ -11,3 +13,34 @@ enum Gamemode {
MASTER,
ZEN
};
/**
* @return A string containing the name of the gamemode
*/
inline std::string getGamemodeName(Gamemode gamemode) {
static const std::string GAMEMODE_NAMES[] = {
"SPRINT",
"MARATHON",
"ULTRA",
"MASTER",
"ZEN"
};
return GAMEMODE_NAMES[gamemode];
}
/**
* @return A tiny string containing the goal of the gamemode
*/
inline std::string getGamemodeGoal(Gamemode gamemode) {
static const std::string GAMEMODE_DESCRIPTIONS[] = {
"40 lines",
"200 lines",
"2 minutes",
"200 lines",
"Chill"
};
return GAMEMODE_DESCRIPTIONS[gamemode];
}