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

game initialization

parent 3b33b9d2
......@@ -11,7 +11,7 @@ exception GameNotFound {
2: string description
}
struct Winner {
1: Player winner,
1: TPlayer winner,
2: string message
}
struct TrackingKard {
......@@ -39,7 +39,7 @@ struct PlayerStateResponse {
2: string message
}
struct Player{
struct TPlayer{
1: i32 id
2: string name
3: string ip
......
......@@ -4,25 +4,25 @@ namespace java fr.univnantes.alma.thrift
namespace js common
struct JoinRequest {
1: common.Player player;
1: common.TPlayer player;
2: i32 gameId;
}
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)
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 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 {
1: i32 assimilationTokenPosition,
2: i32 rescuePawnPosition,
3: optional bool isBoardFacing,
4: list<common.Player> players
4: list<common.TPlayer> players
}
service PlayerService {
......
......@@ -2,7 +2,7 @@ package fr.univnantes.alma.common;
import fr.univnantes.alma.thrift.GameNotFound;
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;
public interface GameInterface {
......
package fr.univnantes.alma.common;
import fr.univnantes.alma.thrift.Player;
import fr.univnantes.alma.model.player.Player;
public class GameJoinRequest {
private Player player;
......
......@@ -5,12 +5,15 @@ import fr.univnantes.alma.model.BoardGame;
import fr.univnantes.alma.model.card.BasicCard;
import fr.univnantes.alma.model.card.place.*;
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.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.interfaces.OneToOneAssociation;
import fr.univnantes.alma.thrift.Board;
import fr.univnantes.alma.thrift.InvalidOperationException;
import fr.univnantes.alma.thrift.Player;
import org.atlanmod.commons.log.Log;
import java.lang.reflect.Constructor;
......@@ -73,17 +76,17 @@ public class Game {
/**
* Deck of survival cards
*/
private List<BasicSurvivalCard> survivalCardsDeck;
private List<BasicSurvivalCard> survivalCardsDeck = new ArrayList<BasicSurvivalCard>();
/**
* Deck of tracking cards
*/
private List<BasicTrackingCard> trackingCardsDeck;
private List<BasicTrackingCard> trackingCardsDeck = new ArrayList<BasicTrackingCard>();
/**
* Deck of reserve
*/
private List<BasicPlaceCard> reserve;
private List<BasicPlaceCard> reserve = new ArrayList<BasicPlaceCard>();
/**
* Create new instance of game.
......@@ -99,19 +102,46 @@ public class Game {
initilizationSurvivalCards();
initializationTrackCards();
initializationReserve();
play = new Thread(() -> this.start());
play.start();
//play = new Thread(() -> this.start());
// play.start();
}
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 DroneCard());
this.survivalCardsDeck.add(new EquipmentCard());
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 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 WrongPathCard());
}
private void initializationTrackCards(){
this.trackingCardsDeck.add(new AnguishCard());
/*this.trackingCardsDeck.add(new AnguishCard());
this.trackingCardsDeck.add(new AnticipationCard());
this.trackingCardsDeck.add(new CataclysmCard());
this.trackingCardsDeck.add(new CloneCard());
......@@ -146,34 +176,34 @@ public class Game {
this.trackingCardsDeck.add(new TornadoCard());
this.trackingCardsDeck.add(new ToxinCard());
this.trackingCardsDeck.add(new UbiquityCard());
this.trackingCardsDeck.add(new VirusCard());
this.trackingCardsDeck.add(new VirusCard());*/
}
private void initializationReserve(){
int nb_players = players.size();
int nb_players = expectedPlayers.intValue();
List<BasicPlaceCard> liste = new ArrayList<BasicPlaceCard>();
if (nb_players == 2){
liste.addAll(generateCard(SwampCard.class.getCanonicalName(),1));
liste.addAll(generateCard(ShelterCard.class.getCanonicalName(),1));
liste.addAll(generateCard(WreckCard.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){
liste.addAll(generateCard(SwampCard.class.getCanonicalName(),2));
liste.addAll(generateCard(ShelterCard.class.getCanonicalName(),2));
liste.addAll(generateCard(WreckCard.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){
liste.addAll(generateCard(SwampCard.class.getCanonicalName(),3));
liste.addAll(generateCard(ShelterCard.class.getCanonicalName(),3));
liste.addAll(generateCard(WreckCard.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
......@@ -203,6 +233,7 @@ public class Game {
this.waitForPlayers();
Log.info("We can start !");
}
/**
......@@ -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<>();
System.out.println(className);
try {
Class clazz = Class.forName(className);
Constructor<?> constructor = clazz.getConstructor(String.class);
for(int i = 0; i< number; i++) {
BasicPlaceCard card = (BasicPlaceCard) constructor.newInstance(new Object[0]);
result.add(card);
Class<?> clazz = Class.forName(className);
if (colors.length == 0) {
Constructor<?> constructor = clazz.getConstructor();
for (int i = 0; i < number; i++) {
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) {
e.printStackTrace();
......@@ -257,8 +298,9 @@ public class Game {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
return result;
}
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ import fr.univnantes.alma.common.GameJoinRequest;
import fr.univnantes.alma.common.GameInterface;
import fr.univnantes.alma.thrift.GameNotFound;
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 java.util.HashMap;
......
......@@ -2,7 +2,10 @@ package fr.univnantes.alma.handler;
import fr.univnantes.alma.common.GameInterface;
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.model.player.Player;
import org.apache.thrift.TException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -14,14 +17,16 @@ public class GameServiceHandler implements GameService.Iface {
GameInterface service;
@Override
public int createGame(Player creator, int numberOfPlayers) throws TException {
return service.createGame(creator,numberOfPlayers);
public int createGame(TPlayer creator, int numberOfPlayers) throws TException {
Player playerCreator = TPlayerToPlayer(creator);
return service.createGame(playerCreator,numberOfPlayers);
}
@Override
public int join(JoinRequest request) throws TException {
//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
......@@ -30,17 +35,17 @@ public class GameServiceHandler implements GameService.Iface {
}
@Override
public Response resits(Player hunted) throws TException {
public Response resits(TPlayer hunted) throws TException {
return null;
}
@Override
public Response toGo(Player hunted) throws TException {
public Response letGo(TPlayer hunted) throws TException {
return null;
}
@Override
public Response playPlaceCard(Player hunted, Card card) throws TException {
public Response playPlaceCard(TPlayer hunted, Card card) throws TException {
return null;
}
......@@ -50,8 +55,16 @@ public class GameServiceHandler implements GameService.Iface {
}
@Override
public Response playHuntCard(Player creature, Card card) throws TException {
public Response playHuntCard(TPlayer creature, Card card) throws TException {
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;
import fr.univnantes.alma.model.BoardGame;
/**
* Artefact place card.
*/
public abstract class ArtefactCard extends BasicPlaceCard {
public class ArtefactCard extends BasicPlaceCard {
/**
* Card number.
......@@ -36,4 +38,14 @@ public abstract class ArtefactCard extends BasicPlaceCard {
public ArtefactColor getColor() {
return color;
}
/**
* {@inheritdoc}
*
* @param boardGame
*/
@Override
public void applyEffect(BoardGame boardGame) {
}
}
......@@ -2,6 +2,7 @@ package fr.univnantes.alma.model.card.place;
import fr.univnantes.alma.model.BoardGame;
/**
* Swamp place card.
*/
......@@ -20,6 +21,7 @@ public class SwampCard extends BasicPlaceCard {
/**
* Create new instance of swamp card.
*/
public SwampCard() {
super(CARD_NUMBER, CARD_NAME);
}
......
......@@ -2,7 +2,7 @@ package fr.univnantes.alma.model.card.player.survival;
import fr.univnantes.alma.model.BoardGame;
public class InterferenceCard extends BasicSurvivalCard {
public class JammingCard extends BasicSurvivalCard {
/**
* Phase of game.
......@@ -17,7 +17,7 @@ public class InterferenceCard extends BasicSurvivalCard {
/**
* Create new instance of interference card.
*/
public InterferenceCard() {
public JammingCard() {
super(PHASE, CARD_NAME);
}
......
......@@ -208,4 +208,5 @@ public class Creature extends Player {
}
hand.addAll(cards);
}
}
package fr.univnantes.alma.model.player;
import fr.univnantes.alma.thrift.PlayerRole;
import fr.univnantes.alma.thrift.TPlayer;
/**
* Single game player.
*/
......@@ -56,4 +59,20 @@ public abstract class Player {
return name;
}
/**
* Set the state for a Player
* @param state
*/
public void setState(PlayerState state) {
this.state = state;
}
public 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;
}
}
......@@ -2,7 +2,7 @@ package fr.univnantes.alma;
import fr.univnantes.alma.thrift.GameService;
import fr.univnantes.alma.thrift.JoinRequest;
import fr.univnantes.alma.thrift.Player;
import fr.univnantes.alma.thrift.TPlayer;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
......@@ -38,7 +38,7 @@ class NotAloneApplicationTest {
@Test
public void testCreateGame() throws TException {
Player creator = new Player();
TPlayer creator = new TPlayer();
int id = client.createGame(creator,4);
assertThat(id).isGreaterThan(0);
......@@ -46,17 +46,17 @@ class NotAloneApplicationTest {
@Test
public void testJoinGame() throws TException, InterruptedException {
Player creator = new Player();
Player player1 = new Player();
Player player2 = new Player();
Player player3 = new Player();
Player player4 = new Player();
TPlayer creator = new TPlayer();
TPlayer Tplayer1 = new TPlayer();
TPlayer Tplayer2 = new TPlayer();
TPlayer Tplayer3 = new TPlayer();
TPlayer Tplayer4 = new TPlayer();
int id = client.createGame(creator,4);
client.join(new JoinRequest(player1,id));
client.join(new JoinRequest(player2,id));
client.join(new JoinRequest(player3,id));
client.join(new JoinRequest(player4,id));
client.join(new JoinRequest(Tplayer1,id));
client.join(new JoinRequest(Tplayer2,id));
client.join(new JoinRequest(Tplayer3,id));
client.join(new JoinRequest(Tplayer4,id));
Thread.sleep(1000);
......
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