-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.php
110 lines (88 loc) · 2.74 KB
/
game.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
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Game on</title>
<link rel="stylesheet" href="../style.css">
</head>
<?php
include 'conn.php';
session_start();
$playerID = $_SESSION['playerID'];
$gameCode = $_SESSION['gameCode'];
//echo "USER TYPE: ".$_SESSION['userType'];
?>
<body>
<!-- CONTAINER FOR QUESTION: loaded via AJAX -->
<div class = 'content'>
<div id = 'timer'></div>
<div id = 'question-container'></div>
</div>
<!--<button onclick ='test()'>remove this</button>-->
</body>
<script src = 'scripts.js'></script>
<script>
/*
function test() {
load_php_file('src/addScore.php', null, { answer: savedAnswer, code: savedCode, question:savedQuestion })
window.location.href = 'roundScore.php';
}
*/
function nextQuestion() {
$.ajax({
url: "src/isLastRound.php",
method: "POST",
data: {code: 1},
success: function(data) {
load_php_file("src/getQuestion.php", '#question-container', null);
//load_php_file('src/nextQuestion.php',null,null);
console.log("nextQuestion: "+data);
/*
if (data == 0) {
console.log("REDIRECT");
window.location.href = 'roundScore.php';
} else */
if (data == 1) {
window.location.href = 'finalScores.php';
}
}
});
}
nextQuestion();
let savedAnswer = -1;
let savedCode = "";
let savedQuestion = "";
setInterval(function() {
$.ajax({
url: "src/getTimeLeft.php",
method: "POST",
data: {code: 1},
success: function(data) {
console.log("time: "+data);
$('#timer').html("<p>"+data+"</p>");
if (data <= 0) {
console.log(savedAnswer)
load_php_file('src/addScore.php', null, { answer: savedAnswer, code: savedCode, question:savedQuestion })
//load_php_file('src/nextQuestion.php',null,null);
window.location.href = 'roundScore.php';
//nextQuestion();
};
//load_php_file("src/getTimeLeft.php", '#timer', null);
// update_timer(data)
}
});
// call function every second
}, 1000);
function checkAnswer(answer, code, question) {
savedAnswer = answer;
savedCode = code;
savedQuestion = question;
console.log(answer)
console.log(code)
console.log(question)
$('.btn').css("background-color","#6667AB");
$('#ans-'+answer).css("background-color","#4b4c80");
}
</script>
</html>