This repository was archived by the owner on Dec 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.php
More file actions
63 lines (54 loc) · 1.48 KB
/
app.php
File metadata and controls
63 lines (54 loc) · 1.48 KB
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
// globals
define('ROCK', 'resources\style_2\rock.png');
define('PAPER', 'resources\style_2\paper.png');
define('SCISSORS', 'resources\style_2\scissors.png');
$result = '';
$computer = '';
// i made the arr like this so computer has "more" options to choose from rather than only 3 options
$arr = [ROCK, PAPER, SCISSORS, ROCK, PAPER, SCISSORS, ROCK, SCISSORS, PAPER];
$computer = $arr[rand(0, 8)];
if (isset($_GET['id'])) {
$user = $_GET['id'];
switch ($user . $computer) {
case 'r'.SCISSORS:
$result = 'Win';
$_SESSION['win'] += 1;
break;
case 's'.PAPER:
$result = 'Win';
$_SESSION['win'] += 1;
break;
case 'p'.ROCK:
$result = 'Win';
$_SESSION['win'] += 1;
break;
case 's'.ROCK:
$result = 'Lose';
$_SESSION['lose'] += 1;
break;
case 'r'.PAPER:
$result = 'Lose';
$_SESSION['lose'] += 1;
break;
case 'p'.SCISSORS:
$result = 'Lose';
$_SESSION['lose'] += 1;
break;
default:
$result = 'Tie';
}
}
if (isset($_GET['reset'])) {
session_unset();
session_destroy();
$_SESSION['win'] = 0;
$_SESSION['lose'] = 0;
$computer = '';
}
if (isset($_GET['subject'])) {
$_SESSION['username'] = $_GET['subject'];
}
elseif (!isset($_SESSION['username'])) {
$_SESSION['username'] = 'Human';
}