Add silly statistic

This commit is contained in:
Florine W. Dekker 2020-09-01 17:47:45 +02:00
parent 07f028d369
commit 11bc3f9be7
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
3 changed files with 18 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{
"name": "minesweeper",
"version": "0.81.9",
"version": "0.81.10",
"description": "Just Minesweeper!",
"author": "Felix W. Dekker",
"browser": "dist/bundle.js",

View File

@ -405,8 +405,11 @@ export class Field {
* @param amount the maximum amount of actions to redo, or all future actions if `undefined`
*/
redo(amount: number | undefined = undefined): void {
const wasLost = this.hasLost;
const redone = this.history.redo(amount);
if (!this.isAutoSolving && redone > 0) this.statistics.actionsRedone++;
if (!this.isAutoSolving && !wasLost && this.hasLost) this.statistics.lossesRedone++;
}
/**

View File

@ -9,6 +9,7 @@ export interface Statistics {
actionsUndone: number;
actionsRedone: number;
lossesUndone: number;
lossesRedone: number;
timeSpent: number;
gamesStarted: number;
@ -68,6 +69,14 @@ export class LocalStatistics implements Statistics {
this.storage.setNumber("lossesUndone", value);
}
get lossesRedone(): number {
return this.storage.getNumber("lossesRedone", 0);
}
set lossesRedone(value: number) {
this.storage.setNumber("lossesRedone", value);
}
get timeSpent(): number {
return this.storage.getNumber("timeSpent", 0);
}
@ -184,6 +193,7 @@ export class LocalStatistics implements Statistics {
<th>Losses undone</th>
<td>${this.lossesUndone}</td>
</tr>
${this.lossesRedone > 0 ? `<tr><th>Losses redone</th><td>${this.lossesRedone}</td></tr>` : ``}
<tr>
<th>Time spent</th>
<td>${formatTime(Math.floor(+this.timeSpent / 1000), true, true)}</td>
@ -199,13 +209,13 @@ export class LocalStatistics implements Statistics {
<tr>
<th>Games completed</th>
<td>
${this.gamesWon}&nbsp;(${Math.round(100 * this.gamesWon / this.gamesStarted)}%)
${this.gamesWon}${this.gamesStarted > 0 ? `&nbsp;(${Math.round(100 * this.gamesWon / this.gamesStarted)}%)` : ``}
</td>
</tr>
<tr>
<th>Games completed without losing</th>
<td>
${this.gamesWonWithoutLosing}&nbsp;(${Math.round(100 * this.gamesWonWithoutLosing / this.gamesStarted)}%)
${this.gamesWonWithoutLosing}${this.gamesStarted > 0 ? `&nbsp;(${Math.round(100 * this.gamesWonWithoutLosing / this.gamesStarted)}%)` : ``}
</td>
</tr>
</table>
@ -259,6 +269,7 @@ export class MemoryStatistics implements Statistics {
actionsUndone: number = 0;
actionsRedone: number = 0;
lossesUndone: number = 0;
lossesRedone: number = 0;
timeSpent: number = 0;
gamesStarted: number = 0;
gamesWon: number = 0;
@ -277,6 +288,7 @@ export class MemoryStatistics implements Statistics {
this.actionsUndone = 0;
this.actionsRedone = 0;
this.lossesUndone = 0;
this.lossesRedone = 0;
this.timeSpent = 0;
this.gamesStarted = 0;
this.gamesWon = 0;