initial commit

This commit is contained in:
2025-02-25 12:07:16 +01:00
commit 0657bc9b25
34 changed files with 3069 additions and 0 deletions

124
src/Core/Game.h Normal file
View File

@@ -0,0 +1,124 @@
#pragma once
#include "GameBoard.h"
#include "GameParameters.h"
#include "Action.h"
#include <Vector>
/**
* Interprets the player action into the game, depending on the state of the board and the current gamemode
*/
class Game {
private:
GameParameters parameters; // the current parameters of the game
GameBoard board; // the board in which the game is played
bool started; // wheter the game has started
bool lost; // wheter the game is lost
long int score; // the current score
int framesPassed; // how many frames have passed since the start of the game
bool B2BChain; // wheter the player is currently on a B2B chain
std::set<Action> heldActions; // the list of actions that were pressed last frame
std::set<Action> initialActions; // the list of actions that have been pressed while there was no active piece
int heldDAS; // the number of frames DAS has been held, positive for right or negative for left
int heldARR; // the number of frames ARR has been held
int subVerticalPosition; // how far the active piece is to go down one line
int leftARETime; // how many frames are left before ARE period finishes
int totalLockDelay; // how many frames has the active piece touched the ground without moving
int totalForcedLockDelay; // how many frames the active piece has touched the ground since the last spawned piece
public:
/**
* Initialize the parameters and creates a new board
*/
Game(Gamemode gamemode, const Player& controls, int boardWidth, int boardHeight, const std::vector<Piece>& bag);
/**
* Starts the game
*/
void start();
/**
* Advance to the next frame while excecuting the actions taken by the player,
* this is where the main game logic takes place
*/
void nextFrame(const std::set<Action>& playerActions);
private:
/**
* Move the piece in the specified direction
*/
void movePiece(int movement, bool resetDirection);
/**
* Locks the piece, updates level and score and spawn the next piece if necessary
*/
void lockPiece();
public:
/**
* Returns wheter the player has won
*/
bool hasWon();
/**
* Returns wheter the player has lost
*/
bool hasLost();
/**
* Returns the current level
*/
int getLevel();
/**
* Returns the current number of cleared lines
*/
int getClearedLines();
/**
* Returns the number of frames passed since the start of the game
*/
int getFramesPassed();
/**
* Returns the current score
*/
int getScore();
/**
* Returns wheter the player is currently on a B2B chain
*/
bool isOnB2BChain();
/**
* Returns wheter all blocks are currently bone blocks
*/
bool areBlocksBones();
/**
* Returns a copy of the board
*/
Board getBoard();
/**
* Returns a copy of the active piece
*/
Piece getActivePiece();
/**
* Returns a copy of the active piece position
*/
Cell getActivePiecePosition();
/**
* Returns a copy of the held piece
*/
Piece getHeldPiece();
/**
* Return a copy of the next pieces queue
*/
std::vector<Piece> getNextPieces();
};