Repository navigation
Expand file tree
/
Copy pathGameMechs.cpp
More file actions
166 lines (119 loc) · 2.76 KB
/
Copy pathGameMechs.cpp
File metadata and controls
166 lines (119 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "GameMechs.h"
#include "MacUILib.h"
GameMechs::GameMechs() //default constructor
{
input = 0;
exitFlag = false;
loseFlag = false;
score = 0;
boardSizeX = 30;
boardSizeY = 15;
speed = 0; //initial speed level
food.setObjPos(-100,-100,'*'); //initialize it outside the game board
}
GameMechs::GameMechs(int boardX, int boardY) //other constructor
{
input = 0;
exitFlag = false;
loseFlag = false;
score = 0;
boardSizeX = boardX;
boardSizeY = boardY;
speed = 0;
food.setObjPos(-100,-100,'*');//initialize it outside the game board
}
GameMechs::~GameMechs() //we do not need destructor
{
//nothing on heap for now
}
bool GameMechs::getExitFlagStatus() const //returns exit flag
{
return exitFlag;
}
bool GameMechs::getLoseFlagStatus() const //returns losing status
{
return loseFlag;
}
char GameMechs::getInput() //receives inputs
{
if(MacUILib_hasChar()!=0)
{
input = MacUILib_getChar();
}
return input;
}
int GameMechs::getScore() const //returns scores
{
return score;
}
void GameMechs::incrementScore() //increment sscore
{
score++;
}
int GameMechs::getBoardSizeX() const //returns board's row size
{
return boardSizeX;
}
int GameMechs::getBoardSizeY() const //returns boards column size
{
return boardSizeY;
}
void GameMechs::setExitTrue() //stes the exit statustrue
{
exitFlag = true;
}
void GameMechs::setLoseFlag() //sets loseflag as true
{
loseFlag = true;
}
void GameMechs::setInput(char this_input) //stes input
{
input = this_input;
}
void GameMechs::clearInput() // resets input
{
input = 0;
}
int GameMechs::getSpeed() const //returns speed
{
return speed;
}
void GameMechs::setSpeed(char symbol) //speed management function
{
if (symbol == '+')
{
speed++;
if (speed >= 4) {speed = 4;}
}
else
{
speed--;
if (speed <= 0) {speed = 0;}
}
}
void GameMechs::setFoodPos(int x, int y, char symbol) //sets food
{
food.setObjPos(x, y, symbol);
}
objPos GameMechs::getFoodPos() const //returns food
{
return food;
}
void GameMechs::generateFood(objPosArrayList* blockoff) //generate food at randomlocations
{
int randX, randY;
bool uniquePos = false;
while(!uniquePos)
{
randX = rand()%(boardSizeX-2) + 1; //generates random co-ordinates
randY = rand()%(boardSizeY-2) + 1;
for (int i=0; i<blockoff->getSize(); i++) //makes sure it dosent generate on the sanke body
{
if(randX != blockoff->getElement(i).pos->x && randY != blockoff->getElement(i).pos->y)
{
uniquePos = true;
setFoodPos(randX, randY, '*');
}
}
}
}