Commit e01f4372 authored by Joseph NISON--GUYON's avatar Joseph NISON--GUYON
Browse files

Refactoring de game-proxy.ts pour utiliser les méthodes du serveur

Passage en paramètre de phase dans askCarteTraque et askCarteSurvie
Ajout de piocherSurvie à traque.ts
Ajout de piocherTraque à creature.ts
parent c2cbf5a3
......@@ -11,7 +11,9 @@ service PlayerService {
void recupLieuxFromDefausse()
void askCarteSurvie()
void askCarteTraque(i32 phase)
void askCarteSurvie(i32 phase)
void askCartesLieu()
......@@ -23,14 +25,16 @@ service PlayerService {
void resister(i32 gameId, list<i32> cartes)
void troisCartes()
void troisCartes(i32 gameId)
void placerArtemia(i32 gameId, i32 lieu)
void placerArtemia(i32 gameId, list<i32> lieux)
void placerCreature(i32 gameId, i32 lieu)
void placerCreature(i32 gameId, list<i32> lieux)
void placerCible(i32 gameId, list<i32> lieux)
void askCarteTraque(i32 gameId, string carte)
void piocherTraque(i32 gameId)
void piocherSurvie(i32 gameId)
}
......@@ -42,19 +42,19 @@ export class ClientServiceHandler<Context> implements IHandler<Context> {
}
askCarteTraque(): void | Promise<void> {
public recupLieuxFromDefausse(): void | Promise<void> {
}
public recupLieuxFromDefausse(): void | Promise<void> {
public askCarteSurvie(phase: number): void | Promise<void> {
}
public askCardSurvie(): void | Promise<void> {
public askCarteTraque(phase: number): void | Promise<void> {
}
public askCardLieux(): void | Promise<void> {
public askCartesLieux(): void | Promise<void> {
}
......
......@@ -10,24 +10,30 @@ export class Creature {
this.gameProxy = gameProxy;
}
public troisCartes(gameId: number): void | Promise<void> {
public async troisCartes(gameId: number): Promise<void> {
while (this.main.length < 3) {
this.main.push(this.gameProxy.piocherTraque(gameId));
const carte = await this.gameProxy.piocherTraque(gameId);
this.main.push(carte);
}
}
public placerArtemia(gameId: number, lieu: Array<Lieu>): void | Promise<void> {
public placerArtemia(gameId: number, lieu: Array<number>): void | Promise<void> {
this.gameProxy.placerArtemia(gameId, lieu);
}
public placerCreature(gameId: number, lieu: Array<Lieu>): void | Promise<void> {
public placerCreature(gameId: number, lieu: Array<number>): void | Promise<void> {
this.gameProxy.placerCreature(gameId, lieu);
}
public placerCible(gameId: number, lieux: Array<Lieu>): void | Promise<void> {
public placerCible(gameId: number, lieux: Array<number>): void | Promise<void> {
this.gameProxy.placerCible(gameId, lieux);
}
public setCarteTraque(gameId: number, carte: CarteTraque): void | Promise<void> {
this.gameProxy.setCarteTraque(gameId, carte);
this.gameProxy.askCarteTraque(gameId, carte);
}
public async piocherTraque(gameId: number): Promise<void> {
const carte = await this.gameProxy.piocherTraque(gameId);
this.main.push(carte);
}
}
......@@ -17,17 +17,19 @@ export class PlayerService implements IHandler<any> {
// methodes des traqués
recupLieuxFromDefausse(): void {}
askCarteSurvie(): void {}
askCarteSurvie(phase: number): void {}
askCartesLieu(): void {}
getLieuxDefausse(): Array<number> {return []; }
perdrePionsVolonte(nbPerdus: number ): void {}
lacherPrise(gameId: number): void {}
resister(gameId: number, cartes: Array<number>): void {}
piocherSurvie(gameId: number): void {}
// methodes de la créature
troisCartes(): void {}
placerArtemia(gameId: number, lieu: number): void {}
placerCreature(gameId: number, lieu: number ): void {}
troisCartes(gameId: number): void {}
placerArtemia(gameId: number, lieux: Array<number> ): void {}
placerCreature(gameId: number, lieux: Array<number> ): void {}
placerCible(gameId: number, lieux: Array<number> ): void {}
askCarteTraque(gameId: number, carte: string): void {}
askCarteTraque(phase: number): void {}
piocherTraque(gameId: number): void {}
}
......@@ -75,4 +75,9 @@ export class Traque {
}
}
}
public async piocherSurvie(gameId: number, id: number): Promise<void> {
const carte = await this.gameProxy.piocherSurvie(gameId, id);
this.mainSurvie.push(carte);
}
}
......@@ -17,37 +17,23 @@ export interface CarteSurvie {
}
export class GameProxy implements GameInterface {
private piocheSurvie: Array<CarteSurvie>;
private defausseSurvie: Array<CarteSurvie>;
private piocheTraque: Array<CarteTraque>;
private defausseTraque: Array<CarteTraque>;
private survie: Array<CarteSurvie>;
private traque: Array<CarteTraque>;
private thriftClient: Client<CoreOptions>;
private assimilation: number;
private artemia: Array<Lieu>;
private cible: Array<Lieu>;
private creature: Array<Lieu>;
constructor(options: ICreateHttpClientOptions) {
this.thriftClient = createHttpClient(Client, options);
this.assimilation = 0;
this.piocheSurvie = [];
this.defausseSurvie = [{phase: 1, name: 'Adrénaline'}, {phase: 3, name: 'Alerte'}, {phase: 4, name: 'Amplificateur'}];
this.defausseSurvie.concat([{phase: 1, name: 'Brouillage'}, {phase: 1, name: 'Cavale'}, {phase: 3, name: 'Détecteur'}]);
this.defausseSurvie.concat([{phase: 3, name: 'Drone'}, {phase: 1, name: 'Entrave'}, {phase: 4, name: 'Équipement'}]);
this.defausseSurvie.concat([{phase: 3, name: 'Esquive'}, {phase: 3, name: 'Fausse piste'}, {phase: 3, name: 'Hologramme'}]);
this.defausseSurvie.concat([{phase: 3, name: 'Leurre'}, {phase: 1, name: 'Mimétisme'}, {phase: 4, name: 'Navette'}]);
this.defausseSurvie.concat([{phase: 4, name: 'Planques'}, {phase: 3, name: 'Portail'}, {phase: 4, name: 'Ralliement'}]);
this.defausseSurvie.concat([{phase: 1, name: 'Refuge'}, {phase: 3, name: 'Régénération'}, {phase: 3, name: 'Résistance'}]);
this.defausseSurvie.concat([{phase: 3, name: 'Retraite'}, {phase: 1, name: 'Riposte'}, {phase: 1, name: 'Sacrifice'}]);
this.defausseSurvie.concat([{phase: 1, name: 'Second souffle'}, {phase: 1, name: 'Sixième sens'}, {phase: 1, name: 'Système D'}]);
this.defausseSurvie.concat([{phase: 1, name: 'Ténacité'}, {phase: 1, name: 'Vaccin'}, {phase: 4, name: 'Volte-face'}]);
this.defausseSurvie.concat([{phase: 2, name: 'Vortex'}]);
this.piocheTraque = [];
this.defausseTraque = [{phase: 2, name: 'Acharnement', token: ''}, {phase: 1, name: 'Angoisse', token: 'Artémia'}, {phase: 2, name: 'Anticipation', token: ''}, {phase: 3, name: 'Cataclysme', token: ''}, {phase: 1, name: 'Champ de force', token: 'Cible'}, {phase: 2, name: 'Clone', token: 'Cible'}, {phase: 3, name: 'Déploiement', token: ''}, {phase: 1, name: 'Désespoir', token: 'Artémia'}, {phase: 3, name: 'Détour', token: ''}, {phase: 2, name: 'Domination', token: ''}, {phase: 1, name: 'Effroi', token: ''}, {phase: 2, name: 'Emprise', token: ''}, {phase: 2, name: 'Épidémie', token: ''}, {phase: 2, name: 'Faille temporelle', token: 'Cible'}, {phase: 0, name: 'Flashback', token: ''}, {phase: 2, name: 'Gargantua', token: ''}, {phase: 2, name: 'Harcèlement', token: ''}, {phase: 2, name: 'Hurlements', token: 'Cible'}, {phase: 2, name: 'Inertie', token: 'Cible'}, {phase: 2, name: 'Interférences', token: ''}, {phase: 1, name: 'Intuition', token: ''}, {phase: 2, name: 'Magnétisme', token: 'Cible'}, {phase: 2, name: 'Mirage', token: 'Cible'}, {phase: 2, name: 'Mutation', token: 'Artémia'}, {phase: 2, name: 'Psychose', token: 'Artémia'}, {phase: 2, name: 'Réminiscence', token: 'Artémia'}, {phase: 4, name: 'Repérage', token: ''}, {phase: 2, name: 'Sables mouvants', token: 'Cible'}, {phase: 2, name: 'Soif de sang', token: 'Cible'}, {phase: 4, name: 'Stase', token: ''}, {phase: 2, name: 'Télépathie', token: 'Artémia'}, {phase: 2, name: 'Tornade', token: 'Artémia'}, {phase: 2, name: 'Toxine', token: 'Cible'}, {phase: 2, name: 'Ubiquité', token: 'Artémia + Cible'}, {phase: 2, name: 'Virus', token: 'Artémia'}, {phase: 2, name: 'Zone interdite', token: 'Artémia'}];
this.melangerSurvie();
this.melangerTraque();
this.artemia = [];
this.cible = [];
this.creature = [];
this.survie = [{phase: 1, name: 'Adrénaline'}, {phase: 3, name: 'Alerte'}, {phase: 4, name: 'Amplificateur'}];
this.survie.concat([{phase: 1, name: 'Brouillage'}, {phase: 1, name: 'Cavale'}, {phase: 3, name: 'Détecteur'}]);
this.survie.concat([{phase: 3, name: 'Drone'}, {phase: 1, name: 'Entrave'}, {phase: 4, name: 'Équipement'}]);
this.survie.concat([{phase: 3, name: 'Esquive'}, {phase: 3, name: 'Fausse piste'}, {phase: 3, name: 'Hologramme'}]);
this.survie.concat([{phase: 3, name: 'Leurre'}, {phase: 1, name: 'Mimétisme'}, {phase: 4, name: 'Navette'}]);
this.survie.concat([{phase: 4, name: 'Planques'}, {phase: 3, name: 'Portail'}, {phase: 4, name: 'Ralliement'}]);
this.survie.concat([{phase: 1, name: 'Refuge'}, {phase: 3, name: 'Régénération'}, {phase: 3, name: 'Résistance'}]);
this.survie.concat([{phase: 3, name: 'Retraite'}, {phase: 1, name: 'Riposte'}, {phase: 1, name: 'Sacrifice'}]);
this.survie.concat([{phase: 1, name: 'Second souffle'}, {phase: 1, name: 'Sixième sens'}, {phase: 1, name: 'Système D'}]);
this.survie.concat([{phase: 1, name: 'Ténacité'}, {phase: 1, name: 'Vaccin'}, {phase: 4, name: 'Volte-face'}]);
this.survie.concat([{phase: 2, name: 'Vortex'}]);
this.traque = [{phase: 2, name: 'Acharnement', token: ''}, {phase: 1, name: 'Angoisse', token: 'Artémia'}, {phase: 2, name: 'Anticipation', token: ''}, {phase: 3, name: 'Cataclysme', token: ''}, {phase: 1, name: 'Champ de force', token: 'Cible'}, {phase: 2, name: 'Clone', token: 'Cible'}, {phase: 3, name: 'Déploiement', token: ''}, {phase: 1, name: 'Désespoir', token: 'Artémia'}, {phase: 3, name: 'Détour', token: ''}, {phase: 2, name: 'Domination', token: ''}, {phase: 1, name: 'Effroi', token: ''}, {phase: 2, name: 'Emprise', token: ''}, {phase: 2, name: 'Épidémie', token: ''}, {phase: 2, name: 'Faille temporelle', token: 'Cible'}, {phase: 0, name: 'Flashback', token: ''}, {phase: 2, name: 'Gargantua', token: ''}, {phase: 2, name: 'Harcèlement', token: ''}, {phase: 2, name: 'Hurlements', token: 'Cible'}, {phase: 2, name: 'Inertie', token: 'Cible'}, {phase: 2, name: 'Interférences', token: ''}, {phase: 1, name: 'Intuition', token: ''}, {phase: 2, name: 'Magnétisme', token: 'Cible'}, {phase: 2, name: 'Mirage', token: 'Cible'}, {phase: 2, name: 'Mutation', token: 'Artémia'}, {phase: 2, name: 'Psychose', token: 'Artémia'}, {phase: 2, name: 'Réminiscence', token: 'Artémia'}, {phase: 4, name: 'Repérage', token: ''}, {phase: 2, name: 'Sables mouvants', token: 'Cible'}, {phase: 2, name: 'Soif de sang', token: 'Cible'}, {phase: 4, name: 'Stase', token: ''}, {phase: 2, name: 'Télépathie', token: 'Artémia'}, {phase: 2, name: 'Tornade', token: 'Artémia'}, {phase: 2, name: 'Toxine', token: 'Cible'}, {phase: 2, name: 'Ubiquité', token: 'Artémia + Cible'}, {phase: 2, name: 'Virus', token: 'Artémia'}, {phase: 2, name: 'Zone interdite', token: 'Artémia'}];
}
createGame(numberOfPlayers: number): Promise<number> {
......@@ -60,101 +46,79 @@ export class GameProxy implements GameInterface {
return this.thriftClient.join(gameId, request);
}
private melangerTraque(): void {
while (this.defausseTraque.length > 0) {
const rand: number = Math.random() * this.defausseTraque.length;
this.piocheTraque.push(this.defausseTraque[rand]);
this.defausseTraque.splice(rand, 1);
}
}
private melangerSurvie(): void {
while (this.defausseSurvie.length > 0) {
const rand: number = Math.random() * this.defausseSurvie.length;
this.piocheSurvie.push(this.defausseSurvie[rand]);
this.defausseSurvie.splice(rand, 1);
}
}
public piocherSurvie(gameId: number): CarteSurvie {
let card;
if (this.defausseSurvie.length > 0) {
card = this.defausseSurvie.pop();
} else {
this.melangerSurvie();
card = this.defausseSurvie.pop();
}
if (this.defausseSurvie.length === 0) {
this.melangerSurvie();
}
if (card == null) {
return {phase: -1, name: 'Undefined'};
}
return card;
public async piocherSurvie(gameId: number, id: number): Promise<CarteSurvie> {
const card = await (this.thriftClient.piocherSurvie(gameId, id));
this.survie.forEach(function (value) {
if (card === value.name) {
return value;
}
});
return {phase: 0, name: 'Undefined'};
}
public piocherTraque(gameId: number): CarteTraque {
let card;
if (this.defausseTraque.length > 0) {
card = this.defausseTraque.pop();
} else {
this.melangerTraque();
card = this.defausseTraque.pop();
}
if (this.defausseTraque.length === 0) {
this.melangerTraque();
}
if (card == null) {
return {phase: -1, name: 'Undefined', token: ''};
}
return card;
public async piocherTraque(gameId: number): Promise<CarteTraque> {
const card = await (this.thriftClient.piocherTraque(gameId));
this.traque.forEach(function (value) {
if (card === value.name) {
return value;
}
});
return {phase: 0, name: 'Undefined', token: ''};
}
public avancerAssimilation(gameId: number): void | Promise<void> {
this.assimilation++;
this.thriftClient.avancerAssimilation(gameId);
}
placerCreature(gameId: number, lieux: Array<Lieu>): void | Promise<void> {
if (lieux.length >= 1 && lieux[0] >= 1 && lieux[0] <= 10) {
if ((lieux.length === 2 && lieux[1] >= 1 && lieux[1] <= 10) || (lieux.length === 1)) {
this.creature = lieux;
}
}
placerCreature(gameId: number, lieux: Array<number>): void | Promise<void> {
this.thriftClient.placerCreature(gameId, lieux);
}
placerCible(gameId: number, lieux: Array<Lieu>): void | Promise<void> {
if (lieux.length >= 1 && lieux[0] >= 1 && lieux[0] <= 10) {
if ((lieux.length === 2 && lieux[1] >= 1 && lieux[1] <= 10) || (lieux.length === 1)) {
this.cible = lieux;
}
}
placerCible(gameId: number, lieux: Array<number>): void | Promise<void> {
this.thriftClient.placerCible(gameId, lieux);
}
placerArtemia(gameId: number, lieux: Array<Lieu>): void | Promise<void> {
if (lieux.length >= 1 && lieux[0] >= 1 && lieux[0] <= 10) {
if ((lieux.length === 2 && lieux[1] >= 1 && lieux[1] <= 10) || (lieux.length === 1)) {
this.artemia = lieux;
}
}
placerArtemia(gameId: number, lieux: Array<number>): void | Promise<void> {
this.thriftClient.placerArtemia(gameId, lieux);
}
public setLieu(gameId: number, playerId: number, lieu: Lieu): void | Promise<void> {
if (lieu.id == null) {
this.thriftClient.setLieu(gameId, playerId, 0);
} else {
this.thriftClient.setLieu(gameId, playerId, lieu.id);
}
}
public setCarteSurvie(gameId: number, playerId: number, carte: CarteSurvie): void | Promise<void> {
}
public setCarteTraque(gameId: number, carte: CarteTraque): void | Promise<void> {
if (carte.name == null) {
this.thriftClient.setCarteSurvie(gameId, playerId, '');
} else {
this.thriftClient.setCarteSurvie(gameId, playerId, carte.name);
}
}
public wantRole(gameId: number, id: number, role: string): void | Promise<void> {
this.thriftClient.wantRole(gameId, id, role);
}
public rendDefausse(gameId: number, id: number, lieux: Array<number>): void | Promise<void> {
this.thriftClient.rendDefausse(gameId, id, lieux);
}
public rendDefausse(gameId: number, id: number, lieux: Array<Lieu>): void | Promise<void> {
public askCarteSurvie(gameId: number, playerId: number, carte: CarteSurvie): void | Promise<void> {
if (carte.name == null) {
this.thriftClient.setCarteSurvie(gameId, playerId, '');
} else {
this.thriftClient.setCarteSurvie(gameId, playerId, carte.name);
}
}
public askCarteTraque(gameId: number, carte: CarteTraque): void | Promise<void> {
if (carte.name == null) {
this.thriftClient.setCarteTraque(gameId, '');
} else {
this.thriftClient.setCarteTraque(gameId, carte.name);
}
}
}
......@@ -87,10 +87,12 @@ public class GameServiceHandler implements GameService.Iface {
service.rendDefausse(idGame, id, listLieu);
}
@Override
public String piocherTraque(int idGame) {
return this.service.piocherTraque(idGame);
}
@Override
public String piocherSurvie(int idGame, int id) {
return this.service.piocherSurvie(idGame, id);
}
......
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