Commit 328eaa8b authored by Alex MOULIN's avatar Alex MOULIN
Browse files

game initialization

parent 3b33b9d2
...@@ -11,7 +11,7 @@ exception GameNotFound { ...@@ -11,7 +11,7 @@ exception GameNotFound {
2: string description 2: string description
} }
struct Winner { struct Winner {
1: Player winner, 1: TPlayer winner,
2: string message 2: string message
} }
struct TrackingKard { struct TrackingKard {
...@@ -39,7 +39,7 @@ struct PlayerStateResponse { ...@@ -39,7 +39,7 @@ struct PlayerStateResponse {
2: string message 2: string message
} }
struct Player{ struct TPlayer{
1: i32 id 1: i32 id
2: string name 2: string name
3: string ip 3: string ip
......
...@@ -4,25 +4,25 @@ namespace java fr.univnantes.alma.thrift ...@@ -4,25 +4,25 @@ namespace java fr.univnantes.alma.thrift
namespace js common namespace js common
struct JoinRequest { struct JoinRequest {
1: common.Player player; 1: common.TPlayer player;
2: i32 gameId; 2: i32 gameId;
} }
service GameService { service GameService {
i32 createGame(common.Player creator, i32 numberOfPlayers) i32 createGame(common.TPlayer creator, i32 numberOfTPlayers)
i32 join(JoinRequest request) throws (1:common.GameNotFound e) i32 join(JoinRequest request) throws (1:common.GameNotFound e)
common.Phase nextPhase(common.Phase phase) common.Phase nextPhase(common.Phase phase)
common.Response resits(common.Player hunted) common.Response resits(common.TPlayer hunted)
common.Response letGo(common.Player hunted) common.Response letGo(common.TPlayer hunted)
common.Response playPlaceCard(common.Player hunted, common.Card card) common.Response playPlaceCard(common.TPlayer hunted, common.Card card)
common.Response putToken(common.Token token, common.Place place) common.Response putToken(common.Token token, common.Place place)
common.Response playHuntCard(common.Player creature, common.Card card) common.Response playHuntCard(common.TPlayer creature, common.Card card)
} }
\ No newline at end of file
...@@ -7,7 +7,7 @@ struct BoardGameState { ...@@ -7,7 +7,7 @@ struct BoardGameState {
1: i32 assimilationTokenPosition, 1: i32 assimilationTokenPosition,
2: i32 rescuePawnPosition, 2: i32 rescuePawnPosition,
3: optional bool isBoardFacing, 3: optional bool isBoardFacing,
4: list<common.Player> players 4: list<common.TPlayer> players
} }
service PlayerService { service PlayerService {
......
...@@ -2,7 +2,7 @@ package fr.univnantes.alma.common; ...@@ -2,7 +2,7 @@ package fr.univnantes.alma.common;
import fr.univnantes.alma.thrift.GameNotFound; import fr.univnantes.alma.thrift.GameNotFound;
import fr.univnantes.alma.thrift.InvalidOperationException; import fr.univnantes.alma.thrift.InvalidOperationException;
import fr.univnantes.alma.thrift.Player; import fr.univnantes.alma.model.player.Player;
import fr.univnantes.alma.thrift.Response; import fr.univnantes.alma.thrift.Response;
public interface GameInterface { public interface GameInterface {
......
package fr.univnantes.alma.common; package fr.univnantes.alma.common;
import fr.univnantes.alma.thrift.Player; import fr.univnantes.alma.model.player.Player;
public class GameJoinRequest { public class GameJoinRequest {
private Player player; private Player player;
......
...@@ -5,12 +5,15 @@ import fr.univnantes.alma.model.BoardGame; ...@@ -5,12 +5,15 @@ import fr.univnantes.alma.model.BoardGame;
import fr.univnantes.alma.model.card.BasicCard; import fr.univnantes.alma.model.card.BasicCard;
import fr.univnantes.alma.model.card.place.*; import fr.univnantes.alma.model.card.place.*;
import fr.univnantes.alma.model.card.player.survival.*; import fr.univnantes.alma.model.card.player.survival.*;
import fr.univnantes.alma.model.card.player.survival.PortalCard;
import fr.univnantes.alma.model.card.player.track.*; import fr.univnantes.alma.model.card.player.track.*;
import fr.univnantes.alma.model.player.Player;
import fr.univnantes.alma.model.player.Tracked;
import fr.univnantes.alma.model.player.Creature;
import fr.univnantes.alma.references.associations.BidirectionalOneToOne; import fr.univnantes.alma.references.associations.BidirectionalOneToOne;
import fr.univnantes.alma.references.interfaces.OneToOneAssociation; import fr.univnantes.alma.references.interfaces.OneToOneAssociation;
import fr.univnantes.alma.thrift.Board; import fr.univnantes.alma.thrift.Board;
import fr.univnantes.alma.thrift.InvalidOperationException; import fr.univnantes.alma.thrift.InvalidOperationException;
import fr.univnantes.alma.thrift.Player;
import org.atlanmod.commons.log.Log; import org.atlanmod.commons.log.Log;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
...@@ -73,17 +76,17 @@ public class Game { ...@@ -73,17 +76,17 @@ public class Game {
/** /**
* Deck of survival cards * Deck of survival cards
*/ */
private List<BasicSurvivalCard> survivalCardsDeck; private List<BasicSurvivalCard> survivalCardsDeck = new ArrayList<BasicSurvivalCard>();
/** /**
* Deck of tracking cards * Deck of tracking cards
*/ */
private List<BasicTrackingCard> trackingCardsDeck; private List<BasicTrackingCard> trackingCardsDeck = new ArrayList<BasicTrackingCard>();
/** /**
* Deck of reserve * Deck of reserve
*/ */
private List<BasicPlaceCard> reserve; private List<BasicPlaceCard> reserve = new ArrayList<BasicPlaceCard>();
/** /**
* Create new instance of game. * Create new instance of game.
...@@ -99,19 +102,46 @@ public class Game { ...@@ -99,19 +102,46 @@ public class Game {
initilizationSurvivalCards(); initilizationSurvivalCards();
initializationTrackCards(); initializationTrackCards();
initializationReserve(); initializationReserve();
play = new Thread(() -> this.start()); //play = new Thread(() -> this.start());
play.start(); // play.start();
} }
private void initilizationSurvivalCards(){ private void initilizationSurvivalCards(){
this.survivalCardsDeck.add(new AdrenalineCard());
this.survivalCardsDeck.add(new AlertCard());
this.survivalCardsDeck.add(new AmplifierCard());
this.survivalCardsDeck.add(new DetectorCard());
this.survivalCardsDeck.add(new DodgeCard()); this.survivalCardsDeck.add(new DodgeCard());
this.survivalCardsDeck.add(new DroneCard());
this.survivalCardsDeck.add(new EquipmentCard());
this.survivalCardsDeck.add(new FlipFlopCard()); this.survivalCardsDeck.add(new FlipFlopCard());
this.survivalCardsDeck.add(new GatheringCard());
this.survivalCardsDeck.add(new HologramCard());
this.survivalCardsDeck.add(new JammingCard());
this.survivalCardsDeck.add(new LureCard());
this.survivalCardsDeck.add(new MimicryCard());
this.survivalCardsDeck.add(new ObstacleCard());
this.survivalCardsDeck.add(new PortalCard());
this.survivalCardsDeck.add(new RefugeCard());
this.survivalCardsDeck.add(new RegenerationCard());
this.survivalCardsDeck.add(new ResistanceCard());
this.survivalCardsDeck.add(new RetirementCard());
this.survivalCardsDeck.add(new RisposteCard()); this.survivalCardsDeck.add(new RisposteCard());
this.survivalCardsDeck.add(new RunCard());
this.survivalCardsDeck.add(new SacrificeCard());
this.survivalCardsDeck.add(new SecondBreathCard());
this.survivalCardsDeck.add(new ShuttleCard());
this.survivalCardsDeck.add(new SixthSenseCard());
this.survivalCardsDeck.add(new StashsCard());
this.survivalCardsDeck.add(new SystemDCard());
this.survivalCardsDeck.add(new TenacityCard());
this.survivalCardsDeck.add(new VaccineCard());
this.survivalCardsDeck.add(new VortexCard()); this.survivalCardsDeck.add(new VortexCard());
this.survivalCardsDeck.add(new WrongPathCard());
} }
private void initializationTrackCards(){ private void initializationTrackCards(){
this.trackingCardsDeck.add(new AnguishCard()); /*this.trackingCardsDeck.add(new AnguishCard());
this.trackingCardsDeck.add(new AnticipationCard()); this.trackingCardsDeck.add(new AnticipationCard());
this.trackingCardsDeck.add(new CataclysmCard()); this.trackingCardsDeck.add(new CataclysmCard());
this.trackingCardsDeck.add(new CloneCard()); this.trackingCardsDeck.add(new CloneCard());
...@@ -146,34 +176,34 @@ public class Game { ...@@ -146,34 +176,34 @@ public class Game {
this.trackingCardsDeck.add(new TornadoCard()); this.trackingCardsDeck.add(new TornadoCard());
this.trackingCardsDeck.add(new ToxinCard()); this.trackingCardsDeck.add(new ToxinCard());
this.trackingCardsDeck.add(new UbiquityCard()); this.trackingCardsDeck.add(new UbiquityCard());
this.trackingCardsDeck.add(new VirusCard()); this.trackingCardsDeck.add(new VirusCard());*/
} }
private void initializationReserve(){ private void initializationReserve(){
int nb_players = players.size(); int nb_players = expectedPlayers.intValue();
List<BasicPlaceCard> liste = new ArrayList<BasicPlaceCard>(); List<BasicPlaceCard> liste = new ArrayList<BasicPlaceCard>();
if (nb_players == 2){ if (nb_players == 2){
liste.addAll(generateCard(SwampCard.class.getCanonicalName(),1)); liste.addAll(generateCard(SwampCard.class.getCanonicalName(),1));
liste.addAll(generateCard(ShelterCard.class.getCanonicalName(),1)); liste.addAll(generateCard(ShelterCard.class.getCanonicalName(),1));
liste.addAll(generateCard(WreckCard.class.getCanonicalName(),1)); liste.addAll(generateCard(WreckCard.class.getCanonicalName(),1));
liste.addAll(generateCard(SourceCard.class.getCanonicalName(),1)); liste.addAll(generateCard(SourceCard.class.getCanonicalName(),1));
liste.addAll(generateCard(ArtefactCard.class.getCanonicalName(),1)); liste.addAll(generateCard(ArtefactCard.class.getCanonicalName(),1,ArtefactColor.BLUE));
} }
else if (nb_players == 2 || nb_players == 3){ else if (nb_players == 2 || nb_players == 3){
liste.addAll(generateCard(SwampCard.class.getCanonicalName(),2)); liste.addAll(generateCard(SwampCard.class.getCanonicalName(),2));
liste.addAll(generateCard(ShelterCard.class.getCanonicalName(),2)); liste.addAll(generateCard(ShelterCard.class.getCanonicalName(),2));
liste.addAll(generateCard(WreckCard.class.getCanonicalName(),2)); liste.addAll(generateCard(WreckCard.class.getCanonicalName(),2));
liste.addAll(generateCard(SourceCard.class.getCanonicalName(),2)); liste.addAll(generateCard(SourceCard.class.getCanonicalName(),2));
liste.addAll(generateCard(ArtefactCard.class.getCanonicalName(),2)); liste.addAll(generateCard(ArtefactCard.class.getCanonicalName(),2,ArtefactColor.BLUE));
} }
else if (nb_players >= 4 || nb_players <= 6){ else if (nb_players >= 4 || nb_players <= 6){
liste.addAll(generateCard(SwampCard.class.getCanonicalName(),3)); liste.addAll(generateCard(SwampCard.class.getCanonicalName(),3));
liste.addAll(generateCard(ShelterCard.class.getCanonicalName(),3)); liste.addAll(generateCard(ShelterCard.class.getCanonicalName(),3));
liste.addAll(generateCard(WreckCard.class.getCanonicalName(),3)); liste.addAll(generateCard(WreckCard.class.getCanonicalName(),3));
liste.addAll(generateCard(SourceCard.class.getCanonicalName(),3)); liste.addAll(generateCard(SourceCard.class.getCanonicalName(),3));
liste.addAll(generateCard(ArtefactCard.class.getCanonicalName(),3)); liste.addAll(generateCard(ArtefactCard.class.getCanonicalName(),3,ArtefactColor.BLUE));
} }
reserve.addAll(liste); this.reserve.addAll(liste);
} }
/** /**
* Set the creature * Set the creature
...@@ -203,6 +233,7 @@ public class Game { ...@@ -203,6 +233,7 @@ public class Game {
this.waitForPlayers(); this.waitForPlayers();
Log.info("We can start !"); Log.info("We can start !");
} }
/** /**
...@@ -240,14 +271,24 @@ public class Game { ...@@ -240,14 +271,24 @@ public class Game {
} }
private List<BasicPlaceCard> generateCard(String className, int number) { private List<BasicPlaceCard> generateCard(String className, int number, ArtefactColor... colors) {
List<BasicPlaceCard> result = new ArrayList<>(); List<BasicPlaceCard> result = new ArrayList<>();
System.out.println(className);
try { try {
Class clazz = Class.forName(className); Class<?> clazz = Class.forName(className);
Constructor<?> constructor = clazz.getConstructor(String.class); if (colors.length == 0) {
for(int i = 0; i< number; i++) { Constructor<?> constructor = clazz.getConstructor();
BasicPlaceCard card = (BasicPlaceCard) constructor.newInstance(new Object[0]); for (int i = 0; i < number; i++) {
result.add(card); BasicPlaceCard card = (BasicPlaceCard) constructor.newInstance();
result.add(card);
}
}
else {
Constructor<?> constructor = clazz.getConstructor(ArtefactColor.class);
for (int i = 0; i < number; i++) {
BasicPlaceCard card = (BasicPlaceCard) constructor.newInstance(colors[0]);
result.add(card);
}
} }
} catch (ClassNotFoundException | NoSuchMethodException e) { } catch (ClassNotFoundException | NoSuchMethodException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -257,8 +298,9 @@ public class Game { ...@@ -257,8 +298,9 @@ public class Game {
e.printStackTrace(); e.printStackTrace();
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
} }
return result; return result;
} }
} }
\ No newline at end of file
...@@ -5,7 +5,7 @@ import fr.univnantes.alma.common.GameJoinRequest; ...@@ -5,7 +5,7 @@ import fr.univnantes.alma.common.GameJoinRequest;
import fr.univnantes.alma.common.GameInterface; import fr.univnantes.alma.common.GameInterface;
import fr.univnantes.alma.thrift.GameNotFound; import fr.univnantes.alma.thrift.GameNotFound;
import fr.univnantes.alma.thrift.InvalidOperationException; import fr.univnantes.alma.thrift.InvalidOperationException;
import fr.univnantes.alma.thrift.Player; import fr.univnantes.alma.model.player.Player;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.HashMap; import java.util.HashMap;
......
...@@ -2,7 +2,10 @@ package fr.univnantes.alma.handler; ...@@ -2,7 +2,10 @@ package fr.univnantes.alma.handler;
import fr.univnantes.alma.common.GameInterface; import fr.univnantes.alma.common.GameInterface;
import fr.univnantes.alma.common.GameJoinRequest; import fr.univnantes.alma.common.GameJoinRequest;
import fr.univnantes.alma.model.player.Creature;
import fr.univnantes.alma.model.player.Tracked;
import fr.univnantes.alma.thrift.*; import fr.univnantes.alma.thrift.*;
import fr.univnantes.alma.model.player.Player;
import org.apache.thrift.TException; import org.apache.thrift.TException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -14,14 +17,16 @@ public class GameServiceHandler implements GameService.Iface { ...@@ -14,14 +17,16 @@ public class GameServiceHandler implements GameService.Iface {
GameInterface service; GameInterface service;
@Override @Override
public int createGame(Player creator, int numberOfPlayers) throws TException { public int createGame(TPlayer creator, int numberOfPlayers) throws TException {
return service.createGame(creator,numberOfPlayers); Player playerCreator = TPlayerToPlayer(creator);
return service.createGame(playerCreator,numberOfPlayers);
} }
@Override @Override
public int join(JoinRequest request) throws TException { public int join(JoinRequest request) throws TException {
//TODO: translate JoinRequest into GameJoinRequest //TODO: translate JoinRequest into GameJoinRequest
return service.join(new GameJoinRequest(request.getPlayer(), request.getGameId())); Player player = TPlayerToPlayer(request.getPlayer());
return service.join(new GameJoinRequest(player, request.getGameId()));
} }
@Override @Override
...@@ -30,17 +35,17 @@ public class GameServiceHandler implements GameService.Iface { ...@@ -30,17 +35,17 @@ public class GameServiceHandler implements GameService.Iface {
} }
@Override @Override
public Response resits(Player hunted) throws TException { public Response resits(TPlayer hunted) throws TException {
return null; return null;
} }
@Override @Override
public Response toGo(Player hunted) throws TException { public Response letGo(TPlayer hunted) throws TException {
return null; return null;
} }
@Override @Override
public Response playPlaceCard(Player hunted, Card card) throws TException { public Response playPlaceCard(TPlayer hunted, Card card) throws TException {
return null; return null;
} }
...@@ -50,8 +55,16 @@ public class GameServiceHandler implements GameService.Iface { ...@@ -50,8 +55,16 @@ public class GameServiceHandler implements GameService.Iface {
} }
@Override @Override
public Response playHuntCard(Player creature, Card card) throws TException { public Response playHuntCard(TPlayer creature, Card card) throws TException {
return null; return null;
} }
private static Player TPlayerToPlayer(TPlayer player){
if (player.role == PlayerRole.CREATURE){
Player creature = new Creature(player.getId() +"/"+ player.getIp()+":"+player.getPort(), player.getName());
return creature;
}
Player tracked = new Tracked(player.getId() +"/"+ player.getIp()+":"+player.getPort(), player.getName());
return tracked;
}
} }
\ No newline at end of file
package fr.univnantes.alma.model.card.place; package fr.univnantes.alma.model.card.place;
import fr.univnantes.alma.model.BoardGame;
/** /**
* Artefact place card. * Artefact place card.
*/ */
public abstract class ArtefactCard extends BasicPlaceCard { public class ArtefactCard extends BasicPlaceCard {
/** /**
* Card number. * Card number.
...@@ -36,4 +38,14 @@ public abstract class ArtefactCard extends BasicPlaceCard { ...@@ -36,4 +38,14 @@ public abstract class ArtefactCard extends BasicPlaceCard {
public ArtefactColor getColor() { public ArtefactColor getColor() {
return color; return color;
} }
/**
* {@inheritdoc}
*
* @param boardGame
*/
@Override
public void applyEffect(BoardGame boardGame) {
}
} }
...@@ -2,6 +2,7 @@ package fr.univnantes.alma.model.card.place; ...@@ -2,6 +2,7 @@ package fr.univnantes.alma.model.card.place;
import fr.univnantes.alma.model.BoardGame; import fr.univnantes.alma.model.BoardGame;
/** /**
* Swamp place card. * Swamp place card.
*/ */
...@@ -20,6 +21,7 @@ public class SwampCard extends BasicPlaceCard { ...@@ -20,6 +21,7 @@ public class SwampCard extends BasicPlaceCard {
/** /**
* Create new instance of swamp card. * Create new instance of swamp card.
*/ */
public SwampCard() { public SwampCard() {
super(CARD_NUMBER, CARD_NAME); super(CARD_NUMBER, CARD_NAME);
} }
......
...@@ -2,7 +2,7 @@ package fr.univnantes.alma.model.card.player.survival; ...@@ -2,7 +2,7 @@ package fr.univnantes.alma.model.card.player.survival;
import fr.univnantes.alma.model.BoardGame; import fr.univnantes.alma.model.BoardGame;
public class InterferenceCard extends BasicSurvivalCard { public class JammingCard extends BasicSurvivalCard {
/** /**
* Phase of game. * Phase of game.
...@@ -17,7 +17,7 @@ public class InterferenceCard extends BasicSurvivalCard { ...@@ -17,7 +17,7 @@ public class InterferenceCard extends BasicSurvivalCard {
/** /**
* Create new instance of interference card. * Create new instance of interference card.
*/ */
public InterferenceCard() { public JammingCard() {
super(PHASE, CARD_NAME); super(PHASE, CARD_NAME);
} }
......
...@@ -208,4 +208,5 @@ public class Creature extends Player { ...@@ -208,4 +208,5 @@ public class Creature extends Player {
} }
hand.addAll(cards); hand.addAll(cards);
} }
} }
package fr.univnantes.alma.model.player; package fr.univnantes.alma.model.player;