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()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