Merge branch 'RMI' into main
This commit is contained in:
@@ -5,11 +5,10 @@ import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
|
|||||||
import it.polimi.ingsw.gc14.Model.PlayableCard;
|
import it.polimi.ingsw.gc14.Model.PlayableCard;
|
||||||
import it.polimi.ingsw.gc14.Model.Player;
|
import it.polimi.ingsw.gc14.Model.Player;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
public class BuildingCard extends PlayableCard implements Cloneable , BuildingEffect, Serializable {
|
||||||
public class BuildingCard extends PlayableCard implements Cloneable , BuildingEffect {
|
/**
|
||||||
|
|
||||||
/**
|
|
||||||
* The price of this building card.
|
* The price of this building card.
|
||||||
*/
|
*/
|
||||||
private int price;
|
private int price;
|
||||||
@@ -78,7 +77,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
|
|||||||
* @param prestigeValue the prestige value of the building card.
|
* @param prestigeValue the prestige value of the building card.
|
||||||
* @throws IllegalArgumentException if {@code price <= 0} or {@code prestigeValue < 0}
|
* @throws IllegalArgumentException if {@code price <= 0} or {@code prestigeValue < 0}
|
||||||
*/
|
*/
|
||||||
public BuildingCard(int era,int price,int prestigeValue) throws IllegalArgumentException{
|
protected BuildingCard(int era,int price,int prestigeValue) throws IllegalArgumentException{
|
||||||
super(era);
|
super(era);
|
||||||
if (price > 0) {
|
if (price > 0) {
|
||||||
this.price = price;
|
this.price = price;
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ package it.polimi.ingsw.gc14.Model.Cards;
|
|||||||
|
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
|
||||||
import it.polimi.ingsw.gc14.Model.PlayableCard;
|
import it.polimi.ingsw.gc14.Model.PlayableCard;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base class for all tribe cards.
|
* Abstract base class for all tribe cards.
|
||||||
* A TribeCard is a {@link PlayableCard} that may either be an event card
|
* A TribeCard is a {@link PlayableCard} that may either be an event card
|
||||||
* or a non-event card, and may optionally specify a minimum number of players.
|
* or a non-event card, and may optionally specify a minimum number of players.
|
||||||
*/
|
*/
|
||||||
public abstract class TribeCard extends PlayableCard {
|
public abstract class TribeCard extends PlayableCard implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether this tribe card is an event card.
|
* Indicates whether this tribe card is an event card.
|
||||||
|
|||||||
@@ -8,13 +8,14 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Events.Sustenance;
|
|||||||
import it.polimi.ingsw.gc14.Model.DecksCreator;
|
import it.polimi.ingsw.gc14.Model.DecksCreator;
|
||||||
import it.polimi.ingsw.gc14.Model.Slot;
|
import it.polimi.ingsw.gc14.Model.Slot;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Board manages all the elements during the game such as decks, upper and lower rows, totems, tiles...
|
* Board manages all the elements during the game such as decks, upper and lower rows, totems, tiles...
|
||||||
*/
|
*/
|
||||||
public class Board {
|
public class Board implements Serializable {
|
||||||
/**
|
/**
|
||||||
* slotList contains the ordered list of slots (tiles). The slots changes based on the number of players.
|
* slotList contains the ordered list of slots (tiles). The slots changes based on the number of players.
|
||||||
* Each slot (tile) has special action as drawing from the upper/lower row or taking food.
|
* Each slot (tile) has special action as drawing from the upper/lower row or taking food.
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ package it.polimi.ingsw.gc14.Model.GamePackage;
|
|||||||
import it.polimi.ingsw.gc14.Model.Player;
|
import it.polimi.ingsw.gc14.Model.Player;
|
||||||
import it.polimi.ingsw.gc14.Model.Slot;
|
import it.polimi.ingsw.gc14.Model.Slot;
|
||||||
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the current state of the game.
|
* Represents the current state of the game.
|
||||||
* A CurrentState object stores the current player, slot, era, round,
|
* A CurrentState object stores the current player, slot, era, round,
|
||||||
* remaining upper and lower cards, and the current game stage.
|
* remaining upper and lower cards, and the current game stage.
|
||||||
*/
|
*/
|
||||||
public class CurrentState {
|
public class CurrentState implements Serializable {
|
||||||
// region Getters
|
// region Getters
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.Model;
|
|||||||
|
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,7 +10,7 @@ import java.util.*;
|
|||||||
* An OrderLogicCard manages a queue of players and defines the effects
|
* An OrderLogicCard manages a queue of players and defines the effects
|
||||||
* applied when players are pushed back into the queue.
|
* applied when players are pushed back into the queue.
|
||||||
*/
|
*/
|
||||||
public abstract class OrderLogicCard {
|
public abstract class OrderLogicCard implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The queue of players associated with this order logic card.
|
* The queue of players associated with this order logic card.
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package it.polimi.ingsw.gc14.Model;
|
package it.polimi.ingsw.gc14.Model;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base class for all playable cards.
|
* Abstract base class for all playable cards.
|
||||||
* A PlayableCard is characterized by an era value.
|
* A PlayableCard is characterized by an era value.
|
||||||
*/
|
*/
|
||||||
public abstract class PlayableCard {
|
public abstract class PlayableCard implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The era associated with this playable card.
|
* The era associated with this playable card.
|
||||||
|
|||||||
@@ -4,13 +4,14 @@ import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
|
|||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
|
||||||
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.*;
|
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Player class; contains all identifiers and methods needed.
|
* Default Player class; contains all identifiers and methods needed.
|
||||||
*/
|
*/
|
||||||
public class Player {
|
public class Player implements Serializable {
|
||||||
/**
|
/**
|
||||||
* The maximum length allowed for the username string.
|
* The maximum length allowed for the username string.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package it.polimi.ingsw.gc14.Model;
|
package it.polimi.ingsw.gc14.Model;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a slot with a specific identifier and associated values
|
* Represents a slot with a specific identifier and associated values
|
||||||
* for upper cards, lower cards, food, and minimum number of players.
|
* for upper cards, lower cards, food, and minimum number of players.
|
||||||
* The slot configuration depends on the specified slot identifier.
|
* The slot configuration depends on the specified slot identifier.
|
||||||
*/
|
*/
|
||||||
public class Slot {
|
public class Slot implements Serializable {
|
||||||
// Getters
|
// Getters
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network.RMI.Client;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Model.Game;
|
||||||
|
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
||||||
|
|
||||||
|
import java.rmi.*;
|
||||||
|
|
||||||
|
public interface IClientCallback extends Remote {
|
||||||
|
void onGameInit(Game model) throws RemoteException;
|
||||||
|
void onAction(NetworkEvent action) throws RemoteException;
|
||||||
|
void onError(String message) throws RemoteException;
|
||||||
|
void onGameOver(String winner) throws RemoteException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network.RMI.Client;
|
||||||
|
import java.rmi.RemoteException;
|
||||||
|
import java.rmi.registry.LocateRegistry;
|
||||||
|
import java.rmi.registry.Registry;
|
||||||
|
import java.rmi.server.UnicastRemoteObject;
|
||||||
|
|
||||||
|
public class RMIClient {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network.RMI.Server;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Network.RMI.Client.IClientCallback;
|
||||||
|
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
||||||
|
|
||||||
|
import java.rmi.*;
|
||||||
|
|
||||||
|
public interface IGameServer extends Remote {
|
||||||
|
// Connessione
|
||||||
|
String joinGame(String username, IClientCallback callback) throws RemoteException;
|
||||||
|
|
||||||
|
// Azioni di gioco — specchio dei tuoi metodi GameController
|
||||||
|
boolean drawUpperTribeCard(String playerUsername, int pos) throws RemoteException;
|
||||||
|
boolean drawLowerTribeCard(String playerUsername, int pos) throws RemoteException;
|
||||||
|
boolean drawUpperBuildingCard(String playerUsername, int pos) throws RemoteException;
|
||||||
|
boolean drawLowerBuildingCard(String playerUsername, int pos) throws RemoteException;
|
||||||
|
boolean pickOptionalTribeCard(String playerUsername, int pos) throws RemoteException;
|
||||||
|
boolean pickOptionalBuildingCard(String playerUsername, int pos) throws RemoteException;
|
||||||
|
boolean slotChoice(String playerUsername, int pos) throws RemoteException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network.RMI.Server;
|
||||||
|
|
||||||
|
import java.rmi.RemoteException;
|
||||||
|
|
||||||
|
public interface IRMIServer {
|
||||||
|
void connect(VirtualView client) throws RemoteException;
|
||||||
|
void add(Integer number) throws RemoteException;
|
||||||
|
void reset() throws RemoteException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network.RMI.Server;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
|
import it.polimi.ingsw.gc14.Network.RMI.Client.IClientCallback;
|
||||||
|
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
||||||
|
|
||||||
|
import java.rmi.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class RMIGameController implements IGameServer {
|
||||||
|
|
||||||
|
private final GameController controller; // delega tutto qui
|
||||||
|
private final Map<String, IClientCallback> clients = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public RMIGameController(GameController controller) {
|
||||||
|
this.controller = controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String joinGame(String username, IClientCallback callback) throws RemoteException {
|
||||||
|
controller.addPlayer(username);
|
||||||
|
clients.put(username, callback);
|
||||||
|
callback.onGameInit(controller.getModel());
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean drawUpperTribeCard(String username, int pos) throws RemoteException {
|
||||||
|
boolean result = controller.drawUpperTribeCard(username, pos);
|
||||||
|
if (!result) {
|
||||||
|
notifyError(username, "Mossa non valida");
|
||||||
|
} else {
|
||||||
|
notifyAll(new NetworkEvent(Action.ActionType.DRAW_UPPER_TRIBE, username, pos));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void notifyAll(Action action) throws RemoteException {
|
||||||
|
for (IClientCallback cb : clients.values()) {
|
||||||
|
cb.onAction(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifyError(String username, String message) throws RemoteException {
|
||||||
|
IClientCallback cb = clients.get(username);
|
||||||
|
if (cb != null) cb.onError(message);
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package it.polimi.ingsw.gc14.Network.RMI.Server;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
|
|
||||||
|
import java.rmi.RemoteException;
|
||||||
|
import java.rmi.registry.LocateRegistry;
|
||||||
|
import java.rmi.registry.Registry;
|
||||||
|
import java.rmi.server.UnicastRemoteObject;
|
||||||
|
|
||||||
|
public class RMIServer {
|
||||||
|
|
||||||
|
private final RMIGameController controller;
|
||||||
|
private Registry registry;
|
||||||
|
|
||||||
|
public RMIServer(RMIGameController controller) {
|
||||||
|
this.controller = controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() throws Exception {
|
||||||
|
IGameServer stub = (IGameServer) UnicastRemoteObject.exportObject(controller, 0);
|
||||||
|
registry = LocateRegistry.createRegistry(1099);
|
||||||
|
registry.rebind("GameServer", stub);
|
||||||
|
System.out.println("RMI Server avviato sulla porta 1099");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop() throws Exception {
|
||||||
|
registry.unbind("GameServer");
|
||||||
|
UnicastRemoteObject.unexportObject(controller, true);
|
||||||
|
System.out.println("RMI Server fermato");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,21 @@
|
|||||||
package it.polimi.ingsw.gc14.View;
|
package it.polimi.ingsw.gc14.View;
|
||||||
|
|
||||||
|
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
|
||||||
|
|
||||||
public interface IView {
|
public interface IView {
|
||||||
|
// --- Setup ---
|
||||||
|
void showWelcome();
|
||||||
|
String askPlayerName();
|
||||||
|
|
||||||
|
// --- Rendering ---
|
||||||
|
void render(GameState state);
|
||||||
|
void showMessage(String message);
|
||||||
|
void showError(String message);
|
||||||
|
void showWinner(String winner);
|
||||||
|
|
||||||
|
// --- Input giocatore ---
|
||||||
|
NetworkEvent askMove(GameState state);
|
||||||
|
|
||||||
|
// --- Lifecycle ---
|
||||||
|
void close();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user