-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.php
89 lines (75 loc) · 1.83 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
<?php //start session;
if(!isset($_GET['name']) || strlen($_GET['name']) < 1 )
{
die("Name Parameter cannot be blank");
}
if(isset($_POST['logout']))
{
header('Location: index.php');
return;
}
// Set up the values for the game...
// 0 is Rock, 1 is Paper, and 2 is Scissors
$names = array('Rock', 'Paper', 'Scissors');
$human = isset($_POST['human']) ? $_POST['human']+0 : -1 ;
$computer = rand(0, 2);
function check($computer, $human)
{
if($human == $computer)
{
return "Tie";
}elseif ($human > $computer)
{
return "You Win";
}elseif ($human < $computer) {
return "You lose";
}
return false;
}
$result = check($computer, $human);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Oluwafemi Banji's Game Page</title>
</head>
<body>
<h1>Rock Paper Scissors</h1>
<?php
if (isset($_REQUEST['name'])){
echo "<p>Welcome: ";
echo htmlentities($_REQUEST['name']);
echo "</p>\n";
}
?>
<form method="post">
<select name="human">
<option value="-1">Select</option>
<option value="0">Rock</option>
<option value="1">Paper</option>
<option value="2">Scissors</option>
<option value="3">Test</option>
</select>
<input type="submit" value="Play">
<input type="submit" name="logout" value="Logout">
</form>
<pre>
<?php
if($human == -1){
print "Please select a strategy and Play.\n";
}elseif ($human == 3) {
for($c=0;$c<3;$c++) {
for($h=0;$h<3;$h++) {
$r = check($c, $h);
print "Human=$names[$h] Computer=$names[$c] Result=$r\n";
}
}
}else {
print "Your Play=$names[$human] Computer Play=$names[$computer] Result=$result\n";
}
?>
</pre>
</body>
</html>