-
Notifications
You must be signed in to change notification settings - Fork 32
/
stonepaperscissor in php.php
72 lines (67 loc) · 3.03 KB
/
stonepaperscissor in php.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
<html>
<body>
<?php
error_reporting(E_ALL);
session_start();
$_SESSION['username'] = true;// to bypass Login page (remove it once you test it)
if(!isset($_POST['user_choice'])){
if(!isset($_SESSION['username'])){
header('location:login.php');
}
else{
echo "First page:";
$_SESSION['secondPage'] = true;
echo '<form action=htmlspecialchars($_SERVER["PHP_SELF"]); method="post" />
<input type="radio" name="user_choice" value="Rock" title="Rock" />Rock <br /><br />
<input type="radio" name="user_choice" value="Paper" title="Paper" />Paper <br /><br />
<input type="radio" name="user_choice" value="Scissors" title="Scissors" />Scissors <br /><br />
<input type="submit" name="form_submit" value="submit"/>
</form> ';
}
}
?>
<?php
if(!isset($_SESSION['username'])) {
header('location:login.php');
} else {
if(isset($_POST['user_choice'])) {
echo "Second Page:<br><br>";
$CPUChoice = array('Rock', 'Paper', 'Scissors');
shuffle($CPUChoice);
//echo "CPU Select". $CPUChoice[0];exit;
$CPU = $CPUChoice[0];
$User = $_POST['user_choice'];
echo 'Player: '.$User.' <br>CPU: '.$CPU;
if($User === $CPU){
echo '<br>Result: Tie!';
}
else if($User === "Rock"){
if($CPU === "Scissors") {
echo '<br>Result: User wins';
} else {
echo '<br>Result: CPU wins';
}
}
else if($User === "Paper") {
if($CPU === "Rock") {
echo '<br>Result: User wins';
}else {
if($CPU === "Scissors") {
echo '<br>Result: Computer wins';
}
}
}
else if($User === "Scissors") {
if($CPU === "Rock") {
echo '<br>Result: CPU wins';
} else {
if($CPU === "Paper") {
echo '<br>Result: User wins';
}
}
}
}
}
?>
</body>
</html>