Removed: Board in ApplyNextRound, MiniModel constructor

Added: upperListTribe,lowerListTribe,upperListBuilding,lowerListBuilding in MiniModel constructor
This commit is contained in:
rubenpirreram
2026-05-19 18:28:05 +02:00
parent d37c111c3c
commit 6da5670dff
10 changed files with 58 additions and 44 deletions
@@ -59,12 +59,7 @@ public class ClientController {
* @param model the model to set * @param model the model to set
*/ */
public void setModel(MiniModel model) { public void setModel(MiniModel model) {
this.miniModel.currentState=model.currentState; this.miniModel = model;
this.miniModel.availableTotems=model.availableTotems;
this.miniModel.board=model.board;
this.miniModel.orderLogicCard= model.orderLogicCard;
this.miniModel.players=model.players;
this.miniModel.slotPlayerMap=model.slotPlayerMap;
view.setModel(miniModel); view.setModel(miniModel);
} }
@@ -265,8 +265,8 @@ public class Game implements Serializable {
* *
* @return a list containing clones of the upper tribe cards currently available on the board. * @return a list containing clones of the upper tribe cards currently available on the board.
*/ */
public List<TribeCard>getUpperListTribeCards() { public ArrayList<TribeCard>getUpperListTribeCards() {
List<TribeCard> cards = new ArrayList<>(); ArrayList<TribeCard> cards = new ArrayList<>();
board.upperListTribe.forEach(x->cards.add(x.clone())); board.upperListTribe.forEach(x->cards.add(x.clone()));
return cards; return cards;
} }
@@ -276,8 +276,8 @@ public class Game implements Serializable {
* *
* @return a list containing clones of the lower tribe cards currently available on the board. * @return a list containing clones of the lower tribe cards currently available on the board.
*/ */
public List<TribeCard>getLowerListTribeCards() { public ArrayList<TribeCard>getLowerListTribeCards() {
List<TribeCard> cards = new ArrayList<>(); ArrayList<TribeCard> cards = new ArrayList<>();
board.lowerListTribe.forEach(x->cards.add(x.clone())); board.lowerListTribe.forEach(x->cards.add(x.clone()));
return cards; return cards;
} }
@@ -287,8 +287,8 @@ public class Game implements Serializable {
* *
* @return a list containing clones of the upper building cards currently available on the board. * @return a list containing clones of the upper building cards currently available on the board.
*/ */
public List<BuildingCard>getUpperListBuilding() { public ArrayList<BuildingCard>getUpperListBuilding() {
List<BuildingCard> cards = new ArrayList<>(); ArrayList<BuildingCard> cards = new ArrayList<>();
board.upperListBuilding.forEach(x->cards.add(x.clone())); board.upperListBuilding.forEach(x->cards.add(x.clone()));
return cards; return cards;
} }
@@ -298,8 +298,8 @@ public class Game implements Serializable {
* *
* @return a list containing clones of the lower building cards currently available on the board. * @return a list containing clones of the lower building cards currently available on the board.
*/ */
public List<BuildingCard>getLowerListBuilding() { public ArrayList<BuildingCard>getLowerListBuilding() {
List<BuildingCard> cards = new ArrayList<>(); ArrayList<BuildingCard> cards = new ArrayList<>();
board.lowerListBuilding.forEach(x->cards.add(x.clone())); board.lowerListBuilding.forEach(x->cards.add(x.clone()));
return cards; return cards;
} }
@@ -69,26 +69,29 @@ public class MiniModel implements Serializable {
/** /**
* Constructs a complete mini model from the current server-side game data. * Constructs a complete mini model from the current server-side game data.
* *
* @param board the current game board. *TODO
* @param slotPlayerMap the map associating occupied slots with players. * @param slotPlayerMap the map associating occupied slots with players.
* @param orderLogicCard the card managing player turn order. * @param orderLogicCard the card managing player turn order.
* @param currentState the current state of the game. * @param currentState the current state of the game.
* @param players the list of players in the match. * @param players the list of players in the match.
* @param availableTotems the list of totems still available for selection. * @param availableTotems the list of totems still available for selection.
*/ */
public MiniModel(Board board, public MiniModel(Map<Slot, Player> slotPlayerMap,
Map<Slot, Player> slotPlayerMap,
OrderLogicCard orderLogicCard, OrderLogicCard orderLogicCard,
CurrentState currentState, CurrentState currentState,
List<Player> players, List<Player> players,
List<Totems> availableTotems) { List<Totems> availableTotems,ArrayList<TribeCard> upperListTribeCards,ArrayList<TribeCard>lowerListTribeCards,ArrayList<BuildingCard> upperListBuildingCards,ArrayList<BuildingCard>lowerListBuildingCards) {
this.board = board;
this.slotPlayerMap = slotPlayerMap; this.slotPlayerMap = slotPlayerMap;
this.orderLogicCard = orderLogicCard; this.orderLogicCard = orderLogicCard;
this.currentState = currentState; this.currentState = currentState;
this.players = new HashMap<>(); this.players = new HashMap<>();
this.availableTotems = availableTotems; this.availableTotems = availableTotems;
this.standingPlayers = new ArrayList<>(); this.standingPlayers = new ArrayList<>();
this.upperListTribeCards = upperListTribeCards;
this.lowerListTribeCards = lowerListTribeCards;
this.upperListBuildingCards = upperListBuildingCards;
this.lowerListBuildingCards = lowerListBuildingCards;
setPlayers(players); setPlayers(players);
} }
@@ -1,6 +1,8 @@
package it.polimi.ingsw.gc14.Network.NetworkEvents; package it.polimi.ingsw.gc14.Network.NetworkEvents;
import it.polimi.ingsw.gc14.Controller.GameController; import it.polimi.ingsw.gc14.Controller.GameController;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState; import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
import it.polimi.ingsw.gc14.Model.MiniModel; import it.polimi.ingsw.gc14.Model.MiniModel;
import it.polimi.ingsw.gc14.Model.OrderLogicCard; import it.polimi.ingsw.gc14.Model.OrderLogicCard;
@@ -11,6 +13,7 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
import it.polimi.ingsw.gc14.View.IView; import it.polimi.ingsw.gc14.View.IView;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -20,6 +23,11 @@ import java.util.Map;
public class ApplyNextRound extends NetworkEvent implements Serializable{ public class ApplyNextRound extends NetworkEvent implements Serializable{
List<Player> players; List<Player> players;
ArrayList<TribeCard> upperListTribeCards;
ArrayList<TribeCard> lowerListTribeCards;
ArrayList<BuildingCard> upperListBuildingCards;
ArrayList<BuildingCard> lowerListBuildingCards;
/** /**
* Constructs an event that updates the game state for the next round. * Constructs an event that updates the game state for the next round.
@@ -29,8 +37,12 @@ public class ApplyNextRound extends NetworkEvent implements Serializable{
* @param currentState the current state of the game. * @param currentState the current state of the game.
* @param players the list of players in the game. * @param players the list of players in the game.
*/ */
public ApplyNextRound(Map<Slot, Player> slotPlayerMap, OrderLogicCard orderLogicCard, CurrentState currentState, List<Player> players){ 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);
this.upperListBuildingCards = upperListBuildingCards;
this.lowerListBuildingCards = lowerListBuildingCards;
this.upperListTribeCards = upperListTribeCards;
this.lowerListTribeCards = lowerListTribeCards;
this.slotPlayerMap = slotPlayerMap; this.slotPlayerMap = slotPlayerMap;
this.orderLogicCard = orderLogicCard; this.orderLogicCard = orderLogicCard;
this.currentState = currentState; this.currentState = currentState;
@@ -51,7 +63,10 @@ public class ApplyNextRound extends NetworkEvent implements Serializable{
miniModel.setOrderLogicCard(orderLogicCard); miniModel.setOrderLogicCard(orderLogicCard);
miniModel.setCurrentState(currentState); miniModel.setCurrentState(currentState);
miniModel.setPlayers(players); miniModel.setPlayers(players);
miniModel.board.nextRound(); miniModel.upperListTribeCards=upperListTribeCards;
miniModel.lowerListTribeCards=lowerListTribeCards;
miniModel.upperListBuildingCards=upperListBuildingCards;
miniModel.lowerListBuildingCards=lowerListBuildingCards;
return true; return true;
} }
@@ -111,7 +111,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
System.out.println("Reconnected player: " + username); System.out.println("Reconnected player: " + username);
startWatchdog(username); startWatchdog(username);
Game game = controller.getModel(); Game game = controller.getModel();
callback.onGameInit(new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers(),game.getAvailableTotems())); 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); System.out.println("Model sent: " + username);
actionQueue.add(new ReconnectPlayer(username)); actionQueue.add(new ReconnectPlayer(username));
return true; return true;
@@ -137,7 +137,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
System.out.println("Reconnected player: " + username); System.out.println("Reconnected player: " + username);
startWatchdog(username); startWatchdog(username);
Game game = controller.getModel(); Game game = controller.getModel();
callback.onGameInit(new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers(),game.getAvailableTotems())); 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); System.out.println("Model sent: " + username);
actionQueue.add(new ReconnectPlayer(username)); actionQueue.add(new ReconnectPlayer(username));
return true; return true;
@@ -228,12 +228,12 @@ public class TCPServer {
Game game = controller.getModel(); Game game = controller.getModel();
handler.notifyMiniModel(new MiniModel( handler.notifyMiniModel(new MiniModel(
game.getBoard(),
game.getSlotMap(), game.getSlotMap(),
game.orderLogicCard, game.orderLogicCard,
game.getCurrentState(), game.getCurrentState(),
game.getPlayers(), game.getPlayers(),
game.getAvailableTotems() game.getAvailableTotems(),
game.getUpperListTribeCards(),game.getLowerListTribeCards(),game.getUpperListBuilding(),game.getLowerListBuilding()
)); ));
Thread thread = new Thread(handler); Thread thread = new Thread(handler);
@@ -300,12 +300,13 @@ public class TCPServer {
Game game = controller.getModel(); Game game = controller.getModel();
handler.notifyMiniModel(new MiniModel( handler.notifyMiniModel(new MiniModel(
game.getBoard(),
game.getSlotMap(), game.getSlotMap(),
game.orderLogicCard, game.orderLogicCard,
game.getCurrentState(), game.getCurrentState(),
game.getPlayers(), game.getPlayers(),
game.getAvailableTotems() game.getAvailableTotems(),
game.getUpperListTribeCards(),game.getLowerListTribeCards(),game.getUpperListBuilding(),game.getLowerListBuilding()
)); ));
Thread thread = new Thread(handler); Thread thread = new Thread(handler);
@@ -150,7 +150,7 @@ public class ServerLauncher {
serverTCP.notifyAll(event); serverTCP.notifyAll(event);
if(game.getCurrentState().getRound()!=roundPrev) if(game.getCurrentState().getRound()!=roundPrev)
{ {
ApplyNextRound nextRound=new ApplyNextRound(game.getSlotMap(), game.orderLogicCard, game.getCurrentState(),game.getPlayers()); ApplyNextRound nextRound=new ApplyNextRound(game.getSlotMap(), game.orderLogicCard, game.getCurrentState(),game.getPlayers(),game.getUpperListTribeCards(),game.getLowerListTribeCards(),game.getUpperListBuilding(),game.getLowerListBuilding());
serverRMI.notifyAll(nextRound); serverRMI.notifyAll(nextRound);
serverTCP.notifyAll(nextRound); serverTCP.notifyAll(nextRound);
} }
@@ -247,7 +247,7 @@ public class ServerLauncher {
MiniModel miniModel; MiniModel miniModel;
synchronized (gameController) { synchronized (gameController) {
Game game = gameController.getModel(); Game game = gameController.getModel();
miniModel= new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers(), new ArrayList<>(List.of(Totems.values()))); miniModel= new MiniModel(game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers(), new ArrayList<>(List.of(Totems.values())),game.getUpperListTribeCards(),game.getLowerListTribeCards(),game.getUpperListBuilding(),game.getLowerListBuilding());
} }
serverRMI.notifyAll(miniModel); serverRMI.notifyAll(miniModel);
serverTCP.notifyAll(miniModel); serverTCP.notifyAll(miniModel);
@@ -67,7 +67,7 @@ public class LeaderboardFXMLController {
public void render() { public void render() {
rankingList.getChildren().clear(); rankingList.getChildren().clear();
if(controller.miniModel.standingPlayers!=null) if(!controller.miniModel.standingPlayers.isEmpty())
{ {
List<Player> sorted = controller.miniModel.standingPlayers; List<Player> sorted = controller.miniModel.standingPlayers;
@@ -272,7 +272,7 @@ public class MainFXMLController {
upperList.getChildren().clear(); upperList.getChildren().clear();
int i = 0; int i = 0;
for (TribeCard card : controller.miniModel.board.upperListTribe) { for (TribeCard card : controller.miniModel.upperListTribeCards) {
final int index = i; final int index = i;
StackPane img = createCard(card, true, true, upperList); StackPane img = createCard(card, true, true, upperList);
img.setOnMouseClicked(e -> controller.drawUpperTribeCard(controller.myUsername, index)); img.setOnMouseClicked(e -> controller.drawUpperTribeCard(controller.myUsername, index));
@@ -288,7 +288,7 @@ public class MainFXMLController {
lowerList.getChildren().clear(); lowerList.getChildren().clear();
int i = 0; int i = 0;
for (TribeCard card : controller.miniModel.board.lowerListTribe) { for (TribeCard card : controller.miniModel.lowerListTribeCards) {
final int index = i; final int index = i;
StackPane img = createCard(card, true, true, lowerList); StackPane img = createCard(card, true, true, lowerList);
img.setOnMouseClicked(e -> controller.drawLowerTribeCard(controller.myUsername, index)); img.setOnMouseClicked(e -> controller.drawLowerTribeCard(controller.myUsername, index));
@@ -299,7 +299,7 @@ public class MainFXMLController {
} }
private void drawUpperBuilding() { private void drawUpperBuilding() {
ArrayList<BuildingCard> cardList = new ArrayList<>(controller.miniModel.board.upperListBuilding); ArrayList<BuildingCard> cardList = new ArrayList<>(controller.miniModel.upperListBuildingCards);
if (!cardList.isEmpty()) { if (!cardList.isEmpty()) {
StackPane img = createCard(cardList.getLast(), true, true, upperList); StackPane img = createCard(cardList.getLast(), true, true, upperList);
Label label = new Label(String.valueOf(cardList.size())); Label label = new Label(String.valueOf(cardList.size()));
@@ -314,7 +314,7 @@ public class MainFXMLController {
} }
private void drawLowerBuilding() { private void drawLowerBuilding() {
ArrayList<BuildingCard> cardList = new ArrayList<>(controller.miniModel.board.lowerListBuilding); ArrayList<BuildingCard> cardList = new ArrayList<>(controller.miniModel.lowerListBuildingCards);
if (!cardList.isEmpty()) { if (!cardList.isEmpty()) {
StackPane img = createCard(cardList.getLast(), true, true, lowerList); StackPane img = createCard(cardList.getLast(), true, true, lowerList);
Label label = new Label(String.valueOf(cardList.size())); Label label = new Label(String.valueOf(cardList.size()));
@@ -333,15 +333,15 @@ public class TUI implements IView {
List<String> stringLowerListTribe=new ArrayList<>(); List<String> stringLowerListTribe=new ArrayList<>();
stringUpperListTribe.add("Char/Events"); stringUpperListTribe.add("Char/Events");
stringLowerListTribe.add("Char/Events"); stringLowerListTribe.add("Char/Events");
for(int i=0;i<Math.max(model.board.upperListTribe.size(),model.board.lowerListTribe.size());i++) for(int i=0;i<Math.max(model.upperListTribeCards.size(),model.lowerListTribeCards.size());i++)
{ {
if(i<model.board.upperListTribe.size()) if(i<model.upperListTribeCards.size())
{ {
stringUpperListTribe.add(i+"-"+model.board.upperListTribe.get(i).toStringBoard()); stringUpperListTribe.add(i+"-"+model.upperListTribeCards.get(i).toStringBoard());
} }
if(i<model.board.lowerListTribe.size()) if(i<model.lowerListTribeCards.size())
{ {
stringLowerListTribe.add(i+"-"+model.board.lowerListTribe.get(i).toStringBoard()); stringLowerListTribe.add(i+"-"+model.lowerListTribeCards.get(i).toStringBoard());
} }
} }
var BuildTableUpper = new AsciiTable(BorderStyle.UNICODE,1); var BuildTableUpper = new AsciiTable(BorderStyle.UNICODE,1);
@@ -349,15 +349,15 @@ public class TUI implements IView {
var BuildTableLower = new AsciiTable(BorderStyle.UNICODE,1); var BuildTableLower = new AsciiTable(BorderStyle.UNICODE,1);
BuildTableLower.addHeader("Building "); BuildTableLower.addHeader("Building ");
for(int i=0;i<Math.max(model.board.upperListBuilding.size(),model.board.lowerListBuilding.size());i++) for(int i=0;i<Math.max(model.upperListBuildingCards.size(),model.lowerListBuildingCards.size());i++)
{ {
if(i<model.board.upperListBuilding.size()) if(i<model.upperListBuildingCards.size())
{ {
BuildTableUpper.addRow(i+"-"+model.board.upperListBuilding.get(i).toString()); BuildTableUpper.addRow(i+"-"+model.upperListBuildingCards.get(i).toString());
} }
if(i<model.board.lowerListBuilding.size()) if(i<model.lowerListBuildingCards.size())
{ {
BuildTableLower.addRow(i+"-"+model.board.lowerListBuilding.get(i).toString()); BuildTableLower.addRow(i+"-"+model.lowerListBuildingCards.get(i).toString());
} }
} }
stringUpperListTribe.forEach(x->TribeTableUpper.addRow(x)); stringUpperListTribe.forEach(x->TribeTableUpper.addRow(x));