Merge branch 'main' into TCP

This commit is contained in:
GabrieleRadice
2026-04-18 18:15:43 +02:00
10 changed files with 313 additions and 5 deletions
@@ -8,6 +8,14 @@ public class GameController {
public GameController(Game model) {
this.model = model;
}
public GameController() {
}
public Game getModel() {
return model;
}
public void setModel(Game model) {
this.model = model;
}
public boolean addPlayer(String username) {
return model.addPlayer(new Player(username));
}
@@ -60,7 +60,9 @@ public class Game {
public int getNPlayers() {
return nPlayers;
}
public Game(int nPlayers) {
public Game(int nPlayers) throws IllegalArgumentException{
if(nPlayers < 0||nPlayers > 5)
throw new IllegalArgumentException();
this.nPlayers = nPlayers;
board=new Board(nPlayers);
slotMap = new LinkedHashMap<>();
@@ -72,8 +74,16 @@ public class Game {
playersList = new ArrayList<>();
OptionalCardQueue = new LinkedList<>();
}
public Game()
{
this(0);
}
public boolean addPlayer(Player player) {
if(this.nPlayers==0)
{
return false;
}
if(currentState.getGameStage()!= GameStages.WAITING)
return false;
if(playersList.contains(player))
@@ -415,7 +425,13 @@ public class Game {
currentState.GameStageUpdate(GameStages.ENDED);
}
public boolean setNPlayer(int nPlayers)
{
if(this.nPlayers!=0)
return false;
this.nPlayers=nPlayers;
return true;
}
@@ -1,4 +1,4 @@
package it.polimi.ingsw.gc14.Network.Client.TCP;
package it.polimi.ingsw.gc14.Network.TCP.Client;
import it.polimi.ingsw.gc14.View.IView;
@@ -0,0 +1,12 @@
package it.polimi.ingsw.gc14.Network.TCP;
public enum EventType {
ADD_PLAYER,
SLOT_CHOICE,
DRAW_UPPER_TRIBE,
DRAW_LOWER_TRIBE,
DRAW_UPPER_BUILD,
DRAW_LOWER_BUILD,
PICK_OPTIONAL_TRIBE,
PICK_OPTIONAL_BUILD
}
@@ -0,0 +1,10 @@
package it.polimi.ingsw.gc14.Network.TCP;
import it.polimi.ingsw.gc14.Controller.GameController;
import java.io.Serializable;
public abstract class NetworkEvent implements Serializable {
public abstract boolean apply(GameController gameController);
}
@@ -0,0 +1,26 @@
package it.polimi.ingsw.gc14.Network.TCP.NetworkEvents;
import it.polimi.ingsw.gc14.Controller.GameController;
import it.polimi.ingsw.gc14.Network.TCP.EventType;
import it.polimi.ingsw.gc14.Network.TCP.NetworkEvent;
import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable;
public class AddPlayer extends NetworkEvent implements Serializable {
private String username;
private EventType eventType;
public AddPlayer(String username) {
this.username = username;
this.eventType = EventType.ADD_PLAYER;
}
@Override
public boolean apply(GameController gameController)
{
return gameController.addPlayer(username);
}
public String apply(IView gameController)
{
return gameController.toString();
}
}
@@ -1,4 +1,4 @@
package it.polimi.ingsw.gc14.Network.Server.TCP;
package it.polimi.ingsw.gc14.Network.TCP.Server;
import it.polimi.ingsw.gc14.Controller.GameController;
@@ -1,4 +1,4 @@
package it.polimi.ingsw.gc14.Network.Server.TCP;
package it.polimi.ingsw.gc14.Network.TCP.Server;
import it.polimi.ingsw.gc14.Controller.GameController;