commit b256fda5
Puzzle mode no longer has its own start function
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 767a916..726e1f6 100644
--- a/source/code/BlockGame.cpp
+++ b/source/code/BlockGame.cpp
@@ -268,6 +268,40 @@ void BlockGame::NewGame(const BlockGameStartInfo &s) {
speed = baseSpeed;
}
}
+ if (s.puzzleMode) {
+ if (s.level>-1) {
+ puzzleMode = true;
+ Level = s.level;
+ MovesLeft = PuzzleNumberOfMovesAllowed(Level);
+ for (int i=0; i<6; i++)
+ for (int j=0; j<12; j++) {
+ board[i][j+1] = PuzzleGetBrick(Level,i,j);
+ }
+ baseSpeed = 100000;
+ speed = 100000;
+
+ //Now push the blines up
+ for (int i=19; i>0; i--)
+ for (int j=0; j<6; j++) {
+ board[j][i] = board[j][i-1];
+ }
+ for (int j=0; j<6; j++) {
+ board[j][0] = rand() % 6;
+ if (j > 0) {
+ if (board[j][0] == board[j-1][0]) {
+ board[j][0] = rand() % 6;
+ }
+ }
+ if (board[j][0] == board[j][1]) {
+ board[j][0] = 6;
+ }
+ if (board[j][0] == board[j][1]) {
+ board[j][0] = 6;
+ }
+
+ }
+ }
+ }
}
//Instead of creating new object new game is called, to prevent memory leaks
@@ -311,43 +345,6 @@ void BlockGame::NewGame( unsigned int ticks) {
lastAImove = ticks+3000;
} //NewGame
-void BlockGame::NewPuzzleGame(int level, unsigned int ticks) {
- if (level>-1) {
- NewGame(ticks);
- puzzleMode = true;
- Level = level;
- MovesLeft = PuzzleNumberOfMovesAllowed(Level);
- for (int i=0; i<6; i++)
- for (int j=0; j<12; j++) {
- board[i][j+1] = PuzzleGetBrick(Level,i,j);
- }
- baseSpeed = 100000;
- speed = 100000;
-
- //Now push the blines up
- for (int i=19; i>0; i--)
- for (int j=0; j<6; j++) {
- board[j][i] = board[j][i-1];
- }
- for (int j=0; j<6; j++) {
- board[j][0] = rand() % 6;
- if (j > 0) {
- if (board[j][0] == board[j-1][0]) {
- board[j][0] = rand() % 6;
- }
- }
- if (board[j][0] == board[j][1]) {
- board[j][0] = 6;
- }
- if (board[j][0] == board[j][1]) {
- board[j][0] = 6;
- }
-
- }
- }
-}
-
-
//Starts new Vs Game (two Player)
void BlockGame::NewVsGame(BlockGame* target, unsigned int ticks) {
NewGame(ticks);
@@ -1926,17 +1923,18 @@ int BlockGame::getLevel() const {
//Play the next level
void nextLevel(BlockGame& g, unsigned int ticks) {
+ BlockGameStartInfo s;
+ s.ticks = ticks;
+ s.level = g.getLevel()+1;
if (g.isPuzzleMode()) {
if (g.getLevel()<PuzzleGetNumberOfPuzzles()-1) {
- g.NewPuzzleGame(g.getLevel()+1, ticks);
+ s.puzzleMode = true;
+ g.NewGame(s);
}
}
else if (g.isStageClear()) {
if (g.getLevel() < 50-1) {
- BlockGameStartInfo s;
- s.ticks = ticks;
s.stageClear = true;
- s.level = g.getLevel()+1;
g.NewGame(s);
}
}
@@ -1945,12 +1943,13 @@ void nextLevel(BlockGame& g, unsigned int ticks) {
void retryLevel(BlockGame& g, unsigned int ticks) {
BlockGameStartInfo s;
s.ticks = ticks;
+ s.level = g.getLevel();
if (g.isPuzzleMode()) {
- g.NewPuzzleGame(g.getLevel(), ticks);
+ s.puzzleMode = true;
+ g.NewGame(s);
}
else if (g.isStageClear()) {
s.stageClear = true;
- s.level = g.getLevel();
g.NewGame(s);
}
-}
\ No newline at end of file
+}
diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp
index 352b444..3596f56 100644
--- a/source/code/BlockGame.hpp
+++ b/source/code/BlockGame.hpp
@@ -62,8 +62,10 @@ const int bsize = 50;
struct BlockGameStartInfo {
unsigned int ticks = 0;
bool timeTrial = false;
- ///True means a stage clear game will be started. Level must be set too.
+ ///True means a stage clear game will be started. level must be set too.
bool stageClear = false;
+ ///True if puzzle mode. level must be set too.
+ bool puzzleMode = false;
int level = 0;
};
@@ -183,7 +185,6 @@ public:
void MoveCursorTo(int x, int y);
bool GetIsWinner() const;
void NewGame(const BlockGameStartInfo &s);
- void NewPuzzleGame(int level, unsigned int ticks);
//Starts new Vs Game (two Player)
void NewVsGame(BlockGame *target,unsigned int ticks);
//Starts new Vs Game (two Player)
diff --git a/source/code/main.cpp b/source/code/main.cpp
index 0316644..a082a7c 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -1503,11 +1503,14 @@ static void StartSinglePlayerTimeTrial() {
}
static int StartSinglePlayerPuzzle(int level) {
- int myLevel = PuzzleLevelSelect(0);
- if (myLevel == -1) {
+ BlockGameStartInfo startInfo;
+ startInfo.ticks = SDL_GetTicks();
+ startInfo.puzzleMode = true;
+ startInfo.level = PuzzleLevelSelect(0);
+ if (startInfo.level == -1) {
return 1;
}
- player1->NewPuzzleGame(myLevel,SDL_GetTicks());
+ player1->NewGame(startInfo);
DrawIMG(backgroundImage, screen, 0, 0);
twoPlayers = false;
player2->SetGameOver();
@@ -1826,7 +1829,10 @@ int main(int argc, char* argv[]) {
if (singlePuzzle) {
LoadPuzzleStages();
- theGame.NewPuzzleGame(singlePuzzleNr, SDL_GetTicks());
+ BlockGameStartInfo s;
+ s.puzzleMode = true;
+ s.level = singlePuzzleNr;
+ theGame.NewGame(s);
theGame.setSinglePuzzle(true);
}
SDL_RenderClear(screen);
@@ -1924,7 +1930,10 @@ int runGame(int gametype, int level) {
if (singlePuzzle) {
LoadPuzzleStages();
- theGame.NewPuzzleGame(singlePuzzleNr, SDL_GetTicks());
+ BlockGameStartInfo s;
+ s.puzzleMode = true;
+ s.level = singlePuzzleNr;
+ theGame.NewGame(s);
theGame.setSinglePuzzle(true);
}
//game loop