-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrock_paper.php~
63 lines (50 loc) · 1.35 KB
/
rock_paper.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
<?php
// Assign moves to integers (1 = Rock, 2 = Paper, 3 = Scissors, 4 = Lizard, 5 = Spock)
echo 'Welcome to Rock, Paper Scissors, Lizard, Spock';
echo "\n";
// Randomize Moves
$computer = rand(1, 5);
// Declare wins
$rock_wins = array(3, 4);
$paper_wins = array(1, 5);
$scissors_wins = array(2, 4);
$lizard_wins = array(5, 2);
$spock_wins = array(3, 1);
// Conditional logic for wins
if ($computer == $_GET["name"]) {
echo "Tie.";
echo "\n";
} elseif ($computer == 1) {
if (in_array($_GET["name"], $rock_wins)) {
echo "\nPlayer 1 wins";
echo "\n";
}
} elseif ($computer == 2) {
if (in_array($_GET["name"], $paper_wins)) {
echo "\nPlayer 1 wins";
echo "\n";
}
} elseif ($computer == 3) {
if (in_array($_GET["name"], $scissors_wins)) {
echo "\nPlayer 1 wins";
echo "\n";
}
}
elseif ($computer == 4) {
if (in_array($_GET["name"], $lizard_wins)) {
echo "\nPlayer 1 wins";
echo "\n";
}
}
elseif ($computer == 5) {
if (in_array($_GET["name"], $spock_wins)) {
echo "\nPlayer 1 wins";
echo "\n";
}
} else {
echo "\nPlayer 2 wins";
}
?>
<form action="<?php $_PHP_SELF ?>" method="GET"><br>
Name: <input type="text" name="name"><br>
</form>