-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameplay-submit.php
53 lines (48 loc) · 1.6 KB
/
gameplay-submit.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
<?php
include "util.php";
session_handler();
// echo $current_question["answer"];
// echo $_POST["choice"];
#CORRECT CASE
if( (isset($_POST["choice"])) && ($_POST["choice"] == $current_question["answer"])){
$data["state"] = "runnning";
$data["score"] = $data["score"] += (int)$current_question["points"];
#echo $data["score"];
echo "correct";
#ANSWERED ALL QUESTIONS CORRECTLY
if(count($question_stack) == 0){
$data["state"] = "winner";
$data["score"] = $data["score"];
write_user_data($username, $data);
submit_score($username, $data["score"]);
header('Location: winner.php');
exit();
}
#GET NEXT QUESTION AND PROCEED
$current_question = array_pop($question_stack);
write_user_data($username, $data);
store_question_stack($username, $question_stack);
store_current_question($username, $current_question);
header('Location: gameplay.php');
exit();
}
#INCORRECT CASE
if( (isset($_POST["choice"])) && ($_POST["choice"] != $current_question["answer"])){
#go to lost game retry page
submit_score($username, $data["score"]);
echo "wrong choice";
header('Location: try-again.php');
exit();
}
#TOOL BAR BUTTON CASES
if(isset($_POST["tb_button"])){
if($_POST["tb_buttn"] == "Main menu"){
header('Location: index.php');
exit();
}
else{
header('Location: logout.php');
exit();
}
}
?>