Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lowlights solved tiles in countdownMode #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class Game {
}
return result;
}

countFlags() {
let result = 0;
for (let y = 0; y < this.height; y++) {
Expand All @@ -355,6 +355,35 @@ class Game {
return result;
}

// all adjacent tiles are flagged and revealed (not necessarily solved)
isComplete(x, y) {
for (const [x0, y0] of neighbors(x, y, this.width, this.height)) {
if (this.map.labels[y0][x0] === null && !this.flags[y0][x0]) {
return false;
}
}
return true;
}

labeledTile(x, y, label)
{
// TODO: can a stylesheet be adjusted to lowlight any tile?
// not just hard-coded to just 0 in countdownMode
// Maybe create an overlay, instead...

if (this.countdownMode) {
const flagsAround = this.countFlagsAround(x, y);

if( flagsAround === label && this.isComplete(x,y) ) {
return `known label-solved`;
} else{
return`known label-${label - flagsAround}`;
}
} else {
return `known label-${label}`;
}
}

refresh() {
for (let y = 0; y < this.height; y++) {
for (let x = 0; x < this.width; x++) {
Expand All @@ -372,12 +401,7 @@ class Game {
} else if (this.state === State.WIN && mine) {
className = 'unknown bomb-win';
} else if (label !== null && label > 0) {
if (this.countdownMode) {
const modLabel = label - this.countFlagsAround(x, y);
className = `known label-${modLabel}`;
} else {
className = `known label-${label}`;
}
className = this.labeledTile(x, y, label);
} else if (label === 0) {
className = 'known';
} else if (flag) {
Expand Down
7 changes: 7 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
.cell.label--3 { color: #ff0000; }
.cell.label--2 { color: #ff0000; }
.cell.label--1 { color: #ff0000; }
.cell.label-solved {
background: #888;
border-top-color: #888;
border-left-color: #888;
color: #050505;
}
.cell.label-0 {
background: #aaa;
border-top-color: #aaa;
Expand Down Expand Up @@ -93,6 +99,7 @@
.cell.label--3::after { content: "-3"; }
.cell.label--2::after { content: "-2"; }
.cell.label--1::after { content: "-1"; }
.cell.label-solved::after { content: "0"; }
.cell.label-0::after { content: "0"; }
.cell.label-1::after { content: "1"; }
.cell.label-2::after { content: "2"; }
Expand Down