about summary refs log tree commit diff stats
path: root/js/puzzle-dungeon/index.html
blob: 3d024873a6500980c9a297b0d0274aaa037ad059 (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
<!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 {
            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 black;
            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="playerEndurance">Endurance: 10</span> /
        <span id="playerScore">Score: 0</span> /
        <span id="playerPosition">(0, 0)</span>
    </p>
    <canvas id="gameCanvas"></canvas>
    <p id="playerInventory">Inventory: []</p>
    <form id="commandForm">
        <textarea id="commands" rows="10" cols="30"></textarea><br>
        <button type="submit">Submit</button>
    </form>
    <script type="module">
        import { parseCommands } from './parser.js';
        import { initializeGame, resizeCanvas } from './game.js';

        document.getElementById('commandForm').addEventListener('submit', function(event) {
            event.preventDefault();
            const commands = document.getElementById('commands').value;
            parseCommands(commands);
        });

        window.addEventListener('resize', resizeCanvas);
        
        initializeGame();
    </script>
</body>
</html>