blob: 65138a6182815ab488451c7af97a42621decc77a (
plain) (
blame)
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
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Puzzle Game</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body, html {
font-size: 22px;
background-color: #f0f0f0;
margin: 0;
padding: 0 1em;
max-width: 100%;
overflow-x: hidden; /* a stupid hack to say "no no no" to horizontal scrolling */
display: block;
}
canvas {
border: 1px solid #2d2d2d;
display: block;
margin: 0 auto;
}
form#commandForm {
padding: 0 1em;
display: block;
margin: 0 auto;
max-width: 28em;
width: 100%;
}
textarea#commands {
display: block;
margin: 0 auto;
width: 100%;
font-size: 16px;
}
</style>
</head>
<body>
<p>
<span id="playerHealth">Health: 10</span> /
<span id="playerPower">Power: 10</span> /
<span id="playerLevel">Level: 0</span> /
<span id="playerPosition">(0, 0)</span> /
<a href="about.html">About</a>
</p>
<canvas id="gameCanvas"></canvas>
<p id="par">Par:</p>
<p id="playerInventory">Inventory: []</p>
<form id="commandForm">
<textarea id="commands" rows="7" cols="30"></textarea><br>
<button type="submit">Submit</button>
</form>
<script type="module">
import { parseCommands } from './parser.js';
import { initializeGame, resizeCanvas, player, alertGameOver, levelPar } from './game.js';
document.getElementById('commandForm').addEventListener('submit', function(event) {
event.preventDefault();
player.par = player.par + 1;
console.log(`Par: ${levelPar}`);
const commands = document.getElementById('commands').value;
if (player.par === levelPar) {
alertGameOver();
return;
}
parseCommands(commands);
});
window.addEventListener('resize', resizeCanvas);
initializeGame();
</script>
</body>
</html>
|