From 5d76a5cd465522fe0b6e04442e879908c2abe8d4 Mon Sep 17 00:00:00 2001 From: chiefdaft Date: Thu, 31 Mar 2022 23:56:02 +0200 Subject: [PATCH] v0.08: Bug fix at end of the game with victorious splash and glorious orchestra --- apps/game1024/ChangeLog | 3 ++- apps/game1024/app.js | 31 +++++++++++++++++++++++++++---- apps/game1024/metadata.json | 2 +- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/apps/game1024/ChangeLog b/apps/game1024/ChangeLog index 6ec8a15fc..c917bb90c 100644 --- a/apps/game1024/ChangeLog +++ b/apps/game1024/ChangeLog @@ -4,4 +4,5 @@ 0.04: Bug fix score reset after Game Over, new icon 0.05: Chevron marker on the randomly added square 0.06: Fixed issue 1609 added a message popup state handler to control unwanted screen redraw -0.07: Optimized the mover algorithm for efficiency (work in progress) \ No newline at end of file +0.07: Optimized the mover algorithm for efficiency (work in progress) +0.08: Bug fix at end of the game with victorious splash and glorious orchestra \ No newline at end of file diff --git a/apps/game1024/app.js b/apps/game1024/app.js index b0e8d74f7..13430ff2d 100644 --- a/apps/game1024/app.js +++ b/apps/game1024/app.js @@ -162,6 +162,7 @@ const buttons = { */ const mover = { + gameWon: false, direction: { up: {name: 'up', step: 1, innerBegin: 0, innerEnd: rows-1, outerBegin: 0, outerEnd: cols-1, iter: rows -1, sqIndex: function (i,o) {return i*(cols) + o;}, sqNextIndex: function (i,o) {return i < rows -1 ? (i+1)*(cols) + o : -1;} @@ -397,7 +398,7 @@ function addToUndo() { } function addToScore (val) { scores.add(val); - if (val == 10) messageYouWin(); + if (val == 10) mover.gameWon = true; } function createGrid () { let cn =0; @@ -421,15 +422,30 @@ function messageGameOver () { .drawString("O V E R !", middle.x+12, middle.y+25); } function messageYouWin () { - g.setColor("#1a0d00") + const c = (g.theme.dark) ? {"fg": "#FFFFFF", "bg": "#808080"} : {"fg": "#FF0000", "bg": "#000000"}; + g.setColor(c.bg) .setFont12x20(2) .setFontAlign(0,0,0) .drawString("YOU HAVE", middle.x+18, middle.y-24) .drawString("W O N ! !", middle.x+18, middle.y+24); - g.setColor("#FF0808") + g.setColor(c.fg) .drawString("YOU HAVE", middle.x+17, middle.y-25) .drawString("W O N ! !", middle.x+17, middle.y+25); - Bangle.buzz(200, 1); + for (let r=0;r<4;r++){ + Bangle.buzz(200,0.2) + .then((result) => { + Bangle.buzz(200,0.5) + .then((result)=>{ + Bangle.buzz(200,0.8) + .then((result)=>{ + Bangle.buzz(200,1) + .then((result)=>{ + Bangle.buzz(500,0); + }) + }) + }) + }) + } } function makeRandomNumber () { return Math.ceil(2*Math.random()); @@ -527,6 +543,7 @@ function handlePopUpClicks(btn) { function resetGame() { g.clear(); scores.reset(); + mover.gameWon=false; allSquares.forEach(sq => {sq.setExpVal(0);sq.removeUndo();sq.setRndmFalse();}); addRandomNumber(); addRandomNumber(); @@ -653,6 +670,12 @@ function runGame(dir){ debug(() => console.log("G A M E O V E R !!")); snapshot.reset(); messageGameOver(); + } else { + if (mover.gameWon) { + debug(() => console.log("Y O U H A V E W O N !!")); + snapshot.reset(); + messageYouWin(); + } } } diff --git a/apps/game1024/metadata.json b/apps/game1024/metadata.json index 14e64347a..dd350d2b9 100644 --- a/apps/game1024/metadata.json +++ b/apps/game1024/metadata.json @@ -1,7 +1,7 @@ { "id": "game1024", "name": "1024 Game", "shortName" : "1024 Game", - "version": "0.07", + "version": "0.08", "icon": "game1024.png", "screenshots": [ {"url":"screenshot.png" } ], "readme":"README.md",