Added:(Network) Totem Choice first implementation
This commit is contained in:
@@ -29,4 +29,5 @@ public interface IClient {
|
||||
public void noOptionalCard(String playerUsername) throws RemoteException;
|
||||
|
||||
public void slotChoice(String playerUsername,int pos) throws RemoteException;
|
||||
public void totemChoice(String playerUsername,String totem) throws RemoteException;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Model.Totems;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.View.IView;
|
||||
@@ -15,20 +16,15 @@ import java.util.List;
|
||||
public class TotemChoice extends NetworkEvent implements Serializable {
|
||||
|
||||
/** Index of the card to draw */
|
||||
private int pos;
|
||||
private List<Object>availableTotems;
|
||||
public void setAvailableTotems(List<Object> availableTotems) {
|
||||
private String totem;
|
||||
private List<Totems>availableTotems;
|
||||
public void setAvailableTotems(List<Totems> availableTotems) {
|
||||
this.availableTotems = availableTotems;
|
||||
}
|
||||
/**
|
||||
* Class constructor.
|
||||
* Initializes all the attributes.
|
||||
* @param username the name of the player requesting the event
|
||||
* @param pos the index of the card to draw
|
||||
*/
|
||||
public TotemChoice(String username, int pos) {
|
||||
//TODO
|
||||
public TotemChoice(String username, String totem) {
|
||||
super(username, EventType.TOTEM_CHOICE, false);
|
||||
this.pos = pos;
|
||||
this.totem = totem;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +33,7 @@ public class TotemChoice extends NetworkEvent implements Serializable {
|
||||
*/
|
||||
@Override
|
||||
public boolean apply(GameController gameController) {
|
||||
return gameController.slotChoice(username, pos);
|
||||
return gameController.TotemChoice(username, totem);
|
||||
}
|
||||
|
||||
//TODO
|
||||
|
||||
@@ -224,6 +224,10 @@ public class RMIClient implements IClient {
|
||||
public void slotChoice(String playerUsername,int pos) throws RemoteException {
|
||||
stub.slotChoice(playerUsername,pos);
|
||||
}
|
||||
//TODO
|
||||
public void totemChoice(String playerUsername,String totem) throws RemoteException {
|
||||
stub.totemChoice(playerUsername,totem);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public interface IGameServer extends Remote {
|
||||
void pickOptionalBuildingCard(String playerUsername, int pos) throws RemoteException;
|
||||
void noOptionalCard(String playerUsername) throws RemoteException;
|
||||
void slotChoice(String playerUsername, int pos) throws RemoteException;
|
||||
|
||||
void totemChoice(String playerUsername, String totems) throws RemoteException;
|
||||
/**
|
||||
* Heartbeat: called periodically by the client to signal it is still alive.
|
||||
* Mirrors the PING/PONG mechanism used in the TCP heartbeat channel.
|
||||
|
||||
@@ -91,7 +91,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
System.out.println("Reconnected player: " + username);
|
||||
startWatchdog(username);
|
||||
Game game = controller.getModel();
|
||||
callback.onGameInit(new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers()));
|
||||
callback.onGameInit(new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers(),game.getAvailableTotems()));
|
||||
System.out.println("Model sent: " + username);
|
||||
actionQueue.add(new ReconnectPlayer(username));
|
||||
return true;
|
||||
@@ -117,7 +117,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
System.out.println("Reconnected player: " + username);
|
||||
startWatchdog(username);
|
||||
Game game = controller.getModel();
|
||||
callback.onGameInit(new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers()));
|
||||
callback.onGameInit(new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers(),game.getAvailableTotems()));
|
||||
System.out.println("Model sent: " + username);
|
||||
actionQueue.add(new ReconnectPlayer(username));
|
||||
return true;
|
||||
@@ -285,7 +285,9 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void totemChoice(String playerUsername, String totems) throws RemoteException {
|
||||
actionQueue.offer(new TotemChoice(playerUsername,totems));
|
||||
}
|
||||
|
||||
|
||||
// Metodi per avviare server RMI
|
||||
|
||||
@@ -292,4 +292,9 @@ public class TCPClient implements IClient {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO
|
||||
public void totemChoice(String playerUsername,String totems) {
|
||||
doEvent(new TotemChoice(playerUsername,totems));
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public class TCPServer {
|
||||
clientSocket.getOutputStream().write(1);
|
||||
pendingHeartbeat.put(username, handler);
|
||||
Game game = controller.getModel();
|
||||
handler.notifyMiniModel(new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers()));
|
||||
handler.notifyMiniModel(new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers(),game.getAvailableTotems()));
|
||||
Thread thread = new Thread(handler);
|
||||
thread.start();
|
||||
clientHandlers.add(handler);
|
||||
@@ -175,7 +175,7 @@ public class TCPServer {
|
||||
clientSocket.getOutputStream().write(1);
|
||||
pendingHeartbeat.put(username, handler);
|
||||
Game game = controller.getModel();
|
||||
handler.notifyMiniModel(new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers()));
|
||||
handler.notifyMiniModel(new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers(),game.getAvailableTotems()));
|
||||
Thread thread = new Thread(handler);
|
||||
thread.start();
|
||||
clientHandlers.add(handler);
|
||||
|
||||
Reference in New Issue
Block a user