-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame3.html
164 lines (135 loc) · 5.04 KB
/
game3.html
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Basic Page Needs
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta charset="utf-8">
<title>Score game 3 - Genesis Retreat</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Mobile Specific Metas
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<!-- Favicon
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="icon" type="image/png" href="images/favicon.png">
<style>
/* import ttf font */
@font-face {
font-family: 'DMSans';
src: url('dmsans/DMSans-Bold.ttf') format('truetype');
}
body {
font-family: 'DMSans';
background-color: #000000;
color: #aaa
}
/* body background starts red, then fades back to black after 500 ms */
body.flashred {
background-color: #660900;
transition: background-color 500ms ease-in-out;
}
html,
body {
height: 100%;
margin: 0;
}
.flexcol {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-evenly;
align-content: space-around;
width: 100%;
height: 55%;
padding-top: 15vh;
left: 0;
right: 0;
}
.row {
display: flex;
justify-content: space-evenly;
align-items: center;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: 0;
width: 100%;
}
.ansbox {
height: 15rem;
width: 15rem;
background-color: #aaa;
}
.ansbox.correct {
background-color: darkgreen;
}
</style>
</head>
<body>
<!-- Primary Page Layout
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<div class="flexcol">
<h1>Do you know the way?</h1>
<div class="row">
</div>
</div>
<!-- End Document
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<script>
const values = ['mt14.29', 'jn4.14', 'mk7.1-2', 'gn1.3-4', '1pt1.6-7', 'mk7.19'];
// generate boxes
for (const v of values) {
const box = document.createElement('div');
box.classList.add('ansbox');
box.dataset.value = v;
document.querySelector('.row').appendChild(box);
}
function showIncorrect() {
// add flashred class to body
document.body.classList.add('flashred');
// remove flashred class after 500ms
setTimeout(() => {
document.body.classList.remove('flashred');
}, 500);
}
let textbuffer = '';
// if keys are pressed in the document, add to buffer until enter is pressed
document.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
// check if buffer is correct
if (values.includes(textbuffer)) {
// find box with data value matching
const box = document.querySelector(`.ansbox[data-value="${textbuffer}"]`);
if (box.classList.contains('correct')) {
// if this ticket has already been scanned, flash red
showIncorrect();
} else {
// mark ticket as correct
box.classList.add('correct');
}
} else {
// if buffer doesn't match anything, flash red
showIncorrect();
}
// clear buffer
textbuffer = '';
} else {
textbuffer += e.key;
}
});
// clicking on the document will reset all boxes
document.addEventListener('click', () => {
const boxes = document.querySelectorAll('.ansbox');
for (const box of boxes) {
box.classList.remove('correct');
}
});
</script>
</body>
</html>