-
Notifications
You must be signed in to change notification settings - Fork 0
/
gs hangman solver.html
84 lines (70 loc) · 2.42 KB
/
gs hangman solver.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
<!DOCTYPE html>
<html>
<body>
<p>
Start new game:
<input type="button" class="gameStart" value="five" />
<input type="button" class="gameStart" value="seven" />
<input type="button" class="gameStart" value="nine" />
</p>
<p id="inputZone"></p>
<p>
<input type="button" id="btnFound" value="found" />
<input type="button" id="btnNotFound" value="notFound" />
</p>
<p id="infoZone"></p>
<script src="gs hangman solver.js"></script>
<script>
var letterInput = '<input type="text" maxlength="1" />';
[...document.querySelectorAll('.gameStart')].forEach(btnGameStart => {
btnGameStart.addEventListener('click', () => {
document.querySelector('#inputZone').innerHTML = letterInput + letterInput + letterInput + letterInput + letterInput;
if (btnGameStart.value == 'seven')
document.querySelector('#inputZone').innerHTML += letterInput + letterInput;
else if (btnGameStart.value == 'nine')
document.querySelector('#inputZone').innerHTML += letterInput + letterInput + letterInput + letterInput;
//bindNextEvent(); //no likey
setInfo(startGame(btnGameStart.value));
});
});
document.querySelector('#btnFound').addEventListener('click', () => {
var currentGuess = Array.from([...document.querySelectorAll('input[type="text"]')], letterInput => letterInput.value ? letterInput.value : '.').join('');
processFound(currentGuess);
setInfo(calculateNextGuess());
});
document.querySelector('#btnNotFound').addEventListener('click', () => {
processNotFound(document.querySelector('#infoZone strong').innerText);
setInfo(calculateNextGuess());
});
function bindNextEvent() {
document.querySelectorAll('input[type="text"]').forEach(txtInput => {
txtInput.addEventListener('keyup', (e) => {
if (e.which < 48 || e.which > 90)
return;
if (e.target.nextElementSibling) {
e.target.nextElementSibling.focus();
}
});
});
}
function setInfo(txtInfo) {
document.querySelector('#infoZone').innerHTML = txtInfo;
}
document.querySelector('.gameStart[value="five"]').click();
</script>
<style>
body {
font-family: sans-serif;
margin-top: 10rem;
text-align: center;
background-color: #181818;
color: #fff;
}
input[type="text"] {
width: 20px;
margin-right: 1rem;
text-align: center;
}
</style>
</body>
</html>