Commit d896d37e authored by Corentin Guillevic's avatar Corentin Guillevic
Browse files

Add interface GameInterface ; Defines methods of client-service-handler,...

Add interface GameInterface ; Defines methods of client-service-handler, game-proxy ; Small changes in thrit-server and thrift-client
parent d71bda48
import { TPlayer, TRoomId, TBoard, TColor, TCard, TPlacedJeton, TPhase, TDescription } from 'src/codegen/common';
export interface GameInterface {
/*
createGame(numberOfPlayers: number): Promise<number>;
join(gameId: number): Promise<number>;
*/
createRoom(player: TPlayer): Promise<TRoomId>;
sendStartGame(player: TPlayer, creatureId: number, board: TBoard, color: TColor, placeCards: TCard[]): Promise<Response>;
joinRoom(player: TPlayer, roomId: TRoomId): Promise<Response>;
getGameDescription(player: TPlayer): Promise<TDescription>;
sendFinishPhase(player: TPlayer, phase: TPhase): Promise<void>;
sendPlayCards(player: TPlayer, playerCards: TCard[]): Promise<void>;
sendPlaceJetons(player: TPlayer, placedJetons: TPlacedJeton[]): Promise<void>;
sendResist(player: TPlayer, number: number): Promise<void>;
sendGiveUp(player: TPlayer): Promise<void>;
}
import { IJoinRequest } from 'src/codegen/common';
import { IHandler } from '../codegen/common/GameService';
import { TDescription, TPlayerTeam, TPhase, TAction, TAskAction, Response } from 'src/codegen/common';
// import { IHandler } from '../codegen/common/GameService';
import { IHandler } from '../codegen/common/PlayerService';
import { PlayerService } from '../player/player-service';
export class ClientServiceHandler<Context> implements IHandler<Context> {
private service: PlayerService;
constructor() {
this.service = new PlayerService();
}
/*
public createGame(numberOfPlayers: number, context?: Context): number | Promise<number> {
throw new Error('Method not implemented.');
}
......@@ -21,6 +23,81 @@ export class ClientServiceHandler<Context> implements IHandler<Context> {
public startGame(gameId: number): void | Promise<void> {
return this.service.startGame(gameId);
}
*/
public ping(): boolean | Promise<boolean> {
// return this.service.ping();
throw new Error('Method not implemented.');
}
public sendGameDescription(gameDescription: TDescription): void | Promise<void> {
throw new Error('Method not implemented.');
}
public sendGameStart(): void | Promise<void> {
throw new Error('Method not implemented.');
}
public sendGameIsFinished(winner: TPlayerTeam): void | Promise<void> {
throw new Error('Method not implemented.');
}
public sendFirstRoundStart(): void | Promise<void> {
throw new Error('Method not implemented.');
}
public sendStartPhase(phase: TPhase, gameDescription: TDescription): void | Promise<void> {
throw new Error('Method not implemented.');
}
public askAction(askedAction: TAskAction): TAction | Promise<TAction> {
throw new Error('Method not implemented.');
}
public sendAction(askedAction: TAskAction): void | Promise<void> {
throw new Error('Method not implemented.');
}
public sendResponse(response: Response): void | Promise<void> {
throw new Error('Method not implemented.');
}
/*
public ping(): boolean | Promise<boolean> {
return service.ping();
}
public sendGameDescription(gameDescription: TDescription): void | Promise<void> {
throw new Error('Method not implemented.');
}
public void sendGameStart() : void | Promise<void> {
throw new Error('Method not implemented.');
}
public void sendGameIsFinished(winner : TPlayerTeam) : void | Promise<void> {
throw new Error('Method not implemented.');
}
public void sendFirstRoundStart() : void | Promise<void> {
throw new Error('Method not implemented.');
}
public void sendStartPhase(phase : TPhase, gameDescription : TDescription) : void | Promise<void> {
throw new Error('Method not implemented.');
}
public askAction(askedAction : TAskAction) : TAction | Promise<TAction> {
return null;
}
public sendAction(askedAction : TAskAction) : void | Promise<void> {
throw new Error('Method not implemented.');
}
public sendResponse(response : Response) : void | Promise<void> {
throw new Error('Method not implemented.');
}
*/
}
......@@ -3,6 +3,7 @@ import { GameInterface } from '../core/game';
import { CoreOptions } from 'request';
import { createHttpClient, ICreateHttpClientOptions } from '@creditkarma/thrift-client';
import { IJoinRequest, JoinRequest } from '../codegen/common/JoinRequest';
import { TPlayer, TRoomId, TBoard, TColor, TCard, TDescription, TPhase, TPlacedJeton } from 'src/codegen/common';
export class GameProxy implements GameInterface {
private thriftClient: Client<CoreOptions>;
......@@ -10,7 +11,35 @@ export class GameProxy implements GameInterface {
constructor(options: ICreateHttpClientOptions) {
this.thriftClient = createHttpClient(Client, options);
}
createRoom(player: TPlayer): Promise<TRoomId> {
throw new Error('Method not implemented.');
}
sendStartGame(player: TPlayer, creatureId: number, board: TBoard, color: TColor, placeCards: TCard[]): Promise<Response> {
throw new Error('Method not implemented.');
}
joinRoom(player: TPlayer, roomId: TRoomId): Promise<Response> {
throw new Error('Method not implemented.');
}
getGameDescription(player: TPlayer): Promise<TDescription> {
throw new Error('Method not implemented.');
}
sendFinishPhase(player: TPlayer, phase: TPhase): Promise<void> {
throw new Error('Method not implemented.');
}
sendPlayCards(player: TPlayer, playerCards: TCard[]): Promise<void> {
throw new Error('Method not implemented.');
}
sendPlaceJetons(player: TPlayer, placedJetons: TPlacedJeton[]): Promise<void> {
throw new Error('Method not implemented.');
}
sendResist(player: TPlayer, number: number): Promise<void> {
throw new Error('Method not implemented.');
}
sendGiveUp(player: TPlayer): Promise<void> {
throw new Error('Method not implemented.');
}
/*
createGame(numberOfPlayers: number): Promise<number> {
return this.thriftClient.createGame(numberOfPlayers);
}
......@@ -20,4 +49,5 @@ export class GameProxy implements GameInterface {
request.name = 'me';
return this.thriftClient.join(gameId, request);
}
*/
}
......@@ -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 {}
import { GameService } from '../codegen/common/';
// import { GameService } from '../codegen/common/';
import { PlayerService } from '../codegen/common/';
import { ClientServiceHandler } from '../handler/client-service-handler';
import * as express from 'express';
import { createThriftServer } from '@creditkarma/thrift-server-express';
......@@ -14,7 +15,7 @@ export class ThriftServer {
path: '/thrift',
thriftOptions: {
serviceName: 'calculator-service',
handler: new GameService.Processor(handler),
handler: new PlayerService.Processor(handler),
},
});
this.app.listen(port, () => {
......
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