git repos / blockattack-game

commit 4ce4646e

Poul Sander · 2024-03-27 17:45
4ce4646ef8912dee87ee50a71e745e19d17b2f96 patch · browse files
parent 421e71ed475735148bb032ce58df4e054130e4e1

Start supporting an easy mode

Changed files

M source/code/BlockGame.cpp before
M source/code/BlockGame.hpp before
M source/code/main.cpp before
diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index 24965d6..f58562c 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp
@@ -134,6 +134,7 @@ BlockGame::BlockGame() {
gameEndedAfter = 0;
pushedPixelAt = gameStartedAt;
nextGarbageNumber = 10;
+ basicBlockVariants = 6;
handicap=0;
for (int i=0; i<7; i++) {
for (int j=0; j<30; j++) {
@@ -266,6 +267,7 @@ void BlockGame::NewGame(const BlockGameStartInfo& s) {
recordStats = false;
}
NewGameInternal(s.ticks);
+ basicBlockVariants = 6;
if (s.timeTrial) {
timetrial = true;
putStartBlocks();
@@ -720,7 +722,7 @@ int BlockGame::GarbageClearer(int x, int y, int number, bool aLineToClear, int c
return -1;
}
if (aLineToClear) {
- board[x][y] = this->rand2() % 6;
+ board[x][y] = this->rand2() % basicBlockVariants;
board[x][y] += 10*HANGTIME+BLOCKHANG+CHAINPLACE*chain;
}
garbageToBeCleared[x][y] = false;
@@ -1230,17 +1232,17 @@ void BlockGame::PushLineInternal() {
board[j][0] = rand2() % 4;
if (j > 0) {
if (board[j][0] == board[j-1][0]) {
- board[j][0] = rand2() % 6;
+ board[j][0] = rand2() % basicBlockVariants;
}
}
if (board[j][0] == board[j][1]) {
- board[j][0] = rand2() % 6;
+ board[j][0] = rand2() % basicBlockVariants;
}
if (board[j][0] == board[j][1]) {
- board[j][0] = rand2() % 6;
+ board[j][0] = rand2() % basicBlockVariants;
}
while ((j>0)&&(board[j][0]==board[j-1][0])) {
- board[j][0] = rand2() % 6;
+ board[j][0] = rand2() % basicBlockVariants;
}
}
score+=1;
diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp index ed5d766..ea3aac9 100644 --- a/source/code/BlockGame.hpp +++ b/source/code/BlockGame.hpp
@@ -194,6 +194,9 @@ protected:
int handicap = 0;
+ // Number of different basic blocks. Default is 6. Easy mde is limited t 5.
+ int basicBlockVariants = 6;
+
std::vector<GarbageStruct> garbageSendQueue;
int AIlineToClear = 0;
@@ -258,6 +261,9 @@ public:
double GetBaseSpeed() const {
return baseSpeed;
}
+ int GetBasicBlockVariants() const {
+ return basicBlockVariants;
+ }
const BlockGameInfo& GetBlockGameInfo() {
return replayInfo;
}
diff --git a/source/code/main.cpp b/source/code/main.cpp index 9a43d94..3d8ae9f 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -1309,7 +1309,6 @@ int main(int argc, char* argv[]) {
}
int runGame(Gametype gametype, int level) {
- Highscore theTopScoresTimeTrial = Highscore("timetrial", 0.5);
drawBalls = true;
puzzleLoaded = false;
bool bNearDeath = false; //Play music faster or louder while tru
@@ -1863,16 +1862,31 @@ int runGame(Gametype gametype, int level) {
}
}
- if (theGame.isGameOver() && registerTTHighscorePlayer1) {
- registerTTHighscorePlayer1 = false;
- theTopScoresTimeTrial.addScore(theGame.name, theGame.GetScore());
- }
- if (theGame2.isGameOver() && registerTTHighscorePlayer2) {
- registerTTHighscorePlayer2 = false;
- theTopScoresTimeTrial.addScore(theGame2.name, theGame2.GetScore());
+ if (theGame.isGameOver() && (registerTTHighscorePlayer1 || registerTTHighscorePlayer2)) {
+ std::string highscore_name = "timetrial";
+ int block_variants = theGame.GetBasicBlockVariants();
+ // If the block variants are not the default 6, add the number of block variants to the highscore name
+ if (block_variants != 6) {
+ highscore_name += "_block" + std::to_string(block_variants);
+ }
+ Highscore theTopScoresTimeTrial = Highscore(highscore_name, 0.5);
+ if (registerTTHighscorePlayer1) {
+ registerTTHighscorePlayer1 = false;
+ theTopScoresTimeTrial.addScore(theGame.name, theGame.GetScore());
+ }
+ if (theGame2.isGameOver() && registerTTHighscorePlayer2) {
+ registerTTHighscorePlayer2 = false;
+ theTopScoresTimeTrial.addScore(theGame2.name, theGame2.GetScore());
+ }
}
if (theGame.isGameOver() && registerEndlessHighscore) {
- Highscore theTopScoresEndless = Highscore("endless", theGame.GetBaseSpeed());
+ std::string highscore_name = "endless";
+ int block_variants = theGame.GetBasicBlockVariants();
+ // If the block variants are not the default 6, add the number of block variants to the highscore name
+ if (block_variants != 6) {
+ highscore_name += "_block" + std::to_string(block_variants);
+ }
+ Highscore theTopScoresEndless = Highscore(highscore_name.c_str(), theGame.GetBaseSpeed());
registerEndlessHighscore = false;
theTopScoresEndless.addScore(theGame.name, theGame.GetScore());
theGame.EndlessHighscoreEvent();