commit ae5fb2bb
AI level is now also recorded in the human struct.
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 5eb745a..7d4a8a3 100644
--- a/source/code/BlockGame.cpp
+++ b/source/code/BlockGame.cpp
@@ -166,7 +166,6 @@ void BlockGame::setHandicap(int globalHandicap) {
//Set the move speed of the AI based on the aiLevel parameter
//Also enables AI
void BlockGame::setAIlevel(int aiLevel) {
- AI_Enabled = true;
AI_MoveSpeed=120-(20*(aiLevel-3));
};
@@ -254,6 +253,9 @@ bool BlockGame::GetIsWinner() const {
void BlockGame::NewGame(const BlockGameStartInfo& s) {
this->recordStats = s.recordStats;
+ if (s.AI) {
+ recordStats = false;
+ }
NewGame(s.ticks);
if (s.timeTrial) {
timetrial = true;
@@ -310,6 +312,10 @@ void BlockGame::NewGame(const BlockGameStartInfo& s) {
if (recordStats) {
Stats::getInstance()->addOne("VSgamesStarted");
}
+ if (s.vsAI) {
+ setAIlevel(s.level);
+ vsAI = true;
+ }
if (AI_Enabled) {
name = "CPU";
setAIlevel(s.level);
@@ -380,12 +386,12 @@ void BlockGame::setPlayerWon() {
PlayerWonEvent();
if (recordStats) {
Stats::getInstance()->addOne("totalWins");
- if (garbageTarget->AI_Enabled) {
+ if (vsAI) {
//We have defeated an AI
Stats::getInstance()->addOne("defeatedAI"+itoa(garbageTarget->getAIlevel()));
}
}
- if (AI_Enabled && !(garbageTarget->AI_Enabled)) {
+ if (AI_Enabled && vsAI) {
//The AI have defeated a human player
Stats::getInstance()->addOne("defeatedByAI"+itoa(getAIlevel()));
}
diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp
index 4fdbec5..18bafd4 100644
--- a/source/code/BlockGame.hpp
+++ b/source/code/BlockGame.hpp
@@ -52,8 +52,16 @@ struct BlockGameStartInfo {
bool singlePuzzle = false;
int level = 0;
bool AI = false;
+ /**
+ * True means that stats will be recorded.
+ * If AI is true then this will be overruled to false
+ */
bool recordStats = true;
bool vsMode = false;
+ /**
+ * Set to true if we are fighting an AI. level should be the AI level we are fighting
+ */
+ bool vsAI = false;
int startBlocks = -1;
int handicap = 0;
int gameSpeed = 0;
@@ -128,6 +136,7 @@ protected:
int AI_MoveSpeed; //How often will the computer move? milliseconds
bool AI_Enabled;
bool recordStats = true;
+ bool vsAI = false; //Set to true for single player vs
int handicap;
@@ -271,7 +280,6 @@ private:
////////
//////////////////////////////////////////////////////////////////
//Set the move speed of the AI based on the aiLevel parameter
- //Also enables AI
void setAIlevel(int aiLevel);
void PushLineInternal();
//Updates evrything, if not called nothing happends
diff --git a/source/code/main.cpp b/source/code/main.cpp
index e923369..0e9b811 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -1898,10 +1898,11 @@ int runGame(int gametype, int level) {
BlockGameStartInfo startInfo;
startInfo.ticks = SDL_GetTicks();
startInfo.vsMode = true;
+ startInfo.vsAI = true;
+ startInfo.level = theAIlevel;
theGame.NewGame(startInfo);
theGame.setGarbageTarget(&theGame2);
startInfo.AI = true;
- startInfo.level = theAIlevel;
theGame2.NewGame(startInfo);
theGame2.setGarbageTarget(&theGame);
DrawIMG(backgroundImage, screen, 0, 0);