Fix: Tui adapted to new input case

This commit is contained in:
rubenpirreram
2026-05-01 17:40:36 +02:00
parent 50a3012cf1
commit 44388ee1e4
9 changed files with 56 additions and 58 deletions
@@ -9,13 +9,15 @@ import java.util.Scanner;
public class ClientLauncherTUI {
//TODO Javadoc
TUI view;
public void main() throws InterruptedException {
TUI view=new TUI(null);
view=new TUI(null);
ClientController controller = new ClientController(view);
Scanner scanner = new Scanner(System.in);
System.out.println("Selezionare nome utente: ");
String username = scanner.next();
view.setUsername(username);
System.out.println("Selezionare numero di giocatori desiderato: ");
int proposedNumPlayers = scanner.nextInt();
System.out.println("Selezionare RMI[0] o TCP[1]: ");
@@ -70,9 +72,10 @@ public class ClientLauncherTUI {
private void getInput(Scanner scanner, ClientController controller, String username) {
String action = scanner.next();
int pos=-1;
if(!action.equals("8")) {
if(!action.equals("8")&&!action.equals("A")&&!action.equals("B")&&!action.equals("C")&&!action.equals("D")) {
try
{
System.out.println("Insert the required position:");
pos = scanner.nextInt();
}
catch(Exception e)
@@ -89,6 +92,9 @@ public class ClientLauncherTUI {
case "6" -> controller.pickOptionalTribeCard(username, pos);
case "7" -> controller.pickOptionalBuildingCard(username, pos);
case "8" -> controller.noOptionalCard(username);
case "A" -> view.fullRender();
case "B" -> view.renderBoard();
case "C" -> view.renderPlayer();
}
return;
@@ -62,7 +62,7 @@ public abstract class EventCard extends TribeCard {
*/
@Override
public String toString() {
return super.toString()+" "+type.toString();
return super.toString()+"(Event)"+type.toString();
}
/**
@@ -77,7 +77,7 @@ public abstract class EventCard extends TribeCard {
*/
@Override
public String toStringBoard() {
return super.toString()+" "+type.toString();
return super.toString()+"(Event)"+type.toString();
}
/**
@@ -793,9 +793,10 @@ public class Game implements Serializable {
List<String> stringUpOffer=new ArrayList<>();
List<String> stringDownOffer=new ArrayList<>();
int index=0;
for(Map.Entry<Slot,Player> entry:slotMap.entrySet())
{
stringDownOffer.add(entry.getKey().toStringTUI());
stringDownOffer.add((index++)+"."+entry.getKey().toStringTUI());
if(entry.getValue()!=null)
stringUpOffer.add(entry.getValue().getUserName());
else
@@ -813,11 +814,11 @@ public class Game implements Serializable {
{
if(i<getUpperListTribeCards().size())
{
stringUpperListTribe.add(getUpperListTribeCards().get(i).toStringBoard());
stringUpperListTribe.add(i+"-"+getUpperListTribeCards().get(i).toStringBoard());
}
if(i<getLowerListTribeCards().size())
{
stringLowerListTribe.add(getLowerListTribeCards().get(i).toStringBoard());
stringLowerListTribe.add(i+"-"+getLowerListTribeCards().get(i).toStringBoard());
}
}
var BuildTableUpper = new AsciiTable(BorderStyle.UNICODE,1);
@@ -829,11 +830,11 @@ public class Game implements Serializable {
{
if(i<getUpperListBuilding().size())
{
BuildTableUpper.addRow(getUpperListBuilding().get(i).toString());
BuildTableUpper.addRow(i+"-"+getUpperListBuilding().get(i).toString());
}
if(i<getLowerListBuilding().size())
{
BuildTableLower.addRow(getLowerListBuilding().get(i).toString());
BuildTableLower.addRow(i+"-"+getLowerListBuilding().get(i).toString());
}
}
stringUpperListTribe.forEach(x->TribeTableUpper.addRow(x));
@@ -58,24 +58,19 @@ public class Order2 extends OrderLogicCard {
var table = new AsciiTable(BorderStyle.UNICODE, 2);
List<String> stringUp=new ArrayList<>();
List<String> stringDown=new ArrayList<>();
for(int i=0;i<2;i++)
{
try {
playerList.get(i);
stringUp.add(i+". "+playerList.get(i).player.getUserName());
if(playerList.get(i).played)
stringDown.add(" Placed");
stringUp.add(" ");
else
stringDown.add(" Not Placed");
stringUp.add(i+". "+playerList.get(i).player.getUserName());
}
catch (IndexOutOfBoundsException e) {
stringUp.add("");
stringDown.add("");
}
}
table.addRow(stringUp);
table.addRow(stringDown);
List<String> stringList=new ArrayList<>();
stringList.add("+1 Food");
@@ -60,24 +60,19 @@ public class Order3 extends OrderLogicCard {
var table = new AsciiTable(BorderStyle.UNICODE, 3);
List<String> stringUp=new ArrayList<>();
List<String> stringDown=new ArrayList<>();
for(int i=0;i<3;i++)
{
try {
playerList.get(i);
stringUp.add(i+". "+playerList.get(i).player.getUserName());
if(playerList.get(i).played)
stringDown.add(" Placed");
stringUp.add(" ");
else
stringDown.add(" Not Placed");
stringUp.add(i+". "+playerList.get(i).player.getUserName());
}
catch (IndexOutOfBoundsException e) {
stringUp.add("");
stringDown.add("");
}
}
table.addRow(stringUp);
table.addRow(stringDown);
List<String> stringList=new ArrayList<>();
@@ -66,24 +66,19 @@ public class Order4 extends OrderLogicCard {
var table = new AsciiTable(BorderStyle.UNICODE, 4);
List<String> stringUp=new ArrayList<>();
List<String> stringDown=new ArrayList<>();
for(int i=0;i<4;i++)
{
try {
playerList.get(i);
stringUp.add(i+". "+playerList.get(i).player.getUserName());
if(playerList.get(i).played)
stringDown.add(" Placed");
stringUp.add(" ");
else
stringDown.add(" Not Placed");
stringUp.add(i+". "+playerList.get(i).player.getUserName());
}
catch (IndexOutOfBoundsException e) {
stringUp.add("");
stringDown.add("");
}
}
table.addRow(stringUp);
table.addRow(stringDown);
List<String> stringList=new ArrayList<>();
stringList.add("+2 Food");
@@ -67,24 +67,19 @@ public class Order5 extends OrderLogicCard {
var table = new AsciiTable(BorderStyle.UNICODE, 5);
List<String> stringUp=new ArrayList<>();
List<String> stringDown=new ArrayList<>();
for(int i=0;i<5;i++)
{
try {
playerList.get(i);
stringUp.add(i+". "+playerList.get(i).player.getUserName());
if(playerList.get(i).played)
stringDown.add(" Placed");
stringUp.add(" ");
else
stringDown.add(" Not Placed");
stringUp.add(i+". "+playerList.get(i).player.getUserName());
}
catch (IndexOutOfBoundsException e) {
stringUp.add("");
stringDown.add("");
}
}
table.addRow(stringUp);
table.addRow(stringDown);
List<String> stringList=new ArrayList<>();
stringList.add("+3 Food");
@@ -172,7 +172,7 @@ public class Slot implements Serializable {
public String toStringTUI()
{
StringBuilder s = new StringBuilder();
s.append(this.getSlotId()+" ");
//s.append(this.getSlotId()+" ");
for(int i=0;i<this.getNUpper();i++)
{
s.append("");
@@ -2,6 +2,8 @@ package it.polimi.ingsw.gc14.View.TUI;
import it.polimi.ingsw.gc14.Model.Game;
import it.polimi.ingsw.gc14.View.IView;
import java.util.List;
public class TUI implements IView {
// ── dati di stato ───────────────────────────────────────────
@@ -23,6 +25,10 @@ public class TUI implements IView {
// ── punto di ingresso ───────────────────────────────────────
public void render()
{
renderBoard();
}
public void fullRender()
{
try{
String os = System.getProperty("os.name").toLowerCase();
@@ -36,7 +42,10 @@ public class TUI implements IView {
}
catch(Exception e){
}
System.out.println(model.toString());
List<String>lines=List.of(model.BoardStamp().split("\n"));
List<String> lines2=List.of((PrintMenuOptions()+"\n"+model.getPlayerByUsername(username)).split("\n"));
System.out.println(model.PlayersStamp()+"\n"+ AsciiTable.sideBySide(lines,lines2,3));
}
public void renderBoard()
@@ -53,7 +62,9 @@ public class TUI implements IView {
}
catch(Exception e){
}
System.out.println(model.BoardStamp());
List<String>lines=List.of(model.BoardStamp().split("\n"));
List<String> lines2=List.of((PrintMenuOptions()+"\nYOUR HAND\n"+model.getPlayerByUsername(username)).split("\n"));
System.out.println(AsciiTable.sideBySide(lines,lines2,3));
}
public void renderPlayer()
{
@@ -69,25 +80,10 @@ public class TUI implements IView {
}
catch(Exception e){
}
System.out.println(model.BoardStamp());
List<String>lines=List.of(model.PlayersStamp().split("\n"));
List<String> lines2=List.of(PrintMenuOptions().split("\n"));
System.out.println(AsciiTable.sideBySide(lines,lines2,3));
}
public void renderMyHand()
{
try{
String os = System.getProperty("os.name").toLowerCase();
ProcessBuilder pb;
if (os.contains("win")) {
pb = new ProcessBuilder("cmd", "/c", "cls");
} else {
pb = new ProcessBuilder("clear");
}
pb.inheritIO().start().waitFor();
}
catch(Exception e){
}
System.out.println(model.getPlayerByUsername(username));
}
public void showMessage(String message)
{
@@ -100,4 +96,19 @@ public class TUI implements IView {
System.out.println(message);
}
private String PrintMenuOptions()
{
var table=new AsciiTable(BorderStyle.ROUNDED,2);
table.addHeader( "Menu Options","Render Options");
table.addRow( List.of("1-SlotChoice(pos)","A-Full Render"));
table.addRow(List.of("2-DrawUpperTribe(pos)","B-Board Render"));
table.addRow(List.of("3-DrawUpperBuilding(pos)","C-Players Render"));
table.addRow(List.of("4-DrawLowerTribe(pos)",""));
table.addRow(List.of("5-DrawLowerBuilding(pos)",""));
table.addRow(List.of("6-PickOptionalTribe(pos)",""));
table.addRow(List.of("7-PickOptionalBuilding(pos)",""));
table.addRow(List.of("8-NoOptional",""));
return table.build();
}
}