Skip to content

Commit d80a2fa

Browse files
author
Roman Babaev
committed
Fix unflagged mines counter
1 parent 9f09e77 commit d80a2fa

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/App/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,23 @@ export default class App extends React.Component {
4040
newGame = (arena = [10, 10], mines = 25) => this.game.configure(arena, mines);
4141

4242
render() {
43-
const { flaggingMode, gameState, minesCountTotal, arena, flagged, timerValue } = this.game.getStats();
43+
const {
44+
flaggingMode,
45+
gameState,
46+
minesCountLeft,
47+
minesCountTotal,
48+
arena,
49+
flagged,
50+
timerValue
51+
} = this.game.getStats();
4452
const { showOptions, zoom } = this.state;
4553

4654
return (
4755
<div className="App">
4856
<Hat
4957
gameState={gameState}
5058
timerValue={timerValue}
51-
minesLeftCount={minesCountTotal - flagged}
59+
minesLeftCount={minesCountLeft}
5260
onResetClick={this.game.reset}
5361
onOptionsClick={this.toggleOptions}
5462
/>

src/core/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ export class Minesweeper {
151151
gameState: this.gameState,
152152
arena: this.arena,
153153
minesCountTotal: this.minesCountTotal,
154+
minesCountLeft: this.gameState === 'won'
155+
? 0
156+
: this.minesCountTotal - this.flaggedCells,
154157
opened: this.openedCells,
155158
flagged: this.flaggedCells,
156159
timerValue: this.startTime ? (this.endTime || Date.now()) - this.startTime : null,
@@ -162,6 +165,7 @@ export class Minesweeper {
162165
reset = () => {
163166
const [cells, minedCells] = genCells(this.arena, 0, 0);
164167
this.stopTimer();
168+
165169
this.openedCells = 0;
166170
this.flaggedCells = 0;
167171
this.gameState = 'playing';
@@ -170,6 +174,7 @@ export class Minesweeper {
170174
this.startTime = null;
171175
this.endTime = null;
172176
this.flaggingMode = false;
177+
173178
this._render();
174179
};
175180

0 commit comments

Comments
 (0)