-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFullGameTest.php
More file actions
212 lines (163 loc) · 4.88 KB
/
FullGameTest.php
File metadata and controls
212 lines (163 loc) · 4.88 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
<?php
// Full Game Test
require_once 'debugSettings.php';
require_once 'Game.php';
require_once 'gameManager.php';
require_once '../dbinfo/dbcred.php';
require_once 'DBSessionHandler.php';
require_once 'LobbyManager.php';
require_once 'CardManager.php';
$handler = new DBSessionHandler();
session_set_save_handler($handler);
session_start();
header('Content-Type: application/json');
//echo "Hello world";
if ( !isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true ) {
header('Content-Type: application/json');
$status = "Unauthenticated access attempt.";
$response = array('status' => $status);
echo json_encode($response);
exit;
}
$gameManager = new gameManager();
$lobbyManager = new LobbyManager();
$cardManager = new CardManager();
$lobby = $lobbyManager->getLobby();
echo "lobby:";
echo json_encode($lobby);
try {
$game = new Game();
// get the game status
$game->setGame($gameManager->getCurrentGame());
} catch (Exception $e){
$game = false;
}
$active = false;
if(is_object($game)){
if(isset($game->active)){
$active = true;
$game->resetNumbers();
$gameManager->update($game);
}
}
echo " \n\nactive:";
echo json_encode($active);
// Start a New Game
if(!$active){
$game = new Game();
$gameManager->new($game);
$game->setGame($gameManager->getCurrentGame());
// empty lobby and put users in activeGamePlayers
$gameManager->moveUsersFromLobbyToGame();
}
//Run 5 rounds of the game
$players = $gameManager->getActiveGamePlayers();
echo " \n\nactive players:";
echo json_encode($players);
//$game->callNextNumber();
//$gameManager->update($game);
// function $game->checkForBingos($players, $cardManager){
// $bingos = array();
// foreach ($game->types as $type) {
// // echo " \n\nchecking for '.$type.':";
// foreach ($players as $player) {
// $email = $player->email;
// $cards = $cardManager->getCards($email);
// //$bingos[$email] = array();
// foreach ($cards as $card) {
// // echo " \ncheck:";
// // echo json_encode($card);
// //$check = $game->bingo($card);
// $check = $game->checkCard($type, $card);
// // echo " \ncheck:";
// // echo json_encode($check);
// $bingoData = array();
// if($check){
// if(!isset($bingos[$email])){
// $bingos[$email] = array();
// }
// $_data = $game->bingo($card);
// // echo " email: " . $email . " > ";
// // echo json_encode($_data);
// array_push($bingos[$email], $_data);
// }
// //array_push($bingos[$email], $bingoData);
// }
// }
// }
// return $bingos;
// }
// Play 25 rounds, check if a user has got bingo
for($i = 0; $i < 30; $i++){
$game->callNextNumber();
$gameManager->update($game);
}
echo " \n\ngame:";
echo json_encode($game);
$bingos = $game->checkForBingos($players, $cardManager);
echo "\n\nbingos:";
echo json_encode($bingos);
echo "\n \n";
// set game to xes
// Play 45 rounds, check if a user has got bingo
//echo " \n\nResetting numbers.";
//$game->resetNumbers();
echo " \n\nChange game to xes:";
$game->addType('xes');
$game->removeType('bingo');
echo " \n\nxes bingos:\n";
$bingos = $game->checkForBingos($players, $cardManager);
echo json_encode($bingos);
echo " \n\nCall 30 more numbers.\n";
for($i = 0; $i < 30; $i++){
$game->callNextNumber();
$gameManager->update($game);
}
$bingos = $game->checkForBingos($players, $cardManager);
//echo " \ngame:";
//echo json_encode($game);
echo "\n \nxes bingos again:\n";
echo json_encode($bingos);
echo "\n \n";
// set game to window
// Play 25 rounds, check if a user has got bingo
// $game->resetNumbers();
echo " \n\nchange type to window:";
$game->setType('window');
$bingos = $game->checkForBingos($players, $cardManager);
echo " \nwindow bingos:";
echo json_encode($bingos);
echo " \n\nCall 10 more numbers.\n";
for($i = 0; $i < 10; $i++){
$game->callNextNumber();
$gameManager->update($game);
}
$bingos = $game->checkForBingos($players, $cardManager);
echo " \nwindow bingos after:";
echo json_encode($bingos);
// set game to blackout
// Play 25 rounds, check if a user has got bingo
//$game->resetNumbers();
echo " \n\nchange type to blackout:";
$game->setType('blackout');
$bingos = $game->checkForBingos($players, $cardManager);
echo " \nblackout bingos:\n";
echo json_encode($bingos);
echo " \n\nCall last 5 numbers.\n";
for($i = 0; $i < 5; $i++){
try {
$game->callNextNumber();
} catch (Exception $e){
echo $e->getMessage();
}
$gameManager->update($game);
}
$bingos = $game->checkForBingos($players, $cardManager);
echo "\nblackout bingos after all number called (everyone should win):\n";
echo json_encode($bingos);
$game->setType('bingo');
$gameManager->update($game);
// end game
echo "\n\nend game.\n";
$gameManager->end($game);
?>