git repos / blockattack-game

commit 87a0a1db

sago007 · 2016-04-16 13:11
87a0a1db49db9ee92f0847c9588646edb44b6c67 patch · browse files
parent 30ca55656d8bd09cabbb27f61eabef27da529ad1

Moved most of the variable initialization out of the contructor

Changed files

M source/code/BlockGame.cpp before
M source/code/BlockGame.hpp before
diff --git a/source/code/BlockGame.cpp b/source/code/BlockGame.cpp index 38c3ae0..fb7264e 100644 --- a/source/code/BlockGame.cpp +++ b/source/code/BlockGame.cpp
@@ -81,31 +81,7 @@ int BlockGame::firstUnusedChain() {
//Constructor
BlockGame::BlockGame() {
srand((int)time(nullptr));
- nrFellDown = 0;
- nrPushedPixel = 0;
- nrStops=0;
- //topx = tx;
- //topy = ty;
- cursorx = 2;
- cursory = 3;
- stop = 0;
- pixels = 0;
- score = 0;
- bGameOver = false;
- bDraw = false;
- timetrial = false;
- stageClear = false;
- vsMode = false;
- puzzleMode = false;
- linesCleared = 0;
- AI_Enabled = false;
AI_MoveSpeed=100;
- AIlineToClear = 0;
- AIcolorToClear = 0;
- hasWonTheGame = false;
- combo=0; //counts
- chain=0;
- hangTicks = 0;
baseSpeed = 0.5; //All other speeds are relative to this
speed = baseSpeed;
speedLevel = 1;
@@ -120,10 +96,6 @@ BlockGame::BlockGame() {
board[i][j] = -1;
}
}
- for (int i=0; i<NUMBEROFCHAINS; i++) {
- chainUsed[i]=false;
- chainSize[i] = 0;
- }
lastCounter = -1; //To prevent the final chunk to be played when stating the program
} //Constructor
diff --git a/source/code/BlockGame.hpp b/source/code/BlockGame.hpp index 6a04847..990f724 100644 --- a/source/code/BlockGame.hpp +++ b/source/code/BlockGame.hpp
@@ -84,25 +84,26 @@ struct GarbageStruct {
class BlockGame
{
private:
- int prevTowerHeight;
- bool bGarbageFallLeft;
+ int prevTowerHeight = 0;
+ bool bGarbageFallLeft = false;
bool singlePuzzle = false;
- int nextGarbageNumber;
- int pushedPixelAt;
- int nrPushedPixel, nrFellDown;
- unsigned int nrStops;
+ int nextGarbageNumber = 0;
+ int pushedPixelAt = 0;
+ int nrPushedPixel = 0;
+ int nrFellDown = 0;
+ unsigned int nrStops = 0;
bool garbageToBeCleared[7][30];
- unsigned int lastAImove;
+ unsigned int lastAImove = 0;
- int AI_LineOffset; //how many lines have changed since command
- int hangTicks; //How many times have hang been decreased?
+ int AI_LineOffset = 0; //how many lines have changed since command
+ int hangTicks = 0; //How many times have hang been decreased?
//int the two following index 0 may NOT be used (what the fuck did I meen?)
- int chainSize[NUMBEROFCHAINS]; //Contains the chains
- bool chainUsed[NUMBEROFCHAINS]; //True if the chain is used
+ int chainSize[NUMBEROFCHAINS]{}; //Contains the chains
+ bool chainUsed[NUMBEROFCHAINS]{}; //True if the chain is used
- unsigned int nextRandomNumber;
- int Level; //Only used in stageClear and puzzle (not implemented)
+ unsigned int nextRandomNumber = 0;
+ int Level = 0; //Only used in stageClear and puzzle (not implemented)
int rand2();
int firstUnusedChain();
@@ -129,8 +130,8 @@ protected:
int stageClearLimit = 0; //stores number of lines user must clear to win
int combo = 0;
int chain = 0;
- int cursorx = 0; //stores cursor position
- int cursory = 0; // -||-
+ int cursorx = 2; //stores cursor position
+ int cursory = 3; // -||-
int mouse_cursorx = -1; //Stores the mouse hold cursor. -1 if nothing is selected.
int mouse_cursory = -1;
double speed = 0.0;