Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/flex-layout": "^2.0.0-beta.12",
"@angular/flex-layout": "2.0.0-beta.12",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/material": "^5.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operators';
import * as fromStore from '../../store';
import { ResetScore, StartPlaying, StopPlaying } from '../../store/actions';
import { ResetScore, StartPlaying, StopPlaying, ResetAttempts } from '../../store/actions';
// import { AddScore } from '../../store/actions/score.actions';
// import { AddAttempt } from '../../store/actions/attempts.actions';
import { Attempt } from './../../store/reducers/attempts.reducer';
Expand Down Expand Up @@ -105,6 +105,7 @@ export class ControlContainerComponent implements OnInit {
private startGame() {
this.store.dispatch(new StartPlaying());
this.store.dispatch(new ResetScore());
this.store.dispatch(new ResetAttempts());
// TODO #10 dispatch the Action for reset the attempts here
this.startGameSound.nativeElement.play();
setTimeout(() => this.generateRandomControl(), this.TIME_TO_START_GAME);
Expand Down
14 changes: 11 additions & 3 deletions src/app/store/actions/attempts.actions.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { Action } from '@ngrx/store';
// Action Constants

// TODO #1 : Define the ADD_ATTEMPT and RESET_ATTEMPT actions
export const RESET_ATTEMPTS = '[Attempts] Reset Attempts';
export const ADD_ATTEMPT='Add attempts'

export const RESET_ATTEMPT = '[Attempts] Reset Attempts';

// Action Creators
// TODO #2 : Define the AddAttempt and ResetAttempts implementing the Action (@ngrx/store) interface
export class ResetAttempts {
export class ResetAttempts implements Action {
readonly type = RESET_ATTEMPT;
}

export class AddAttempts implements Action {
readonly type = ADD_ATTEMPT;
}

// Action Types
// TODO #3: Complete types for the Attempts Actions
export type AttemptsActions = ResetAttempts;
export type AttemptsActions = ResetAttempts | AddAttempts;
14 changes: 10 additions & 4 deletions src/app/store/actions/score.actions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
// Action Constants
// TODO #4 Add actions here
// TODO #4 Add the action to add score here
import { Action } from '@ngrx/store';

export const RESET_SCORE = '[Score] Setting the score to 0';

export const ADD_SCORE = 'Adding 1 to the score';

// Action Creators
// TODO #5 Implement action creators here
// TODO #5 Implement action creators to add the score here
export class ResetScore implements Action {
readonly type = RESET_SCORE;
}

export class AddScore implements Action {
readonly type = ADD_SCORE;
}

// Action Types
// TODO #6 Implement action types here. Do not forget export your things.
export type ScoreActions = ResetScore;
// TODO #6 Implement action types remaining here. Do not forget export your things.
export type ScoreActions = ResetScore | AddScore;
8 changes: 8 additions & 0 deletions src/app/store/reducers/attempts.reducer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fromAttempts from '../actions/attempts.actions';
import { ADD_ATTEMPT, RESET_ATTEMPT } from '../index';

// Interface
export interface Attempt {
Expand All @@ -23,6 +24,13 @@ export const initialState: AttemptsState = {
* @returns {AttemptsState}
*/
export function reducer(state = initialState, action: fromAttempts.AttemptsActions): AttemptsState {
switch(action.type) {
case ADD_ATTEMPT:
let newAttempts = Object.assign([], state.attempts);
newAttempts.push({});
case RESET_ATTEMPT:
return initialState;
}
// TODO #7 : Implement the reducer for the actions created
return state;
}
4 changes: 4 additions & 0 deletions src/app/store/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { ActionReducerMap } from '@ngrx/store';
*/
export interface ApplicationState {
ui: fromUi.UiState;
attempts: any;
score: any;
}

/**
Expand All @@ -16,4 +18,6 @@ export interface ApplicationState {
*/
export const reducers: ActionReducerMap<ApplicationState> = {
ui: fromUi.reducer,
attempts: () => {},
score: () => {}
};
5 changes: 3 additions & 2 deletions src/app/store/reducers/score.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface ScoreState {
// Initial state definition
// TODO #9 : Fix the initial state
export const initialState: ScoreState = {
scoreValue: 9999999
scoreValue: 0
};

/**
Expand All @@ -25,7 +25,8 @@ export function reducer(state = initialState, action: fromScore.ScoreActions): S
return {
scoreValue: 0
};

case fromScore.ADD_SCORE:
return { scoreValue: state.scoreValue++}
default:
return state;
}
Expand Down