diff options
| author | Aiden Woodruff <aiden.woodruff@gmail.com> | 2018-06-29 18:08:10 -0500 |
|---|---|---|
| committer | Aiden Woodruff <aiden.woodruff@gmail.com> | 2018-06-29 18:08:10 -0500 |
| commit | 636977dc6093f65154fd50848e86e92c2ccaa1d0 (patch) | |
| tree | 0e34b711bc7daae6ca03782a772a06d7e250226b | |
| parent | c8d0e69e0407b8638d888d3efb6742ddc5a3ed0c (diff) | |
| download | sweeper-636977dc6093f65154fd50848e86e92c2ccaa1d0.tar.gz sweeper-636977dc6093f65154fd50848e86e92c2ccaa1d0.tar.bz2 sweeper-636977dc6093f65154fd50848e86e92c2ccaa1d0.zip | |
Fixed issue where onscreen Mine count didn't reincrease if flag was clicked
Added function unflagged that updates screen value.
Signed-off-by: Aiden Woodruff <aiden.woodruff@gmail.com>
| -rw-r--r-- | ChangeLog | 7 | ||||
| -rw-r--r-- | sweeper.js | 18 |
2 files changed, 18 insertions, 7 deletions
| @@ -1,3 +1,10 @@ | |||
| 1 | 2018-06-29 Aiden Woodruff <aiden.woodruff@gmail.com> | ||
| 2 | |||
| 3 | * sweeper.js (unflagged): Function added. Scans and updates Mine count on screen. | ||
| 4 | (flag): Calls unflagged() | ||
| 5 | (reveal): Calls unflagged() if item is flagged. | ||
| 6 | (populate_board): Don't do anything with unflagged. | ||
| 7 | |||
| 1 | 2018-06-28 Aiden Woodruff <aiden.woodruff@gmail.com> | 8 | 2018-06-28 Aiden Woodruff <aiden.woodruff@gmail.com> |
| 2 | 9 | ||
| 3 | * index.html: Fixed meta with no close bracket. | 10 | * index.html: Fixed meta with no close bracket. |
| @@ -1,7 +1,6 @@ | |||
| 1 | // Global variables | 1 | // Global variables |
| 2 | var boardmap = Array(); | 2 | var boardmap = Array(); |
| 3 | var mines = Array(); | 3 | var mines = Array(); |
| 4 | var unflagged = 0; | ||
| 5 | var table = ""; | 4 | var table = ""; |
| 6 | var height = 0; | 5 | var height = 0; |
| 7 | var width = 0; | 6 | var width = 0; |
| @@ -83,6 +82,12 @@ function get_cell (x, y) { | |||
| 83 | return document.getElementById( (x.toString() + "," + y.toString() ) ); | 82 | return document.getElementById( (x.toString() + "," + y.toString() ) ); |
| 84 | } | 83 | } |
| 85 | 84 | ||
| 85 | // Updates unflagged (or really, unrevealed) mine count | ||
| 86 | function unflagged () { | ||
| 87 | document.getElementById("minecount").innerHTML = "Mines: " + (total_mines - Array.concat.apply([], boardmap).filter(x => x.status === "F").length).toString(); | ||
| 88 | return true; | ||
| 89 | } | ||
| 90 | |||
| 86 | // Return x y dict from cell object | 91 | // Return x y dict from cell object |
| 87 | function get_cell_xy (object) { | 92 | function get_cell_xy (object) { |
| 88 | coord = new Coordinates(); | 93 | coord = new Coordinates(); |
| @@ -221,8 +226,11 @@ function reveal (e) { | |||
| 221 | coord = get_cell_xy(object); | 226 | coord = get_cell_xy(object); |
| 222 | if (boardmap[coord.y][coord.x].status === "R") { | 227 | if (boardmap[coord.y][coord.x].status === "R") { |
| 223 | return; | 228 | return; |
| 224 | } else if (boardmap[coord.y][coord.x].status === "U" || boardmap[coord.y][coord.x].status === "F") { | 229 | } else if (boardmap[coord.y][coord.x].status === "U") { |
| 225 | boardmap[coord.y][coord.x].status = "R"; | 230 | boardmap[coord.y][coord.x].status = "R"; |
| 231 | } else if (boardmap[coord.y][coord.x].status === "F") { | ||
| 232 | boardmap[coord.y][coord.x].status = "R"; | ||
| 233 | unflagged(); | ||
| 226 | } | 234 | } |
| 227 | object.classList.remove("flagged"); | 235 | object.classList.remove("flagged"); |
| 228 | object.classList.remove("unrevealed"); | 236 | object.classList.remove("unrevealed"); |
| @@ -295,15 +303,13 @@ function flag (e) { | |||
| 295 | boardmap[coord.y][coord.x].status = "U"; | 303 | boardmap[coord.y][coord.x].status = "U"; |
| 296 | object.classList.remove("flagged"); | 304 | object.classList.remove("flagged"); |
| 297 | object.classList.add("unrevealed"); | 305 | object.classList.add("unrevealed"); |
| 298 | unflagged++; | ||
| 299 | } else if (boardmap[coord.y][coord.x].status === "U") { | 306 | } else if (boardmap[coord.y][coord.x].status === "U") { |
| 300 | boardmap[coord.y][coord.x].status = "F"; | 307 | boardmap[coord.y][coord.x].status = "F"; |
| 301 | object.classList.remove("unrevealed"); | 308 | object.classList.remove("unrevealed"); |
| 302 | object.classList.add("flagged"); | 309 | object.classList.add("flagged"); |
| 303 | unflagged--; | ||
| 304 | } else if (boardmap[coord.y][coord.x].status === "R") { | 310 | } else if (boardmap[coord.y][coord.x].status === "R") { |
| 305 | } | 311 | } |
| 306 | document.getElementById("minecount").innerHTML = "Mines: " + unflagged.toString(); | 312 | unflagged(); |
| 307 | } | 313 | } |
| 308 | 314 | ||
| 309 | function update_leaderboard () { | 315 | function update_leaderboard () { |
| @@ -401,8 +407,6 @@ function populate_board (e) { | |||
| 401 | mines = mines.filter(value => { return ! value.equals(disclude); }); | 407 | mines = mines.filter(value => { return ! value.equals(disclude); }); |
| 402 | } | 408 | } |
| 403 | 409 | ||
| 404 | unflagged = mines.length; | ||
| 405 | |||
| 406 | // Place mines | 410 | // Place mines |
| 407 | for (var i = 0; i < mines.length; i++) { | 411 | for (var i = 0; i < mines.length; i++) { |
| 408 | boardmap[mines[i].y][mines[i].x].value = "M"; | 412 | boardmap[mines[i].y][mines[i].x].value = "M"; |
