Puzzle15: v0.05: Central game end function

pull/1218/head
Dirk Hillbrecht (home) 2022-01-05 09:52:06 +01:00
parent 3633078a46
commit cabb0c2d7d
3 changed files with 15 additions and 8 deletions

View File

@ -5393,7 +5393,7 @@
{ {
"id": "puzzle15", "id": "puzzle15",
"name": "15 puzzle", "name": "15 puzzle",
"version": "0.04", "version": "0.05",
"description": "A 15 puzzle game with drag gesture interface", "description": "A 15 puzzle game with drag gesture interface",
"readme":"README.md", "readme":"README.md",
"icon": "puzzle15.app.png", "icon": "puzzle15.app.png",

View File

@ -2,3 +2,4 @@
0.02: Lots of enhancements, menu system not yet functional, but packaging should be now... 0.02: Lots of enhancements, menu system not yet functional, but packaging should be now...
0.03: Menu logic now generally functioning, splash screen added. The first really playable version! 0.03: Menu logic now generally functioning, splash screen added. The first really playable version!
0.04: Settings dialog, about screen 0.04: Settings dialog, about screen
0.05: Central game end function

View File

@ -391,23 +391,23 @@ class Board {
//this.setAlmostSolved(); // to test the game end //this.setAlmostSolved(); // to test the game end
} }
/* /* Set the board into the "solved" position. Useful for showcasing and development
// Set the board into the "solved" position. Useful for showcasing
setSolved() { setSolved() {
this.stones = []; this.stones = [];
for (i = 0; i < stonesPerBoard; i++) for (i = 0; i < stonesPerBoard; i++)
this.stones[i] = new Stone((i + 1) % stonesPerBoard, i); this.stones[i] = new Stone((i + 1) % stonesPerBoard, i);
this.moveCount = 0; this.moveCount = 0;
} }
/* */
// Initialize an almost solved playing field. Useful for tests and development /* Initialize an almost solved playing field. Useful for tests and development
setAlmostSolved() { setAlmostSolved() {
this.setSolved(); this.setSolved();
b = this.stones[this.stones.length - 1]; b = this.stones[this.stones.length - 1];
this.stones[this.stones.length - 1] = this.stones[this.stones.length - 2]; this.stones[this.stones.length - 1] = this.stones[this.stones.length - 2];
this.stones[this.stones.length - 2] = b; this.stones[this.stones.length - 2] = b;
} }
*/ /* */
// Initialize a shuffled field. The fields are always solvable. // Initialize a shuffled field. The fields are always solvable.
setShuffled() { setShuffled() {
@ -671,7 +671,7 @@ function gameEnd(moveCount) {
buttons: { buttons: {
"Again": newGame, "Again": newGame,
"Menu": () => showMenu(false), "Menu": () => showMenu(false),
"Exit": load "Exit": exitGame
} }
}).then(v => { }).then(v => {
E.showPrompt(); E.showPrompt();
@ -702,7 +702,7 @@ function showMenu(withContinue) {
mainmenu["Start 4x4"] = () => initGame(4); mainmenu["Start 4x4"] = () => initGame(4);
mainmenu["Start 5x5"] = () => initGame(5); mainmenu["Start 5x5"] = () => initGame(5);
mainmenu.About = () => showAbout(withContinue); mainmenu.About = () => showAbout(withContinue);
mainmenu.Exit = () => load(); mainmenu.Exit = exitGame;
dragger.setEnabled(false); dragger.setEnabled(false);
g.clear(true); g.clear(true);
E.showMenu(mainmenu); E.showMenu(mainmenu);
@ -722,6 +722,12 @@ function handledrag(e) {
worker.addTask(e => board.drawResult(e)); worker.addTask(e => board.drawResult(e));
} }
// exit the game, clear screen first to prevent ghost images
function exitGame() {
g.clear(true);
setTimeout(load, 300);
}
// *** Main program // *** Main program