-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathGameBoard.php
More file actions
59 lines (49 loc) · 1.79 KB
/
GameBoard.php
File metadata and controls
59 lines (49 loc) · 1.79 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
<?php
namespace trivia;
class GameBoard
{
private $places;
private $popQuestions;
private $scienceQuestions;
private $sportsQuestions;
private $rockQuestions;
private const MAX_QUESTIONS_PER_CATEGORY = 50;
function __construct()
{
$this->places = [
"Pop", "Science", "Sports",
"Rock", "Pop", "Science",
"Sports", "Rock", "Pop",
"Science", "Sports", "Rock"
];
$this->popQuestions = array();
$this->scienceQuestions = array();
$this->sportsQuestions = array();
$this->rockQuestions = array();
for ($index = 0; $index < self::MAX_QUESTIONS_PER_CATEGORY; $index++) {
array_push($this->popQuestions, "Pop Question " . $index);
array_push($this->scienceQuestions, ("Science Question " . $index));
array_push($this->sportsQuestions, ("Sports Question " . $index));
array_push($this->rockQuestions, $this->createRockQuestion($index));
}
}
function createRockQuestion($index)
{
return "Rock Question " . $index;
}
function getcurrentCategory($currentPlayerPosition)
{
return $this->places[$currentPlayerPosition];
}
function askQuestion($currentPlayerPosition)
{
if ($this->getcurrentCategory($currentPlayerPosition) == "Pop")
echoln(array_shift($this->popQuestions));
if ($this->getcurrentCategory($currentPlayerPosition) == "Science")
echoln(array_shift($this->scienceQuestions));
if ($this->getcurrentCategory($currentPlayerPosition) == "Sports")
echoln(array_shift($this->sportsQuestions));;
if ($this->getcurrentCategory($currentPlayerPosition) == "Rock")
echoln(array_shift($this->rockQuestions));
}
}