Skip to content

Commit

Permalink
sokoban: small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
frederic wagner committed Aug 24, 2023
1 parent e379e52 commit 52ee082
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 4 additions & 0 deletions apps/sokoban/ChangeLog
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
0.01: Initial code
0.02:
* Fix for last level offsets parsing
* Fix for title display

17 changes: 12 additions & 5 deletions apps/sokoban/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ function next_map_offsets(filename, start_offset) {
}
}
}
if (offsets.length == 1) {
offsets.push(raw_maps.length);
}
return offsets;
}

Expand Down Expand Up @@ -88,7 +91,7 @@ function load_current_map() {
let current_set = config.levels_set;
let offsets = config.offsets[current_set];
let set_filename = config.levels_sets[current_set];
let set_name = set_filename.substring(0, set_filename.length - 4); // remove '.txt'
let set_name = set_filename.substring(8, set_filename.length - 4); // remove '.txt' and 'sokoban.'
let current_map = config.current_maps[current_set];
map = load_map(set_filename, offsets[2 * current_map], offsets[2 * current_map + 1], set_name + " " + (current_map + 1));
map.display();
Expand All @@ -98,10 +101,12 @@ function next_map() {
let current_set = config.levels_set;
let current_map = config.current_maps[current_set];
let offsets = config.offsets[current_set];
let won = false;
if (2 * (current_map + 1) >= offsets.length) {
// we parse some new offsets
let new_offsets = next_map_offsets(config.levels_sets[current_set], offsets[offsets.length - 1] + 2); // +2 since we need to start at ';' (we did -2 from ';' in previous parser call)
if (new_offsets.length == 0) {
if (new_offsets.length != 2) {
won = true;
E.showAlert("You Win", "All levels completed").then(function() {
load();
});
Expand All @@ -110,9 +115,11 @@ function next_map() {
config.offsets[current_set].push(new_offsets[1]);
}
}
config.current_maps[current_set]++;
s.writeJSON("sokoban.json", config);
load_current_map();
if (!won) {
config.current_maps[current_set]++;
s.writeJSON("sokoban.json", config);
load_current_map();
}
}

function previous_map() {
Expand Down
2 changes: 1 addition & 1 deletion apps/sokoban/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "sokoban",
"name": "Sokoban",
"shortName": "Sokoban",
"version": "0.01",
"version": "0.02",
"description": "Classic Sokoban game (microban levels).",
"allow_emulator":false,
"icon": "sokoban.png",
Expand Down

0 comments on commit 52ee082

Please sign in to comment.