-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetGameQuestions.php
111 lines (96 loc) · 3.45 KB
/
getGameQuestions.php
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
<?php
if (!isset($_SESSION["Continent"])) {
die("Kein Kontinent gewaehlt!");
}
//Variablen setzen und prüfen
if (!isset($_SESSION['gameQuestionCounter'])) {
$_SESSION['gameQuestionCounter'] = 0;
}
/*
if(!isset($_SESSION['playedContinents']))
{
$_SESSION['playedContinents'] = [];
}
*/
if (!isset($_SESSION['playedCountries'])) {
$_SESSION['playedCountries'] = [];
}
if (!isset($_SESSION['playedCountriesAnswered'])) {
$_SESSION['playedCountriesAnswered'] = [];
}
if (!isset($_SESSION['score'])) {
$_SESSION['score'] = 0;
}
if ($_SESSION['hearts'] < 0) {
resetGame();
header('Location: index.php?page=GameOver');
}
if ($_SESSION['gameQuestionCounter'] >= 6) {
//aktuell gespielten Kontinent auf das
//Array playedContinents in der Session drücken
//array_push($_SESSION['playedContinents'], $_SESSION["Continent"]);
//gibt Probleme bei der Variablenübertragung in JS
//Lösung durch switch
switch ($_SESSION["Continent"]) {
case 'Asien':
$_SESSION['playedAsien'] = "Yes";
break;
case 'Afrika':
$_SESSION['playedAfrika'] = "Yes";
break;
case 'Australien_Ozeanien':
$_SESSION['playedAustralien_Ozeanien'] = "Yes";
break;
case 'Europa':
$_SESSION['playedEuropa'] = "Yes";
break;
case 'Suedamerika':
$_SESSION['playedSuedamerika'] = "Yes";
break;
case 'Nordamerika':
$_SESSION['playedNordamerika'] = "Yes";
break;
}
//Eventuell verbleibende Variablen setzen (z.b. Hearts wieder auf 0)
//Für jedes Herz 120 extrapunkte
$herzbonus = $_SESSION['hearts'] * 120;
$_SESSION['score'] += $herzbonus;
saveScore($_SESSION['score'], $_SESSION['hearts'], $_SESSION['username'], $_SESSION["Continent"]);
//resetGame();
if (($_SESSION['playedAsien'] == "Yes") && ($_SESSION['playedAfrika'] == "Yes") && ($_SESSION['playedAustralien_Ozeanien'] == "Yes") && ($_SESSION['playedEuropa'] == "Yes") && ($_SESSION['playedSuedamerika'] == "Yes") && ($_SESSION['playedNordamerika'] == "Yes")) {
die('Spiel vorbei! Alle Kontinente wurden gespielt!');
} else {
header('Location: index.php?page=GameTransitionContinentSelect');
}
//wieder zurueck zur WorldMap
}
$gameQuestions = [];
$gameData = loadData('gameQuestions.json'); // Daten aus Datei laden
// itteriert über alle Kontinente + Fragen
foreach ($gameData as $Continent => $CountriesOfContinent) {
// wenn Kontinent == dem gewählten Kontinent dann alle Fragen in $Questions speichern
if ($_SESSION["Continent"] == $Continent) {
$gameQuestions = $CountriesOfContinent;
break;
}
}
//wenn Kontinent Fragen "noch" nicht vorhanden
if (count($gameQuestions) == 0) {
die("Fehler, keine Länder zum abfragen da!");
}
if (count($gameQuestions) < 6) {
die("´Nicht genug Länder da um Abfrage zu starten!");
}
if (count($_SESSION['playedCountries']) == count($gameQuestions)) {
die("Es wurden schon alle Länder gefragt");
}
if ($_SESSION['playedCountriesAnswered'] == $_SESSION['playedCountries']) {
do {
// zufällige Frage holen
$arrayPos = mt_rand(0, count($gameQuestions) - 1);
} while (in_array($arrayPos, $_SESSION['playedCountries']));
$_SESSION['playedCountries'][] = $arrayPos;
}else{
$arrayPos = $_SESSION['playedCountries'][count($_SESSION['playedCountries']) - 1];
}
$randomCountry = $gameQuestions[$arrayPos];