git repos / blockattack-game

commit 56241205

sago007 · 2012-08-05 11:15
56241205356d0190a83001022d41328ca182729e patch · browse files
parent b283e0f7c9e7c7ccb21658b977dd8495a4a67580

Fixed a problem with an uninitialized variable in the BlockGame class. Also a lot of code cleanup

Changed files

M source/code/BlockGame.cpp before
M source/code/MenuSystem.cc before
M source/code/NetworkThing.hpp before
M source/code/ReadKeyboard.cpp before
M source/code/ReadKeyboard.h before
M source/code/block.make before
M source/code/main.cpp before
M source/code/mainVars.hpp before
M source/code/menudef.cpp before
M source/code/replay.cpp before
diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index d6ed099..c9cdcde 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp
@@ -80,6 +80,8 @@ BlockGame::BlockGame()
linesCleared = 0;
AI_Enabled = false;
AI_MoveSpeed=100;
+ AIlineToClear = 0;
+ AIcolorToClear = 0;
hasWonTheGame = false;
combo=0; //counts
chain=0;
@@ -485,7 +487,7 @@ void BlockGame::playReplay(int tx, int ty, unsigned int ticks, Replay r)
{
if(r.getActions().size()==0)
{
- cout << "Empty replay data" << endl;
+ cerr << "Empty replay data" << endl;
return;
}
NewGame(tx, ty,ticks);
@@ -620,7 +622,9 @@ void BlockGame::putStartBlocks(Uint32 n)
format f("%1%");
f % n;
ActionPerformed(ACTION_STARTBLOCKS ,f.str());
+#if DEBUG
cout << n << ":" << f.str() << endl;
+#endif
for (int i=0; i<7; i++)
for (int j=0; j<30; j++)
{
@@ -1452,7 +1456,8 @@ void BlockGame::PushLineInternal()
{
if (SoundEnabled)Mix_PlayChannel(1, applause, 0);
theTopScoresEndless.addScore(name, score);
- cout << "New high score!" << endl;
+ if(verboseLevel)
+ cout << "New high score!" << endl;
}
SetGameOver();
}
@@ -1607,6 +1612,11 @@ bool BlockGame::ThereIsATower()
double BlockGame::firstInLine1(int line)
{
+ if(line > 20 || line < 0)
+ {
+ cerr << "Warning: first in Line1: " << line << endl;
+ return 3.0;
+ }
for (int i=0; i<6; i++)
if ((board[i][line]>-1)&&(board[i][line]<7))
return (double)i;
@@ -1616,6 +1626,11 @@ double BlockGame::firstInLine1(int line)
//returns the first coordinate of the block of type
double BlockGame::firstInLine(int line, int type)
{
+ if(line > 20 || line < 0)
+ {
+ cerr << "Warning: first in Line: " << line << endl;
+ return 3.0;
+ }
for (int i=0; i<6; i++)
if (board[i][line]==type)
return (double)i;
@@ -1778,6 +1793,17 @@ void BlockGame::AI_ClearVertical()
//First we find the place there we will align the bricks
int placeToCenter = (int)(firstInLine(AIlineToClear, AIcolorToClear)/3.0+firstInLine(AIlineToClear+1, AIcolorToClear)/3.0+firstInLine(AIlineToClear+2, AIcolorToClear)/3.0);
int unlimitedLoop=0;
+ if(AIlineToClear < 0 || AIlineToClear > 20)
+ {
+ cerr << "AIlineToClear out of range: " << AIlineToClear << endl;
+ return;
+ }
+ if(placeToCenter<0 || placeToCenter > 5)
+ {
+ cerr << "placeToCenter out of range: " << placeToCenter << endl;
+ return;
+ }
+ //cout << "AI_ClearVertical: " << placeToCenter << ", " << AIlineToClear << endl;
while (((board[placeToCenter][AIlineToClear]>1000000)||(board[placeToCenter][AIlineToClear+1]>1000000)||(board[placeToCenter][AIlineToClear+2]>1000000))&&(unlimitedLoop<10))
{
unlimitedLoop++;
@@ -1788,6 +1814,7 @@ void BlockGame::AI_ClearVertical()
if(unlimitedLoop>9)
{
AIstatus = 0;
+ return;
}
//cout << ", ptc: " << placeToCenter << ", line: " << AIlineToClear << ", cy: " << cursory;
if (cursory+1>AIlineToClear+2)
@@ -1933,7 +1960,7 @@ void BlockGame::Update()
outfile.open(stageClearSavePath.c_str(), ios::binary |ios::trunc);
if (!outfile)
{
- cout << "Error writing to file: " << stageClearSavePath << endl;
+ cerr << "Error writing to file: " << stageClearSavePath << endl;
}
else
{
@@ -1989,7 +2016,7 @@ void BlockGame::Update()
outfile.open(puzzleSavePath.c_str(), ios::binary |ios::trunc);
if (!outfile)
{
- cout << "Error writing to file: " << puzzleSavePath << endl;
+ cerr << "Error writing to file: " << puzzleSavePath << endl;
}
else
{
diff --git a/source/code/MenuSystem.cc b/source/code/MenuSystem.cc index 5f8edfe..9379daa 100644 --- a/source/code/MenuSystem.cc +++ b/source/code/MenuSystem.cc
@@ -30,6 +30,7 @@ http://blockattack.sf.net
extern CppSdl::CppSdlImageHolder mouse;
extern SDL_Surface *backgroundImage;
extern bool highPriority;
+extern int verboseLevel;
int mousex;
int mousey;
@@ -56,7 +57,8 @@ void ButtonGfx::setSurfaces(CppSdl::CppSdlImageHolder marked,CppSdl::CppSdlImage
ButtonGfx::_unmarked = unmarked;
xsize=(marked).GetWidth();
ysize=(marked).GetHeight();
- cout << "Surfaces set, size: " <<xsize << " , " << ysize << endl;
+ if(verboseLevel)
+ cout << "Surfaces set, size: " <<xsize << " , " << ysize << endl;
}
Button::Button()
@@ -104,7 +106,7 @@ void Button::doAction()
if(action)
action(this);
else
- cout << "Warning: button \"" << label << "\" has no action assigned!";
+ cerr << "Warning: button \"" << label << "\" has no action assigned!";
}
void Button::drawTo(SDL_Surface **surface)
diff --git a/source/code/NetworkThing.hpp b/source/code/NetworkThing.hpp index ab75416..3067340 100644 --- a/source/code/NetworkThing.hpp +++ b/source/code/NetworkThing.hpp
@@ -60,7 +60,8 @@ public:
}
else
{
- cout << "Network is working!" << endl;
+ if(verboseLevel)
+ cout << "Network is working!" << endl;
}
//atexit (enet_deinitialize); in deconstructor
}
@@ -100,10 +101,12 @@ public:
//Lets disconnect before we close...
~NetworkThing()
{
- cout << "Network system is going down" << endl;
+ if(verboseLevel)
+ cout << "Network system is going down" << endl;
ntDisconnect();
enet_deinitialize();
- cout << "Network system went down" << endl;
+ if(verboseLevel)
+ cout << "Network system went down" << endl;
}
void theGameHasStarted()
@@ -149,7 +152,8 @@ public:
weAreAServer = true;
enemyIsReady = false;
gameHasStarted = false;
- cout << "Server is listening on port " << SERVERPORT << endl;
+ if(verboseLevel)
+ cout << "Server is listening on port " << SERVERPORT << endl;
}
}
}
@@ -171,7 +175,7 @@ public:
if (client == NULL)
{
- cout << "An error occurred while trying to create an ENet client host." << endl;
+ cerr << "Error: An error occurred while trying to create an ENet client host." << endl;
}
else
{
@@ -180,12 +184,13 @@ public:
if (peer == NULL)
{
- cout << "No available peers for initiating an ENet connection." << endl;
+ cerr << "Error: No available peers for initiating an ENet connection." << endl;
}
else if (enet_host_service (client, & event, 2000) > 0 &&
event.type == ENET_EVENT_TYPE_CONNECT)
{
- cout << "We are connected!" << endl;
+ if(verboseLevel)
+ cout << "We are connected!" << endl;
enemyIsReady = false;
weAreAClient = true;
weAreConnected = true;
@@ -274,7 +279,8 @@ public:
enet_host_broadcast (server, 2, packet);
else if (weAreAClient)
enet_peer_send (peer, 2, packet);
- cout << "We send a garbage block: " << (int)x << "," << (int)y << "==" << g << endl;
+ if(verboseLevel)
+ cout << "We send a garbage block: " << (int)x << "," << (int)y << "==" << g << endl;
}
}
ENetEvent event;
@@ -304,7 +310,8 @@ public:
bgHome->putStartBlocks(theSeed);
ENetPacket * timePacket = enet_packet_create(&theSeed,sizeof(theSeed),ENET_PACKET_FLAG_RELIABLE);
enet_host_broadcast (server, 3, timePacket);
- cout << "We send the seed: " << theSeed << endl;
+ if(verboseLevel)
+ cout << "We send the seed: " << theSeed << endl;
}
break;
@@ -346,7 +353,8 @@ public:
memcpy(&g,event.packet->data,sizeof(Uint16));
Uint8 x = (g/256);
Uint8 y = (g%256);
- cout << "Recieved Garbage: " << (int)x << "," << (int)y << endl;
+ if(verboseLevel)
+ cout << "Recieved Garbage: " << (int)x << "," << (int)y << endl;
if ((x==255)&&(y==255))
bgHome->CreateGreyGarbage();
else
@@ -358,7 +366,8 @@ public:
if (event.packet->dataLength==sizeof(char[30])) //We have reveived a name
{
strcpy(bgAway->name,(const char*)event.packet->data);
- cout << "The enemy name is: " << bgAway->name << " Length: " << sizeof(char[30])<< endl;
+ if(verboseLevel)
+ cout << "The enemy name is: " << bgAway->name << " Length: " << sizeof(char[30])<< endl;
if (weAreAClient) //We have just recieved the servers name and must send our own
{
ENetPacket * answerPacket = enet_packet_create(bgHome->name,sizeof(char[30]),ENET_PACKET_FLAG_RELIABLE);
@@ -369,7 +378,7 @@ public:
{
if (0!=strcmp((const char*)event.packet->data,"version4"))
{
- cout << "Incompatible version: " << event.packet->data << "!=" << "version4" << endl;
+ cerr << "Error: Incompatible version: " << event.packet->data << "!=" << "version4" << endl;
ntDisconnect();
}
if (weAreAClient) //We will send our version number
@@ -382,7 +391,8 @@ public:
{
memcpy(&theSeed,event.packet->data,sizeof(Uint32));
bgHome->putStartBlocks(theSeed);
- cout << "We recieved a seed: " << theSeed << endl;
+ if(verboseLevel)
+ cout << "We recieved a seed: " << theSeed << endl;
}
}
@@ -393,7 +403,8 @@ public:
case ENET_EVENT_TYPE_DISCONNECT:
//printf ("%s disconected.\n", event.peer -> data);
- cout << event.peer -> data << " disconnected." << endl;
+ if(verboseLevel)
+ cout << event.peer -> data << " disconnected." << endl;
/* Reset the peer's client information. */
diff --git a/source/code/ReadKeyboard.cpp b/source/code/ReadKeyboard.cpp index 54e0643..6b6ce9b 100644 --- a/source/code/ReadKeyboard.cpp +++ b/source/code/ReadKeyboard.cpp
@@ -28,7 +28,7 @@ ReadKeyboard::ReadKeyboard(void)
length = 0;
maxLength = 16;
position = 0;
- strcpy(textstring," ");
+ strcpy(textstring," ");
}
ReadKeyboard::~ReadKeyboard(void)
@@ -45,7 +45,7 @@ ReadKeyboard::ReadKeyboard(char *oldName)
length = 0;
maxLength = 16;
position = 0;
- strcpy(textstring," ");
+ strcpy(textstring," ");
strncpy(textstring,oldName,strlen(oldName));
char charecter = textstring[maxLength+1];
int i = maxLength+1;
@@ -371,7 +371,7 @@ bool ReadKeyboard::ReadKey(SDLKey keyPressed)
return true;
}
-char* ReadKeyboard::GetString()
+const char* ReadKeyboard::GetString()
{
textstring[29]='\0';
return &textstring[0];
diff --git a/source/code/ReadKeyboard.h b/source/code/ReadKeyboard.h index a78fab5..54b452a 100644 --- a/source/code/ReadKeyboard.h +++ b/source/code/ReadKeyboard.h
@@ -43,5 +43,5 @@ public:
ReadKeyboard(char*);
Uint8 CharsBeforeCursor(); //Where should the cursor be placed?
bool ReadKey(SDLKey); //true if key accepted
- char* GetString(void);
+ const char* GetString(void);
};
diff --git a/source/code/block.make b/source/code/block.make index f1282ee..c2efb3f 100644 --- a/source/code/block.make +++ b/source/code/block.make
@@ -20,7 +20,7 @@ BASE_LIBS=$(shell sdl-config --libs) -lSDL_image -lSDL_mixer -lSDL_ttf
#For developement only
ifndef DEBUG
-DEBUG=1
+DEBUG=0
endif
ifndef NETWORK
diff --git a/source/code/main.cpp b/source/code/main.cpp index 16f1fbc..aa229cf 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -126,15 +126,15 @@ void closeAllMenus()
}
-SDL_Surface * IMG_Load2(string path)
+SDL_Surface * IMG_Load2(const char* path)
{
- if (!PHYSFS_exists(path.c_str()))
+ if (!PHYSFS_exists(path))
{
- cout << "File not in blockattack.data: " << path << endl;
+ cerr << "Error: File not in blockattack.data: " << path << endl;
return NULL; //file doesn't exist
}
- PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
+ PHYSFS_file* myfile = PHYSFS_openRead(path);
// Get the lenght of the file
unsigned int m_size = PHYSFS_fileLength(myfile);
@@ -149,7 +149,7 @@ SDL_Surface * IMG_Load2(string path)
delete [] m_data;
m_data = 0;
PHYSFS_close(myfile);
- cout << "Error. Curropt data file!" << endl;
+ cerr << "Error: Curropt data file!" << endl;
return NULL;
}
@@ -164,7 +164,7 @@ SDL_Surface * IMG_Load2(string path)
delete [] m_data;
m_data = 0;
PHYSFS_close(myfile);
- cout << "Error. Curropt data file!" << endl;
+ cerr << "Error: Curropt data file!" << endl;
return NULL;
}
@@ -177,7 +177,7 @@ CppSdl::CppSdlImageHolder IMG_Load3(string path)
{
if (!PHYSFS_exists(path.c_str()))
{
- cout << "File not in blockattack.data: " << path << endl;
+ cerr << "Error: File not in blockattack.data: " << path << endl;
throw exception();
}
@@ -196,7 +196,7 @@ CppSdl::CppSdlImageHolder IMG_Load3(string path)
delete [] m_data;
m_data = 0;
PHYSFS_close(myfile);
- cout << "Error. Curropt data file!" << endl;
+ cerr << "Error: Curropt data file!" << endl;
throw exception();
}
@@ -253,18 +253,18 @@ void loadTheme(string themeName)
}
-long NFont_OpenFont(NFont *target, string path,int ptsize, SDL_Color color, int style=TTF_STYLE_NORMAL)
+long NFont_OpenFont(NFont *target, const char* path,int ptsize, SDL_Color color, int style=TTF_STYLE_NORMAL)
{
- if (!PHYSFS_exists(path.c_str()))
+ if (!PHYSFS_exists(path))
{
- cout << "File not in blockattack.data: " << path << endl;
+ cerr << "Error: File not in blockattack.data: " << path << endl;
return -1; //file doesn't exist
}
if(!(TTF_WasInit()))
TTF_Init();
- PHYSFS_file* myfile = PHYSFS_openRead(path.c_str());
+ PHYSFS_file* myfile = PHYSFS_openRead(path);
// Get the lenght of the file
unsigned int m_size = PHYSFS_fileLength(myfile);
@@ -278,7 +278,7 @@ long NFont_OpenFont(NFont *target, string path,int ptsize, SDL_Color color, int
delete [] m_data;
m_data = 0;
PHYSFS_close(myfile);
- cout << "Error. Curropt data file!" << endl;
+ cerr << "Error: Curropt data file!" << endl;
return -3;
}
@@ -293,7 +293,7 @@ long NFont_OpenFont(NFont *target, string path,int ptsize, SDL_Color color, int
delete [] m_data;
m_data = 0;
PHYSFS_close(myfile);
- cout << "Error. Curropt data file!" << endl;
+ cerr << "Error: Curropt data file!" << endl;
return -2;
}
@@ -313,7 +313,7 @@ Mix_Music * Mix_LoadMUS2(string path)
{
if (!PHYSFS_exists(path.c_str()))
{
- cout << "File not in blockattack.data: " << path << endl;
+ cerr << "Warning: File not in blockattack.data: " << path << endl;
return NULL; //file doesn't exist
}
@@ -332,7 +332,7 @@ Mix_Music * Mix_LoadMUS2(string path)
delete [] m_data;
m_data = 0;
PHYSFS_close(myfile);
- cout << "Error. Curropt data file!" << endl;
+ cerr << "Error: Curropt data file!" << endl;
return NULL;
}
@@ -347,7 +347,7 @@ Mix_Music * Mix_LoadMUS2(string path)
delete [] m_data;
m_data = 0;
PHYSFS_close(myfile);
- cout << "Error. Curropt data file!" << endl;
+ cerr << "Error: Curropt data file!" << endl;
return NULL;
}
@@ -357,11 +357,11 @@ Mix_Music * Mix_LoadMUS2(string path)
}
-Mix_Chunk * Mix_LoadWAV2(char* path)
+Mix_Chunk * Mix_LoadWAV2(const char* path)
{
if (!PHYSFS_exists(path))
{
- cout << "File not in blockattack.data: " << path << endl;
+ cerr << "Warning: File not in blockattack.data: " << path << endl;
return NULL; //file doesn't exist
}
@@ -380,7 +380,7 @@ Mix_Chunk * Mix_LoadWAV2(char* path)
delete [] m_data;
m_data = 0;
PHYSFS_close(myfile);
- cout << "Error. Curropt data file!" << endl;
+ cerr << "Error: Curropt data file!" << endl;
return NULL;
}
@@ -395,7 +395,7 @@ Mix_Chunk * Mix_LoadWAV2(char* path)
delete [] m_data;
m_data = 0;
PHYSFS_close(myfile);
- cout << "Error. Curropt data file!" << endl;
+ cerr << "Error: Curropt data file!" << endl;
return NULL;
}
@@ -413,120 +413,120 @@ static int InitImages()
// && (b2players = IMG_Load2("gfx/bTwoPlayers.png"))
// && (bVsMode = IMG_Load2("gfx/bVsGame.png"))
// && (bVsModeConfig = IMG_Load2("gfx/bVsGameConfig.png"))
-// && (bPuzzle = IMG_Load2((char*)"gfx/bPuzzle.png"))
-// && (bStageClear = IMG_Load2((char*)"gfx/bStageClear.png"))
-// && (bTimeTrial = IMG_Load2((char*)"gfx/bTimeTrial.png"))
- //&& (bEndless = IMG_Load2((char*)"gfx/bEndless.png"))
- && (bOptions = IMG_Load2((char*)"gfx/bOptions.png"))
- && (bConfigure = IMG_Load2((char*)"gfx/bConfigure.png"))
- && (bSelectPuzzle = IMG_Load2((char*)"gfx/bSelectPuzzle.png"))
- && (bHighScore = IMG_Load2((char*)"gfx/bHighScore.png"))
-// && (bExit = IMG_Load2((char*)"gfx/bExit.png"))
- && (bBack = IMG_Load2((char*)"gfx/bBlank.png"))
- && (bForward = IMG_Load2((char*)"gfx/bForward.png"))
-// && (bReplay = IMG_Load2((char*)"gfx/bReplays.png"))
-// && (bSave = IMG_Load2((char*)"gfx/bSave.png"))
-// && (bLoad = IMG_Load2((char*)"gfx/bLoad.png"))
+// && (bPuzzle = IMG_Load2("gfx/bPuzzle.png"))
+// && (bStageClear = IMG_Load2("gfx/bStageClear.png"))
+// && (bTimeTrial = IMG_Load2("gfx/bTimeTrial.png"))
+ //&& (bEndless = IMG_Load2("gfx/bEndless.png"))
+ && (bOptions = IMG_Load2("gfx/bOptions.png"))
+ && (bConfigure = IMG_Load2("gfx/bConfigure.png"))
+ && (bSelectPuzzle = IMG_Load2("gfx/bSelectPuzzle.png"))
+ && (bHighScore = IMG_Load2("gfx/bHighScore.png"))
+// && (bExit = IMG_Load2("gfx/bExit.png"))
+ && (bBack = IMG_Load2("gfx/bBlank.png"))
+ && (bForward = IMG_Load2("gfx/bForward.png"))
+// && (bReplay = IMG_Load2("gfx/bReplays.png"))
+// && (bSave = IMG_Load2("gfx/bSave.png"))
+// && (bLoad = IMG_Load2("gfx/bLoad.png"))
/*#if NETWORK
- && (bNetwork = IMG_Load2((char*)"gfx/bNetwork.png"))
- && (bHost = IMG_Load2((char*)"gfx/bHost.png"))
- && (bConnect = IMG_Load2((char*)"gfx/bConnect.png"))
+ && (bNetwork = IMG_Load2("gfx/bNetwork.png"))
+ && (bHost = IMG_Load2("gfx/bHost.png"))
+ && (bConnect = IMG_Load2("gfx/bConnect.png"))
#endif*/
- && (blackLine = IMG_Load2((char*)"gfx/blackLine.png"))
- && (stageBobble = IMG_Load2((char*)"gfx/iStageClearLimit.png"))
- && (bricks[0] = IMG_Load2((char*)"gfx/bricks/blue.png"))
- && (bricks[1] = IMG_Load2((char*)"gfx/bricks/green.png"))
- && (bricks[2] = IMG_Load2((char*)"gfx/bricks/purple.png"))
- && (bricks[3] = IMG_Load2((char*)"gfx/bricks/red.png"))
- && (bricks[4] = IMG_Load2((char*)"gfx/bricks/turkish.png"))
- && (bricks[5] = IMG_Load2((char*)"gfx/bricks/yellow.png"))
- && (bricks[6] = IMG_Load2((char*)"gfx/bricks/grey.png"))
- && (crossover = IMG_Load2((char*)"gfx/crossover.png"))
- && (balls[0] = IMG_Load2((char*)"gfx/balls/ballBlue.png"))
- && (balls[1] = IMG_Load2((char*)"gfx/balls/ballGreen.png"))
- && (balls[2] = IMG_Load2((char*)"gfx/balls/ballPurple.png"))
- && (balls[3] = IMG_Load2((char*)"gfx/balls/ballRed.png"))
- && (balls[4] = IMG_Load2((char*)"gfx/balls/ballTurkish.png"))
- && (balls[5] = IMG_Load2((char*)"gfx/balls/ballYellow.png"))
- && (balls[6] = IMG_Load2((char*)"gfx/balls/ballGray.png"))
- && (cursor[0] = IMG_Load2((char*)"gfx/animations/cursor/1.png"))
- && (cursor[1] = IMG_Load2((char*)"gfx/animations/cursor/2.png"))
- && (bomb[0] = IMG_Load2((char*)"gfx/animations/bomb/bomb_1.png"))
- && (bomb[1] = IMG_Load2((char*)"gfx/animations/bomb/bomb_2.png"))
- && (ready[0] = IMG_Load2((char*)"gfx/animations/ready/ready_1.png"))
- && (ready[1] = IMG_Load2((char*)"gfx/animations/ready/ready_2.png"))
- && (explosion[0] = IMG_Load2((char*)"gfx/animations/explosion/0.png"))
- && (explosion[1] = IMG_Load2((char*)"gfx/animations/explosion/1.png"))
- && (explosion[2] = IMG_Load2((char*)"gfx/animations/explosion/2.png"))
- && (explosion[3] = IMG_Load2((char*)"gfx/animations/explosion/3.png"))
- && (counter[0] = IMG_Load2((char*)"gfx/counter/1.png"))
- && (counter[1] = IMG_Load2((char*)"gfx/counter/2.png"))
- && (counter[2] = IMG_Load2((char*)"gfx/counter/3.png"))
- && (backBoard = IMG_Load2((char*)"gfx/BackBoard.png")) //not used, we just test if it exists :)
- && (iGameOver = IMG_Load2((char*)"gfx/iGameOver.png"))
- && (iWinner = IMG_Load2((char*)"gfx/iWinner.png"))
- && (iDraw = IMG_Load2((char*)"gfx/iDraw.png"))
- && (iLoser = IMG_Load2((char*)"gfx/iLoser.png"))
- && (iChainBack = IMG_Load2((char*)"gfx/chainFrame.png"))
-// && (optionsBack = IMG_Load2((char*)"gfx/options.png"))
- && (bOn = IMG_Load2((char*)"gfx/bOn.png"))
- && (bOff = IMG_Load2((char*)"gfx/bOff.png"))
-// && (bChange = IMG_Load2((char*)"gfx/bChange.png"))
- && (b1024 = IMG_Load2((char*)"gfx/b1024.png"))
- && (dialogBox = IMG_Load2((char*)"gfx/dialogbox.png"))
+ && (blackLine = IMG_Load2("gfx/blackLine.png"))
+ && (stageBobble = IMG_Load2("gfx/iStageClearLimit.png"))
+ && (bricks[0] = IMG_Load2("gfx/bricks/blue.png"))
+ && (bricks[1] = IMG_Load2("gfx/bricks/green.png"))
+ && (bricks[2] = IMG_Load2("gfx/bricks/purple.png"))
+ && (bricks[3] = IMG_Load2("gfx/bricks/red.png"))
+ && (bricks[4] = IMG_Load2("gfx/bricks/turkish.png"))
+ && (bricks[5] = IMG_Load2("gfx/bricks/yellow.png"))
+ && (bricks[6] = IMG_Load2("gfx/bricks/grey.png"))
+ && (crossover = IMG_Load2("gfx/crossover.png"))
+ && (balls[0] = IMG_Load2("gfx/balls/ballBlue.png"))
+ && (balls[1] = IMG_Load2("gfx/balls/ballGreen.png"))
+ && (balls[2] = IMG_Load2("gfx/balls/ballPurple.png"))
+ && (balls[3] = IMG_Load2("gfx/balls/ballRed.png"))
+ && (balls[4] = IMG_Load2("gfx/balls/ballTurkish.png"))
+ && (balls[5] = IMG_Load2("gfx/balls/ballYellow.png"))
+ && (balls[6] = IMG_Load2("gfx/balls/ballGray.png"))
+ && (cursor[0] = IMG_Load2("gfx/animations/cursor/1.png"))
+ && (cursor[1] = IMG_Load2("gfx/animations/cursor/2.png"))
+ && (bomb[0] = IMG_Load2("gfx/animations/bomb/bomb_1.png"))
+ && (bomb[1] = IMG_Load2("gfx/animations/bomb/bomb_2.png"))
+ && (ready[0] = IMG_Load2("gfx/animations/ready/ready_1.png"))
+ && (ready[1] = IMG_Load2("gfx/animations/ready/ready_2.png"))
+ && (explosion[0] = IMG_Load2("gfx/animations/explosion/0.png"))
+ && (explosion[1] = IMG_Load2("gfx/animations/explosion/1.png"))
+ && (explosion[2] = IMG_Load2("gfx/animations/explosion/2.png"))
+ && (explosion[3] = IMG_Load2("gfx/animations/explosion/3.png"))
+ && (counter[0] = IMG_Load2("gfx/counter/1.png"))
+ && (counter[1] = IMG_Load2("gfx/counter/2.png"))
+ && (counter[2] = IMG_Load2("gfx/counter/3.png"))
+ && (backBoard = IMG_Load2("gfx/BackBoard.png")) //not used, we just test if it exists :)
+ && (iGameOver = IMG_Load2("gfx/iGameOver.png"))
+ && (iWinner = IMG_Load2("gfx/iWinner.png"))
+ && (iDraw = IMG_Load2("gfx/iDraw.png"))
+ && (iLoser = IMG_Load2("gfx/iLoser.png"))
+ && (iChainBack = IMG_Load2("gfx/chainFrame.png"))
+// && (optionsBack = IMG_Load2("gfx/options.png"))
+ && (bOn = IMG_Load2("gfx/bOn.png"))
+ && (bOff = IMG_Load2("gfx/bOff.png"))
+// && (bChange = IMG_Load2("gfx/bChange.png"))
+ && (b1024 = IMG_Load2("gfx/b1024.png"))
+ && (dialogBox = IMG_Load2("gfx/dialogbox.png"))
// && (fileDialogBox = IMG_Load2("gfx/fileDialogbox.png"))
- && (iLevelCheck = IMG_Load2((char*)"gfx/iLevelCheck.png"))
- && (iLevelCheckBox = IMG_Load2((char*)"gfx/iLevelCheckBox.png"))
- && (iLevelCheckBoxMarked = IMG_Load2((char*)"gfx/iLevelCheckBoxMarked.png"))
- && (iCheckBoxArea = IMG_Load2((char*)"gfx/iCheckBoxArea.png"))
- && (boardBackBack = IMG_Load2((char*)"gfx/boardBackBack.png"))
- && (changeButtonsBack = IMG_Load2((char*)"gfx/changeButtonsBack.png"))
- && (garbageTL = IMG_Load2((char*)"gfx/garbage/garbageTL.png"))
- && (garbageT = IMG_Load2((char*)"gfx/garbage/garbageT.png"))
- && (garbageTR = IMG_Load2((char*)"gfx/garbage/garbageTR.png"))
- && (garbageR = IMG_Load2((char*)"gfx/garbage/garbageR.png"))
- && (garbageBR = IMG_Load2((char*)"gfx/garbage/garbageBR.png"))
- && (garbageB = IMG_Load2((char*)"gfx/garbage/garbageB.png"))
- && (garbageBL = IMG_Load2((char*)"gfx/garbage/garbageBL.png"))
- && (garbageL = IMG_Load2((char*)"gfx/garbage/garbageL.png"))
- && (garbageFill = IMG_Load2((char*)"gfx/garbage/garbageFill.png"))
- && (garbageML = IMG_Load2((char*)"gfx/garbage/garbageML.png"))
- && (garbageM = IMG_Load2((char*)"gfx/garbage/garbageM.png"))
- && (garbageMR = IMG_Load2((char*)"gfx/garbage/garbageMR.png"))
- && (garbageGM = IMG_Load2((char*)"gfx/garbage/garbageGM.png"))
- && (garbageGML = IMG_Load2((char*)"gfx/garbage/garbageGML.png"))
- && (garbageGMR = IMG_Load2((char*)"gfx/garbage/garbageGMR.png"))
- && (smiley[0] = IMG_Load2((char*)"gfx/smileys/0.png"))
- && (smiley[1] = IMG_Load2((char*)"gfx/smileys/1.png"))
- && (smiley[2] = IMG_Load2((char*)"gfx/smileys/2.png"))
- && (smiley[3] = IMG_Load2((char*)"gfx/smileys/3.png"))
+ && (iLevelCheck = IMG_Load2("gfx/iLevelCheck.png"))
+ && (iLevelCheckBox = IMG_Load2("gfx/iLevelCheckBox.png"))
+ && (iLevelCheckBoxMarked = IMG_Load2("gfx/iLevelCheckBoxMarked.png"))
+ && (iCheckBoxArea = IMG_Load2("gfx/iCheckBoxArea.png"))
+ && (boardBackBack = IMG_Load2("gfx/boardBackBack.png"))
+ && (changeButtonsBack = IMG_Load2("gfx/changeButtonsBack.png"))
+ && (garbageTL = IMG_Load2("gfx/garbage/garbageTL.png"))
+ && (garbageT = IMG_Load2("gfx/garbage/garbageT.png"))
+ && (garbageTR = IMG_Load2("gfx/garbage/garbageTR.png"))
+ && (garbageR = IMG_Load2("gfx/garbage/garbageR.png"))
+ && (garbageBR = IMG_Load2("gfx/garbage/garbageBR.png"))
+ && (garbageB = IMG_Load2("gfx/garbage/garbageB.png"))
+ && (garbageBL = IMG_Load2("gfx/garbage/garbageBL.png"))
+ && (garbageL = IMG_Load2("gfx/garbage/garbageL.png"))
+ && (garbageFill = IMG_Load2("gfx/garbage/garbageFill.png"))
+ && (garbageML = IMG_Load2("gfx/garbage/garbageML.png"))
+ && (garbageM = IMG_Load2("gfx/garbage/garbageM.png"))
+ && (garbageMR = IMG_Load2("gfx/garbage/garbageMR.png"))
+ && (garbageGM = IMG_Load2("gfx/garbage/garbageGM.png"))
+ && (garbageGML = IMG_Load2("gfx/garbage/garbageGML.png"))
+ && (garbageGMR = IMG_Load2("gfx/garbage/garbageGMR.png"))
+ && (smiley[0] = IMG_Load2("gfx/smileys/0.png"))
+ && (smiley[1] = IMG_Load2("gfx/smileys/1.png"))
+ && (smiley[2] = IMG_Load2("gfx/smileys/2.png"))
+ && (smiley[3] = IMG_Load2("gfx/smileys/3.png"))
//new in 1.3.2
- && (transCover = IMG_Load2((char*)"gfx/transCover.png"))
+ && (transCover = IMG_Load2("gfx/transCover.png"))
#if LEVELEDITOR
- && (bCreateFile = IMG_Load2((char*)"gfx/editor/bCreateFile.png"))
- && (bDeletePuzzle = IMG_Load2((char*)"gfx/editor/bDeletePuzzle.png"))
- && (bLoadFile = IMG_Load2((char*)"gfx/editor/bLoadFile.png"))
- && (bMoveBack = IMG_Load2((char*)"gfx/editor/bMoveBack.png"))
- && (bMoveDown = IMG_Load2((char*)"gfx/editor/bMoveDown.png"))
- && (bMoveForward = IMG_Load2((char*)"gfx/editor/bMoveForward.png"))
- && (bMoveLeft = IMG_Load2((char*)"gfx/editor/bMoveLeft.png"))
- && (bMoveRight = IMG_Load2((char*)"gfx/editor/bMoveRight.png"))
- && (bMoveUp = IMG_Load2((char*)"gfx/editor/bMoveUp.png"))
- && (bNewPuzzle = IMG_Load2((char*)"gfx/editor/bNewPuzzle.png"))
- && (bSaveFileAs = IMG_Load2((char*)"gfx/editor/bSaveFileAs.png"))
- && (bSavePuzzle = IMG_Load2((char*)"gfx/editor/bSavePuzzle.png"))
- && (bSaveToFile = IMG_Load2((char*)"gfx/editor/bSaveToFile.png"))
- && (bTestPuzzle = IMG_Load2((char*)"gfx/editor/bTestPuzzle.png"))
+ && (bCreateFile = IMG_Load2("gfx/editor/bCreateFile.png"))
+ && (bDeletePuzzle = IMG_Load2("gfx/editor/bDeletePuzzle.png"))
+ && (bLoadFile = IMG_Load2("gfx/editor/bLoadFile.png"))
+ && (bMoveBack = IMG_Load2("gfx/editor/bMoveBack.png"))
+ && (bMoveDown = IMG_Load2("gfx/editor/bMoveDown.png"))
+ && (bMoveForward = IMG_Load2("gfx/editor/bMoveForward.png"))
+ && (bMoveLeft = IMG_Load2("gfx/editor/bMoveLeft.png"))
+ && (bMoveRight = IMG_Load2("gfx/editor/bMoveRight.png"))
+ && (bMoveUp = IMG_Load2("gfx/editor/bMoveUp.png"))
+ && (bNewPuzzle = IMG_Load2("gfx/editor/bNewPuzzle.png"))
+ && (bSaveFileAs = IMG_Load2("gfx/editor/bSaveFileAs.png"))
+ && (bSavePuzzle = IMG_Load2("gfx/editor/bSavePuzzle.png"))
+ && (bSaveToFile = IMG_Load2("gfx/editor/bSaveToFile.png"))
+ && (bTestPuzzle = IMG_Load2("gfx/editor/bTestPuzzle.png"))
#endif
//end new in 1.3.2
//new in 1.4.0
- && (bSkip = IMG_Load2((char*)"gfx/bBlank.png"))
- && (bNext = IMG_Load2((char*)"gfx/bBlank.png"))
- && (bRetry = IMG_Load2((char*)"gfx/bBlank.png"))
+ && (bSkip = IMG_Load2("gfx/bBlank.png"))
+ && (bNext = IMG_Load2("gfx/bBlank.png"))
+ && (bRetry = IMG_Load2("gfx/bBlank.png"))
))
//if there was a problem ie. "File not found"
{
- cout << "Error loading image file: " << SDL_GetError() << endl;
+ cerr << "Error: Failed to load image file: " << SDL_GetError() << endl;
exit(1);
}
try
@@ -538,7 +538,7 @@ static int InitImages()
}
catch (exception e)
{
- cout << e.what() << endl;
+ cerr << e.what() << endl;
exit(1);
}
@@ -684,16 +684,16 @@ static int InitImages()
if (!NoSound)
{
//And here the music:
- bgMusic = Mix_LoadMUS2((char*)"music/bgMusic.ogg");
- highbeatMusic = Mix_LoadMUS2((char*)"music/highbeat.ogg");
+ bgMusic = Mix_LoadMUS2("music/bgMusic.ogg");
+ highbeatMusic = Mix_LoadMUS2("music/highbeat.ogg");
//the music... we just hope it exists, else the user won't hear anything
//Same goes for the sounds
- boing = Mix_LoadWAV2((char*)"sound/pop.ogg");
- applause = Mix_LoadWAV2((char*)"sound/applause.ogg");
- photoClick = Mix_LoadWAV2((char*)"sound/cameraclick.ogg");
- typingChunk = Mix_LoadWAV2((char*)"sound/typing.ogg");
- counterChunk = Mix_LoadWAV2((char*)"sound/counter.ogg");
- counterFinalChunk = Mix_LoadWAV2((char*)"sound/counterFinal.ogg");
+ boing = Mix_LoadWAV2("sound/pop.ogg");
+ applause = Mix_LoadWAV2("sound/applause.ogg");
+ photoClick = Mix_LoadWAV2("sound/cameraclick.ogg");
+ typingChunk = Mix_LoadWAV2("sound/typing.ogg");
+ counterChunk = Mix_LoadWAV2("sound/counter.ogg");
+ counterFinalChunk = Mix_LoadWAV2("sound/counterFinal.ogg");
} //All sound has been loaded or not
return 0;
} //InitImages()
@@ -702,7 +702,8 @@ static int InitImages()
//Unload images and fonts and sounds
void UnloadImages()
{
- cout << "Unloading data..." << endl;
+ if(verboseLevel)
+ cout << "Unloading data..." << endl;
if (!NoSound) //Only unload then it has been loaded!
{
Mix_HaltMusic();
@@ -833,7 +834,7 @@ static int LoadPuzzleStages()
// return 1;
if (!PHYSFS_exists(("puzzles/"+puzzleName).c_str()))
{
- cout << "File not in blockattack.data: " << ("puzzles/"+puzzleName) << endl;
+ cerr << "Warning: File not in blockattack.data: " << ("puzzles/"+puzzleName) << endl;
return -1; //file doesn't exist
}
PhysFS::ifstream inFile(("puzzles/"+puzzleName).c_str());
@@ -1103,7 +1104,6 @@ public:
int addExplosion(int x, int y)
{
- //cout << "Tries to add an explosion" << endl;
int explosionNumber = 0;
while ((explosionUsed[explosionNumber])&&(explosionNumber<maxNumberOfBalls))
explosionNumber++;
@@ -1112,7 +1112,6 @@ public:
currentTime = SDL_GetTicks();
explosionArray[explosionNumber] = anExplosion(x,y);
explosionUsed[explosionNumber] = true;
- //cout << "Explosion added" << endl;
return 1;
} //addBall
@@ -1130,7 +1129,6 @@ public:
{
explosionArray[i].~anExplosion();
explosionUsed[i] = false;
- //cout << "Explosion removed" << endl;
}
}
else
@@ -1212,13 +1210,11 @@ public:
int addText(int x, int y,string Text,unsigned int Time)
{
- //cout << "Tries to add text" << endl;
int textNumber = 0;
while ((textNumber<maxNumberOfBalls)&&((textUsed[textNumber])||(oldTextUsed[textNumber])))
textNumber++;
if (textNumber==maxNumberOfBalls)
return -1;
- //cout << "adding to: " << textNumber << ":" << textUsed[textNumber] << ":" << &textArray[textNumber] << endl;
currentTime = SDL_GetTicks();
textArray[textNumber] = textMessage(x,y,Text.c_str(),Time);
textUsed[textNumber] = true;
@@ -1227,7 +1223,6 @@ public:
void update()
{
- //cout << "Running update" << endl;
currentTime = SDL_GetTicks();
for (int i = 0; i<maxNumberOfBalls; i++)
{
@@ -1269,7 +1264,7 @@ public:
BlockGameSdl(int tx, int ty)
{
- tmp = IMG_Load2((char*)"gfx/BackBoard.png");
+ tmp = IMG_Load2("gfx/BackBoard.png");
sBoard = SDL_DisplayFormat(tmp);
SDL_FreeSurface(tmp);
//BlockGame::BlockGame(tx,ty);
@@ -1375,7 +1370,6 @@ private:
}
else
{
- //cout << "In garbage" << endl;
garbageSize++;
}
@@ -1525,7 +1519,6 @@ private:
default:
DrawIMG(garbageGM, sBoard,j*bsize, 12*bsize-i*bsize-pixels);
}
- //cout << "IS: " << board[j][i] << endl;
}
@@ -1544,7 +1537,6 @@ private:
}
else
{
- //cout << "In garbage" << endl;
garbageSize++;
}
@@ -1673,7 +1665,8 @@ public:
//writeScreenShot saves the screen as a bmp file, it uses the time to get a unique filename
void writeScreenShot()
{
- cout << "Saving screenshot" << endl;
+ if(verboseLevel)
+ cout << "Saving screenshot" << endl;
int rightNow = (int)time(NULL);
/*#if defined(__unix__)
char buf[514];
@@ -2020,7 +2013,8 @@ bool OpenFileDialogbox(int x, int y, char *name)
int mousex, mousey;
ListFiles lf = ListFiles();
string folder = (string)SHAREDIR+(string)"/puzzles";
- cout << "Looking in " << folder << endl;
+ if(verboseLevel)
+ cout << "Looking in " << folder << endl;
lf.setDirectory(folder.c_str());
#ifdef __unix__
string homeFolder = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/puzzles";
@@ -2122,7 +2116,8 @@ bool SelectThemeDialogbox(int x, int y, char *name)
int mousex, mousey;
ListFiles lf = ListFiles();
string folder = (string)SHAREDIR+(string)"/themes";
- cout << "Looking in " << folder << endl;
+ if(verboseLevel)
+ cout << "Looking in " << folder << endl;
lf.setDirectory(folder.c_str());
#ifdef __unix__
string homeFolder = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/themes";
@@ -2224,7 +2219,8 @@ bool OpenReplayDialogbox(int x, int y, char *name)
bool done = false; //We are done!
int mousex, mousey;
ListFiles lf = ListFiles();
- cout << "Ready to set directory!" << endl;
+ if(verboseLevel)
+ cout << "Ready to set directory!" << endl;
#ifdef __unix__
string directory = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/replays";
#elif WIN32
@@ -2233,7 +2229,8 @@ bool OpenReplayDialogbox(int x, int y, char *name)
string directory = "./replays";
#endif
lf.setDirectory(directory);
- cout << "Directory sat" << endl;
+ if(verboseLevel)
+ cout << "Directory sat" << endl;
Uint8* keys;
string strHolder;
MakeBackground(xsize,ysize);
@@ -3159,11 +3156,11 @@ int main(int argc, char *argv[])
#if defined(__unix__)
//Compiler warns about unused result. The users envisonment should normally give the user all the information he needs
if(system("mkdir -p ~/.gamesaves/blockattack/screenshots"))
- cout << "mkdir error creating ~/.gamesaves/blockattack/screenshots" << endl;
+ cerr << "mkdir error creating ~/.gamesaves/blockattack/screenshots" << endl;
if(system("mkdir -p ~/.gamesaves/blockattack/replays"))
- cout << "mkdir error creating ~/.gamesaves/blockattack/replays" << endl;
+ cerr << "mkdir error creating ~/.gamesaves/blockattack/replays" << endl;
if(system("mkdir -p ~/.gamesaves/blockattack/puzzles"))
- cout << "mkdir error creating ~/.gamesaves/blockattack/puzzles" << endl;
+ cerr << "mkdir error creating ~/.gamesaves/blockattack/puzzles" << endl;
#elif defined(_WIN32)
//Now for Windows NT/2k/xp/2k3 etc.
string tempA = getMyDocumentsPath()+"\\My Games";
@@ -3188,14 +3185,15 @@ int main(int argc, char *argv[])
forceredraw = 2;
while (argc>argumentNr)
{
- char helpString[] = "--help";
- char priorityString[] = "-priority";
- char forceRedrawString[] = "-forceredraw";
- char forcepartdrawString[] = "-forcepartdraw";
- char singlePuzzleString[] = "-SP";
- char noSoundAtAll[] = "-nosound";
- char IntegratedEditor[] = "-editor";
- char selectTheme[] = "-theme";
+ const char helpString[] = "--help";
+ const char priorityString[] = "-priority";
+ const char forceRedrawString[] = "-forceredraw";
+ const char forcepartdrawString[] = "-forcepartdraw";
+ const char singlePuzzleString[] = "-SP";
+ const char noSoundAtAll[] = "-nosound";
+ const char IntegratedEditor[] = "-editor";
+ const char selectTheme[] = "-theme";
+ const char verbose[] = "-v";
if (!(strncmp(argv[argumentNr],helpString,6)))
{
cout << "Block Attack Help" << endl << "--help " << _("Displays this message") <<
@@ -3212,7 +3210,8 @@ int main(int argc, char *argv[])
}
if (!(strncmp(argv[argumentNr],priorityString,9)))
{
- cout << "Priority mode" << endl;
+ if(verboseLevel)
+ cout << "Priority mode" << endl;
highPriority = true;
}
if (!(strncmp(argv[argumentNr],forceRedrawString,12)))
@@ -3232,7 +3231,8 @@ int main(int argc, char *argv[])
singlePuzzleNr = (argv[argumentNr+1][0]-'0');
singlePuzzleFile = argv[argumentNr+2];
argumentNr+=2;
- cout << "SinglePuzzleMode, File: " << singlePuzzleFile << " and Level: " << singlePuzzleNr << endl;
+ if(verboseLevel)
+ cout << "SinglePuzzleMode, File: " << singlePuzzleFile << " and Level: " << singlePuzzleNr << endl;
}
if (!(strncmp(argv[argumentNr],noSoundAtAll,8)))
{
@@ -3242,7 +3242,8 @@ int main(int argc, char *argv[])
{
#if LEVELEDITOR
editorMode = true;
- cout << "Integrated Puzzle Editor Activated" << endl;
+ if(verboseLevel)
+ cout << "Integrated Puzzle Editor Activated" << endl;
#else
cout << "Integrated Puzzle Editor was disabled at compile time" << endl;
return -1;
@@ -3251,9 +3252,14 @@ int main(int argc, char *argv[])
if(!(strncmp(argv[argumentNr],selectTheme,6)))
{
argumentNr++; //Go to themename (the next argument)
- cout << "Theme set to \"" << argv[argumentNr] << '"' << endl;
+ if(verboseLevel)
+ cout << "Theme set to \"" << argv[argumentNr] << '"' << endl;
Config::getInstance()->setString("themename",argv[argumentNr]);
}
+ if(!(strcmp(argv[argumentNr],verbose)))
+ {
+ verboseLevel++;
+ }
argumentNr++;
} //while
} //if
@@ -3319,7 +3325,7 @@ int main(int argc, char *argv[])
//Init SDL
if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
{
- cout << "Unable to init SDL: " << SDL_GetError() << endl;
+ cerr << "Unable to init SDL: " << SDL_GetError() << endl;
exit(1);
}
atexit(SDL_Quit); //quits SDL when the game stops for some reason (like you hit exit or Esc)
@@ -3337,28 +3343,30 @@ int main(int argc, char *argv[])
if (!NoSound) //If sound has not been disabled, then load the sound system
if (Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048) < 0)
{
- cout << "Warning: Couldn't set 44100 Hz 16-bit audio - Reason: " << SDL_GetError() << endl
+ cerr << "Warning: Couldn't set 44100 Hz 16-bit audio - Reason: " << SDL_GetError() << endl
<< "Sound will be disabled!" << endl;
NoSound = true; //Tries to stop all sound from playing/loading
}
SDL_WM_SetCaption("Block Attack - Rise of the Blocks", NULL); //Sets title line
-
- //Copyright notice:
- cout << "Block Attack - Rise of the Blocks (" << VERSION_NUMBER << ")" << endl << "http://blockattack.sf.net" << endl << "Copyright 2004-2011 Poul Sander" << endl <<
- "A SDL based game (see www.libsdl.org)" << endl <<
- "The game is availeble under the GPL, see COPYING for details." << endl;
+ if(verboseLevel)
+ {
+ //Copyright notice:
+ cout << "Block Attack - Rise of the Blocks (" << VERSION_NUMBER << ")" << endl << "http://blockattack.sf.net" << endl << "Copyright 2004-2011 Poul Sander" << endl <<
+ "A SDL based game (see www.libsdl.org)" << endl <<
+ "The game is availeble under the GPL, see COPYING for details." << endl;
#if defined(_WIN32)
- cout << "Windows build" << endl;
+ cout << "Windows build" << endl;
#elif defined(__linux__)
- cout << "Linux build" << endl;
+ cout << "Linux build" << endl;
#elif defined(__unix__)
- cout << "Unix build" << endl;
+ cout << "Unix build" << endl;
#else
- cout << "Alternative build" << endl;
+ cout << "Alternative build" << endl;
#endif
- cout << "-------------------------------------------" << endl;
+ cout << "-------------------------------------------" << endl;
+ }
keySettings[0].up= SDLK_UP;
@@ -3411,7 +3419,8 @@ int main(int argc, char *argv[])
strncpy(player1name,(configSettings->getString("player1name")).c_str(),28);
if(configSettings->exists("player2name"))
strncpy(player2name,(configSettings->getString("player2name")).c_str(),28);
- cout << "Data loaded from config file" << endl;
+ if(verboseLevel)
+ cout << "Data loaded from config file" << endl;
}
else
{
@@ -3448,11 +3457,13 @@ int main(int argc, char *argv[])
optionsFile.read(reinterpret_cast<char*>(&joyplay2),sizeof(bool));
}
optionsFile.close();
- cout << "Data loaded from oldstyle options file" << endl;
+ if(verboseLevel)
+ cout << "Data loaded from oldstyle options file" << endl;
}
else
{
- cout << "Unable to load options file, using default values" << endl;
+ if(verboseLevel)
+ cout << "Unable to load options file, using default values" << endl;
}
}
@@ -3479,7 +3490,7 @@ int main(int argc, char *argv[])
if ( screen == NULL )
{
- cout << "Unable to set " << xsize << "x" << ysize << " video: " << SDL_GetError() << endl;
+ cerr << "Unable to set " << xsize << "x" << ysize << " video: " << SDL_GetError() << endl;
exit(1);
}
@@ -3491,7 +3502,8 @@ int main(int argc, char *argv[])
SDL_Surface *icon = IMG_Load2("gfx/icon.png");
SDL_WM_SetIcon(icon,NULL);
- cout << "Images loaded" << endl;
+ if(verboseLevel)
+ cout << "Images loaded" << endl;
//InitMenues();
@@ -3580,11 +3592,12 @@ int main(int argc, char *argv[])
commonTime ct = TimeHandler::ms2ct(SDL_GetTicks());
//cout << "Block Attack - Rise of the Blocks ran for: " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << endl;
- cout << boost::format("Block Attack - Rise of the Blocks ran for: %1% hours %2% mins and %3% secs") % ct.hours % ct.minutes % ct.seconds << endl;
+ if(verboseLevel)
+ cout << boost::format("Block Attack - Rise of the Blocks ran for: %1% hours %2% mins and %3% secs") % ct.hours % ct.minutes % ct.seconds << endl;
ct = TimeHandler::addTime("totalTime",ct);
-
- cout << "Total run time is now: " << ct.days << " days " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << endl;
+ if(verboseLevel)
+ cout << "Total run time is now: " << ct.days << " days " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << endl;
Stats::getInstance()->save();
@@ -3694,7 +3707,8 @@ int runGame(int gametype, int level)
SDL_Flip(screen);*/
//game loop
int done = 0;
- cout << "Starting game loop" << endl;
+ if(verboseLevel)
+ cout << "Starting game loop" << endl;
bool mustsetupgame = true;
diff --git a/source/code/mainVars.hpp b/source/code/mainVars.hpp index 8b77ff7..47cf09c 100644 --- a/source/code/mainVars.hpp +++ b/source/code/mainVars.hpp
@@ -35,7 +35,7 @@ http://blockattack.sf.net
using namespace std; //remove it if you dare...
-char sharedir[] = SHAREDIR;
+const char sharedir[] = SHAREDIR;
//All graphic in the game (as pointers):
static SDL_Surface *background; //Stores background
@@ -282,6 +282,8 @@ char FPS[10];
int lastNrOfPlayers; //1 if 1 player and 2 if vs. mode
+int verboseLevel = 0;
+
//keySetup
int player1keys, player2keys;
bool mouseplay1=false; //The mouse works on the play field
diff --git a/source/code/menudef.cpp b/source/code/menudef.cpp index 7143e5f..3677d55 100644 --- a/source/code/menudef.cpp +++ b/source/code/menudef.cpp
@@ -29,6 +29,8 @@ Copyright (C) 2011 Poul Sander
using namespace std;
+extern int verboseLevel;
+
//Menu
static void PrintHi(Button* b)
{
@@ -54,7 +56,8 @@ extern control keySettings[3];
static string getKeyName(SDLKey key)
{
string keyname(SDL_GetKeyName(key));
- cout << key << " translated to " << keyname << endl;
+ if(verboseLevel)
+ cout << key << " translated to " << keyname << endl;
return keyname;
}
diff --git a/source/code/replay.cpp b/source/code/replay.cpp index 5556e52..33ee750 100644 --- a/source/code/replay.cpp +++ b/source/code/replay.cpp
@@ -29,6 +29,8 @@ Handles replay
#include "replay.h"
+extern int verboseLevel;
+
Replay::Replay()
{
isLoaded = false;
@@ -51,7 +53,8 @@ Replay::Replay(const Replay& r)
bool Replay::saveReplay(string filename)
{
//Saving as fileversion 4
- cout << "Saving as version 4 save file" << endl;
+ if(verboseLevel)
+ cout << "Saving as version 4 save file" << endl;
ofstream saveFile;
saveFile.open(filename.c_str(),ios::binary|ios::trunc);
if (saveFile)
@@ -73,7 +76,8 @@ bool Replay::saveReplay(string filename)
bool Replay::saveReplay(string filename,Replay p2)
{
//Saving as fileversion 4
- cout << "Saving as version 4 save file (2 players)" << endl;
+ if(verboseLevel)
+ cout << "Saving as version 4 save file (2 players)" << endl;
ofstream saveFile;
saveFile.open(filename.c_str(),ios::binary|ios::trunc);
if (saveFile)
@@ -136,11 +140,12 @@ bool Replay::loadReplay(string filename)
}
loadFile.close();
- cout << "Loaded 1 player, actions.size="<< actions.size() << endl;
+ if(verboseLevel)
+ cout << "Loaded 1 player, actions.size="<< actions.size() << endl;
}
else
{
- cout << "File not found or couldn't open: " << filename << endl;
+ cerr << "File not found or couldn't open: " << filename << endl;
return false;
}
@@ -188,11 +193,12 @@ bool Replay::loadReplay2(string filename)
}
loadFile.close();
- cout << "Loaded 2 player, actions.size="<< actions.size() << endl;
+ if(verboseLevel)
+ cout << "Loaded 2 player, actions.size="<< actions.size() << endl;
}
else
{
- cout << "File not found or couldn't open: " << filename << endl;
+ cerr << "File not found or couldn't open: " << filename << endl;
return false;
}
@@ -214,7 +220,9 @@ vector<Action> Replay::getActions() const {
void Replay::addAction(int tick, int action, string param)
{
+#if DEBUG
cout << tick << " " << action << " " << param << endl;
+#endif
Action a;
a.time = tick;
a.action = action;