finished align game

This commit is contained in:
Ryan Bakkes 2022-01-07 17:53:05 +01:00
parent 2e62c0f3f6
commit 93c3387afd
2 changed files with 35 additions and 5 deletions

View File

@ -65,3 +65,9 @@
</ion-item>
</ion-list>
</ion-content>
<ion-footer>
<ion-toolbar>
<ion-button [disabled]="!this.mayContinue" (click)="continueGame()" color="primary" size="large" shape="round" expand="block">Continue</ion-button>
</ion-toolbar>
</ion-footer>

View File

@ -1,7 +1,6 @@
import { Component, Input, ViewChildren, QueryList, ElementRef, EventEmitter, Output, Renderer2, ViewChild } from '@angular/core';
import { Component, Renderer2 } from '@angular/core';
import { Router } from '@angular/router';
import { GestureController } from '@ionic/angular';
import { retry } from 'rxjs/operators';
import { AlertService } from '../services/alert.service';
import { GameService } from '../services/game.service';
@Component({
@ -11,7 +10,9 @@ import { GameService } from '../services/game.service';
})
export class ValuesAlignPage {
constructor(private router: Router, private game: GameService, private renderer: Renderer2) {}
mayContinue: boolean;
constructor(private router: Router, private game: GameService, private renderer: Renderer2, public alert: AlertService) {}
async checkValues(){
@ -33,9 +34,32 @@ export class ValuesAlignPage {
if(!(await this.checkValues())){
return;
}
this.mayContinue = true;
// User may continue
console.log("hihi go go");
};
async continueGame(){
// check one more time if the user may continue
if(!this.mayContinue){
this.alert.presentToast("Give to all the cards a value first");
return;
}
this.alert.showLoader("Please wait");
// remove all the cards with value false from array
for(var i = 0; i < this.game.cardset.length; i++){
const card = this.game.cardset[i];
console.log(card.id);
if(card.value == 2){
this.game.cardset.splice(i,1);
i--;
}
}
// set storage and go to the next page
await this.game.saveGameStorage("Values", "Insert", this.game.cardset);
this.alert.hideLoader();
this.router.navigateByUrl(`/home`);
}
}