TUI colors and clear added
This commit is contained in:
@@ -153,6 +153,15 @@ public class ClientLauncherTUI {
|
|||||||
.completer(new StringsCompleter("localhost"))
|
.completer(new StringsCompleter("localhost"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
view.setLineReader(loginReader);
|
||||||
|
try {
|
||||||
|
return doLoginInner(controller, loginReader, ipReader);
|
||||||
|
} finally {
|
||||||
|
view.setLineReader(gameReader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean doLoginInner(ClientController controller, LineReader loginReader, LineReader ipReader) {
|
||||||
String username, networkStr, ip;
|
String username, networkStr, ip;
|
||||||
int nPlayers;
|
int nPlayers;
|
||||||
|
|
||||||
@@ -166,7 +175,7 @@ public class ClientLauncherTUI {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
return false;
|
return false;
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
System.out.println("Invalid number of players.");
|
loginReader.printAbove("\033[31mInvalid number of players.\033[0m");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,16 +189,14 @@ public class ClientLauncherTUI {
|
|||||||
try {
|
try {
|
||||||
myIP = InterfaceResolver.resolveLocalInterface(ip);
|
myIP = InterfaceResolver.resolveLocalInterface(ip);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Cannot resolve local interface: " + e.getMessage());
|
loginReader.printAbove("\033[31mCannot resolve local interface: " + e.getMessage() + "\033[0m");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
System.setProperty("java.rmi.server.hostname", myIP);
|
System.setProperty("java.rmi.server.hostname", myIP);
|
||||||
client = new RMIClient(controller, ip, NetworkConfig.RMI_PORT, myIP);
|
client = new RMIClient(controller, ip, NetworkConfig.RMI_PORT, myIP);
|
||||||
ErrorType err = client.connect(username, nPlayers);
|
ErrorType err = client.connect(username, nPlayers);
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
terminal.writer().print("\033[H\033[2J");
|
loginReader.printAbove("\033[31mErrore: " + err + "\033[0m");
|
||||||
terminal.writer().flush();
|
|
||||||
System.out.println("Errore: " + err);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
System.out.println("Connected via RMI, waiting for other players...");
|
System.out.println("Connected via RMI, waiting for other players...");
|
||||||
@@ -199,16 +206,14 @@ public class ClientLauncherTUI {
|
|||||||
client = new TCPClient(controller, ip, NetworkConfig.TCP_PORT, NetworkConfig.HEARTBEAT_PORT);
|
client = new TCPClient(controller, ip, NetworkConfig.TCP_PORT, NetworkConfig.HEARTBEAT_PORT);
|
||||||
ErrorType err = client.connect(username, nPlayers);
|
ErrorType err = client.connect(username, nPlayers);
|
||||||
if (err != null) {
|
if (err != null) {
|
||||||
terminal.writer().print("\033[H\033[2J");
|
loginReader.printAbove("\033[31mErrore: " + err + "\033[0m");
|
||||||
terminal.writer().flush();
|
|
||||||
System.out.println("Errore: " + err);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
System.out.println("Connected via TCP, waiting for other players...");
|
System.out.println("Connected via TCP, waiting for other players...");
|
||||||
controller.setClient(client);
|
controller.setClient(client);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Unknown network type '" + networkStr + "'. Use rmi or tcp.");
|
loginReader.printAbove("\033[31mUnknown network type '" + networkStr + "'. Use rmi or tcp.\033[0m");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -232,7 +237,6 @@ public class ClientLauncherTUI {
|
|||||||
node("totem"),
|
node("totem"),
|
||||||
node("skip"),
|
node("skip"),
|
||||||
node("clear"),
|
node("clear"),
|
||||||
node("help"),
|
|
||||||
node("details", node("buildings"), node("events"), node("characters")),
|
node("details", node("buildings"), node("events"), node("characters")),
|
||||||
node("rematch"),
|
node("rematch"),
|
||||||
node("quit")
|
node("quit")
|
||||||
@@ -269,7 +273,6 @@ public class ClientLauncherTUI {
|
|||||||
}
|
}
|
||||||
case "skip" -> controller.skipTurn();
|
case "skip" -> controller.skipTurn();
|
||||||
case "clear" -> handleRender();
|
case "clear" -> handleRender();
|
||||||
case "help" -> gameReader.printAbove("Commands: slot, draw, totem, skip, clear, help, details, rematch, quit");
|
|
||||||
case "details" -> {
|
case "details" -> {
|
||||||
if (parts.length > 1 && parts[1].equalsIgnoreCase("buildings"))
|
if (parts.length > 1 && parts[1].equalsIgnoreCase("buildings"))
|
||||||
gameReader.printAbove(BUILDING_DETAILS);
|
gameReader.printAbove(BUILDING_DETAILS);
|
||||||
|
|||||||
@@ -90,18 +90,20 @@ public class TUI implements IView {
|
|||||||
GameStages stage = model.currentState.getGameStage();
|
GameStages stage = model.currentState.getGameStage();
|
||||||
if (stage == GameStages.TOTEM_CHOICE) {
|
if (stage == GameStages.TOTEM_CHOICE) {
|
||||||
display(buildTotemsContent());
|
display(buildTotemsContent());
|
||||||
printLine("Type: totem <pos>");
|
printLine("\033[2mCommands: totem <pos>\033[0m");
|
||||||
} else if (stage == GameStages.ENDED) {
|
} else if (stage == GameStages.ENDED) {
|
||||||
display(buildStandingContent());
|
display(buildStandingContent());
|
||||||
printLine("Type 'rematch' to play again or 'quit' to exit");
|
printLine("Type 'rematch' to play again or 'quit' to exit");
|
||||||
} else {
|
} else {
|
||||||
display(buildBoardContent());
|
display(buildBoardContent());
|
||||||
|
printLine("\033[2mCommands: slot <pos> | draw upper|lower tribe|building <pos> | totem <pos> | skip | clear | details buildings|events|characters | rematch | quit\033[0m");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Renders the board + menu (top) and all players' hands in a grid (bottom). */
|
/** Renders the board + menu (top) and all players' hands in a grid (bottom). */
|
||||||
public void renderBoard() {
|
public void renderBoard() {
|
||||||
display(buildBoardContent());
|
display(buildBoardContent());
|
||||||
|
printLine("Commands: slot <pos> | draw upper|lower tribe|building <pos> | totem <pos> | skip | clear | details buildings|events|characters | rematch | quit");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,7 +126,8 @@ public class TUI implements IView {
|
|||||||
text += "\nPress any key to continue";
|
text += "\nPress any key to continue";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printLine(text);
|
render();
|
||||||
|
printLine("\033[31m" + text + "\033[0m");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Content builders (return strings, do not print) ───────────────────────
|
// ── Content builders (return strings, do not print) ───────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user