Almost working BioTrivia
This commit is contained in:
parent
32cfb0fcaa
commit
a5fd7f49c7
@ -1,4 +1,5 @@
|
|||||||
import { Component, ElementRef, NgZone, OnInit, ViewChild, ViewChildren } from '@angular/core';
|
import { Component, ElementRef, NgZone, OnInit, ViewChild, ViewChildren } from '@angular/core';
|
||||||
|
import { IgxRadioComponent, IgxRadioGroupDirective } from 'igniteui-angular';
|
||||||
import { Observable, Subject } from 'rxjs';
|
import { Observable, Subject } from 'rxjs';
|
||||||
import { Answer, DbService, Question } from '../db.service';
|
import { Answer, DbService, Question } from '../db.service';
|
||||||
|
|
||||||
@ -11,28 +12,65 @@ import { Answer, DbService, Question } from '../db.service';
|
|||||||
export class MinigameBiotriviaComponent implements OnInit {
|
export class MinigameBiotriviaComponent implements OnInit {
|
||||||
@ViewChildren('startDialog') startingElementRef;
|
@ViewChildren('startDialog') startingElementRef;
|
||||||
@ViewChildren('ongoingDialog') ongoingElementRef;
|
@ViewChildren('ongoingDialog') ongoingElementRef;
|
||||||
|
@ViewChildren('endDialog') endingElementRef;
|
||||||
|
|
||||||
guessedQuestions = 0;
|
stage: 'starting' | 'starting-ongoing' | 'ongoing' | 'ongoing-ended' | 'ended' = 'starting';
|
||||||
stage: 'starting' | 'starting-ongoing' | 'ongoing' | 'ended' = 'starting';
|
|
||||||
|
|
||||||
questions: Question[];
|
questions: Question[];
|
||||||
|
|
||||||
|
displayError = false;
|
||||||
|
|
||||||
|
guessedQuestions = 0;
|
||||||
currQuestionN = 0;
|
currQuestionN = 0;
|
||||||
currQuestion: Question;
|
currQuestion: Question;
|
||||||
currAnswers: string[];
|
currAnswers: string[];
|
||||||
|
|
||||||
selected: string;
|
previousAnswers: Array<{ question: Question, answer: string }> = [];
|
||||||
|
|
||||||
|
selectedAnswer = '';
|
||||||
|
isAnswered(): boolean {
|
||||||
|
return this.selectedAnswer !== '';
|
||||||
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private zone: NgZone,
|
|
||||||
private db: DbService
|
private db: DbService
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
test() {
|
submitAnswer(): void {
|
||||||
console.log('sdfgui s');
|
if (!this.isAnswered()) {
|
||||||
|
this.displayError = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.ongoingElementRef.first.nativeElement.style.position = 'absolute';
|
||||||
|
|
||||||
|
if (this.selectedAnswer === this.currQuestion.answer.correctChoise) this.guessedQuestions++;
|
||||||
|
|
||||||
|
this.previousAnswers.push({
|
||||||
|
answer: ''
|
||||||
|
})
|
||||||
|
|
||||||
|
if (this.currQuestionN >= this.questions.length) {
|
||||||
|
this.stage = 'ongoing-ended';
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
this.endingElementRef.first.nativeElement.style.opacity = 0;
|
||||||
|
this.animateElements(
|
||||||
|
this.ongoingElementRef.first.nativeElement,
|
||||||
|
this.endingElementRef.first.nativeElement
|
||||||
|
// tslint:disable-next-line: deprecation
|
||||||
|
).subscribe(() => {
|
||||||
|
this.stage = 'ended';
|
||||||
|
});
|
||||||
|
}, 10);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.displayError = false;
|
||||||
|
this.selectedAnswer = '';
|
||||||
|
this.loadNextQuestion();
|
||||||
}
|
}
|
||||||
|
|
||||||
animateElements(el1: HTMLElement, el2: HTMLElement): Observable<void> {
|
animateElements(el1: HTMLElement, el2: HTMLElement): Observable<void> {
|
||||||
@ -87,14 +125,12 @@ export class MinigameBiotriviaComponent implements OnInit {
|
|||||||
startingEl.style.position = 'absolute';
|
startingEl.style.position = 'absolute';
|
||||||
|
|
||||||
this.stage = 'starting-ongoing';
|
this.stage = 'starting-ongoing';
|
||||||
this.questions = this.db.getRandomQuestions(5, this.db.getRandomCategory());
|
this.questions = this.db.getRandomQuestions(1, this.db.getRandomCategory());
|
||||||
this.loadNextQuestion();
|
this.loadNextQuestion();
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const ongoingEl = this.ongoingElementRef.first.nativeElement as HTMLElement;
|
const ongoingEl = this.ongoingElementRef.first.nativeElement as HTMLElement;
|
||||||
|
|
||||||
console.log(this.questions);
|
|
||||||
|
|
||||||
// tslint:disable-next-line: deprecation
|
// tslint:disable-next-line: deprecation
|
||||||
this.animateElements(startingEl, ongoingEl).subscribe(() => {
|
this.animateElements(startingEl, ongoingEl).subscribe(() => {
|
||||||
this.stage = 'ongoing';
|
this.stage = 'ongoing';
|
||||||
|
Loading…
Reference in New Issue
Block a user