Skip to content

Commit

Permalink
fix click handler service #handleLeftClick method
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesribeiro committed Aug 13, 2023
1 parent 28304f4 commit a969429
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ describe("SettingsComponent", () => {
fixture = TestBed.createComponent(SettingsComponent);
component = fixture.componentInstance;
store = TestBed.inject(MockStore);

component = fixture.componentInstance;
store.overrideSelector(fromAppSelectors.selectSettings, mockSettings);

fixture.detectChanges();
Expand Down
7 changes: 7 additions & 0 deletions src/app/services/click-handler.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { Store } from "@ngrx/store";
import { IApp } from "../state/app.interface";
import { neighborOffsets } from "../utils/neighbor-offsets";
import { CellPosition } from "../models/cellPosition.model";
import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";

@UntilDestroy()
@Injectable({
providedIn: "root",
})
Expand All @@ -25,18 +27,22 @@ export class ClickHandlerService {
constructor(private readonly store: Store<IApp>) {
this.store
.select(fromAppSelectors.selectSettingsLevel)
.pipe(untilDestroyed(this))
.subscribe((level: Level) => (this.level = level));

this.store
.select(fromAppSelectors.selectGridHeight)
.pipe(untilDestroyed(this))
.subscribe((height: number) => (this.height = height));

this.store
.select(fromAppSelectors.selectGridWidth)
.pipe(untilDestroyed(this))
.subscribe((width: number) => (this.width = width));

this.store
.select(fromAppSelectors.selectRealBoard)
.pipe(untilDestroyed(this))
.subscribe((realCells: Cell[][]) => (this.realCells = realCells));
}

Expand All @@ -50,6 +56,7 @@ export class ClickHandlerService {
}

this.revealedCells = [];
this.visitedCells = new Set<string>();

this.deepSearchFirst(selectedCell);

Expand Down
2 changes: 1 addition & 1 deletion src/app/state/app.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class AppEffects {
) {}
startGame$ = createEffect(() =>
this.actions$.pipe(
ofType(fromAppActions.startGame),
ofType(fromAppActions.startGame, fromAppActions.resetGame),
mergeMap(() =>
this.createLevelService.createMatrix().pipe(
map((entities) => fromAppActions.createMatrixSuccess({ entities })),
Expand Down
9 changes: 9 additions & 0 deletions src/app/state/app.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
wonGame,
continueGame,
setSettings,
resetGame,
} from "./app.actions";
import { GameStatus } from "../models/gameStatus.model";

Expand Down Expand Up @@ -51,6 +52,14 @@ export const reducer = createReducer(
entities,
},
})),
on(resetGame, (state) => ({
...state,
playerBoard: {
...state.playerBoard,
gameStatus: GameStatus.IN_PROGRESS,
flagsLeft: state.settings.totalMines,
},
})),
on(startGame, (state) => ({
...state,
playerBoard: {
Expand Down
5 changes: 4 additions & 1 deletion src/styles.sass
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
font-family: 'DSEG7Classic'
src: url('/assets/fonts/DSEG7Classic-Regular.ttf') format('truetype')
font-weight: normal
font-style: normal
font-style: normal

body
@apply bg-gradient-to-r from-cyan-100 to-blue-100

0 comments on commit a969429

Please sign in to comment.