-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
124 lines (124 loc) · 4.01 KB
/
index.html
File metadata and controls
124 lines (124 loc) · 4.01 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!DOCTYPE html>
<html>
<head>
<title>Snake</title>
</head>
<body>
<canvas id="myCanvas" width="600" height="600"></canvas>
<div id="score"></div>
<!-- add about popup window -->
<div id="about" class="modal">
<div class="modal-content">
<span class="close">×</span>
<h2>About</h2>
<p>
<b>Snake</b> is a simple game that is inspired by the classic <i>Snake</i> game.
<br>
The objective of the game is to eat as much food as possible.
<br>
<br>
<b>Controls:</b>
<br>
<br>
Use the arrow keys to move the snake.
<br>
<br>
<b>The End:</b>
<br>
<br>
The game is over when the snake hits the wall or itself.
<br>
<br>
<b>Credits:</b>
<br>
<br>
Most of the game (and even this menu!) was made by Github Copilot. Small edits were made by me, MathIsFun0, mainly to fix bugs and optimize gameplay.
<br>
<br>
<b>Authors:</b>
<br>
<br>
Github Copilot and MathIsFun0
<br>
</p>
</div>
</div>
<script type="text/javascript" src="js/snake.js"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');
#score {
position: absolute;
top: 0;
left: 0;
width: 100%;
font-family: 'Press Start 2P', cursive;
font-size: 50px;
color: white;
text-align: center;
text-shadow: 0 0 10px black;
}
canvas {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: black;
}
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.4);
}
.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 50%;
height: 50%;
color: black;
font-family: 'Press Start 2P', cursive;
font-size: 14px;
}
.close {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
</style>
<script>
// Get the modal
var modal = document.getElementById("about");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
//When the user clicks on the text in the score element, open the modal
document.getElementById("score").onclick = function() {
modal.style.display = "block";
}
</script>
</body>
</html>