-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathControl.cpp
More file actions
64 lines (54 loc) · 1.56 KB
/
Control.cpp
File metadata and controls
64 lines (54 loc) · 1.56 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
/*
* This class control all the game
*/
#include "Control.h"
Control::Control() = default;
void Control::loop(GameData Data, Draw DrawUi, GameOperator Operator) {
bool flagQuit = false;
bool flagGameOver = false;
Data.InitNewGame();
while (true) {
DrawUi.PrintUi(Data, flagQuit, flagGameOver);
int Tempop;
if (flagGameOver) {
Tempop = Operator.GetMoveNumber();
while (Tempop != YES && Tempop != NO)
Tempop = Operator.GetMoveNumber();
if (Tempop == YES) {
Data.InitNewGame();
flagGameOver = false;
} else
break;
}
else if (flagQuit) {
Tempop = Operator.GetMoveNumber();
while (Tempop != YES && Tempop != NO)
Tempop = Operator.GetMoveNumber();
if (Tempop == YES)
break;
else
flagQuit = false;
}
else
{
Tempop = Operator.GetMoveNumber();
if (Tempop == QUIT)
flagQuit = true;
if (Tempop != NO && Tempop != YES && Tempop != QUIT) {
Operator.Move(Data, Tempop);
if (Data.IsGameOver())
flagGameOver = true;
if(Data.IsMove)
Data.MakeNewNumber();
}
}
DrawUi.ClearScreen();
}
}
void Control::begin() {
Draw DrawUi;
GameData Data;
GameOperator Operator;
srand((unsigned) time(NULL));
loop(Data, DrawUi, Operator);
}