-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.h
187 lines (183 loc) · 5.47 KB
/
game.h
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
#ifndef CGAME_H
#define CGAME_H
#include "knowledge.h"
#include <stdio.h>
#include <QProcess>
#include <QObject>
#include <QTimer>
#include <iostream>
#include <string>
#include <sstream>
#include <QTime>
#include <QCoreApplication>
#include <QEventLoop>
/**
* @brief
* The game driver
*/
class CGame : public QObject
{
Q_OBJECT
public:
CGame(QObject *parent = 0);
~CGame();
private:
QTimer *p1CTimer, *p2CTimer, *p3CTimer, *p4CTimer; /**< Separated timers for players */
QProcess *p1, *p2, *p3, *p4; /**< Separated processes for players which runs the players codes */
QTimer *playTimer; /**< Every _COMMAND_INTERVAL (defined in base.h) time will do one round of game */
bool inited1,inited2,inited3,inited4; /**< is used to check if players are initialized, otherwise will send the initialization commands to players */
/**
* @brief
* Adds robots to a team after checking with "canBuy" function in knowledge
* If purchase is unsucessfull will print the reason in Status bar
* @param team = team id requested to buy robots
* @param numbers = number of robots team wants to buy
* @param model = type of robot team wants to buy
* @param pos = position the robots should place (cell number)
*/
void addRobot( int team, int numbers, char model, int pos);
/**
* @brief
* Moves robots and updates its direction for a team after checking with "canGo" function in knowledge
* If movement is unsucessfull will print the reason in Status bar
* @param id = team id requested to move robots
* @param numbers = number of robots team wants to move
* @param model = type of robot team wants to move
* @param from = current position of robot
* @param to = destination
*/
void moveRobot(int id, int numbers, char model, int from, int to);
/**
* @brief
* Sends command to player #1(ID : 0)
*/
void sendPlayer1();
/**
* @brief
* Sends command to player #2(ID : 1)
*/
void sendPlayer2();
/**
* @brief
* Sends command to player #3(ID : 2)
*/
void sendPlayer3();
/**
* @brief
* Sends command to player #4(ID : 3)
*/
void sendPlayer4();
/**
* @brief
* Initiates the fighting protocol every round
*/
void fight();
/**
* @brief
* Will be called from "fiht()" function
* In given position of map for given team ID does all the possible damages
* @param pos = cell number
* @param id = team ID
*/
void destroyRobs(int pos, int id);
/**
* @brief
* Changes the ownership of the cells after fight in each game round
*/
void updateOwnership();
/**
* @brief
* Just a Dummy wait function, used to be sure the process is started ( I didn't trust "waitForStarted()" function in QProcess"
* @param millisecondsToWait
*/
void delay( int millisecondsToWait );
private slots:
/**
* @brief
* This slot is connected to "readyReadStandardOutput()" of QProcess for player #1
*/
void receivePlayer1();
/**
* @brief
* This slot is connected to "readyReadStandardOutput()" of QProcess for player #2
*/
void receivePlayer2();
/**
* @brief
* This slot is connected to "readyReadStandardOutput()" of QProcess for player #3
*/
void receivePlayer3();
/**
* @brief
* This slot is connected to "readyReadStandardOutput()" of QProcess for player #4
*/
void receivePlayer4();
/**
* @brief
* Playing timer is connected to this slot to run each round of the game
*/
void playing();
public slots:
/**
* @brief
* Compiles the code for player #1 and activates it if the compilation is successful
* In case of unsuccessful compilation shows the GCC error in Status bar
*/
void compilePlayer1();
/**
* @brief
* Compiles the code for player #2 and activates it if the compilation is successful
* In case of unsuccessful compilation shows the GCC error in Status bar
*/
void compilePlayer2();
/**
* @brief
* Compiles the code for player #3 and activates it if the compilation is successful
* In case of unsuccessful compilation shows the GCC error in Status bar
*/
void compilePlayer3();
/**
* @brief
* Compiles the code for player #4 and activates it if the compilation is successful
* In case of unsuccessful compilation shows the GCC error in Status bar
*/
void compilePlayer4();
/**
* @brief
* Start the QProcesses for active players to play
*/
void initiateGame();
signals:
/**
* @brief
* Will be emited to activate a team in knowledge
* @param int = team ID
* @param bool = True: Activate, False: Deactivate
*/
void activateTeam(int, bool);
/**
* @brief
* Changes the label of team #1 in player widget to "Enable" or "Disable"
* @param QString
*/
void activateTeam1Label(QString);
/**
* @brief
* Changes the label of team #2 in player widget to "Enable" or "Disable"
* @param QString
*/
void activateTeam2Label(QString);
/**
* @brief
* Changes the label of team #3 in player widget to "Enable" or "Disable"
* @param QString
*/
void activateTeam3Label(QString);
/**
* @brief
* Changes the label of team #4 in player widget to "Enable" or "Disable"
* @param QString
*/
void activateTeam4Label(QString);
};
#endif // CGAME_H