-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.cpp
More file actions
264 lines (230 loc) · 6.58 KB
/
game.cpp
File metadata and controls
264 lines (230 loc) · 6.58 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#include "game.h"
#include "shapeList.h"
/*---------------------------------------------------
The menu is taken care of in game cpp, it recieves all the input from the user and according to what input is we got we'll go to the desired menu or
-------------------------------------------------*/
void Game::startGame() //we implemented cases for all the different options
{
system("color 0B");
while(m_menu.getInput() != END_GAME)
{
clrscr();
m_menu.openPrimeMenu();
switch( m_menu.getInput() )
{
case(ADD_SHAPE):
{
int n;
clrscr();
cout<<"please enter- (1)square (2)diamond\n";
cin>>n;
m_list.addShape(n);
if (!m_list.m_tail->m_shape->isShapeLegal() )
m_list.deleteShapeNode();
else
{
m_list.drawShapes();
this->escMoment();
}
}break;
case(DRAW_SQUARES):
{
if(m_list.getCounter()>0)
m_list.drawAllSquaresWithMovements();
else
{
cout<<"there are no squares\n";
Sleep(TWO_SECONDS);
}
}break;
case(PICK_SQUARE):
{
if(m_list.getCounter()>0)
{
m_menu.getInputForSecMenu();
m_curr = m_list.findShapeNode( m_menu.getXForSecMenu(), m_menu.getYForSecMenu() );
if(m_curr!=NULL)
{
m_list.drawShapes();
m_curr->m_shape->drawElectedShape();
if( m_menu.isInConsoleLimits() ) //getXForSecMenu() >= 0 && m_menu.getXForSecMenu() <= MAX_ROWS && m_menu.getYForSecMenu() >= 0 && m_menu.getYForSecMenu() <= MAX_COLS)
m_menu.blinkMatchingCoord();
else
this->escMoment();
this->activateSecMenu();
}
else
{
m_list.drawShapes();
m_menu.blinkMatchingCoord();
}
}
else
{
cout<<"there are no sqaures\n";
Sleep(TWO_SECONDS);
}
}break;
}
}
}
void Game::activateSecMenu() //opens up the secondary menu for you and like the first menu we used switch case
{
m_menu.openSecMenu();
switch( m_menu.getInput() )
{
case(CANCEL):
{
m_list.drawShapes();
this->escMoment();
}break;
case(DELETER):
{
m_list.moveShapeNodeToEndOfList(m_curr);
m_list.deleteShapeNode();
}break;
case(MOVE_UP):
{
m_list.moveShapeNodeToEndOfList(m_curr);
}break;
case(MERGE):
{
m_list.merge( m_curr, m_curr->m_shape->get_x(), m_curr->m_shape->get_y() );
}break;
case(ADD_ANIME): //we've added a new case if you want to animate a single square and see it go out of the borders
{
char charForDone = 0;
clrscr();
m_curr->m_shape->getMovement();
clrscr();
m_list.putListInMatrixSpecial(BEFORE);
while(charForDone!=ESC)
{
if(kbhit() )
{
charForDone = getch();
}
m_curr->m_shape->updateShape(ADD_ANIME);
m_list.putListInMatrixSpecial(AFTER);
m_list.printThruMatrixComapre();
m_list.swapMatrixes();
Sleep(TENTH_SECOND);
}
clrscr();
this->activateSecMenu();
}break;
case(ADD_DOUBLE_ANIME): //and this is the other new case which takes care of animating two squares with collision and they stay within the borders
{
this->activeDoubleAnime();
}break;
}
}
void Game::activeDoubleAnime()
{
char charForDone = 0;
clrscr();
cout<<"for the 2nd square-\n";
m_menu.getInputForSecMenu();
m_curr2 = m_list.findShapeNode( m_menu.getXForSecMenu(), m_menu.getYForSecMenu() );
if(m_curr2)
{
cout<<"for the 1st sqaure-\n";
m_curr->m_shape->getMovement();
cout<<"\nfor the 2nd square-\n";
m_curr2->m_shape->getMovement();
clrscr();
if(m_curr->m_shape->get_x() < MIN_ROWS || ( m_curr->m_shape->get_x() + m_curr->m_shape->get_length() >MAX_ROWS) || m_curr->m_shape->get_y() < MIN_COLS || m_curr->m_shape->get_y() + m_curr->m_shape->get_length() > MAX_COLS
|| m_curr2->m_shape->get_x() < MIN_ROWS || ( m_curr2->m_shape->get_x() + m_curr2->m_shape->get_length() > MAX_ROWS) || m_curr2->m_shape->get_y() < MIN_COLS || m_curr2->m_shape->get_y() + m_curr2->m_shape->get_length() > MAX_COLS )
throw("out of borders");
//we've added an exception here that appears if you try to move a sqaure thats on the border or passing it..
if(m_curr != m_curr2)
{
this->handleDoubleAnimeCase(); // and also if you dont choose a square in the right coordinate or you choose the same square by accident it will be ok
}
else
{
clrscr();
cout<<"You can't choose the same square Twice\n";
Sleep(TWO_SECONDS);
clrscr();
}
}
else
{
clrscr();
cout<<"there is no Square at this location\n";
Sleep(TWO_SECONDS);
clrscr();
}
}
void Game::handleDoubleAnimeCase() //when we were working on the double anime we used two escapes.. this means that if you want to quit the double anime before the squares collided you'll have to hit esc twice, it was more comfortable for us to work like this
{
char charForDone = 0;
double curr1Speed= ( abs(m_curr->m_shape->getXmove() ) + abs( m_curr->m_shape->getYmove() ) );
double curr2Speed= ( abs(m_curr2->m_shape->getXmove() ) + abs( m_curr2->m_shape->getYmove() ) );
int len1 = m_curr->m_shape->get_length();
int len2 = m_curr2->m_shape->get_length();
m_list.putListInMatrixSpecial(BEFORE);
while(charForDone!=ESC && m_list.whichMergeForMovements(m_curr, m_curr2) )
{
if(kbhit() )
{
charForDone = getch();
}
m_curr->m_shape->updateShape(ADD_DOUBLE_ANIME);
m_curr2->m_shape->updateShape(ADD_DOUBLE_ANIME);
m_list.putListInMatrixSpecial(AFTER);
m_list.printThruMatrixComapre();
m_list.swapMatrixes();
Sleep(TENTH_SECOND);
}
// Sleep(2000);
clrscr();
m_list.putListInMatrixSpecial(BEFORE);
/* TODO:: FIX IT
charForDone = 0;
while(charForDone!=ESC)
{
if(kbhit() )
charForDone = getch();
if(m_curr2->m_shape)
{
cout<<"got here to the first\n" ;Sleep(1000);
m_curr2->m_shape->updateShape(ADD_DOUBLE_ANIME);
}
if(m_curr->m_shape)
{
cout<<"got here to the second\n" ;Sleep(1000);
//m_curr->m_shape->updateShape(ADD_DOUBLE_ANIME);
}
m_list.putListInMatrixSpecial(AFTER);
m_list.printThruMatrixComapre();
m_list.swapMatrixes();
Sleep(TENTH_SECOND);
}
*/
clrscr();
}
void Game::drawSquares() //drawsquares function goes over the list we defined in game.h and prints it
{
clrscr();
cout<<"number of existing squares: "<<m_list.getCounter();
Sleep(ONE_SECOND);
clrscr();
ShapeNode* curr = m_list.m_head;
while(curr)
{
curr->m_shape->drawShape();
curr=curr->next;
}
}
void Game::escMoment() // takes care of esc so you can go back to whatever menu you are on after printing the squares on screen
{
char charForDone=0;
while(charForDone!=ESC)
{
kbhit();
charForDone = getch();
}
clrscr();
}