Adjust some statistics
This commit is contained in:
parent
f2a0fd69c6
commit
5b62f2c427
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "minesweeper",
|
||||
"version": "0.79.2",
|
||||
"version": "0.79.3",
|
||||
"description": "Just Minesweeper!",
|
||||
"author": "Felix W. Dekker",
|
||||
"browser": "dist/bundle.js",
|
||||
|
|
|
@ -38,11 +38,13 @@ export class Field {
|
|||
return this._hasStarted;
|
||||
}
|
||||
|
||||
private _hasWonBefore: boolean = false;
|
||||
private _hasWon: boolean = false;
|
||||
get hasWon(): boolean {
|
||||
return this._hasWon;
|
||||
}
|
||||
|
||||
private _hasLostBefore: boolean = false;
|
||||
private _hasLost: boolean = false;
|
||||
get hasLost(): boolean {
|
||||
return this._hasLost;
|
||||
|
@ -53,6 +55,8 @@ export class Field {
|
|||
return this._deathCount;
|
||||
}
|
||||
|
||||
wasAutoSolved: boolean = false;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new playing field for a game of Minesweeper.
|
||||
|
@ -290,7 +294,11 @@ export class Field {
|
|||
this.timer.stop();
|
||||
this._hasLost = true;
|
||||
this._deathCount++;
|
||||
this.statistics.gamesLost++;
|
||||
|
||||
if (!this._hasLostBefore && !this.wasAutoSolved) {
|
||||
this._hasLostBefore = true;
|
||||
this.statistics.gamesLost++;
|
||||
}
|
||||
} else {
|
||||
this._coveredNonMineCount--;
|
||||
if (this.coveredNonMineCount === 0) {
|
||||
|
@ -299,7 +307,13 @@ export class Field {
|
|||
remainingFlags.forEach(it => it.hasFlag = true);
|
||||
this._flagCount = this.mineCount;
|
||||
this._hasWon = true;
|
||||
this.statistics.gamesWon++;
|
||||
|
||||
if (!this._hasWonBefore && !this.wasAutoSolved) {
|
||||
this._hasWonBefore = true;
|
||||
this.statistics.gamesWon++;
|
||||
if (this.deathCount === 0)
|
||||
this.statistics.gamesWonWithoutLosing++;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -15,6 +15,7 @@ export class Solver {
|
|||
*/
|
||||
solve(field: Field): void {
|
||||
if (field.hasWon || field.hasLost) return;
|
||||
field.wasAutoSolved = true;
|
||||
|
||||
if (!field.hasStarted) {
|
||||
field.runUndoably(() => {
|
||||
|
|
|
@ -12,6 +12,7 @@ export interface Statistics {
|
|||
gamesStarted: number;
|
||||
gamesLost: number;
|
||||
gamesWon: number;
|
||||
gamesWonWithoutLosing: number;
|
||||
|
||||
squaresChorded: number;
|
||||
squaresChordedLeadingToLoss: number;
|
||||
|
@ -118,6 +119,16 @@ export class LocalStatistics implements Statistics {
|
|||
this.write(statistics);
|
||||
}
|
||||
|
||||
get gamesWonWithoutLosing(): number {
|
||||
return +(this.read()["gamesWonWithoutLosing"] ?? 0);
|
||||
}
|
||||
|
||||
set gamesWonWithoutLosing(value: number) {
|
||||
const statistics = this.read();
|
||||
statistics["gamesWonWithoutLosing"] = "" + value;
|
||||
this.write(statistics);
|
||||
}
|
||||
|
||||
get squaresChorded(): number {
|
||||
return +(this.read()["squaresChorded"] ?? 0);
|
||||
}
|
||||
|
@ -208,6 +219,10 @@ export class LocalStatistics implements Statistics {
|
|||
<th>Games won</th>
|
||||
<td>${this.gamesWon}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Games won without losing</th>
|
||||
<td>${this.gamesWonWithoutLosing}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h3>Steps taken</h3>
|
||||
|
@ -242,6 +257,7 @@ export class MemoryStatistics implements Statistics {
|
|||
gamesLost: number = 0;
|
||||
gamesStarted: number = 0;
|
||||
gamesWon: number = 0;
|
||||
gamesWonWithoutLosing: number = 0;
|
||||
squaresChorded: number = 0;
|
||||
squaresChordedLeadingToLoss: number = 0;
|
||||
squaresFlagged: number = 0;
|
||||
|
@ -256,6 +272,7 @@ export class MemoryStatistics implements Statistics {
|
|||
this.gamesLost = 0;
|
||||
this.gamesStarted = 0;
|
||||
this.gamesWon = 0;
|
||||
this.gamesWonWithoutLosing = 0;
|
||||
this.squaresChorded = 0;
|
||||
this.squaresChordedLeadingToLoss = 0;
|
||||
this.squaresFlagged = 0;
|
||||
|
|
|
@ -29,10 +29,10 @@ export class Overlay {
|
|||
this.hide();
|
||||
}
|
||||
);
|
||||
overlay.addEventListener(
|
||||
document.addEventListener(
|
||||
"keydown",
|
||||
event => {
|
||||
if (event.key === "Escape")
|
||||
if (event.key === "Escape" && this.isVisible())
|
||||
this.hide();
|
||||
}
|
||||
);
|
||||
|
@ -73,4 +73,11 @@ export class Overlay {
|
|||
hide(): void {
|
||||
this.overlay.style.visibility = "hidden";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if and only if this overlay is currently visible.
|
||||
*/
|
||||
isVisible(): boolean {
|
||||
return this.overlay.style.visibility !== "hidden";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue