about summary refs log blame commit diff stats
path: root/js/puzzle-dungeon/index.html
blob: 2caa203c09153757ffc3a58a5f3e005de499f16f (plain) (tree)
1
2
3
4
5
6
7
8
9




                              
                                                                          
           
                    
                                      


                            
                                                                                             

                           
                
                                      

                           
         










                            
                            
         


            

                                                    
                                                 
                                                

                                               
                                     
                        
                                             



                                                                   
                          
                                                    
                                                                                                  


                                                                                           

                                                                            
                                                                       



                                          



                                                        
        
                         
             

       
<!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 {
            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>
    </p>
    <canvas id="gameCanvas"></canvas>
    <p id="par">Par:</p>
    <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, player, alertGameOver, levelPar } from './game.js';

        document.getElementById('commandForm').addEventListener('submit', function(event) {
            event.preventDefault();
            player.par = player.par + 1;
            console.log(`Player command count, ${player.par}, ${levelPar}`);
            const commands = document.getElementById('commands').value;
            if (player.par === levelPar) {
                alertGameOver();
                return;
            }
            parseCommands(commands);
        });

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