Commit af68443a authored by Mamadou Saliou DIALLO's avatar Mamadou Saliou DIALLO
Browse files

feat: create client game proxy

parent 276c39a3
This diff is collapsed.
......@@ -21,7 +21,9 @@
"dependencies": {
"@creditkarma/thrift-client": "^0.16.1",
"@creditkarma/thrift-server-core": "^0.16.1",
"@creditkarma/thrift-server-express": "^0.16.1"
"@creditkarma/thrift-server-express": "^0.16.1",
"@types/express": "^4.17.9",
"express": "^4.17.1"
},
"browser": {
"crypto": false,
......
import { IPlace } from './../codegen/common/Place';
import { IToken } from './../codegen/common/Token';
import { ICard } from './../codegen/common/Card';
import { IPhase } from './../codegen/common/Phase';
import { IResponse } from './../codegen/common/Response';
import { IPlayer } from './../codegen/common/Player';
import { IJoinRequest} from 'src/codegen/common';
import { Player } from 'src/codegen/common/Player';
/**
* Game interface.
*/
export interface GameInterface {
createGame(numberOfPlayers: number): Promise<number>;
join(gameId: number): Promise<number>;
/**
* Create new game.
* @param creator Player
* @param numberOfPlayers number of player
*/
createGame(creator: Player, numberOfPlayers: number): Promise<number>;
/**
* Join an existing game.
* @param request JoinRequest
*/
join(request: IJoinRequest): Promise<number>;
/**
* Next phase.
* @param phase Phase of game
*/
nextPhase(phase: IPhase): Promise<IPhase>;
/**
* Play a tracking card.
* @param creature Creature player
* @param card Card to play
*/
playHuntCard(creature: IPlayer, card: ICard): Promise<IResponse>;
/**
* Play a place card.
* @param hunted Tracked player
* @param card Place card
*/
playPlaceCard(hunted: IPlayer, card: ICard): Promise<IResponse>;
/**
* Put token on a place card.
* @param token Token to put
* @param place Card where to put the token
*/
putToken(token: IToken, place: IPlace): Promise<IResponse>;
/**
* Resists action.
* @param hunted Tracked player
*/
resits(hunted: IPlayer): Promise<IResponse>;
/**
* Let go
* @param hunted Tracked player
*/
toGo(hunted: IPlayer): Promise<IResponse>;
}
import { IJoinRequest } from 'src/codegen/common';
import { ICard, IJoinRequest, IPhase, IPhaseArgs, IPlace, IPlayer, IResponseArgs, IToken } from 'src/codegen/common';
import { IHandler } from '../codegen/common/GameService';
import { PlayerService } from '../player/player-service';
......@@ -10,17 +10,52 @@ export class ClientServiceHandler<Context> implements IHandler<Context> {
this.service = new PlayerService();
}
public createGame(numberOfPlayers: number, context?: Context): number | Promise<number> {
createGame(creator: IPlayer, numberOfPlayers: number, context?: Context): number | Promise<number> {
throw new Error('Method not implemented.');
}
join(request: IJoinRequest, context?: Context): number | Promise<number> {
throw new Error('Method not implemented.');
}
public join(gameId: number, request: IJoinRequest, context?: Context): number | Promise<number> {
/*public createGame(numberOfPlayers: number, context?: Context): number | Promise<number> {
throw new Error('Method not implemented.');
}
public join(gameId: number, request: IJoinRequest, context?: Context): number | Promise<number> {
throw new Error('Method not implemented.');
}*/
public startGame(gameId: number): void | Promise<void> {
return this.service.startGame(gameId);
}
isConnected(player: any, params: any, context?: Context): IResponseArgs | Promise<IResponseArgs> {
throw new Error('Method not implemented.');
}
nextPhase(phase: IPhase, context?: Context): IPhaseArgs | Promise<IPhaseArgs> {
throw new Error('Method not implemented.');
}
resits(hunted: any, context?: Context): IResponseArgs | Promise<IResponseArgs> {
throw new Error('Method not implemented.');
}
toGo(hunted: any, context?: Context): IResponseArgs | Promise<IResponseArgs> {
throw new Error('Method not implemented.');
}
playPlaceCard(hunted: any, card: ICard, context?: Context): IResponseArgs | Promise<IResponseArgs> {
throw new Error('Method not implemented.');
}
putToken(token: IToken, place: IPlace, context?: Context): IResponseArgs | Promise<IResponseArgs> {
throw new Error('Method not implemented.');
}
playHuntCard(creature: any, card: ICard, context?: Context): IResponseArgs | Promise<IResponseArgs> {
throw new Error('Method not implemented.');
}
}
......@@ -2,7 +2,9 @@ import { Client } from 'src/codegen/common/GameService';
import { GameInterface } from '../core/game';
import { CoreOptions } from 'request';
import { createHttpClient, ICreateHttpClientOptions } from '@creditkarma/thrift-client';
import { IJoinRequest, JoinRequest } from '../codegen/common/JoinRequest';
import { JoinRequest } from '../codegen/common/JoinRequest';
import { IPlayer, Player } from 'src/codegen/common/Player';
import { IPhase, ICard, IResponse, IToken, IPlace } from 'src/codegen/common';
export class GameProxy implements GameInterface {
private thriftClient: Client<CoreOptions>;
......@@ -11,13 +13,35 @@ export class GameProxy implements GameInterface {
this.thriftClient = createHttpClient(Client, options);
}
createGame(numberOfPlayers: number): Promise<number> {
return this.thriftClient.createGame(numberOfPlayers);
createGame(creator: Player, numberOfPlayers: number): Promise<number> {
return this.thriftClient.createGame(creator, numberOfPlayers);
}
join(gameId: number): Promise<number> {
const request: IJoinRequest = new JoinRequest();
request.name = 'me';
return this.thriftClient.join(gameId, request);
join(request: JoinRequest): Promise<number> {
return this.thriftClient.join(request);
}
nextPhase(phase: IPhase): Promise<IPhase> {
return this.thriftClient.nextPhase(phase);
}
playHuntCard(creature: IPlayer, card: ICard): Promise<IResponse> {
return this.thriftClient.playHuntCard(creature, card);
}
playPlaceCard(hunted: IPlayer, card: ICard): Promise<IResponse> {
return this.thriftClient.playPlaceCard(hunted, card);
}
putToken(token: IToken, place: IPlace): Promise<IResponse> {
return this.thriftClient.putToken(token, place);
}
resits(hunted: IPlayer): Promise<IResponse> {
return this.thriftClient.resits(hunted);
}
toGo(hunted: IPlayer): Promise<IResponse> {
return this.thriftClient.toGo(hunted);
}
}
......@@ -11,6 +11,6 @@ const CONFIG = {
const thriftClient: Client<CoreOptions> = createHttpClient(Client, CONFIG);
const id: Promise<Number> = thriftClient.createGame(8);
// const id: Promise<Number> = thriftClient.createGame(8);
export class ThriftClient {}
This diff is collapsed.
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