Merge pull request #96 from rubenpirreram/Refactor->minimodel

Refactor->minimodel
This commit is contained in:
rubenpirreram
2026-05-13 16:08:25 +02:00
committed by GitHub
33 changed files with 596 additions and 215 deletions
@@ -41,6 +41,9 @@ public class Game implements Serializable {
return playersList;
}
//TODO
private Queue<Player> totemChoiceQueue = new LinkedList<>();
//TODO
public Map<Player,Boolean> disconnetedPlayers = new HashMap<>();
//TODO
@@ -75,6 +78,8 @@ public class Game implements Serializable {
return true;
}
//Totem
public void ClearDisconnected()
{
disconnetedPlayers.clear();
@@ -128,6 +133,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 +926,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);
}
}
@@ -0,0 +1,68 @@
package it.polimi.ingsw.gc14.Model;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
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 implements Serializable {
public Board board;
public Map<Slot,Player> slotPlayerMap;
public OrderLogicCard orderLogicCard;
public CurrentState currentState;
public Map<String,Player> players;
public List<Object>availableTotems;
public MiniModel(Board board) {
this.board = board;
}
public MiniModel(Board board, Map<Slot,Player> slotPlayerMap, OrderLogicCard orderLogicCard, CurrentState currentState, List<Player> players, List<Object>availableTotems) {
this.board = board;
this.slotPlayerMap = slotPlayerMap;
this.orderLogicCard = orderLogicCard;
this.currentState = currentState;
this.players=new HashMap<>();
setPlayers(players);
}
public void setBoard(Board board) {
this.board = board;
}
public void setAvailableTotems(List<Object>availableTotems) {
this.availableTotems = availableTotems;
}
public void setSlotPlayerMap(Map<Slot,Player> slotPlayerMap) {
this.slotPlayerMap = slotPlayerMap;
}
public void setOrderLogicCard(OrderLogicCard orderLogicCard) {
this.orderLogicCard = orderLogicCard;
}
public void setCurrentState(CurrentState currentState) {
this.currentState = currentState;
}
public void setPlayers(List<Player> players) {
for (Player player : players) {
this.players.put(player.getUserName(),player);
}
}
public void setPlayer(Player player)
{
players.put(player.getUserName(),player);
}
public int getPositionByUsername(String username)
{
int i=0;
for (Player player : players.values())
{
if(player.getUserName().equals(username))
{
return i;
}
i++;
}
return -1;
}
}