Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ const routes: Routes = [
component: QuestionWindowComponent,
},
{
path: PathsEnum.CORRECT_ANSWER,
path: `${PathsEnum.CORRECT_ANSWER}/:points`,
component: CorrectAnswerWindowComponent,
},
{
path: PathsEnum.WRONG_ANSWER,
path: `${PathsEnum.WRONG_ANSWER}/:answer`,
component: WrongAnswerWindowComponent
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@

label
text-align: center


margin: 5px
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, OnInit} from '@angular/core';
import {Router} from "@angular/router";
import {ActivatedRoute, Router} from "@angular/router";
import {PathsEnum} from "../../model/PathsEnum";
import {StorageService} from "../../service/storage.service";
import {AppStorage} from "../../model/AppStorage";
Expand All @@ -11,14 +11,16 @@ import {AppStorage} from "../../model/AppStorage";
})
export class CorrectAnswerWindowComponent implements OnInit {

public questionScore: number = 10;
public questionScore: number = 0;

private correctAnswerSound: HTMLAudioElement = new Audio('assets/sounds/tada.wav');

constructor(
private readonly router: Router,
private readonly route: ActivatedRoute,
private readonly storageService: StorageService
) {
this.questionScore = parseInt(this.route.snapshot.paramMap.get('points') ?? '0');
}

public async ngOnInit(): Promise<void> {
Expand Down
1 change: 1 addition & 0 deletions src/app/question-window/question-window.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ng-container *ngIf="this.questionLoaded">
<div class="window_question_body_loaded">
<label class="window_question_body_loaded_title">{{this.question}}</label>
<label class="window_question_body_loaded_points">[{{this.questionPoints}} point(s) for this question]</label>
<div class="window_question_body_loaded_list">
<ng-container *ngFor="let answer of this.answers">
<button [disabled]="this.selectedAnswer"
Expand Down
4 changes: 4 additions & 0 deletions src/app/question-window/question-window.component.sass
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
font-weight: bold
max-width: 250px

&_points
font-style: italic
margin: 0px 5px 5px 5px

&_list
display: flex
flex-direction: column
Expand Down
25 changes: 21 additions & 4 deletions src/app/question-window/question-window.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class QuestionWindowComponent implements OnInit {

public questionLoaded: boolean = false;
public question: string = '';
public questionPoints: number = 0;
public answers: string[] = [];
public selectedAnswer: string = '';
public confirmedAnswer: boolean = false;
Expand All @@ -24,7 +25,6 @@ export class QuestionWindowComponent implements OnInit {
private confirmAnswerSound: HTMLAudioElement = new Audio('assets/sounds/exclamation.wav');
private correctAnswer: string = '';


constructor(
private readonly triviaService: TriviaService,
private readonly router: Router
Expand Down Expand Up @@ -63,6 +63,8 @@ export class QuestionWindowComponent implements OnInit {
this.questionLoaded = true;

await this.questionReadySound.play();

this.questionPoints = this.sumQuestionPoints(singleQuiz.difficulty, singleQuiz.isNiche);
});
}

Expand All @@ -87,10 +89,25 @@ export class QuestionWindowComponent implements OnInit {

private async redirectFromAnswer(): Promise<void> {
const correctAnswer: boolean = this.selectedAnswer === this.correctAnswer;
const routeToNavigate: string = correctAnswer ? PathsEnum.CORRECT_ANSWER : PathsEnum.WRONG_ANSWER_NO_PARAM;
const answer: string | null = correctAnswer ? null : this.correctAnswer;

await this.router.navigate(answer === null ? [routeToNavigate] : [routeToNavigate, answer]);
if (correctAnswer) {
await this.router.navigate([PathsEnum.CORRECT_ANSWER, this.questionPoints]);
} else {
await this.router.navigate([PathsEnum.WRONG_ANSWER, this.correctAnswer]);
}
}

private sumQuestionPoints(questionDifficulty: string, isNiche: boolean): number {
const difficultyPointsMap: Map<string, number> = new Map<string, number>([
['easy', 1],
['medium', 3],
['hard', 5]
]);

const questionPoints: number = difficultyPointsMap.get(questionDifficulty)!;
const nichePoints: number = isNiche ? 10 : 0;

return questionPoints + nichePoints;
}

private startLoadingProgressBar(): void {
Expand Down
3 changes: 1 addition & 2 deletions src/model/PathsEnum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ export enum PathsEnum {
ABOUT = 'about',
QUIZ = 'quiz',
CORRECT_ANSWER = 'correct-answer',
WRONG_ANSWER = 'wrong-answer/:answer',
WRONG_ANSWER_NO_PARAM = 'wrong-answer'
WRONG_ANSWER = 'wrong-answer',
}