@@ -3,6 +3,7 @@ import {HttpErrorResponse} from '@angular/common/http';
3
3
import { Router } from '@angular/router' ;
4
4
import { ToastrService } from 'ngx-toastr' ;
5
5
import { GameServerService } from '../game-server.service' ;
6
+ import { GameModel } from '../../shared/game.model' ;
6
7
7
8
@Component ( {
8
9
selector : 'app-game' ,
@@ -19,7 +20,7 @@ export class GameComponent implements OnInit {
19
20
buttonLetters : string [ ] ;
20
21
images : string [ ] ;
21
22
letters : string [ ] ;
22
- game : any ;
23
+ game : GameModel ;
23
24
constructor ( private serverService : GameServerService , private router : Router , private toastr : ToastrService ) { }
24
25
ngOnInit ( ) {
25
26
this . loading = false ;
@@ -32,7 +33,7 @@ export class GameComponent implements OnInit {
32
33
, './assets/GRAFIK/forkert5.png' , './assets/GRAFIK/forkert6.png' ] ;
33
34
this . letters = [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' ,
34
35
'o' , 'p' , 'q' , 'r' , 's' , 't' , 'u' , 'v' , 'w' , 'x' , 'y' , 'z' ] ;
35
- this . game = < any > {
36
+ this . game = {
36
37
gameHasBeenLost : false ,
37
38
gameHasBeenWon : false ,
38
39
hasGameBegun : false ,
@@ -54,7 +55,7 @@ export class GameComponent implements OnInit {
54
55
newGame ( ) {
55
56
this . loading = true ;
56
57
this . serverService . getGame ( ) . subscribe (
57
- ( response : Response ) => {
58
+ response => {
58
59
this . loading = false ;
59
60
this . game = response ;
60
61
this . toastr . success ( 'Previous game loaded.' ) ;
@@ -72,7 +73,7 @@ export class GameComponent implements OnInit {
72
73
this . sessionExpired = true ;
73
74
} else if ( error . status !== 400 ) { this . toastr . error ( 'An error occurred, check the console' ) ; console . log ( error ) ; } else {
74
75
this . serverService . restartGame ( ) . subscribe (
75
- ( restartResponse : Response ) => {
76
+ ( restartResponse : GameModel ) => {
76
77
console . log ( 'This is a restart response:' ) ;
77
78
this . game = restartResponse ;
78
79
console . log ( restartResponse ) ;
@@ -91,7 +92,7 @@ export class GameComponent implements OnInit {
91
92
onStartGameClicked ( ) {
92
93
this . loading = true ;
93
94
this . serverService . startGame ( ) . subscribe (
94
- ( response : Response ) => {
95
+ response => {
95
96
this . game = response ;
96
97
this . gameStatus = 'You can start guessing the new game now!' ;
97
98
this . greenText = '' ;
@@ -101,7 +102,7 @@ export class GameComponent implements OnInit {
101
102
console . log ( error . status . toString ( ) ) ;
102
103
console . log ( error . error . error_message ) ;
103
104
this . serverService . restartGame ( ) . subscribe (
104
- ( restartResponse : Response ) => {
105
+ ( restartResponse : GameModel ) => {
105
106
console . log ( 'This is a restart response:' ) ;
106
107
this . game = restartResponse ;
107
108
this . loading = false ;
@@ -117,13 +118,18 @@ export class GameComponent implements OnInit {
117
118
}
118
119
onLetterClick ( letter : string ) {
119
120
this . game . usedLetters . push ( letter ) ;
120
- this . serverService . guessLetter ( letter ) . subscribe ( ( res : Response ) => {
121
- this . game = res ;
121
+ this . serverService . guessLetter ( letter ) . subscribe ( res => {
122
+ this . game . visibleWord = res . visibleWord ;
123
+ this . game . gameHasBeenLost = res . gameHasBeenLost ;
124
+ this . game . gameHasBeenWon = res . gameHasBeenWon ;
125
+ this . game . lastGuessedLetterIsCorrect = res . lastGuessedLetterIsCorrect ;
122
126
if ( this . game . gameHasBeenLost ) {
127
+ this . game = res ;
123
128
this . greenText = '' ;
124
129
this . redText = 'You have lost, ' ;
125
130
this . gameStatus = 'try again' ;
126
131
} else if ( this . game . gameHasBeenWon ) {
132
+ this . game = res ;
127
133
this . redText = '' ;
128
134
this . greenText = 'Great job, ' ;
129
135
this . gameStatus = 'you won the game!' ;
0 commit comments