-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
41 lines (31 loc) · 1.03 KB
/
index.php
File metadata and controls
41 lines (31 loc) · 1.03 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
<?php
// Autoload
function my_autoloader($class) {
include "libraries/{$class}.php";
}
spl_autoload_register('my_autoloader');
require "core/init.php";
$gameCore = new GameCore();
if (isset($_POST['new_game'])) {
$username = $_POST['username'];
$gameCore->newGame($username);
}
if (isset($_POST['do_guess'])) {
$chosen_number = $_POST['new_guess'];
$gameCore->gameTry($chosen_number, $_SESSION['game_id']);
}
if (isset($_POST['close_game'])) {
$gameCore->gameClose($_SESSION['game_id']);
}
$gameID = (isset($_SESSION['game_id'])) ? $_SESSION['game_id'] : false;
$isGameStarted = ($gameID && $_SESSION['game_status'] == 0) ? true : false;
if ($isGameStarted) {
$template = new Template('in_game');
} else {
$template = new Template('new_game');
$template->score = $gameCore->getScore();
$template->username = (isset($_SESSION['username'])) ? $_SESSION['username']: '';
$template->totalPlayed = $gameCore->totalPlayed();
}
$template->title = $config['title'];
echo $template;