From 455594889ade1b210d6d5bff13b4985479f70b1e Mon Sep 17 00:00:00 2001 From: Jimmy Date: Sat, 14 Apr 2018 13:28:26 -0500 Subject: [PATCH 1/2] Solucion --- src/app/core/services/game-state.service.ts | 33 +++++++++++---------- src/app/core/services/player.service.ts | 25 +++++++++++----- src/app/states/game/game.component.html | 12 ++++++-- src/app/states/game/game.component.ts | 29 ++++++++++++++---- 4 files changed, 68 insertions(+), 31 deletions(-) diff --git a/src/app/core/services/game-state.service.ts b/src/app/core/services/game-state.service.ts index 4bc750d..bf05f50 100644 --- a/src/app/core/services/game-state.service.ts +++ b/src/app/core/services/game-state.service.ts @@ -1,16 +1,16 @@ -import {Injectable} from '@angular/core'; +import { Injectable } from '@angular/core'; import 'rxjs/add/operator/map'; import 'rxjs/add/observable/of'; -import {Observable} from 'rxjs/Observable'; -import {HttpClient} from '@angular/common/http'; -import {BehaviorSubject} from 'rxjs/BehaviorSubject'; +import { Observable } from 'rxjs/Observable'; +import { HttpClient } from '@angular/common/http'; +import { BehaviorSubject } from 'rxjs/BehaviorSubject'; -import {environment} from '../../../environments/environment'; -import {SessionService} from './uthorization/session.service'; -import {Credentials} from '../model/credentials'; +import { environment } from '../../../environments/environment'; +import { SessionService } from './uthorization/session.service'; +import { Credentials } from '../model/credentials'; import Player from '../model/player'; -import {PlayerService} from './player.service'; +import { PlayerService } from './player.service'; @Injectable() @@ -26,17 +26,17 @@ export class GameStateService { eventSource.addEventListener('gameState', (e) => { console.log('gameState', e); const game = JSON.parse(e.data); - if (this.getPlayerDto(this.sessionService.getCredentials().email, game.players)){ + if (this.getPlayerDto(this.sessionService.getCredentials().email, game.players)) { this.eventObserver.next(game); } else { this.playerService.getPlayerState().subscribe((playerGame) => { if (playerGame.players) { this.eventObserver.next(playerGame); - return {playerGame}; + return { playerGame }; } else { return playerService.getPlayer().subscribe(player => { - this.eventObserver.next({...playerGame, players: [player]}); - return {...playerGame, players: [player]}; + this.eventObserver.next({ ...playerGame, players: [player] }); + return { ...playerGame, players: [player] }; }); } }); @@ -46,11 +46,11 @@ export class GameStateService { this.playerService.getPlayerState().subscribe((playerGame) => { if (playerGame.players) { this.eventObserver.next(playerGame); - return {playerGame}; + return { playerGame }; } else { return playerService.getPlayer().subscribe(player => { - this.eventObserver.next({...playerGame, players: [player]}); - return {...playerGame, players: [player]}; + this.eventObserver.next({ ...playerGame, players: [player] }); + return { ...playerGame, players: [player] }; }); } }); @@ -95,4 +95,7 @@ export class GameStateService { } } } + + + } diff --git a/src/app/core/services/player.service.ts b/src/app/core/services/player.service.ts index a0d5d4f..2252536 100644 --- a/src/app/core/services/player.service.ts +++ b/src/app/core/services/player.service.ts @@ -1,10 +1,10 @@ -import {Injectable} from '@angular/core'; +import { Injectable } from '@angular/core'; import 'rxjs/add/operator/map'; -import {HttpClient} from '@angular/common/http'; -import {environment} from '../../../environments/environment'; -import {SessionService} from './uthorization/session.service'; -import {Credentials} from '../model/credentials'; -import {Observable} from "rxjs/Observable"; +import { HttpClient } from '@angular/common/http'; +import { environment } from '../../../environments/environment'; +import { SessionService } from './uthorization/session.service'; +import { Credentials } from '../model/credentials'; +import { Observable } from "rxjs/Observable"; @Injectable() @@ -16,12 +16,21 @@ export class PlayerService { this.credentials = sessionService.getCredentials(); } - getPlayerState(): Observable{ + getPlayerState(): Observable { return this.http.get(`${environment.api}/api/player/state`); } - getPlayer(){ + getPlayer() { return this.http.get(`${environment.api}/api/player/`); } + bet(token: string, bet: number) { + console.log(this.http.post(`${environment.api}/api/player/bet`, { + token: token, + bet: bet + }).subscribe((item)=>{ + console.log(item); + }) + } + } diff --git a/src/app/states/game/game.component.html b/src/app/states/game/game.component.html index 8d1b414..8fcd36d 100644 --- a/src/app/states/game/game.component.html +++ b/src/app/states/game/game.component.html @@ -11,11 +11,19 @@

Let's Play!

+ + + +
- + + + + +
- + \ No newline at end of file diff --git a/src/app/states/game/game.component.ts b/src/app/states/game/game.component.ts index 39e1c4c..43214e8 100644 --- a/src/app/states/game/game.component.ts +++ b/src/app/states/game/game.component.ts @@ -1,12 +1,17 @@ -import {Component, OnInit} from '@angular/core'; -import {GameStateService} from '../../core/services/game-state.service'; -import {Observable} from 'rxjs/Observable'; +import { Component, OnInit } from '@angular/core'; +import { GameStateService } from '../../core/services/game-state.service'; +import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; +//Services +import { SessionService } from '../../core/services/uthorization/session.service'; -import {PlayerService} from '../../core/services/player.service'; + + +import { PlayerService } from '../../core/services/player.service'; import Player from '../../core/model/player'; + @Component({ selector: 'app-game', templateUrl: './game.component.html', @@ -24,7 +29,10 @@ export class GameComponent implements OnInit { DEALER_TURN: 'Dealer\'s turn' }; - constructor(private gameStateService: GameStateService, private playerService: PlayerService) { + constructor( + private gameStateService: GameStateService, + private playerService: PlayerService, + private sessionService: SessionService) { } ngOnInit() { @@ -34,7 +42,16 @@ export class GameComponent implements OnInit { }); } - bet() { + bet(betText: any) { + let betValue: number = parseInt(betText == "" ? "0" : betText); + if (betValue == 0) { + betValue = 100; + } + + console.log(betValue); + let token:string = this.sessionService.getSessionToken(); + + this.playerService.bet(token, betValue); } From 360e8d1f46fdf5aba453121b1e4316e12d99dcf5 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Sat, 14 Apr 2018 14:17:38 -0500 Subject: [PATCH 2/2] Nueva Version --- src/app/core/services/player.service.ts | 25 +++++++++++++++++++++---- src/app/states/game/game.component.html | 4 ++-- src/app/states/game/game.component.ts | 8 ++++---- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/app/core/services/player.service.ts b/src/app/core/services/player.service.ts index 2252536..28c66b0 100644 --- a/src/app/core/services/player.service.ts +++ b/src/app/core/services/player.service.ts @@ -25,12 +25,29 @@ export class PlayerService { } bet(token: string, bet: number) { - console.log(this.http.post(`${environment.api}/api/player/bet`, { - token: token, - bet: bet + this.http.post(`${environment.api}/api/player/bet`, { + 'token': token, + 'bet': { + value : bet + } + }).subscribe((item)=>{ + }); + } + + stand(token: string) { + this.http.post(`${environment.api}/api/player/stand`, { + token: token + }).subscribe((item)=>{ + console.log(item); + }); + } + + hit(token: string) { + this.http.post(`${environment.api}/api/player/hit`, { + token: token }).subscribe((item)=>{ console.log(item); - }) + }); } } diff --git a/src/app/states/game/game.component.html b/src/app/states/game/game.component.html index 8fcd36d..cdbf853 100644 --- a/src/app/states/game/game.component.html +++ b/src/app/states/game/game.component.html @@ -19,8 +19,8 @@

Let's Play!

- - + + diff --git a/src/app/states/game/game.component.ts b/src/app/states/game/game.component.ts index 43214e8..3393ee5 100644 --- a/src/app/states/game/game.component.ts +++ b/src/app/states/game/game.component.ts @@ -47,20 +47,20 @@ export class GameComponent implements OnInit { if (betValue == 0) { betValue = 100; } - console.log(betValue); let token:string = this.sessionService.getSessionToken(); this.playerService.bet(token, betValue); - } hit() { - + let token:string = this.sessionService.getSessionToken(); + this.playerService.hit(token); } stand() { - + let token:string = this.sessionService.getSessionToken(); + this.playerService.stand(token); } }