-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhangman.php
76 lines (67 loc) · 2.43 KB
/
hangman.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
<?php
// Starts the session.
// If the user closes the session, session data will be erased.
session_start();
// Array of available words.
$words = array('encapsulation', 'inheritance', 'polymorphism', 'abstraction', 'programming', 'cybersecurity', 'cookies');
// Choose a random word in the array to start the hangman game.
$randInt = rand(0, sizeof($words)-1);
$word = $words[$randInt];
?>
<html>
<head>
<title>hangman.</title>
<link type="text/css" rel="stylesheet" href="./style.css" />
</head>
<body>
<h1>hangman.</h1>
<div class="container">
<h2>enter a letter: </h2>
<form action = "<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method = "post">
<input type="submit" onclick="" value="a">
<input type="button" onclick="" value="b">
<input type="button" onclick="" value="c">
<input type="button" onclick="" value="d">
<input type="button" onclick="" value="e">
<input type="button" onclick="" value="f">
<input type="button" onclick="" value="g">
<input type="button" onclick="" value="h">
<input type="button" onclick="" value="i">
<input type="button" onclick="" value="j">
<input type="button" onclick="" value="k">
<input type="button" onclick="" value="l">
<input type="button" onclick="" value="m">
<input type="button" onclick="" value="n">
<input type="button" onclick="" value="o">
<input type="button" onclick="" value="p">
<input type="button" onclick="" value="q">
<input type="button" onclick="" value="r">
<input type="button" onclick="" value="s">
<input type="button" onclick="" value="t">
<input type="button" onclick="" value="u">
<input type="button" onclick="" value="v">
<input type="button" onclick="" value="w">
<input type="button" onclick="" value="x">
<input type="button" onclick="" value="y">
<input type="button" onclick="" value="z">
<br>
<input type="button" value="reset">
<input type="button" value="leaderboard">
<input type="button" value="exit">
</form>
</div>
<div class="user_feedback">
<h2>letters used:</h2>
<!-- php script to generate blank spaces -->
<?php
for ($i = 0; $i < strlen($word); $i++) {
if (isset($_POST['a'])) {
echo 'a ';
} else {
echo '__ ';
}
}
?>
</div>
</body>
</html>