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



                          
                                 
                                                                          
           
                    
                            
                                      


                            
                                                                                             

                           
                
                                      

                           
         










                            
                            
         


            

                                                    
                                                 
                                                
                                                  
                                      
        
                                     
                        
                                             
                           
                                                                  

                                             
                          
                                                    
                                                                                                                      


                                                                                           
                                        
                                            
                                 
                                                                       



                                          
                                    
                                                           


                                                        
        
                         
             

       
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Puzzle Dungeon</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, updatePlayerStatus } from './game.js';

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

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