diff options
author | elioat <elioat@tilde.institute> | 2024-07-06 17:56:30 -0400 |
---|---|---|
committer | elioat <elioat@tilde.institute> | 2024-07-06 17:56:30 -0400 |
commit | 3a3a78a4e07834bdae6a22e0f199849420bbd6f7 (patch) | |
tree | 90e2898c60257fd15e0d609c940b066e65adcd7b | |
parent | 082b90451a7637bcf2c34d59f58bb0b3d2ed57d7 (diff) | |
download | tour-3a3a78a4e07834bdae6a22e0f199849420bbd6f7.tar.gz |
*
-rw-r--r-- | html/sans/index.html | 9 | ||||
-rw-r--r-- | js/puzzle-dungeon/game.js | 132 | ||||
-rw-r--r-- | js/puzzle-dungeon/index.html | 21 | ||||
-rw-r--r-- | p9c/lbforth/lbforth9.c | 5 |
4 files changed, 164 insertions, 3 deletions
diff --git a/html/sans/index.html b/html/sans/index.html index 3598441..390375f 100644 --- a/html/sans/index.html +++ b/html/sans/index.html @@ -46,10 +46,19 @@ <li><a href="">Hill</a>, a demake of Alto's Adventure</li> <li><a href="">LAZER GATE ONE</a>, pew pew pew! Click the targets</li> </ul> + <h3>Toys</h3> + <ul> + <li><a href="">Life</a>, Conway's game of</li> + <li><a href="">Sand</a>, blocky falling objects</li> + </ul> <h3>Tools</h3> <ul> <li><a href="">Ink n switch</a>, a note taking application that lets you type text and draw notes</li> </ul> + <h3>Other stuff</h3> + <ul> + <li><a href="">Ink n switch</a>, a note taking application that lets you type text and draw notes</li> + </ul> </main> </body> </html> \ No newline at end of file diff --git a/js/puzzle-dungeon/game.js b/js/puzzle-dungeon/game.js new file mode 100644 index 0000000..e5a0fc4 --- /dev/null +++ b/js/puzzle-dungeon/game.js @@ -0,0 +1,132 @@ +// game.js +const canvas = document.getElementById('gameCanvas'); +const ctx = canvas.getContext('2d'); +const cellSize = canvas.width / 10; +const stepDuration = 200; // Duration for each step + +let player = { x: 0, y: 0 }; + +function drawGrid() { + ctx.clearRect(0, 0, canvas.width, canvas.height); + for (let x = 0; x <= canvas.width; x += cellSize) { + ctx.moveTo(x, 0); + ctx.lineTo(x, canvas.height); + } + for (let y = 0; y <= canvas.height; y += cellSize) { + ctx.moveTo(0, y); + ctx.lineTo(canvas.width, y); + } + ctx.strokeStyle = '#ddd'; + ctx.stroke(); +} + +function drawPlayer() { + ctx.fillStyle = 'blue'; + ctx.fillRect(player.x * cellSize, player.y * cellSize, cellSize, cellSize); +} + +document.getElementById('commandForm').addEventListener('submit', function (e) { + e.preventDefault(); + const commands = document.getElementById('commands').value.trim(); + try { + const parsedCommands = parseLispCommands(commands); + console.log("Parsed Commands:", JSON.stringify(parsedCommands, null, 2)); // Debugging output + executeCommands(parsedCommands); + } catch (error) { + console.error("Error parsing commands:", error); + } +}); + +function parseLispCommands(commands) { + const parse = input => { + const tokens = tokenize(input); + const ast = buildAST(tokens); + return ast; + }; + + const tokenize = input => { + return input.replace(/\(/g, ' ( ').replace(/\)/g, ' ) ').trim().split(/\s+/); + }; + + const buildAST = tokens => { + if (!tokens.length) throw new SyntaxError("Unexpected end of input"); + + const token = tokens.shift(); + if (token === '(') { + const list = []; + while (tokens[0] !== ')') { + list.push(buildAST(tokens)); + if (!tokens.length) throw new SyntaxError("Missing closing parenthesis"); + } + tokens.shift(); + return list; + } else if (token === ')') { + throw new SyntaxError("Unexpected ')'"); + } else { + return isNaN(token) ? token : Number(token); + } + }; + + return parse(commands); +} + +function executeCommands(commands) { + if (commands[0] !== 'move') { + console.error("Invalid command: root command must be 'move'"); + return; + } + + let delay = 0; + commands.slice(1).forEach(moveCommand => { + const steps = moveCommand[1]; + for (let i = 0; i < steps; i++) { + setTimeout(() => { + movePlayer([moveCommand[0], 1]); + drawGrid(); + drawPlayer(); + }, delay); + delay += stepDuration; + } + if (moveCommand[0] === 'rest') { + setTimeout(() => { + drawGrid(); + drawPlayer(); + }, delay); + delay += stepDuration; + } + }); +} + +function movePlayer(moveCommand) { + const direction = moveCommand[0]; + const steps = moveCommand[1]; + + if (typeof direction !== 'string' || typeof steps !== 'number') { + console.error(`Invalid move command: ${JSON.stringify(moveCommand)}`); + return; + } + + switch (direction) { + case 'north': + player.y = Math.max(0, player.y - steps); + break; + case 'south': + player.y = Math.min(9, player.y + steps); + break; + case 'east': + player.x = Math.min(9, player.x + steps); + break; + case 'west': + player.x = Math.max(0, player.x - steps); + break; + case 'rest': + // No movement, just wait for the duration + break; + default: + console.error(`Unknown direction: ${direction}`); + return; + } +} + +drawGrid(); +drawPlayer(); diff --git a/js/puzzle-dungeon/index.html b/js/puzzle-dungeon/index.html new file mode 100644 index 0000000..a238af3 --- /dev/null +++ b/js/puzzle-dungeon/index.html @@ -0,0 +1,21 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <title>Puzzle Game</title> + <style> + canvas { + border: 1px solid black; + } + </style> +</head> +<body> + <canvas id="gameCanvas" width="500" height="500"></canvas> + <form id="commandForm"> + <textarea id="commands" rows="10" cols="30"></textarea><br> + <button type="submit">Submit</button> + </form> + + <script src="game.js"></script> +</body> +</html> diff --git a/p9c/lbforth/lbforth9.c b/p9c/lbforth/lbforth9.c index 82dbb42..6ee5fa6 100644 --- a/p9c/lbforth/lbforth9.c +++ b/p9c/lbforth/lbforth9.c @@ -414,9 +414,8 @@ parseNumber(byte* word, cell len, dcell* number, cell* notRead, byte* isDouble) { int negative = 0; cell i; - charn - n - + char c; + cell current; *number = 0; *isDouble = 0; |