Fix: Replaced Model With MiniModel in the client implementation and in the view

This commit is contained in:
rubenpirreram
2026-05-12 23:21:06 +02:00
parent 40aa62e3d0
commit 779b72275c
16 changed files with 224 additions and 217 deletions
@@ -128,6 +128,8 @@ public class Game implements Serializable {
* The board associated with this game.
*/
private Board board;
//TODO
public Board getBoard() {return board;}
/**
* Returns clones of the upper tribe cards currently available on the board.
@@ -919,105 +921,5 @@ public class Game implements Serializable {
return true;
}
/**
* Prints a string representation of the {@code Game}. Used in the TUI implementation to draw:
* <li>{@link it.polimi.ingsw.gc14.Model.GamePackage.Board Board}
* <li>{@link it.polimi.ingsw.gc14.Model.Player Players}
* <li>{@link #getUpperListTribeCards() Upper TribeCard List} <li>{@link #getUpperListBuilding() Upper Building List}
* <li>{@link #getLowerListTribeCards() Lower TribeCard List} <li>{@link #getLowerListBuilding() Lower Building List}
* <li>{@link it.polimi.ingsw.gc14.Model.OrderLogicCard Offer Track}
*
* @return {@code String} - a string representation of the {@code Game}.
*/
@Override
public String toString() {
return PlayersStamp()+"\n"+BoardStamp()+"\n";
}
/**
* Returns a string representation of all the players currently in the game,
* arranged side by side in pairs.
* If the number of players is odd, the last player is printed on its own line.
*
* @return {@code String} - a string representation of all the players.
*/
public String PlayersStamp()
{
StringBuilder stringBuilder=new StringBuilder();
for(int i=0;i<playersList.size()/2;i++)
{
stringBuilder.append(AsciiTable.sideBySide(List.of(playersList.get((i*2)).toString().split("\n")),List.of(playersList.get((i*2+1)).toString().split("\n")),2));
}
stringBuilder.append("\n");
if(playersList.size()%2!=0)
{
stringBuilder.append(playersList.get(playersList.size()-1).toString());
stringBuilder.append("\n");
}
return stringBuilder.toString();
}
/**
* Returns a string representation of the board, including the current state,
* the offer track with slot assignments, the upper and lower tribe card lists,
* and the upper and lower building card lists.
*
* @return {@code String} - a string representation of the board.
*/
public String BoardStamp()
{
var offerTrack = new AsciiTable(BorderStyle.UNICODE, slotMap.size());
List<String> stringUpOffer=new ArrayList<>();
List<String> stringDownOffer=new ArrayList<>();
int index=0;
for(Map.Entry<Slot,Player> entry:slotMap.entrySet())
{
stringDownOffer.add((index++)+"."+entry.getKey().toStringTUI());
if(entry.getValue()!=null)
stringUpOffer.add(entry.getValue().getUserName());
else
stringUpOffer.add(" ");
}
var TribeTableUpper = new AsciiTable(BorderStyle.UNICODE,1);
var TribeTableLower = new AsciiTable(BorderStyle.UNICODE,1);
List<String> stringUpperListTribe=new ArrayList<>();
List<String> stringLowerListTribe=new ArrayList<>();
stringUpperListTribe.add("Char/Events");
stringLowerListTribe.add("Char/Events");
for(int i=0;i<Math.max(getUpperListTribeCards().size(),getLowerListTribeCards().size());i++)
{
if(i<getUpperListTribeCards().size())
{
stringUpperListTribe.add(i+"-"+getUpperListTribeCards().get(i).toStringBoard());
}
if(i<getLowerListTribeCards().size())
{
stringLowerListTribe.add(i+"-"+getLowerListTribeCards().get(i).toStringBoard());
}
}
var BuildTableUpper = new AsciiTable(BorderStyle.UNICODE,1);
BuildTableUpper.addHeader("Building ");
var BuildTableLower = new AsciiTable(BorderStyle.UNICODE,1);
BuildTableLower.addHeader("Building ");
for(int i=0;i<Math.max(getUpperListBuilding().size(),getLowerListBuilding().size());i++)
{
if(i<getUpperListBuilding().size())
{
BuildTableUpper.addRow(i+"-"+getUpperListBuilding().get(i).toString());
}
if(i<getLowerListBuilding().size())
{
BuildTableLower.addRow(i+"-"+getLowerListBuilding().get(i).toString());
}
}
stringUpperListTribe.forEach(x->TribeTableUpper.addRow(x));
stringLowerListTribe.forEach(x->TribeTableLower.addRow(x));
offerTrack.addRow(stringUpOffer);
offerTrack.addRow(stringDownOffer);
return "CURRENT STATE\n"+getCurrentState()+"\n"+orderLogicCard.toString()+"\n"+ AsciiTable.sideBySide(Arrays.stream((TribeTableUpper.build().split("\n"))).toList(), Arrays.stream(BuildTableUpper.build().split("\n")).toList(),2)+"\n"+offerTrack.build()+"\n"+AsciiTable.sideBySide(List.of(TribeTableLower.build().split("\n")), Arrays.stream(BuildTableLower.build().split("\n")).toList(),2);
}
}
@@ -6,21 +6,23 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
import it.polimi.ingsw.gc14.Model.GamePackage.Board;
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.*;
//TODO
public class MiniModel {
public class MiniModel implements Serializable {
public Board board;
public Map<Slot,Player> slotPlayerMap;
public OrderLogicCard orderLogicCard;
public CurrentState currentState;
public Map<String,Player> players;
public MiniModel(Board board, Map<Slot,Player> slotPlayerMap, OrderLogicCard orderLogicCard, CurrentState currentState, Map<String,Player> players) {
public MiniModel(Board board, Map<Slot,Player> slotPlayerMap, OrderLogicCard orderLogicCard, CurrentState currentState, List<Player> players) {
this.board = board;
this.slotPlayerMap = slotPlayerMap;
this.orderLogicCard = orderLogicCard;
this.currentState = currentState;
this.players = players;
this.players=new HashMap<>();
setPlayers(players);
}
public void setBoard(Board board) {
this.board = board;