Removed: Board in ApplyNextRound, MiniModel constructor
Added: upperListTribe,lowerListTribe,upperListBuilding,lowerListBuilding in MiniModel constructor
This commit is contained in:
@@ -59,12 +59,7 @@ public class ClientController {
|
||||
* @param model the model to set
|
||||
*/
|
||||
public void setModel(MiniModel model) {
|
||||
this.miniModel.currentState=model.currentState;
|
||||
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;
|
||||
this.miniModel = model;
|
||||
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.
|
||||
*/
|
||||
public List<TribeCard>getUpperListTribeCards() {
|
||||
List<TribeCard> cards = new ArrayList<>();
|
||||
public ArrayList<TribeCard>getUpperListTribeCards() {
|
||||
ArrayList<TribeCard> cards = new ArrayList<>();
|
||||
board.upperListTribe.forEach(x->cards.add(x.clone()));
|
||||
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.
|
||||
*/
|
||||
public List<TribeCard>getLowerListTribeCards() {
|
||||
List<TribeCard> cards = new ArrayList<>();
|
||||
public ArrayList<TribeCard>getLowerListTribeCards() {
|
||||
ArrayList<TribeCard> cards = new ArrayList<>();
|
||||
board.lowerListTribe.forEach(x->cards.add(x.clone()));
|
||||
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.
|
||||
*/
|
||||
public List<BuildingCard>getUpperListBuilding() {
|
||||
List<BuildingCard> cards = new ArrayList<>();
|
||||
public ArrayList<BuildingCard>getUpperListBuilding() {
|
||||
ArrayList<BuildingCard> cards = new ArrayList<>();
|
||||
board.upperListBuilding.forEach(x->cards.add(x.clone()));
|
||||
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.
|
||||
*/
|
||||
public List<BuildingCard>getLowerListBuilding() {
|
||||
List<BuildingCard> cards = new ArrayList<>();
|
||||
public ArrayList<BuildingCard>getLowerListBuilding() {
|
||||
ArrayList<BuildingCard> cards = new ArrayList<>();
|
||||
board.lowerListBuilding.forEach(x->cards.add(x.clone()));
|
||||
return cards;
|
||||
}
|
||||
|
||||
@@ -69,26 +69,29 @@ public class MiniModel implements Serializable {
|
||||
/**
|
||||
* 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 orderLogicCard the card managing player turn order.
|
||||
* @param currentState the current state of the game.
|
||||
* @param players the list of players in the match.
|
||||
* @param availableTotems the list of totems still available for selection.
|
||||
*/
|
||||
public MiniModel(Board board,
|
||||
Map<Slot, Player> slotPlayerMap,
|
||||
public MiniModel(Map<Slot, Player> slotPlayerMap,
|
||||
OrderLogicCard orderLogicCard,
|
||||
CurrentState currentState,
|
||||
List<Player> players,
|
||||
List<Totems> availableTotems) {
|
||||
this.board = board;
|
||||
List<Totems> availableTotems,ArrayList<TribeCard> upperListTribeCards,ArrayList<TribeCard>lowerListTribeCards,ArrayList<BuildingCard> upperListBuildingCards,ArrayList<BuildingCard>lowerListBuildingCards) {
|
||||
|
||||
this.slotPlayerMap = slotPlayerMap;
|
||||
this.orderLogicCard = orderLogicCard;
|
||||
this.currentState = currentState;
|
||||
this.players = new HashMap<>();
|
||||
this.availableTotems = availableTotems;
|
||||
this.standingPlayers = new ArrayList<>();
|
||||
this.upperListTribeCards = upperListTribeCards;
|
||||
this.lowerListTribeCards = lowerListTribeCards;
|
||||
this.upperListBuildingCards = upperListBuildingCards;
|
||||
this.lowerListBuildingCards = lowerListBuildingCards;
|
||||
setPlayers(players);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package it.polimi.ingsw.gc14.Network.NetworkEvents;
|
||||
|
||||
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.MiniModel;
|
||||
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 java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -20,6 +23,11 @@ import java.util.Map;
|
||||
public class ApplyNextRound extends NetworkEvent implements Serializable{
|
||||
|
||||
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.
|
||||
@@ -29,8 +37,12 @@ public class ApplyNextRound extends NetworkEvent implements Serializable{
|
||||
* @param currentState the current state of 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);
|
||||
this.upperListBuildingCards = upperListBuildingCards;
|
||||
this.lowerListBuildingCards = lowerListBuildingCards;
|
||||
this.upperListTribeCards = upperListTribeCards;
|
||||
this.lowerListTribeCards = lowerListTribeCards;
|
||||
this.slotPlayerMap = slotPlayerMap;
|
||||
this.orderLogicCard = orderLogicCard;
|
||||
this.currentState = currentState;
|
||||
@@ -51,7 +63,10 @@ public class ApplyNextRound extends NetworkEvent implements Serializable{
|
||||
miniModel.setOrderLogicCard(orderLogicCard);
|
||||
miniModel.setCurrentState(currentState);
|
||||
miniModel.setPlayers(players);
|
||||
miniModel.board.nextRound();
|
||||
miniModel.upperListTribeCards=upperListTribeCards;
|
||||
miniModel.lowerListTribeCards=lowerListTribeCards;
|
||||
miniModel.upperListBuildingCards=upperListBuildingCards;
|
||||
miniModel.lowerListBuildingCards=lowerListBuildingCards;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,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(),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);
|
||||
actionQueue.add(new ReconnectPlayer(username));
|
||||
return true;
|
||||
@@ -137,7 +137,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(),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);
|
||||
actionQueue.add(new ReconnectPlayer(username));
|
||||
return true;
|
||||
|
||||
@@ -228,12 +228,12 @@ public class TCPServer {
|
||||
|
||||
Game game = controller.getModel();
|
||||
handler.notifyMiniModel(new MiniModel(
|
||||
game.getBoard(),
|
||||
game.getSlotMap(),
|
||||
game.orderLogicCard,
|
||||
game.getCurrentState(),
|
||||
game.getPlayers(),
|
||||
game.getAvailableTotems()
|
||||
game.getAvailableTotems(),
|
||||
game.getUpperListTribeCards(),game.getLowerListTribeCards(),game.getUpperListBuilding(),game.getLowerListBuilding()
|
||||
));
|
||||
|
||||
Thread thread = new Thread(handler);
|
||||
@@ -300,12 +300,13 @@ public class TCPServer {
|
||||
|
||||
Game game = controller.getModel();
|
||||
handler.notifyMiniModel(new MiniModel(
|
||||
game.getBoard(),
|
||||
game.getSlotMap(),
|
||||
game.orderLogicCard,
|
||||
game.getCurrentState(),
|
||||
game.getPlayers(),
|
||||
game.getAvailableTotems()
|
||||
game.getAvailableTotems(),
|
||||
game.getUpperListTribeCards(),game.getLowerListTribeCards(),game.getUpperListBuilding(),game.getLowerListBuilding()
|
||||
|
||||
));
|
||||
|
||||
Thread thread = new Thread(handler);
|
||||
|
||||
@@ -150,7 +150,7 @@ public class ServerLauncher {
|
||||
serverTCP.notifyAll(event);
|
||||
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);
|
||||
serverTCP.notifyAll(nextRound);
|
||||
}
|
||||
@@ -247,7 +247,7 @@ public class ServerLauncher {
|
||||
MiniModel miniModel;
|
||||
synchronized (gameController) {
|
||||
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);
|
||||
serverTCP.notifyAll(miniModel);
|
||||
|
||||
@@ -67,7 +67,7 @@ public class LeaderboardFXMLController {
|
||||
|
||||
public void render() {
|
||||
rankingList.getChildren().clear();
|
||||
if(controller.miniModel.standingPlayers!=null)
|
||||
if(!controller.miniModel.standingPlayers.isEmpty())
|
||||
{
|
||||
List<Player> sorted = controller.miniModel.standingPlayers;
|
||||
|
||||
|
||||
@@ -272,7 +272,7 @@ public class MainFXMLController {
|
||||
upperList.getChildren().clear();
|
||||
|
||||
int i = 0;
|
||||
for (TribeCard card : controller.miniModel.board.upperListTribe) {
|
||||
for (TribeCard card : controller.miniModel.upperListTribeCards) {
|
||||
final int index = i;
|
||||
StackPane img = createCard(card, true, true, upperList);
|
||||
img.setOnMouseClicked(e -> controller.drawUpperTribeCard(controller.myUsername, index));
|
||||
@@ -288,7 +288,7 @@ public class MainFXMLController {
|
||||
lowerList.getChildren().clear();
|
||||
|
||||
int i = 0;
|
||||
for (TribeCard card : controller.miniModel.board.lowerListTribe) {
|
||||
for (TribeCard card : controller.miniModel.lowerListTribeCards) {
|
||||
final int index = i;
|
||||
StackPane img = createCard(card, true, true, lowerList);
|
||||
img.setOnMouseClicked(e -> controller.drawLowerTribeCard(controller.myUsername, index));
|
||||
@@ -299,7 +299,7 @@ public class MainFXMLController {
|
||||
}
|
||||
|
||||
private void drawUpperBuilding() {
|
||||
ArrayList<BuildingCard> cardList = new ArrayList<>(controller.miniModel.board.upperListBuilding);
|
||||
ArrayList<BuildingCard> cardList = new ArrayList<>(controller.miniModel.upperListBuildingCards);
|
||||
if (!cardList.isEmpty()) {
|
||||
StackPane img = createCard(cardList.getLast(), true, true, upperList);
|
||||
Label label = new Label(String.valueOf(cardList.size()));
|
||||
@@ -314,7 +314,7 @@ public class MainFXMLController {
|
||||
}
|
||||
|
||||
private void drawLowerBuilding() {
|
||||
ArrayList<BuildingCard> cardList = new ArrayList<>(controller.miniModel.board.lowerListBuilding);
|
||||
ArrayList<BuildingCard> cardList = new ArrayList<>(controller.miniModel.lowerListBuildingCards);
|
||||
if (!cardList.isEmpty()) {
|
||||
StackPane img = createCard(cardList.getLast(), true, true, lowerList);
|
||||
Label label = new Label(String.valueOf(cardList.size()));
|
||||
|
||||
@@ -333,15 +333,15 @@ public class TUI implements IView {
|
||||
List<String> stringLowerListTribe=new ArrayList<>();
|
||||
stringUpperListTribe.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);
|
||||
@@ -349,15 +349,15 @@ public class TUI implements IView {
|
||||
var BuildTableLower = new AsciiTable(BorderStyle.UNICODE,1);
|
||||
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));
|
||||
|
||||
Reference in New Issue
Block a user