git repos / blockattack-game

commit b1fe2ae5

sago007 · 2016-02-21 16:01
b1fe2ae54d5089f86bffb3cec603c1ad19f9d3f8 patch · browse files
parent 5159dd903db4696d81759ff64bff156e435fc59e

Stage clear no longer has its own start method.

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 04b0f33..59c44eb 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp
@@ -258,6 +258,16 @@ void BlockGame::NewGame(const BlockGameStartInfo &s) {
timetrial = true;
putStartBlocks();
}
+ if (s.stageClear) {
+ if (s.level > -1) {
+ stageClear = true;
+ Level = s.level;
+ Stats::getInstance()->addOne("PlayedStageLevel"+itoa2(s.level));
+ stageClearLimit = 30+(Level%6)*10;
+ baseSpeed = 0.5/((double)(Level*0.5)+1.0);
+ speed = baseSpeed;
+ }
+ }
}
//Instead of creating new object new game is called, to prevent memory leaks
@@ -301,19 +311,6 @@ void BlockGame::NewGame( unsigned int ticks) {
lastAImove = ticks+3000;
} //NewGame
-//Starts a new stage game, takes level as input!
-void BlockGame::NewStageGame(int level, unsigned int ticks) {
- if (level > -1) {
- NewGame(ticks);
- stageClear = true;
- Level = level;
- Stats::getInstance()->addOne("PlayedStageLevel"+itoa2(level));
- stageClearLimit = 30+(Level%6)*10;
- baseSpeed = 0.5/((double)(Level*0.5)+1.0);
- speed = baseSpeed;
- }
-}
-
void BlockGame::NewPuzzleGame(int level, unsigned int ticks) {
if (level>-1) {
NewGame(ticks);
@@ -359,7 +356,11 @@ void BlockGame::nextLevel(unsigned int ticks) {
}
else if (stageClear) {
if (Level<50-1) {
- NewStageGame(Level+1, ticks);
+ BlockGameStartInfo s;
+ s.ticks = ticks;
+ s.stageClear = true;
+ s.level = Level+1;
+ NewGame(s);
}
}
}
@@ -1942,10 +1943,14 @@ int BlockGame::getLevel() const {
void retryLevel(BlockGame& g, unsigned int ticks) {
+ BlockGameStartInfo s;
+ s.ticks = ticks;
if (g.isPuzzleMode()) {
g.NewPuzzleGame(g.getLevel(), ticks);
}
else if (g.isStageClear()) {
- g.NewStageGame(g.getLevel(), ticks);
+ 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 6bcad28..bdb93f5 100644 --- a/source/code/BlockGame.hpp +++ b/source/code/BlockGame.hpp
@@ -62,6 +62,9 @@ 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.
+ bool stageClear = false;
+ int level = 0;
};
////////////////////////////////////////////////////////////////////////////////
@@ -180,8 +183,6 @@ public:
void MoveCursorTo(int x, int y);
bool GetIsWinner() const;
void NewGame(const BlockGameStartInfo &s);
- //Starts a new stage game, takes level as input!
- void NewStageGame(int level, unsigned int ticks);
void NewPuzzleGame(int level, unsigned int ticks);
//Play the next level
void nextLevel(unsigned int ticks);
diff --git a/source/code/main.cpp b/source/code/main.cpp index 9e25b2d..557ea80 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -1949,7 +1949,11 @@ int runGame(int gametype, int level) {
if (myLevel == -1) {
return 1;
}
- theGame.NewStageGame(myLevel,SDL_GetTicks());
+ BlockGameStartInfo s;
+ s.ticks = SDL_GetTicks();
+ s.stageClear = true;
+ s.level = myLevel;
+ theGame.NewGame(s);
DrawIMG(backgroundImage, screen, 0, 0);
twoPlayers =false;
theGame2.SetGameOver();