Commit a669937e authored by Mamadou Saliou DIALLO's avatar Mamadou Saliou DIALLO

feat:handle multiple player service

parent 0a730747
import { ITPlayer } from 'src/codegen/common/TPlayer';
import { JoinRequest } from './../codegen/common/JoinRequest';
import { GameProxy } from './../thrift/game-proxy';
import { ICard, IJoinRequest, IPhase, IPhaseArgs, IPlace, IResponseArgs, IToken, TPlayer } from '../codegen/common';
......@@ -5,7 +6,7 @@ import { IHandler } from '../codegen/common/GameService';
import { PlayerService } from '../player/player-service';
export class ClientServiceHandler<Context> implements IHandler<Context> {
private service: PlayerService[] = [];
private services: PlayerService[];
private proxy: GameProxy;
private PROXY_CONFIG = {
hostName:'localhost',
......@@ -13,24 +14,50 @@ export class ClientServiceHandler<Context> implements IHandler<Context> {
}
constructor() {
this.proxy = new GameProxy(this.PROXY_CONFIG)
this.proxy = new GameProxy(this.PROXY_CONFIG);
this.services = [];
}
createGame(creator: TPlayer, numberOfPlayers: number, context?: Context): number | Promise<number> {
this.addPlayerService(creator);
return this.proxy.createGame(creator, numberOfPlayers);
}
/**
* Create new PlayerService and add it to the playerService list.
* @param player player to add
*/
private addPlayerService(player:TPlayer): void {
const playerService:PlayerService = new PlayerService(player);
this.services.push(playerService);
}
/**
* Convert ITPlayer object to TPlayer.
* @param iplayer ITPlayer instance to convert
*/
private ITPlayerToTPlayer(iplayer: ITPlayer):TPlayer{
return new TPlayer(iplayer)
}
join(request: IJoinRequest, context?: Context): number | Promise<number> {
const joinRequest = new JoinRequest({gameId:request.gameId, player: request.player})
return this.proxy.join(joinRequest);
return this.proxy.join(joinRequest).then( gameID => {
if(gameID > 0) {
if(request.player != undefined) {
this.addPlayerService(this.ITPlayerToTPlayer(request.player))
}
}
return gameID;
});
}
nextPhase(phase: IPhase, context?: Context): IPhaseArgs | Promise<IPhaseArgs> {
return this.nextPhase(phase);
return this.proxy.nextPhase(phase);
}
resits(hunted: any, context?: Context): IResponseArgs | Promise<IResponseArgs> {
return this.resits(hunted);
return this.proxy.resits(hunted);
}
letGo(hunted: any, context?: Context): IResponseArgs | Promise<IResponseArgs> {
......
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