Fix: Replaced Model With MiniModel in the client implementation and in the view
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
package it.polimi.ingsw.gc14.View.TUI;
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Model.Player;
|
||||
import it.polimi.ingsw.gc14.Model.Slot;
|
||||
import it.polimi.ingsw.gc14.View.IView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Text-based User Interface (TUI) implementation of {@link IView}.
|
||||
@@ -30,9 +36,9 @@ import java.util.List;
|
||||
public class TUI implements IView {
|
||||
|
||||
/**
|
||||
* The {@link Game} model whose state is rendered.
|
||||
* The {@link MiniModel} model whose state is rendered.
|
||||
*/
|
||||
private Game model;
|
||||
private MiniModel model;
|
||||
|
||||
/**
|
||||
* The username of the local player, used to retrieve and display
|
||||
@@ -50,7 +56,7 @@ public class TUI implements IView {
|
||||
*
|
||||
* @param model the {@link Game} model to display; must not be {@code null}
|
||||
*/
|
||||
public TUI(Game model) {
|
||||
public TUI(MiniModel model) {
|
||||
this.model = model;
|
||||
this.username = "";
|
||||
}
|
||||
@@ -76,7 +82,7 @@ public class TUI implements IView {
|
||||
* @param model the new {@link Game} model; must not be {@code null}
|
||||
*/
|
||||
@Override
|
||||
public void setModel(Game model) {
|
||||
public void setModel(MiniModel model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@@ -96,9 +102,9 @@ public class TUI implements IView {
|
||||
* <p>Layout:
|
||||
* <ul>
|
||||
* <li><b>Top</b> — player status table produced by
|
||||
* {@link Game#PlayersStamp()}.</li>
|
||||
* {@link #PlayersStamp()}.</li>
|
||||
* <li><b>Bottom-left</b> — board status produced by
|
||||
* {@link Game#BoardStamp()}.</li>
|
||||
* {@link #BoardStamp()}.</li>
|
||||
* <li><b>Bottom-right</b> — menu options legend and the local
|
||||
* player's hand.</li>
|
||||
* </ul>
|
||||
@@ -107,10 +113,10 @@ public class TUI implements IView {
|
||||
*/
|
||||
public void fullRender() {
|
||||
clearTerminal();
|
||||
List<String> lines = List.of(model.BoardStamp().split("\n"));
|
||||
List<String> lines = List.of(BoardStamp().split("\n"));
|
||||
List<String> lines2 = List.of((printMenuOptions() + "\n" +
|
||||
model.getPlayerByUsername(username)).split("\n"));
|
||||
System.out.println(model.PlayersStamp() + "\n" +
|
||||
model.players.get(username)).split("\n"));
|
||||
System.out.println(PlayersStamp() + "\n" +
|
||||
AsciiTable.sideBySide(lines, lines2, 3));
|
||||
}
|
||||
|
||||
@@ -120,7 +126,7 @@ public class TUI implements IView {
|
||||
* <p>Layout:
|
||||
* <ul>
|
||||
* <li><b>Left panel</b> — turn order, upper card row, offer track,
|
||||
* and lower card row, as produced by {@link Game#BoardStamp()}.</li>
|
||||
* and lower card row, as produced by {@link #BoardStamp()}.</li>
|
||||
* <li><b>Right panel</b> — menu options legend followed by the local
|
||||
* player's hand.</li>
|
||||
* </ul>
|
||||
@@ -129,9 +135,9 @@ public class TUI implements IView {
|
||||
*/
|
||||
public void renderBoard() {
|
||||
clearTerminal();
|
||||
List<String> lines = List.of(model.BoardStamp().split("\n"));
|
||||
List<String> lines = List.of(BoardStamp().split("\n"));
|
||||
List<String> lines2 = List.of((printMenuOptions() + "\nYOUR HAND\n" +
|
||||
model.getPlayerByUsername(username)).split("\n"));
|
||||
model.players.get(username)).split("\n"));
|
||||
System.out.println(AsciiTable.sideBySide(lines, lines2, 3));
|
||||
}
|
||||
|
||||
@@ -141,7 +147,7 @@ public class TUI implements IView {
|
||||
* <p>Layout:
|
||||
* <ul>
|
||||
* <li><b>Left panel</b> — prestige, food, character deck, and building
|
||||
* deck for all players, as produced by {@link Game#PlayersStamp()}.</li>
|
||||
* deck for all players, as produced by {@link #PlayersStamp()}.</li>
|
||||
* <li><b>Right panel</b> — menu options legend.</li>
|
||||
* </ul>
|
||||
*
|
||||
@@ -149,7 +155,7 @@ public class TUI implements IView {
|
||||
*/
|
||||
public void renderPlayer() {
|
||||
clearTerminal();
|
||||
List<String> lines = List.of(model.PlayersStamp().split("\n"));
|
||||
List<String> lines = List.of(PlayersStamp().split("\n"));
|
||||
List<String> lines2 = List.of(printMenuOptions().split("\n"));
|
||||
System.out.println(AsciiTable.sideBySide(lines, lines2, 3));
|
||||
}
|
||||
@@ -212,4 +218,92 @@ public class TUI implements IView {
|
||||
pb.inheritIO().start().waitFor();
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
ArrayList<Player> playersList=new ArrayList<>(model.players.values());
|
||||
for(int i = 0; i< model.players.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, model.slotPlayerMap.size());
|
||||
List<String> stringUpOffer=new ArrayList<>();
|
||||
List<String> stringDownOffer=new ArrayList<>();
|
||||
|
||||
int index=0;
|
||||
for(Map.Entry<Slot, Player> entry:model.slotPlayerMap.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(model.board.upperListTribe.size(),model.board.lowerListTribe.size());i++)
|
||||
{
|
||||
if(i<model.board.upperListTribe.size())
|
||||
{
|
||||
stringUpperListTribe.add(i+"-"+model.board.upperListTribe.get(i).toStringBoard());
|
||||
}
|
||||
if(i<model.board.lowerListTribe.size())
|
||||
{
|
||||
stringLowerListTribe.add(i+"-"+model.board.lowerListTribe.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(model.board.upperListBuilding.size(),model.board.lowerListBuilding.size());i++)
|
||||
{
|
||||
if(i<model.board.upperListBuilding.size())
|
||||
{
|
||||
BuildTableUpper.addRow(i+"-"+model.board.upperListBuilding.get(i).toString());
|
||||
}
|
||||
if(i<model.board.lowerListBuilding.size())
|
||||
{
|
||||
BuildTableLower.addRow(i+"-"+model.board.lowerListBuilding.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"+model.currentState+"\n"+model.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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user