const everywhere + légèrement changer format fichiers
This commit is contained in:
@@ -259,54 +259,54 @@ void Game::lockPiece() {
|
||||
}
|
||||
}
|
||||
|
||||
bool Game::hasWon() {
|
||||
bool Game::hasWon() const {
|
||||
return this->parameters.hasWon(this->framesPassed);
|
||||
}
|
||||
|
||||
bool Game::hasLost() {
|
||||
bool Game::hasLost() const {
|
||||
return this->lost;
|
||||
}
|
||||
|
||||
int Game::getClearedLines() {
|
||||
int Game::getClearedLines() const {
|
||||
return this->parameters.getClearedLines();
|
||||
}
|
||||
|
||||
int Game::getLevel() {
|
||||
int Game::getLevel() const {
|
||||
return this->parameters.getLevel();
|
||||
}
|
||||
|
||||
int Game::getFramesPassed() {
|
||||
int Game::getFramesPassed() const {
|
||||
return this->framesPassed;
|
||||
}
|
||||
|
||||
int Game::getScore() {
|
||||
int Game::getScore() const {
|
||||
return this->score;
|
||||
}
|
||||
|
||||
bool Game::isOnB2BChain() {
|
||||
bool Game::isOnB2BChain() const {
|
||||
return this->B2BChain;
|
||||
}
|
||||
|
||||
bool Game::areBlocksBones() {
|
||||
bool Game::areBlocksBones() const {
|
||||
return this->parameters.getBoneBlocks();
|
||||
}
|
||||
|
||||
Board Game::getBoard() {
|
||||
Board Game::getBoard() const {
|
||||
return this->board.getBoard();
|
||||
}
|
||||
|
||||
Piece Game::getActivePiece() {
|
||||
Piece Game::getActivePiece() const {
|
||||
return this->board.getActivePiece();
|
||||
}
|
||||
|
||||
Position Game::getActivePiecePosition() {
|
||||
Position Game::getActivePiecePosition() const {
|
||||
return this->board.getActivePiecePosition();
|
||||
}
|
||||
|
||||
Piece Game::getHeldPiece() {
|
||||
Piece Game::getHeldPiece() const {
|
||||
return this->board.getHeldPiece();
|
||||
}
|
||||
|
||||
std::vector<Piece> Game::getNextPieces() {
|
||||
std::vector<Piece> Game::getNextPieces() const {
|
||||
return this->board.getNextPieces();
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class Game {
|
||||
|
||||
private:
|
||||
/**
|
||||
* Movse the piece in the specified direction
|
||||
* Move the piece in the specified direction
|
||||
*/
|
||||
void movePiece(int movement, bool resetDirection);
|
||||
|
||||
@@ -74,65 +74,65 @@ class Game {
|
||||
/**
|
||||
* @return If the player has won
|
||||
*/
|
||||
bool hasWon();
|
||||
bool hasWon() const;
|
||||
|
||||
/**
|
||||
* @return If the player has lost
|
||||
*/
|
||||
bool hasLost();
|
||||
bool hasLost() const;
|
||||
|
||||
/**
|
||||
* @return The current level
|
||||
*/
|
||||
int getLevel();
|
||||
int getLevel() const;
|
||||
|
||||
/**
|
||||
* @return The current number of cleared lines
|
||||
*/
|
||||
int getClearedLines();
|
||||
int getClearedLines() const;
|
||||
|
||||
/**
|
||||
* @return The number of frames passed since the start of the game
|
||||
*/
|
||||
int getFramesPassed();
|
||||
int getFramesPassed() const;
|
||||
|
||||
/**
|
||||
* @return The current score
|
||||
*/
|
||||
int getScore();
|
||||
int getScore() const;
|
||||
|
||||
/**
|
||||
* @return If the player is currently on a B2B chain
|
||||
*/
|
||||
bool isOnB2BChain();
|
||||
bool isOnB2BChain() const;
|
||||
|
||||
/**
|
||||
* @return If all blocks are currently bone blocks
|
||||
*/
|
||||
bool areBlocksBones();
|
||||
bool areBlocksBones() const;
|
||||
|
||||
/**
|
||||
* @return A copy of the board
|
||||
*/
|
||||
Board getBoard();
|
||||
Board getBoard() const;
|
||||
|
||||
/**
|
||||
* @return A copy of the active piece
|
||||
*/
|
||||
Piece getActivePiece();
|
||||
Piece getActivePiece() const;
|
||||
|
||||
/**
|
||||
* @return A copy of the active piece position
|
||||
*/
|
||||
Position getActivePiecePosition();
|
||||
Position getActivePiecePosition() const;
|
||||
|
||||
/**
|
||||
* @return A copy of the held piece
|
||||
*/
|
||||
Piece getHeldPiece();
|
||||
Piece getHeldPiece() const;
|
||||
|
||||
/**
|
||||
* @return A copy of the next pieces queue
|
||||
*/
|
||||
std::vector<Piece> getNextPieces();
|
||||
std::vector<Piece> getNextPieces() const;
|
||||
};
|
||||
|
||||
@@ -52,7 +52,7 @@ void GameParameters::clearLines(int lineNumber) {
|
||||
}
|
||||
}
|
||||
|
||||
bool GameParameters::hasWon(int framesPassed) {
|
||||
bool GameParameters::hasWon(int framesPassed) const {
|
||||
switch (this->gamemode) {
|
||||
// win once 40 lines have been cleared
|
||||
case SPRINT : return this->clearedLines >= 40;
|
||||
@@ -198,50 +198,50 @@ void GameParameters::updateStats() {
|
||||
}
|
||||
}
|
||||
|
||||
int GameParameters::getClearedLines() {
|
||||
int GameParameters::getClearedLines() const {
|
||||
return this->clearedLines;
|
||||
}
|
||||
|
||||
int GameParameters::getLevel() {
|
||||
int GameParameters::getLevel() const {
|
||||
return this->level;
|
||||
}
|
||||
|
||||
int GameParameters::getNextQueueLength() {
|
||||
int GameParameters::getNextQueueLength() const {
|
||||
return this->nextQueueLength;
|
||||
}
|
||||
|
||||
bool GameParameters::getBoneBlocks() {
|
||||
bool GameParameters::getBoneBlocks() const {
|
||||
return this->boneBlocks;
|
||||
}
|
||||
|
||||
int GameParameters::getGravity() {
|
||||
int GameParameters::getGravity() const {
|
||||
return this->gravity;
|
||||
}
|
||||
|
||||
int GameParameters::getLockDelay() {
|
||||
int GameParameters::getLockDelay() const {
|
||||
return this->lockDelay;
|
||||
}
|
||||
|
||||
int GameParameters::getForcedLockDelay() {
|
||||
int GameParameters::getForcedLockDelay() const {
|
||||
return this->forcedLockDelay;
|
||||
}
|
||||
|
||||
int GameParameters::getARE() {
|
||||
int GameParameters::getARE() const {
|
||||
return this->ARE;
|
||||
}
|
||||
|
||||
int GameParameters::getLineARE() {
|
||||
int GameParameters::getLineARE() const {
|
||||
return this->lineARE;
|
||||
}
|
||||
|
||||
int GameParameters::getDAS() {
|
||||
int GameParameters::getDAS() const {
|
||||
return this->DAS;
|
||||
}
|
||||
|
||||
int GameParameters::getARR() {
|
||||
int GameParameters::getARR() const {
|
||||
return this->ARR;
|
||||
}
|
||||
|
||||
int GameParameters::getSDR() {
|
||||
int GameParameters::getSDR() const {
|
||||
return this->SDR;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class GameParameters {
|
||||
* Checks if the game ended based on the current states and time passed, accorind to the gamemode
|
||||
* @return If the player has won
|
||||
*/
|
||||
bool hasWon(int framesPassed);
|
||||
bool hasWon(int framesPassed) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
@@ -57,60 +57,60 @@ class GameParameters {
|
||||
/**
|
||||
* @return The current number of cleared line
|
||||
*/
|
||||
int getClearedLines();
|
||||
int getClearedLines() const;
|
||||
|
||||
/**
|
||||
* @return The current level
|
||||
*/
|
||||
int getLevel();
|
||||
int getLevel() const;
|
||||
|
||||
/**
|
||||
* @return The length of the next queue
|
||||
*/
|
||||
int getNextQueueLength();
|
||||
int getNextQueueLength() const;
|
||||
|
||||
/**
|
||||
* Returns wheter the blocks are currently bone blocks
|
||||
*/
|
||||
bool getBoneBlocks();
|
||||
bool getBoneBlocks() const;
|
||||
|
||||
/**
|
||||
* @return The current gravity for a 20-line high board
|
||||
*/
|
||||
int getGravity();
|
||||
int getGravity() const;
|
||||
|
||||
/**
|
||||
* @return The current lock delay
|
||||
*/
|
||||
int getLockDelay();
|
||||
int getLockDelay() const;
|
||||
|
||||
/**
|
||||
* @return The current forced lock delay
|
||||
*/
|
||||
int getForcedLockDelay();
|
||||
int getForcedLockDelay() const;
|
||||
|
||||
/**
|
||||
* @return The current ARE
|
||||
*/
|
||||
int getARE();
|
||||
int getARE() const;
|
||||
|
||||
/**
|
||||
* @return The current line ARE
|
||||
*/
|
||||
int getLineARE();
|
||||
int getLineARE() const;
|
||||
|
||||
/**
|
||||
* @return The current DAS
|
||||
*/
|
||||
int getDAS();
|
||||
int getDAS() const;
|
||||
|
||||
/**
|
||||
* @return The current ARR
|
||||
*/
|
||||
int getARR();
|
||||
int getARR() const;
|
||||
|
||||
/**
|
||||
* @return The current SDR
|
||||
*/
|
||||
int getSDR();
|
||||
int getSDR() const;
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ Menu::Menu() {
|
||||
this->boardWidth = 10;
|
||||
}
|
||||
|
||||
Game Menu::startGame(Gamemode gamemode) {
|
||||
Game Menu::startGame(Gamemode gamemode) const {
|
||||
return Game(gamemode, this->playerControls, this->boardWidth, this->boardHeight, std::make_shared<PiecesList>(this->piecesList));
|
||||
}
|
||||
|
||||
@@ -29,11 +29,11 @@ bool Menu::setBoardHeight(int height) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int Menu::getBoardWidth() {
|
||||
int Menu::getBoardWidth() const {
|
||||
return this->boardWidth;
|
||||
}
|
||||
|
||||
int Menu::getBoardHeight() {
|
||||
int Menu::getBoardHeight() const {
|
||||
return this->boardHeight;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#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
|
||||
|
||||
|
||||
/**
|
||||
* The interface between the UI and the core of the game
|
||||
@@ -25,7 +27,7 @@ class Menu {
|
||||
* Starts a new game with the current settings
|
||||
* @return The game that has been created
|
||||
*/
|
||||
Game startGame(Gamemode gamemode);
|
||||
Game startGame(Gamemode gamemode) const;
|
||||
|
||||
/**
|
||||
* Sets the width of the board, which must be greater than 0
|
||||
@@ -42,12 +44,12 @@ class Menu {
|
||||
/**
|
||||
* @return The width of the board
|
||||
*/
|
||||
int getBoardWidth();
|
||||
int getBoardWidth() const;
|
||||
|
||||
/**
|
||||
* @return The height of the board
|
||||
*/
|
||||
int getBoardHeight();
|
||||
int getBoardHeight() const;
|
||||
|
||||
/**
|
||||
* @return A reference to the player's controls
|
||||
|
||||
@@ -87,21 +87,21 @@ void PiecesList::unselectAll() {
|
||||
this->selectedPieces.clear();
|
||||
}
|
||||
|
||||
int PiecesList::getHighestLoadedSize() {
|
||||
int PiecesList::getHighestLoadedSize() const {
|
||||
return this->highestLoadedSize;
|
||||
}
|
||||
|
||||
int PiecesList::getNumberOfPieces(int size) {
|
||||
int PiecesList::getNumberOfPieces(int size) const {
|
||||
if (size < 1 || size > this->highestLoadedSize) return 0;
|
||||
|
||||
return this->loadedPieces.at(size).size();
|
||||
}
|
||||
|
||||
std::vector<std::pair<int, int>> PiecesList::getSelectedPieces() {
|
||||
std::vector<std::pair<int, int>> PiecesList::getSelectedPieces() const {
|
||||
return this->selectedPieces;
|
||||
}
|
||||
|
||||
Piece PiecesList::getPiece(std::pair<int, int> pieceIndex) {
|
||||
Piece PiecesList::getPiece(std::pair<int, int> pieceIndex) const {
|
||||
return this->loadedPieces.at(pieceIndex.first).at(pieceIndex.second);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,22 +69,22 @@ class PiecesList {
|
||||
/**
|
||||
* @return The highest loaded size of pieces
|
||||
*/
|
||||
int getHighestLoadedSize();
|
||||
int getHighestLoadedSize() const;
|
||||
|
||||
/**
|
||||
* @return The number of pieces of the specified size
|
||||
*/
|
||||
int getNumberOfPieces(int size);
|
||||
int getNumberOfPieces(int size) const;
|
||||
|
||||
/**
|
||||
* @return The indexes of all selected pieces
|
||||
*/
|
||||
std::vector<std::pair<int, int>> getSelectedPieces();
|
||||
std::vector<std::pair<int, int>> getSelectedPieces() const;
|
||||
|
||||
/**
|
||||
* @return The piece corresponding to the specified index
|
||||
*/
|
||||
Piece getPiece(std::pair<int, int> pieceIndex);
|
||||
Piece getPiece(std::pair<int, int> pieceIndex) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
|
||||
@@ -36,14 +36,14 @@ bool Player::setSDR(int SDR) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int Player::getDAS() {
|
||||
int Player::getDAS() const {
|
||||
return this->DAS;
|
||||
}
|
||||
|
||||
int Player::getARR() {
|
||||
int Player::getARR() const {
|
||||
return this->ARR;
|
||||
}
|
||||
|
||||
int Player::getSDR() {
|
||||
int Player::getSDR() const {
|
||||
return this->SDR;
|
||||
}
|
||||
|
||||
@@ -37,15 +37,15 @@ class Player {
|
||||
/**
|
||||
* @return DAS value
|
||||
*/
|
||||
int getDAS();
|
||||
int getDAS() const;
|
||||
|
||||
/**
|
||||
* @return ARR value
|
||||
*/
|
||||
int getARR();
|
||||
int getARR() const;
|
||||
|
||||
/**
|
||||
* @return SDR value
|
||||
*/
|
||||
int getSDR();
|
||||
int getSDR() const;
|
||||
};
|
||||
|
||||
@@ -10,6 +10,8 @@ void testGeneratorForOneSize(int size);
|
||||
void testGeneratorByprintingAllNminos(int n);
|
||||
void testStoringAndRetrievingPieces(int size);
|
||||
void generateFilesForAllSizes(int amount);
|
||||
void generateFilesForOneSize(int size);
|
||||
void loadFromFilesForOneSize(int size);
|
||||
void readStatsFromFilesForAllSizes(int amount);
|
||||
|
||||
|
||||
@@ -107,8 +109,8 @@ void generateFilesForAllSizes(int amount) {
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::duration;
|
||||
using std::chrono::milliseconds;
|
||||
|
||||
PiecesFiles piecesFiles;
|
||||
|
||||
for (int i = 1; i <= amount; i++) {
|
||||
auto t1 = high_resolution_clock::now();
|
||||
piecesFiles.savePieces(i);
|
||||
@@ -118,12 +120,12 @@ void generateFilesForAllSizes(int amount) {
|
||||
std::cout << "Generated pieces files for size " << i << " in " << ms_double.count() << "ms" << std::endl;
|
||||
}
|
||||
|
||||
std::vector<Piece> pieces;
|
||||
std::vector<int> convexPieces;
|
||||
std::vector<int> holelessPieces;
|
||||
std::vector<int> otherPieces;
|
||||
for (int i = 1; i <= amount; i++) {
|
||||
auto t1 = high_resolution_clock::now();
|
||||
std::vector<Piece> pieces;
|
||||
std::vector<int> convexPieces;
|
||||
std::vector<int> holelessPieces;
|
||||
std::vector<int> otherPieces;
|
||||
piecesFiles.loadPieces(i, pieces, convexPieces, holelessPieces, otherPieces);
|
||||
auto t2 = high_resolution_clock::now();
|
||||
|
||||
@@ -132,6 +134,46 @@ void generateFilesForAllSizes(int amount) {
|
||||
}
|
||||
}
|
||||
|
||||
void generateFilesForOneSize(int size) {
|
||||
using std::chrono::high_resolution_clock;
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::duration;
|
||||
using std::chrono::milliseconds;
|
||||
PiecesFiles piecesFiles;
|
||||
|
||||
std::cout << "Generating " << size << "-minos files" << std::endl;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
auto t1 = high_resolution_clock::now();
|
||||
piecesFiles.savePieces(size);
|
||||
auto t2 = high_resolution_clock::now();
|
||||
|
||||
duration<double, std::milli> ms_double = t2 - t1;
|
||||
std::cout << ms_double.count() << "ms" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void loadFromFilesForOneSize(int size) {
|
||||
using std::chrono::high_resolution_clock;
|
||||
using std::chrono::duration_cast;
|
||||
using std::chrono::duration;
|
||||
using std::chrono::milliseconds;
|
||||
PiecesFiles piecesFiles;
|
||||
|
||||
std::vector<Piece> pieces;
|
||||
std::vector<int> convexPieces;
|
||||
std::vector<int> holelessPieces;
|
||||
std::vector<int> otherPieces;
|
||||
std::cout << "Loading " << size << "-minos from files" << std::endl;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
auto t1 = high_resolution_clock::now();
|
||||
piecesFiles.loadPieces(size, pieces, convexPieces, holelessPieces, otherPieces);
|
||||
auto t2 = high_resolution_clock::now();
|
||||
|
||||
duration<double, std::milli> ms_double = t2 - t1;
|
||||
std::cout << ms_double.count() << "ms" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void readStatsFromFilesForAllSizes(int amount) {
|
||||
PiecesFiles piecesFiles;
|
||||
for (int i = 1; i <= amount; i++) {
|
||||
|
||||
Reference in New Issue
Block a user