git repos / blockattack-game

commit 32c9b349

sago007 · 2008-11-20 18:14
32c9b349917f2a5f1935d1d419346f05519181ad patch · browse files
parent f876e3cb471e67179eb695f6d7dd8bcfc1a7d839

Some more statistics are saved


git-svn-id: https://blockattack.svn.sourceforge.net/svnroot/blockattack/trunk@53 9d7177f8-192b-0410-8f35-a16a89829b06

Changed files

M source/code/BlockGame.hpp before
M source/code/stats.cc before
diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp index 964431a..9b1f464 100644 --- a/source/code/BlockGame.hpp +++ b/source/code/BlockGame.hpp
@@ -23,6 +23,10 @@
* blockattack@poulsander.com
*/
+#include "stats.h"
+#include "common.h"
+
+
////////////////////////////////////////////////////////////////////////////////
//The BloackGame class represents a board, score, time etc. for a single player/
////////////////////////////////////////////////////////////////////////////////
@@ -192,6 +196,10 @@ public:
void setAIlevel(Uint8 aiLevel) {
AI_MoveSpeed=120-(20*(aiLevel-3));
};
+
+ Uint8 getAIlevel() {
+ return (120-AI_MoveSpeed)/20+3;
+ }
#if NETWORK
#define garbageStackSize 10
@@ -291,6 +299,7 @@ public:
NewGame(tx, ty);
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;
@@ -362,6 +371,7 @@ public:
vsMode = true;
putStartBlocks();
garbageTarget = target;
+ Stats::getInstance()->addOne("VSgamesStarted");
}
//Starts new Vs Game (two Player)
@@ -369,6 +379,8 @@ public:
NewGame(tx, ty);
vsMode = true;
AI_Enabled = AI;
+ if(!AI)
+ Stats::getInstance()->addOne("VSgamesStarted");
putStartBlocks();
garbageTarget = target;
}
@@ -409,6 +421,20 @@ public:
hasWonTheGame = true;
showGame = false;
if (SoundEnabled)Mix_PlayChannel(1, applause, 0);
+ if(!AI_Enabled && !bReplaying)
+ {
+ Stats::getInstance()->addOne("totalWins");
+ if(garbageTarget->AI_Enabled==true && garbageTarget->bReplaying==false)
+ {
+ //We have defeated an AI
+ Stats::getInstance()->addOne("defeatedAI"+itoa(garbageTarget->getAIlevel()));
+ }
+ }
+ if(AI_Enabled && garbageTarget->AI_Enabled==false && garbageTarget->bReplaying==false)
+ {
+ //The AI have defeated a human player
+ Stats::getInstance()->addOne("defeatedByAI"+itoa(garbageTarget->getAIlevel()));
+ }
}
//void SetGameOver();
@@ -429,6 +455,8 @@ public:
bDraw = true;
showGame = false;
Mix_HaltChannel(1);
+ if(!AI_Enabled && !bReplaying)
+ Stats::getInstance()->addOne("totalDraws");
}
//Function to get a boardpackage
@@ -2149,6 +2177,8 @@ public:
stop++;
if ((puzzleMode)&&(!bGameOver)&&BoardEmpty()) {
if (!singlePuzzle) {
+ if(puzzleCleared[Level]==false)
+ Stats::getInstance()->addOne("puzzlesSolved");
puzzleCleared[Level] = true;
ofstream outfile;
stageButtonStatus = SBpuzzleMode;
diff --git a/source/code/stats.cc b/source/code/stats.cc index f179843..40baa8c 100644 --- a/source/code/stats.cc +++ b/source/code/stats.cc
@@ -27,7 +27,7 @@ Copyright (C) 2008 Poul Sander
#include "stats.h"
#include "common.h"
-Stats* Stats::instance = 0;
+Stats* Stats::instance = NULL;
Stats::Stats()
{
@@ -58,7 +58,7 @@ void Stats::load()
Stats* Stats::getInstance()
{
- if(Stats::instance==0)
+ if(Stats::instance==NULL)
{
Stats::instance = new Stats();