@@ -1,6 +1,7 @@
|
||||
package it.polimi.ingsw.gc14;
|
||||
import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Client.RMIClient;
|
||||
import it.polimi.ingsw.gc14.Network.TCP.Client.TCPClient;
|
||||
@@ -47,64 +48,70 @@ public class ClientLauncherTUI {
|
||||
admissibleChar.add("5");
|
||||
admissibleChar.add("6");
|
||||
admissibleChar.add("7");
|
||||
admissibleChar.add("8");
|
||||
admissibleChar.add("A");
|
||||
admissibleChar.add("B");
|
||||
admissibleChar.add("C");
|
||||
admissibleChar.add("a");
|
||||
admissibleChar.add("b");
|
||||
admissibleChar.add("c");
|
||||
|
||||
ClientController controller = new ClientController(view);
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.println("Insert username: ");
|
||||
String username = scanner.next();
|
||||
view.setUsername(username);
|
||||
controller.setMyUsername(username);
|
||||
System.out.println("Insert preferred number of players: ");
|
||||
int proposedNumPlayers = scanner.nextInt();
|
||||
System.out.println("Select RMI[0] o TCP[1]: ");
|
||||
int networkType = scanner.nextInt();
|
||||
System.out.println("Insert server IP: ");
|
||||
String IP = scanner.next();
|
||||
while (true) {
|
||||
System.out.println("Insert username: ");
|
||||
String username = scanner.next();
|
||||
view.setUsername(username);
|
||||
controller.setMyUsername(username);
|
||||
System.out.println("Insert preferred number of players: ");
|
||||
int proposedNumPlayers = scanner.nextInt();
|
||||
System.out.println("Select RMI[0] o TCP[1]: ");
|
||||
int networkType = scanner.nextInt();
|
||||
System.out.println("Insert server IP: ");
|
||||
String IP = scanner.next();
|
||||
|
||||
// RMI
|
||||
if (networkType == 0) {
|
||||
// Connect
|
||||
String myIP;
|
||||
try {
|
||||
myIP = chooseNetworkInterface(scanner);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.setProperty("java.rmi.server.hostname", myIP);
|
||||
RMIClient client = new RMIClient(controller, IP, 1099, myIP);
|
||||
if (client.connect(username, proposedNumPlayers)) {
|
||||
System.out.println("Succesfully connected to RMI server\n\n");
|
||||
} else {
|
||||
System.out.println("RMI connection refused\n\n");
|
||||
return;
|
||||
}
|
||||
controller.setClient(client);
|
||||
while (true) {
|
||||
getInput(scanner, controller, username);
|
||||
}
|
||||
// TCP
|
||||
} else if (networkType == 1) {
|
||||
// Connect
|
||||
TCPClient client = new TCPClient(controller, IP, 8080,8081);
|
||||
if (client.connect(username, proposedNumPlayers)) {
|
||||
System.out.println("Succesfully connected to TCP server\n\n");
|
||||
} else {
|
||||
System.out.println("TCP connection refused\n\n");
|
||||
return;
|
||||
}
|
||||
controller.setClient(client);
|
||||
// Play
|
||||
while (true) {
|
||||
getInput(scanner, controller, username);
|
||||
// RMI
|
||||
if (networkType == 0) {
|
||||
// Connect
|
||||
String myIP;
|
||||
try {
|
||||
myIP = chooseNetworkInterface(scanner);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.setProperty("java.rmi.server.hostname", myIP);
|
||||
RMIClient client = new RMIClient(controller, IP, 1099, myIP);
|
||||
ErrorType serverResponse=client.connect(username, proposedNumPlayers);
|
||||
if (serverResponse==null) {
|
||||
System.out.println("Succesfully connected to RMI server\n\n");
|
||||
} else {
|
||||
System.out.println("RMI connection refused\n\n");
|
||||
controller.view.showError(serverResponse,serverResponse.toString());
|
||||
continue;
|
||||
}
|
||||
controller.setClient(client);
|
||||
while (controller.getClient() != null) {
|
||||
getInput(scanner, controller, username);
|
||||
}
|
||||
// TCP
|
||||
} else if (networkType == 1) {
|
||||
// Connect
|
||||
TCPClient client = new TCPClient(controller, IP, 8080,8081);
|
||||
ErrorType serverResponse=client.connect(username, proposedNumPlayers);
|
||||
if (serverResponse==null) {
|
||||
System.out.println("Succesfully connected to TCP server\n\n");
|
||||
} else {
|
||||
System.out.println("TCP connection refused\n\n");
|
||||
controller.view.showError(serverResponse,serverResponse.toString());
|
||||
continue;
|
||||
}
|
||||
controller.setClient(client);
|
||||
// Play
|
||||
while (controller.getClient() != null) {
|
||||
getInput(scanner, controller, username);
|
||||
}
|
||||
}
|
||||
}
|
||||
scanner.close();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,9 +142,23 @@ public class ClientLauncherTUI {
|
||||
* @param username the username of the current player.
|
||||
*/
|
||||
private void getInput(Scanner scanner, ClientController controller, String username) {
|
||||
String action = scanner.next();
|
||||
String action = scanner.nextLine().trim();
|
||||
int pos = -1;
|
||||
|
||||
if(controller.getClient() == null)
|
||||
{
|
||||
if(action.equals("0"))
|
||||
{
|
||||
System.out.println("Are you sure? Y/N");
|
||||
String c= scanner.next();
|
||||
if(c.equals("Y") || c.equals("y"))
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(action.isEmpty())
|
||||
return;
|
||||
if(admissibleChar.contains(action))
|
||||
{
|
||||
if(action.equals("0"))
|
||||
@@ -149,20 +170,16 @@ public class ClientLauncherTUI {
|
||||
view.render();
|
||||
return;
|
||||
}
|
||||
}else if (!action.equals("6") && !action.equals("A") && !action.equals("B") && !action.equals("C")&&!action.equals("a") && !action.equals("b") && !action.equals("c")) {
|
||||
}else if (!action.equals("6")&&!action.equals("8") && !action.equals("A") && !action.equals("B") && !action.equals("C")&&!action.equals("a") && !action.equals("b") && !action.equals("c")) {
|
||||
try {
|
||||
System.out.println("Insert the required position:");
|
||||
pos = scanner.nextInt();
|
||||
} catch (Exception e) {
|
||||
view.showError("ERROR: Invalid input(expected number)");
|
||||
view.showMessage("ERROR: Invalid input(expected number)");
|
||||
return;
|
||||
}
|
||||
}
|
||||
switch (action) {
|
||||
case "0" -> {
|
||||
controller.disconnect();
|
||||
System.exit(0);
|
||||
}
|
||||
case "1" -> controller.slotChoice(pos);
|
||||
case "2" -> controller.drawUpperTribeCard(pos);
|
||||
case "3" -> controller.drawUpperBuildingCard(pos);
|
||||
@@ -170,6 +187,13 @@ public class ClientLauncherTUI {
|
||||
case "5" -> controller.drawLowerBuildingCard(pos);
|
||||
case "6" -> controller.skipTurn();
|
||||
case "7" -> controller.totemChoice(pos);
|
||||
case "8" ->{
|
||||
if(controller.miniModel.currentState.getGameStage().equals(GameStages.ENDED)) {
|
||||
controller.disconnect();
|
||||
controller.setClient(null);
|
||||
controller.setModel(null);
|
||||
}
|
||||
}
|
||||
case "A", "a" -> view.fullRender();
|
||||
case "B", "b" -> view.renderBoard();
|
||||
case "C", "c" -> view.renderPlayer();
|
||||
@@ -178,7 +202,7 @@ public class ClientLauncherTUI {
|
||||
}
|
||||
else
|
||||
{
|
||||
view.showError("ERROR: Invalid input(action not valid)");
|
||||
view.showMessage("ERROR: Invalid input(action not valid)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,15 @@ public class ClientController {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the network client.
|
||||
*
|
||||
* @return client return the client, either TCP or RMI.
|
||||
*/
|
||||
public IClient getClient() {
|
||||
return this.client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the local mini model and updates the view accordingly.
|
||||
*
|
||||
@@ -68,14 +77,6 @@ public class ClientController {
|
||||
this.myUsername = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an error message in the view.
|
||||
*
|
||||
* @param message the error message to display.
|
||||
*/
|
||||
public void onError(String message) {
|
||||
view.showError(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests to draw a tribe card from the upper list.
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package it.polimi.ingsw.gc14;
|
||||
|
||||
public enum ErrorType {
|
||||
USER_NOT_FOUND("User not found"),
|
||||
USERNAME_ALREADY_USED("Username is already in use"),
|
||||
USER_ALREADY_CONNECTED("User is already connected"),
|
||||
WRONG_PLAYER_NUMBER("Wrong player number"),
|
||||
SERVER_CRASHED("Server crashed"),
|
||||
GENERIC_ERROR("Generic error"),
|
||||
GAME_ALREADY_STARTED("Game already started"),
|
||||
WRONG_ACTION("Wrong action");
|
||||
private String description;
|
||||
ErrorType(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
@@ -9,60 +9,69 @@ public enum EventType {
|
||||
/**
|
||||
* Event used to add a player to the game.
|
||||
*/
|
||||
ADD_PLAYER,
|
||||
ADD_PLAYER("Add Player Event"),
|
||||
|
||||
/**
|
||||
* Event used to submit a player's totem choice.
|
||||
*/
|
||||
TOTEM_CHOICE,
|
||||
TOTEM_CHOICE("Totem Choice"),
|
||||
|
||||
/**
|
||||
* Event used to submit a player's slot choice.
|
||||
*/
|
||||
SLOT_CHOICE,
|
||||
SLOT_CHOICE("Slot Choice"),
|
||||
|
||||
/**
|
||||
* Event used to draw a tribe card from the upper card list.
|
||||
*/
|
||||
DRAW_UPPER_TRIBE,
|
||||
DRAW_UPPER_TRIBE("Drawing Upper Tribe"),
|
||||
|
||||
/**
|
||||
* Event used to draw a tribe card from the lower card list.
|
||||
*/
|
||||
DRAW_LOWER_TRIBE,
|
||||
DRAW_LOWER_TRIBE("Drawing Lower Tribe"),
|
||||
|
||||
/**
|
||||
* Event used to draw a building card from the upper card list.
|
||||
*/
|
||||
DRAW_UPPER_BUILD,
|
||||
DRAW_UPPER_BUILD("Drawing Upper Build"),
|
||||
|
||||
/**
|
||||
* Event used to draw a building card from the lower card list.
|
||||
*/
|
||||
DRAW_LOWER_BUILD,
|
||||
DRAW_LOWER_BUILD("Drawing Lower Build"),
|
||||
|
||||
/**
|
||||
* Event used to skip the current turn or optional action.
|
||||
*/
|
||||
SKIP_TURN,
|
||||
SKIP_TURN("Skip Turn"),
|
||||
|
||||
/**
|
||||
* Event used to notify that a player has disconnected.
|
||||
*/
|
||||
DISCONNECTED_PLAYER,
|
||||
DISCONNECTED_PLAYER("Disconnected Player"),
|
||||
|
||||
/**
|
||||
* Event used to notify that a player has reconnected.
|
||||
*/
|
||||
RECONNECT_PLAYER,
|
||||
RECONNECT_PLAYER("Reconnect Player"),
|
||||
|
||||
/**
|
||||
* Event used to apply the transition to the next round.
|
||||
*/
|
||||
NEXT_ROUND,
|
||||
NEXT_ROUND("Next Round"),
|
||||
|
||||
/**
|
||||
* Event used to notify that the game has ended.
|
||||
*/
|
||||
ENDED_GAME
|
||||
ENDED_GAME("Ended Game");
|
||||
|
||||
private String description;
|
||||
private EventType(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Network;
|
||||
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
|
||||
/**
|
||||
* Defines the operations that a client can request during the game.
|
||||
*/
|
||||
@@ -14,7 +16,7 @@ public interface IClient {
|
||||
* @return {@code true} if the connection is established successfully,
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
boolean connect(String username, int preferredInt);
|
||||
ErrorType connect(String username, int preferredInt);
|
||||
|
||||
/**
|
||||
* Requests to draw a tribe card from the upper tribe card list.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Network;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Model.OrderLogicCard;
|
||||
@@ -21,6 +22,11 @@ import java.util.Map;
|
||||
*/
|
||||
public abstract class NetworkEvent implements Serializable {
|
||||
|
||||
protected ErrorType errorType;
|
||||
|
||||
public ErrorType getErrorType() {
|
||||
return errorType;
|
||||
}
|
||||
/**
|
||||
* Username of the player requesting the event.
|
||||
*/
|
||||
@@ -120,10 +126,11 @@ public abstract class NetworkEvent implements Serializable {
|
||||
* @param isError {@code true} if the event represents an error,
|
||||
* {@code false} otherwise.
|
||||
*/
|
||||
protected NetworkEvent(String username, EventType eventType, boolean isError) {
|
||||
protected NetworkEvent(String username, EventType eventType, boolean isError,ErrorType errorType) {
|
||||
this.username = username;
|
||||
this.eventType = eventType;
|
||||
this.isError = isError;
|
||||
this.errorType = errorType;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,9 +141,9 @@ public abstract class NetworkEvent implements Serializable {
|
||||
@Override
|
||||
public String toString() {
|
||||
if (isError) {
|
||||
return "ERROR: action " + eventType;
|
||||
return "ERROR: " + eventType;
|
||||
} else {
|
||||
return "ACTION: action " + eventType;
|
||||
return "ACTION: " + eventType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
@@ -14,6 +15,10 @@ import java.io.Serializable;
|
||||
public class AddPlayer extends NetworkEvent implements Serializable {
|
||||
/** Number of proposed players to add to the match */
|
||||
private int proposedNPlayer;
|
||||
public void setErrorType(ErrorType errorType)
|
||||
{
|
||||
this.errorType = errorType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of proposed players to add to the match
|
||||
@@ -29,7 +34,7 @@ public class AddPlayer extends NetworkEvent implements Serializable {
|
||||
* @param proposedNPlayer the number of proposed players to add to the match
|
||||
*/
|
||||
public AddPlayer(String username, int proposedNPlayer) {
|
||||
super(username, EventType.ADD_PLAYER, false);
|
||||
super(username, EventType.ADD_PLAYER, false, ErrorType.GENERIC_ERROR);
|
||||
this.proposedNPlayer = proposedNPlayer;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
|
||||
@@ -38,7 +39,7 @@ public class ApplyNextRound extends NetworkEvent implements Serializable{
|
||||
* @param players the list of players in the game.
|
||||
*/
|
||||
public ApplyNextRound(Map<Slot, Player> slotPlayerMap, OrderLogicCard orderLogicCard, CurrentState currentState, List<Player> players, ArrayList<TribeCard> upperListTribeCards, ArrayList<TribeCard>lowerListTribeCards, ArrayList<BuildingCard> upperListBuildingCards, ArrayList<BuildingCard>lowerListBuildingCards) {
|
||||
super("SERVER",EventType.NEXT_ROUND,false);
|
||||
super("SERVER",EventType.NEXT_ROUND,false, ErrorType.WRONG_ACTION);
|
||||
this.upperListBuildingCards = upperListBuildingCards;
|
||||
this.lowerListBuildingCards = lowerListBuildingCards;
|
||||
this.upperListTribeCards = upperListTribeCards;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
@@ -18,7 +19,7 @@ public class DisconnectedPlayer extends NetworkEvent implements Serializable{
|
||||
* @param username the name of the player requesting the event
|
||||
*/
|
||||
public DisconnectedPlayer(String username){
|
||||
super(username, EventType.DISCONNECTED_PLAYER, false);
|
||||
super(username, EventType.DISCONNECTED_PLAYER, false, ErrorType.GENERIC_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
@@ -22,7 +23,7 @@ public class DrawLowerBuildingCard extends NetworkEvent implements Serializable
|
||||
* @param pos the index of the card to draw
|
||||
*/
|
||||
public DrawLowerBuildingCard(String username, int pos){
|
||||
super(username, EventType.DRAW_LOWER_BUILD, false);
|
||||
super(username, EventType.DRAW_LOWER_BUILD, false, ErrorType.WRONG_ACTION);
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
@@ -23,7 +24,7 @@ public class DrawLowerTribeCard extends NetworkEvent implements Serializable{
|
||||
* @param pos the index of the card to draw
|
||||
*/
|
||||
public DrawLowerTribeCard(String username, int pos){
|
||||
super(username, EventType.DRAW_LOWER_TRIBE, false);
|
||||
super(username, EventType.DRAW_LOWER_TRIBE, false, ErrorType.WRONG_ACTION);
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
@@ -23,7 +24,7 @@ public class DrawUpperBuildingCard extends NetworkEvent implements Serializable
|
||||
* @param pos the index of the card to draw
|
||||
*/
|
||||
public DrawUpperBuildingCard(String username, int pos){
|
||||
super(username, EventType.DRAW_UPPER_BUILD, false);
|
||||
super(username, EventType.DRAW_UPPER_BUILD, false, ErrorType.WRONG_ACTION);
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
@@ -23,7 +24,7 @@ public class DrawUpperTribeCard extends NetworkEvent implements Serializable{
|
||||
* @param pos the index of the card to draw
|
||||
*/
|
||||
public DrawUpperTribeCard(String username, int pos){
|
||||
super(username, EventType.DRAW_UPPER_TRIBE, false);
|
||||
super(username, EventType.DRAW_UPPER_TRIBE, false, ErrorType.WRONG_ACTION);
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Model.OrderLogicCard;
|
||||
@@ -31,7 +32,7 @@ public class EndedGame extends NetworkEvent implements Serializable{
|
||||
* @param players the list of players at the end of the game.
|
||||
*/
|
||||
public EndedGame(Map<Slot, Player> slotPlayerMap, OrderLogicCard orderLogicCard, CurrentState currentState, ArrayList<Player> players){
|
||||
super("SERVER",EventType.ENDED_GAME,false);
|
||||
super("SERVER",EventType.ENDED_GAME,false, ErrorType.GENERIC_ERROR);
|
||||
this.slotPlayerMap = slotPlayerMap;
|
||||
this.orderLogicCard = orderLogicCard;
|
||||
this.currentState = currentState;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
@@ -18,7 +19,7 @@ public class ReconnectPlayer extends NetworkEvent implements Serializable {
|
||||
* @param username the username of the player who reconnected.
|
||||
*/
|
||||
public ReconnectPlayer(String username) {
|
||||
super(username, EventType.RECONNECT_PLAYER, false);
|
||||
super(username, EventType.RECONNECT_PLAYER, false, ErrorType.GENERIC_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
@@ -18,7 +19,7 @@ public class SkipTurn extends NetworkEvent implements Serializable{
|
||||
* @param username the name of the player requesting the event
|
||||
*/
|
||||
public SkipTurn(String username){
|
||||
super(username, EventType.SKIP_TURN, false);
|
||||
super(username, EventType.SKIP_TURN, false, ErrorType.WRONG_ACTION);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
@@ -23,7 +24,7 @@ public class SlotChoice extends NetworkEvent implements Serializable {
|
||||
* @param pos the index of the card to draw
|
||||
*/
|
||||
public SlotChoice(String username, int pos) {
|
||||
super(username, EventType.SLOT_CHOICE, false);
|
||||
super(username, EventType.SLOT_CHOICE, false, ErrorType.WRONG_ACTION);
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Model.Totems;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
@@ -40,7 +41,7 @@ public class TotemChoice extends NetworkEvent implements Serializable {
|
||||
* @param totem the name of the selected totem.
|
||||
*/
|
||||
public TotemChoice(String username, String totem) {
|
||||
super(username, EventType.TOTEM_CHOICE, false);
|
||||
super(username, EventType.TOTEM_CHOICE, false, ErrorType.WRONG_ACTION);
|
||||
this.totem = totem;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
|
||||
@Override
|
||||
public void onAction(NetworkEvent event) throws RemoteException {
|
||||
if(event.getIsError()) {
|
||||
clientController.view.showError(event.toString());
|
||||
clientController.view.showError(event.getErrorType(),event.toString());
|
||||
} else {
|
||||
event.apply(clientController.miniModel);
|
||||
clientController.view.render();
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.rmi.registry.Registry;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Network.IClient;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer;
|
||||
@@ -53,7 +54,7 @@ public class RMIClient implements IClient {
|
||||
* opening a second socket).
|
||||
*/
|
||||
@Override
|
||||
public boolean connect(String username, int preferredInt) {
|
||||
public ErrorType connect(String username, int preferredInt) {
|
||||
try {
|
||||
System.setProperty("java.rmi.server.hostname", this.myIP);
|
||||
Registry registry = LocateRegistry.getRegistry(host, port);
|
||||
@@ -61,16 +62,17 @@ public class RMIClient implements IClient {
|
||||
this.username = username;
|
||||
|
||||
ClientCallbackImpl callback = new ClientCallbackImpl(controller);
|
||||
boolean joined = stub.joinGame(username, preferredInt, callback);
|
||||
if (!joined) return false;
|
||||
|
||||
running = true;
|
||||
startHeartbeat();
|
||||
return true;
|
||||
|
||||
ErrorType status = stub.joinGame(username, preferredInt, callback);
|
||||
if(status==null)
|
||||
{
|
||||
running = true;
|
||||
startHeartbeat();
|
||||
return null;
|
||||
}
|
||||
return status;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
return ErrorType.GENERIC_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +126,9 @@ public class RMIClient implements IClient {
|
||||
if (!running) return;
|
||||
running = false;
|
||||
if (pingSender != null) pingSender.shutdownNow();
|
||||
controller.view.showError("Connection with server closed");
|
||||
controller.miniModel=null;
|
||||
controller.setClient(null);
|
||||
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Network.RMI.Common;
|
||||
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
|
||||
import java.rmi.*;
|
||||
|
||||
/**
|
||||
@@ -18,7 +20,7 @@ public interface IGameServer extends Remote {
|
||||
* {@code false} otherwise.
|
||||
* @throws RemoteException if an RMI communication error occurs.
|
||||
*/
|
||||
boolean joinGame(String username, int preferredInt, IClientCallback callback) throws RemoteException;
|
||||
ErrorType joinGame(String username, int preferredInt, IClientCallback callback) throws RemoteException;
|
||||
|
||||
/**
|
||||
* Requests to draw a tribe card from the upper tribe card list.
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package it.polimi.ingsw.gc14.Network.RMI.Server;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.LimitedMap;
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
|
||||
@@ -81,9 +83,9 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
* {@code TCPServer.acceptHeartbeat()}.
|
||||
*/
|
||||
@Override
|
||||
public boolean joinGame(String username, int preferredInt, IClientCallback callback)
|
||||
public ErrorType joinGame(String username, int preferredInt, IClientCallback callback)
|
||||
throws RemoteException {
|
||||
if (preferredInt < 2 || preferredInt > 5) return false;
|
||||
if (preferredInt < 2 || preferredInt > 5) return ErrorType.WRONG_PLAYER_NUMBER;
|
||||
|
||||
synchronized (controller) {
|
||||
|
||||
@@ -92,32 +94,47 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
playerList.setLimit(preferredInt);
|
||||
System.out.println("Game Created With :"+preferredInt+" Players");
|
||||
}
|
||||
if (controller.addPlayer(username)) {
|
||||
clients.put(username, callback);
|
||||
playerList.put(username, true);
|
||||
startWatchdog(username);
|
||||
System.out.println("Accepted player: " + username);
|
||||
return true;
|
||||
if(controller.getModel().getCurrentState().getGameStage()!= GameStages.WAITING ) {
|
||||
if (!controller.getModel().getPlayers().stream().anyMatch(p -> p.getUserName().equals(username))) {
|
||||
return ErrorType.GAME_ALREADY_STARTED;
|
||||
}
|
||||
}
|
||||
if(controller.getModel().getPlayers().stream().anyMatch(p -> p.getUserName().equals(username))&& !playerList.containsKey(username)) {
|
||||
else {
|
||||
if (controller.addPlayer(username)) {
|
||||
clients.put(username, callback);
|
||||
playerList.put(username, true);
|
||||
startWatchdog(username);
|
||||
System.out.println("Accepted player: " + username);
|
||||
return null;
|
||||
} else {
|
||||
return ErrorType.USERNAME_ALREADY_USED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!playerList.containsKey(username)){
|
||||
clients.put(username, callback);
|
||||
playerList.put(username, true);
|
||||
startWatchdog(username);
|
||||
System.out.println("(After crash)Reconnected player: " + username);
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
if (playerList.containsKey(username) && !playerList.get(username)) {
|
||||
playerList.put(username, true);
|
||||
clients.put(username, callback);
|
||||
System.out.println("Reconnected player: " + username);
|
||||
startWatchdog(username);
|
||||
Game game = controller.getModel();
|
||||
callback.onGameInit(new MiniModel(game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers(),game.getAvailableTotems(),game.getUpperListTribeCards(),game.getLowerListTribeCards(),game.getUpperListBuilding(),game.getLowerListBuilding()));
|
||||
System.out.println("Model sent: " + username);
|
||||
actionQueue.add(new ReconnectPlayer(username));
|
||||
return true;
|
||||
else {
|
||||
if(!playerList.get(username))
|
||||
{
|
||||
playerList.put(username, true);
|
||||
clients.put(username, callback);
|
||||
System.out.println("Reconnected player: " + username);
|
||||
startWatchdog(username);
|
||||
Game game = controller.getModel();
|
||||
callback.onGameInit(new MiniModel(game.getSlotMap(), game.orderLogicCard, game.getCurrentState(), game.getPlayers(), game.getAvailableTotems(), game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding()));
|
||||
System.out.println("Model sent: " + username);
|
||||
actionQueue.add(new ReconnectPlayer(username));
|
||||
return null;
|
||||
}
|
||||
else
|
||||
return ErrorType.USER_ALREADY_CONNECTED;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.Network.TCP.Client;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.IClient;
|
||||
@@ -70,7 +71,7 @@ public class TCPClient implements IClient {
|
||||
* @param proposedNPlayers The desired number of players for the game
|
||||
* @return true if the connection is successful, false otherwise.
|
||||
*/
|
||||
public boolean connect(String user, int proposedNPlayers) {
|
||||
public ErrorType connect(String user, int proposedNPlayers) {
|
||||
try {
|
||||
communicationSocket = new Socket(hostname, mainPort);
|
||||
socketSend = new ObjectOutputStream(communicationSocket.getOutputStream());
|
||||
@@ -80,7 +81,16 @@ public class TCPClient implements IClient {
|
||||
int read= communicationSocket.getInputStream().read();
|
||||
if ( read== -1) {
|
||||
System.out.println("Could not connect to server");
|
||||
return false;
|
||||
|
||||
try {
|
||||
if( socketReceive.readObject() instanceof AddPlayer x)
|
||||
{
|
||||
return x.getErrorType();
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
return ErrorType.GENERIC_ERROR;
|
||||
}
|
||||
return ErrorType.GENERIC_ERROR;
|
||||
}
|
||||
new Thread(this::receiveMessage, "tcp-reader").start();
|
||||
|
||||
@@ -95,11 +105,11 @@ public class TCPClient implements IClient {
|
||||
new Thread(this::heartbeatLoop, "heartbeat").start();
|
||||
|
||||
running = true;
|
||||
return true;
|
||||
return null;
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
return ErrorType.GENERIC_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +153,9 @@ public class TCPClient implements IClient {
|
||||
running = false;
|
||||
try { communicationSocket.close(); } catch (IOException ignored) {}
|
||||
try { heartbeatSocket.close(); } catch (IOException ignored) {}
|
||||
controller.view.showError("Connection with server lost");
|
||||
controller.setClient(null);
|
||||
controller.setModel(null);
|
||||
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -166,7 +178,11 @@ public class TCPClient implements IClient {
|
||||
|
||||
if (read instanceof NetworkEvent event) {
|
||||
if (event.getIsError()) {
|
||||
controller.view.showError(event.toString());
|
||||
if(event.getErrorType() == ErrorType.WRONG_ACTION) {
|
||||
controller.view.showError(ErrorType.WRONG_ACTION,event.toString());
|
||||
}
|
||||
else
|
||||
controller.view.showError(event.getErrorType(),event.getErrorType().toString());
|
||||
} else {
|
||||
event.apply(controller.miniModel);
|
||||
controller.view.render();
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package it.polimi.ingsw.gc14.Network.TCP.Server;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.LimitedMap;
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
@@ -168,35 +170,52 @@ public class TCPServer {
|
||||
playerList.setLimit(eventAddPlayer.getProposedNPlayer());
|
||||
System.out.println("Game Created With :"+eventAddPlayer.getProposedNPlayer()+" Players");
|
||||
}
|
||||
|
||||
if (controller.addPlayer(username)) {
|
||||
playerList.put(username, true);
|
||||
System.out.println("Accepted player: " + username);
|
||||
|
||||
ClientHandler handler = new ClientHandler(
|
||||
username,
|
||||
clientSocket,
|
||||
clientSend,
|
||||
clientReceive,
|
||||
clientHandlers,
|
||||
playerList,
|
||||
actionQueue
|
||||
);
|
||||
|
||||
clientSocket.getOutputStream().write(1);
|
||||
pendingHeartbeat.put(username, handler);
|
||||
|
||||
Thread thread = new Thread(handler);
|
||||
thread.start();
|
||||
|
||||
clientHandlers.add(handler);
|
||||
connectedPlayers++;
|
||||
continue;
|
||||
|
||||
if(controller.getModel().getCurrentState().getGameStage()!= GameStages.WAITING ) {
|
||||
if (!controller.getModel().getPlayers().stream().anyMatch(p -> p.getUserName().equals(username))) {
|
||||
clientSocket.getOutputStream().write(-1);
|
||||
eventAddPlayer.setErrorType(ErrorType.GAME_ALREADY_STARTED);
|
||||
clientSend.writeObject(eventAddPlayer);
|
||||
clientSocket.close();
|
||||
System.out.println("Invalid parameters. Connection terminated.");
|
||||
}
|
||||
}
|
||||
if (controller.getModel().getPlayers().stream()
|
||||
.anyMatch(p -> p.getUserName().equals(username))
|
||||
&& !playerList.containsKey(username)) {
|
||||
else{
|
||||
if (controller.addPlayer(username)) {
|
||||
playerList.put(username, true);
|
||||
System.out.println("Accepted player: " + username);
|
||||
|
||||
ClientHandler handler = new ClientHandler(
|
||||
username,
|
||||
clientSocket,
|
||||
clientSend,
|
||||
clientReceive,
|
||||
clientHandlers,
|
||||
playerList,
|
||||
actionQueue
|
||||
);
|
||||
|
||||
clientSocket.getOutputStream().write(1);
|
||||
pendingHeartbeat.put(username, handler);
|
||||
|
||||
Thread thread = new Thread(handler);
|
||||
thread.start();
|
||||
|
||||
clientHandlers.add(handler);
|
||||
connectedPlayers++;
|
||||
continue;
|
||||
|
||||
}
|
||||
else {
|
||||
clientSocket.getOutputStream().write(-1);
|
||||
eventAddPlayer.setErrorType(ErrorType.USERNAME_ALREADY_USED);
|
||||
clientSend.writeObject(eventAddPlayer);
|
||||
clientSocket.close();
|
||||
System.out.println("Invalid parameters. Connection terminated.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!playerList.containsKey(username)) {
|
||||
playerList.put(username, true);
|
||||
System.out.println("(After crash)Reconnected player: " + username);
|
||||
|
||||
@@ -222,46 +241,49 @@ public class TCPServer {
|
||||
|
||||
}
|
||||
//reconnect a previously disconnected player
|
||||
if (playerList.containsKey(username)
|
||||
&& !playerList.get(username)) {
|
||||
else{
|
||||
if (!playerList.get(username)) {
|
||||
|
||||
playerList.put(username, true);
|
||||
System.out.println("Reconnected player: " + username);
|
||||
playerList.put(username, true);
|
||||
System.out.println("Reconnected player: " + username);
|
||||
|
||||
ClientHandler handler = new ClientHandler(
|
||||
username,
|
||||
clientSocket,
|
||||
clientSend,
|
||||
clientReceive,
|
||||
clientHandlers,
|
||||
playerList,
|
||||
actionQueue
|
||||
);
|
||||
ClientHandler handler = new ClientHandler(
|
||||
username,
|
||||
clientSocket,
|
||||
clientSend,
|
||||
clientReceive,
|
||||
clientHandlers,
|
||||
playerList,
|
||||
actionQueue
|
||||
);
|
||||
|
||||
clientSocket.getOutputStream().write(1);
|
||||
pendingHeartbeat.put(username, handler);
|
||||
clientSocket.getOutputStream().write(1);
|
||||
pendingHeartbeat.put(username, handler);
|
||||
|
||||
Game game = controller.getModel();
|
||||
handler.notifyMiniModel(new MiniModel(
|
||||
game.getSlotMap(),
|
||||
game.orderLogicCard,
|
||||
game.getCurrentState(),
|
||||
game.getPlayers(),
|
||||
game.getAvailableTotems(),
|
||||
game.getUpperListTribeCards(),game.getLowerListTribeCards(),game.getUpperListBuilding(),game.getLowerListBuilding()
|
||||
));
|
||||
Game game = controller.getModel();
|
||||
handler.notifyMiniModel(new MiniModel(
|
||||
game.getSlotMap(),
|
||||
game.orderLogicCard,
|
||||
game.getCurrentState(),
|
||||
game.getPlayers(),
|
||||
game.getAvailableTotems(),
|
||||
game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding()
|
||||
));
|
||||
|
||||
Thread thread = new Thread(handler);
|
||||
thread.start();
|
||||
Thread thread = new Thread(handler);
|
||||
thread.start();
|
||||
|
||||
clientHandlers.add(handler);
|
||||
connectedPlayers++;
|
||||
actionQueue.add(new ReconnectPlayer(username));
|
||||
clientHandlers.add(handler);
|
||||
connectedPlayers++;
|
||||
actionQueue.add(new ReconnectPlayer(username));
|
||||
|
||||
} else {
|
||||
clientSocket.getOutputStream().write(-1);
|
||||
clientSocket.close();
|
||||
System.out.println("Player could not be added. Connection terminated.");
|
||||
} else {
|
||||
clientSocket.getOutputStream().write(-1);
|
||||
eventAddPlayer.setErrorType(ErrorType.USER_ALREADY_CONNECTED);
|
||||
clientSend.writeObject(eventAddPlayer);
|
||||
clientSocket.close();
|
||||
System.out.println("Invalid parameters. Connection terminated.");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
package it.polimi.ingsw.gc14.View.GUI;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.View.GUI.LoginFXMLController;
|
||||
import it.polimi.ingsw.gc14.View.GUI.MainFXMLController;
|
||||
import it.polimi.ingsw.gc14.View.IView;
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.geometry.Rectangle2D;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Screen;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Duration;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static it.polimi.ingsw.gc14.Model.GamePackage.GameStages.ENDED;
|
||||
import static it.polimi.ingsw.gc14.Model.GamePackage.GameStages.TOTEM_CHOICE;
|
||||
@@ -144,12 +135,11 @@ public class GUI extends Application implements IView {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(String message) {
|
||||
public void showError(ErrorType error,String message) {
|
||||
Platform.runLater(() -> {
|
||||
synchronized (miniModel) {
|
||||
controllerMain.isError = true;
|
||||
controllerMain.render();
|
||||
System.out.println("ERRORE PORCODIDODODODOD");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package it.polimi.ingsw.gc14.View.GUI;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Client.RMIClient;
|
||||
import it.polimi.ingsw.gc14.Network.TCP.Client.TCPClient;
|
||||
import javafx.animation.*;
|
||||
@@ -153,23 +154,28 @@ public class LoginFXMLController {
|
||||
private void connect(String nome, String ip, int numPlayers, String localInterface) {
|
||||
if (isRMI) {
|
||||
RMIClient client = new RMIClient(controller, ip, 1099, localInterface);
|
||||
if (client.connect(nome, numPlayers)) {
|
||||
ErrorType serverResponse=client.connect(nome, numPlayers);
|
||||
if (serverResponse==null) {
|
||||
controller.setClient(client);
|
||||
Platform.runLater(() -> showSuccess("Connected! Waiting for other players…"));
|
||||
} else {
|
||||
Platform.runLater(() -> showError("RMI connection failed."));
|
||||
Platform.runLater(() -> showError(serverResponse));
|
||||
}
|
||||
} else {
|
||||
TCPClient client = new TCPClient(controller, ip, 8080, 8081);
|
||||
if (client.connect(nome, numPlayers)) {
|
||||
ErrorType serverResponse=client.connect(nome, numPlayers);
|
||||
if (serverResponse==null) {
|
||||
controller.setClient(client);
|
||||
Platform.runLater(() -> showSuccess("Connected! Waiting for other players…"));
|
||||
} else {
|
||||
Platform.runLater(() -> showError("TCP connection failed."));
|
||||
Platform.runLater(() -> showError(serverResponse));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showError(ErrorType errorType) {
|
||||
labelErrore.setTextFill(Color.web("#e05050"));
|
||||
labelErrore.setText(errorType.toString());
|
||||
}
|
||||
private void showError(String msg) {
|
||||
labelErrore.setTextFill(Color.web("#e05050"));
|
||||
labelErrore.setText(msg);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package it.polimi.ingsw.gc14.View;
|
||||
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
@@ -7,7 +8,9 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
public interface IView {
|
||||
public void setModel(MiniModel miniModel);
|
||||
public void render();
|
||||
public void showMessage(String message);
|
||||
public void showError(String message);
|
||||
|
||||
void showMessage(String message);
|
||||
|
||||
public void showError(ErrorType error,String message);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package it.polimi.ingsw.gc14.View.TUI;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Model.*;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
@@ -100,6 +101,7 @@ public class TUI implements IView {
|
||||
else if(model.currentState.getGameStage().equals(GameStages.ENDED))
|
||||
{
|
||||
renderStanding();
|
||||
System.out.println("Press 8 to start another game or press 0 to exit");
|
||||
return;
|
||||
}
|
||||
else
|
||||
@@ -231,12 +233,14 @@ public class TUI implements IView {
|
||||
/**
|
||||
* Prints an error message to standard output.
|
||||
*
|
||||
* @param message the error message to display
|
||||
* @param error the error message to display
|
||||
*/
|
||||
public void showError(String message) {
|
||||
public void showError(ErrorType error,String message) {
|
||||
clearTerminal();
|
||||
render();
|
||||
System.out.println(message);
|
||||
if(error==ErrorType.SERVER_CRASHED)
|
||||
System.out.println("Press any key to continue");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user