Skip to content

Commit e70b813

Browse files
committed
Keep the sound state when reset/gameover, fix the pause function
1 parent 2bddc7f commit e70b813

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/app/state/tetris/tetris.query.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export class TetrisQuery extends Query<TetrisState> {
3939
return this.raw.gameState === GameState.Started;
4040
}
4141

42+
get isPause() {
43+
return this.raw.gameState === GameState.Paused;
44+
}
45+
4246
get isEnableSound(): boolean {
4347
return !!this.raw.sound;
4448
}

src/app/state/tetris/tetris.service.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ export class TetrisService {
6565
}
6666

6767
resume() {
68+
if (!this._query.isPause) {
69+
return;
70+
}
6871
let { speed } = this._query.raw;
6972
this._store.update({
7073
locked: false,
@@ -74,6 +77,9 @@ export class TetrisService {
7477
}
7578

7679
pause() {
80+
if (!this._query.isPlaying) {
81+
return;
82+
}
7783
this._store.update({
7884
locked: true,
7985
gameState: GameState.Paused
@@ -82,7 +88,11 @@ export class TetrisService {
8288
}
8389

8490
reset() {
85-
this._store.update(createInitialState(this._pieceFactory));
91+
const { sound } = this._query.raw;
92+
this._store.update({
93+
...createInitialState(this._pieceFactory),
94+
sound
95+
});
8696
}
8797

8898
moveLeft() {
@@ -242,13 +252,14 @@ export class TetrisService {
242252
private _onGameOver() {
243253
this.pause();
244254
this._soundManager.gameOver();
245-
let { points, max } = this._query.raw;
255+
let { points, max, sound } = this._query.raw;
246256
let maxPoint = Math.max(points, max);
247257
LocalStorageService.setMaxPoint(maxPoint);
248258
this._store.update({
249259
...createInitialState(this._pieceFactory),
250260
max: maxPoint,
251261
gameState: GameState.Over,
262+
sound
252263
});
253264
}
254265

0 commit comments

Comments
 (0)