-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
169 lines (155 loc) · 5.44 KB
/
index.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
165
166
167
168
169
<html>
<head>
<title>The Band Game</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<style>
body { font-family: 'Droid Serif Pro', 'Garamond', 'Georgia', 'Lucida Serif', serif; font-size: 62%; }
div.band-list-by-letter { display: inline-block; vertical-align: top; padding: 0.5em; min-width: 7em; }
div.band-list-by-letter:nth-of-type(odd) { /* maybe something */ }
div.band-list-by-letter ul { padding-left: 1em; }
input { width: 95%; margin: 1em 0.5em; padding: 0.25em; }
label#current-letter { font-style: italic; color: green;}
button#help-button { display: block; position: absolute; top: 1em; right: 2em;}
div#help { display: none; position: absolute; top: 3em; left: 0em; ; padding: 1em; background: white; border: 1px solid black; }
</style>
</head>
<body>
<h1>The Band Game</h1>
<button id='help-button'>?</button>
<div id="help">
<p>
<b>The Band Game</b> is an easy and fun way to spend time with friends on road/ferry/plane trips.
</p>
<p>
<b>Rules</b> of the game are simple:
<ol type='1'>
<li>Come up with a name of a band that you for sure know exists.</li>
<li>Same as above, but starting with the last letter of the previous band</li>
</ol>
<b>Example chain:</b><br/>
Embreac<i>h</i> -> <b>H</b>elevor<i>n</i> -> <b>N</b>e Obliviscari<i>s</i> ... and so on.
</p>
<p>
That's it!
</p>
<p>
<b>Optional house rules:</b>
<ul>
<li>If no one can come up with any bands starting with a given letter, it may be deemed a wildcard letter and any band can be named next</li>
<li>A time limit of some sort may be applied to keep the ball rolling.</li>
<li>Try to fill up your entire alphabet with at least one artist.</li>
<li>If an artist performs under the names "Artist" and "Artist and the Bandnames" both are expended upon the first being used, e.g. <i>John Doe</i> vs <i>John Doe and the Anonymous</i>.</li>
</ul>
</p>
</div>
<div>
<button id="save-game">Save game</button> | <button id="load-game">Load game</button> | <button id="new-game">New game</button>
</div>
<h2>Current letter: <label id="current-letter"></label></h2>
<div>
<input type="text" id="band-name" autocomplete="no"/>
</div>
<h2>Used bands (<label id='band-count'></label>)</h2>
<div id="used-bands">
</div>
<template id="band-letter-block">
<div class="band-list-by-letter">
<h3></h3>
<ul></ul>
</div>
</template>
</body>
<script>
var currentLetter = 'free choice';
var bandsByLetter = {};
var bandChain = [];
function setCurrentLetter(letter) {
currentLetter = letter;
showCurrentLetter();
}
function showCurrentLetter() {
document.querySelector('#current-letter').innerText = currentLetter;
}
function init() {
refreshBands();
showCurrentLetter();
}
window.onload = init;
document.querySelector('#band-name').onkeyup = (keyEvent) => {
// console.log(keyEvent);
if (keyEvent.key == "Enter") {
var band = keyEvent.target.value.toLowerCase();
var bandIndex = bandChain.indexOf(band);
if (bandIndex >= 0) {
if (bandIndex == 0) {
alert(band + " was the first one played!");
} else {
alert(band + " was played already after " + bandChain[bandIndex - 1]);
}
} else {
addBand(band);
keyEvent.target.value = '';
}
}
}
function addBand(name) {
name = name.toLowerCase();
bandChain.push(name);
var first = name.slice(0,1);
var last = name.slice(-1);
if (first in bandsByLetter) {
bandsByLetter[first].push(name);
} else {
bandsByLetter[first] = [name];
}
setCurrentLetter(last);
refreshBands();
}
function refreshBands() {
var template = document.querySelector('#band-letter-block');
var container = document.querySelector('#used-bands');
var freshContainer = container.cloneNode(false);
container.parentNode.replaceChild(freshContainer, container);
document.querySelector('#band-count').innerText = bandChain.length;
Object.keys(bandsByLetter).sort().forEach((letter) => {
// console.log('showing bands of letter', letter)
var letterBlock = document.importNode(template.content, true);
letterBlock.querySelector('h3').innerText = letter.toUpperCase() + " (" + bandsByLetter[letter].length + ")";
bandsByLetter[letter].sort().forEach((band) => {
let li = document.createElement('li');
li.innerText = band;
letterBlock.querySelector('ul').appendChild(li);
});
freshContainer.appendChild(letterBlock);
});
}
document.querySelector('#save-game').onclick = () => {
for (let variable of ['bandChain', 'bandsByLetter', 'currentLetter']) {
localStorage.setItem('bandgame.' + variable, JSON.stringify(window[variable]));
}
alert('Game successfully saved to your local browser.')
};
document.querySelector('#load-game').onclick = () => {
for (let variable of ['bandChain', 'bandsByLetter', 'currentLetter']) {
let value = JSON.parse(localStorage.getItem('bandgame.' + variable));
if (value == null) {
alert('Loading failed from storage. Please start a new game.');
break;
}
window[variable] = value;
}
init();
}
document.querySelector('#new-game').onclick = () => {
window.location.href = window.location.href;
}
document.querySelector('#help-button').onclick = () => {
let help = document.querySelector('div#help');
if (window.getComputedStyle(help, null).display == 'none') {
help.style.display = 'block';
} else {
help.style.display = 'none';
}
}
</script>
</html>