Commit 76299016 authored by Dennis Willers's avatar Dennis Willers 🏀

Get GameStatus Information

parent aabd33dc
Pipeline #290 passed with stages
in 5 minutes and 24 seconds
......@@ -31,7 +31,11 @@ export class TabuMiddlewareService {
}
addSession(req: any): Promise<any> {
console.log(req);
return this.request('POST', `${environment.tabuMiddlewareURL}addSession`, req);
}
getGamestatus(req: any): Promise<any> {
console.log(req);
return this.request('POST', `${environment.tabuMiddlewareURL}getGamestatus`, req);
}
}
export interface GameStatus {
sessionID: number;
red: number;
blue: number;
redTurn: boolean;
activeExplainer: boolean;
activeWatchdog: boolean;
}
import { Component, OnInit } from '@angular/core';
import {Router} from '@angular/router';
import {ActivatedRoute, Router} from '@angular/router';
import {TabuMiddlewareService} from '../dao/TabuMiddlewareService';
import {GameStatus} from '../interface/gameStatus';
@Component({
selector: 'app-overview',
......@@ -8,10 +10,39 @@ import {Router} from '@angular/router';
})
export class OverviewComponent implements OnInit {
constructor(private router: Router) { }
sessionName = '';
gameStatus: GameStatus = {
sessionID: -1,
red: 0,
blue: 0,
redTurn: true,
activeExplainer: false,
activeWatchdog: false
};
constructor(private router: Router,
private activatedRoute: ActivatedRoute,
private service: TabuMiddlewareService) { }
ngOnInit(): void {
this.activatedRoute.paramMap.subscribe(params => {
this.sessionName = String(params.get('sessionName'));
console.log('SessionName: ', this.sessionName);
this.service.getGamestatus({"spielname": this.sessionName}).then(value => {
const status = JSON.parse(value.status);
if (status) {
this.gameStatus.sessionID = JSON.parse(value.sessionID);
this.gameStatus.red = JSON.parse(value.red);
this.gameStatus.blue = JSON.parse(value.blue);
this.gameStatus.redTurn = JSON.parse(value.redTurn);
this.gameStatus.activeExplainer = JSON.parse(value.activeExplainer);
this.gameStatus.activeWatchdog = JSON.parse(value.activeWatchdog);
}
console.log(this.gameStatus);
}).catch(reason => console.log(reason));
});
}
startGame(): void {
this.router.navigate([this.router.url+'/red/watchdog']);
}
......
......@@ -13,13 +13,13 @@
<form>
<mat-form-field>
<mat-label>Spielname</mat-label>
<input #spielname type="text" matInput (keyup)="checkSpielname(spielname.value)" (keypress)="keyPressAlphaNumeric($event)">
<input #sessionName type="text" matInput (keyup)="checkSpielname(sessionName.value)" (keypress)="keyPressAlphaNumeric($event)">
</mat-form-field>
</form>
</mat-card-content>
<mat-card-actions>
<button [disabled]="buttonCreateGameDisabled" mat-raised-button color="primary" (click)="createGame(spielname.value)">Spiel erstellen</button>
<button [disabled]="buttonJoinGameDisabled" mat-raised-button color="primary" (click)="joinGame(spielname.value)">Spiel beitreten</button>
<button [disabled]="buttonCreateGameDisabled" mat-raised-button color="primary" (click)="createGame(sessionName.value)">Spiel erstellen</button>
<button [disabled]="buttonJoinGameDisabled" mat-raised-button color="primary" (click)="joinGame(sessionName.value)">Spiel beitreten</button>
</mat-card-actions>
</mat-card>
</div>
......@@ -23,12 +23,12 @@ export class SelectGameComponent implements OnInit {
console.log('Response:', response);
}
createGame(spielname: string): void {
this.server.addSession({"spielname": '' + spielname + ''}).then(value => {
createGame(sessionName: string): void {
this.server.addSession({"spielname": sessionName}).then(value => {
console.log(value);
const status = JSON.parse(value.status);
if (status) {
this.router.navigate([spielname]);
this.router.navigate([sessionName]);
}
}).catch(reason => {
console.log(reason);
......@@ -36,8 +36,8 @@ export class SelectGameComponent implements OnInit {
});
}
joinGame(spielname: string): void {
this.router.navigate([spielname]);
joinGame(sessionName: string): void {
this.router.navigate([sessionName]);
}
keyPressAlphaNumeric(event: KeyboardEvent): boolean {
......@@ -49,13 +49,13 @@ export class SelectGameComponent implements OnInit {
}
}
checkSpielname(spielname: string): void {
if (spielname.length === 0) {
checkSpielname(sessionName: string): void {
if (sessionName.length === 0) {
this.buttonCreateGameDisabled = true;
this.buttonJoinGameDisabled = true;
return;
} else {
this.server.isSession({'spielname': spielname}).then(value => {
this.server.isSession({'spielname': sessionName}).then(value => {
console.log('Response: ', value.status);
const status = JSON.parse(value.status);
if (status) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment