Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rossant committed Mar 13, 2024
1 parent aab4f2c commit 4bba4de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion data/listings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3192,7 +3192,7 @@
"5. 🐰 Bunny": {
"visual": "grid",
"version": 1,
"code": "n = 7\nsize(n, n)\nfont(32)\n\nd = {\n \"ArrowRight\": (0, +1),\n \"ArrowLeft\": (0, -1),\n \"ArrowUp\": (-1, 0),\n \"ArrowDown\": (+1, 0),\n}\n\nbunny = 1, 3\ncarrot = (5, 6)\n\ndef show():\n clear()\n block(3, 2, 4, n, black)\n text(*bunny, \"🐰\")\n if bunny != carrot:\n text(*carrot, \"🥕\")\n else:\n print(\"Yummy!\")\n\ndef keyboard(key):\n global bunny\n i, j = bunny\n \n dd = d.get(key, None)\n if dd:\n di, dj = dd\n i += di\n j += dj\n i = max(0, min(i, n-1))\n j = max(0, min(j, n-1))\n if color(i, j) != (0, 0, 0):\n bunny = (i, j)\n show()\n\nprint(\"Press the keyboard arrows to move the bunny toward the carrot.\")\n\nshow()\n",
"code": "n = 7\nsize(n, n)\nfont(32)\n\nd = {\n \"ArrowRight\": (0, +1),\n \"ArrowLeft\": (0, -1),\n \"ArrowUp\": (-1, 0),\n \"ArrowDown\": (+1, 0),\n}\n\nbunny = 1, 3\ncarrot = (5, 6)\n\ndef show():\n clear()\n block(3, 2, 4, n, black)\n text(*bunny, \"🐰\")\n if bunny != carrot:\n text(*carrot, \"🥕\")\n else:\n print(\"Yummy!\")\n\ndef keyboard(key):\n global bunny\n i, j = bunny\n \n dd = d.get(key, None)\n if dd:\n di, dj = dd\n i += di\n j += dj\n i = max(0, min(i, n-1))\n j = max(0, min(j, n-1))\n if color(i, j) != (0, 0, 0):\n bunny = (i, j)\n show()\n\nprint(\"Press the arrow keys on your keyboard to move the bunny towards the carrot.\")\n\nshow()\n",
"lang": "fr",
"data": {
"rows": 7,
Expand Down
16 changes: 10 additions & 6 deletions scripts/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,26 @@ class Runner {
/* Input events */
/*********************************************************************************************/

_firstRun() {
async _firstRun() {
// Run the code if it hasn't run yet.
if (!this.hasGlobals) {
this.clearOutput();
this.clearGrid();

const code = this.model.editor.getCode();
this.start(code);
await this._run(code);
this.hasGlobals = true;
}
}

click(row, col) {
this._firstRun();
async click(row, col) {
await this._firstRun();
if (this.has("click"))
this._run(`click(${row}, ${col})`, false, false, false, false);
}

keyboard(key) {
this._firstRun();
async keyboard(key) {
await this._firstRun();
if (this.has("keyboard"))
this._run(`keyboard("${key}")`, false, false, false, false);
}
Expand Down

0 comments on commit 4bba4de

Please sign in to comment.