Bind: TUI->Launcher
This commit is contained in:
@@ -3,12 +3,15 @@ import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Client.RMIClient;
|
||||
import it.polimi.ingsw.gc14.Network.TCP.Client.TCPClient;
|
||||
import it.polimi.ingsw.gc14.View.IView;
|
||||
import it.polimi.ingsw.gc14.View.TUI.TUI;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ClientLauncherTUI {
|
||||
private IView view;
|
||||
public void main() throws InterruptedException {
|
||||
ClientController controller = new ClientController();
|
||||
view=new TUI(null);
|
||||
ClientController controller = new ClientController(view);
|
||||
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
|
||||
@@ -29,11 +32,12 @@ public class ClientLauncherTUI {
|
||||
System.out.println("Succesfully connected to RMI server\n\n");
|
||||
} else {
|
||||
System.out.println("RMI connection refused\n\n");
|
||||
return;
|
||||
}
|
||||
|
||||
while(true) {
|
||||
System.out.flush();
|
||||
if (controller.localModel!=null) {
|
||||
if (controller.localController.getModel()!=null) {
|
||||
break;
|
||||
}
|
||||
Thread.sleep(500);
|
||||
@@ -43,7 +47,7 @@ public class ClientLauncherTUI {
|
||||
|
||||
System.out.print("\033[H\033[2J");
|
||||
System.out.flush();
|
||||
System.out.println(controller.localModel);
|
||||
System.out.println(controller.localController.getModel());
|
||||
|
||||
|
||||
} else if (networkType == 1) {
|
||||
@@ -56,7 +60,7 @@ public class ClientLauncherTUI {
|
||||
|
||||
while(true) {
|
||||
System.out.flush();
|
||||
if (controller.localModel!=null) {
|
||||
if (controller.localController.getModel()!=null) {
|
||||
break;
|
||||
}
|
||||
Thread.sleep(500);
|
||||
@@ -66,7 +70,7 @@ public class ClientLauncherTUI {
|
||||
|
||||
System.out.print("\033[H\033[2J");
|
||||
System.out.flush();
|
||||
System.out.println(controller.localModel);
|
||||
System.out.println(controller.localController.getModel());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,28 +6,19 @@ import it.polimi.ingsw.gc14.View.IView;
|
||||
|
||||
public class ClientController {
|
||||
|
||||
public Game localModel;
|
||||
public GameController localController;
|
||||
public IView view=null;
|
||||
|
||||
public ClientController(IView view,Game localModel) {
|
||||
public ClientController(IView view) {
|
||||
this.view = view;
|
||||
this.localModel = localModel;
|
||||
this.localController = new GameController(localModel);
|
||||
}
|
||||
|
||||
public ClientController() {
|
||||
this.localController = new GameController();
|
||||
}
|
||||
|
||||
public void setModel(Game model) {
|
||||
this.localModel = model;
|
||||
localController.setModel(model);
|
||||
// localModel.addObserver((Observer) view); // registra la view come observer
|
||||
view.update(localController.getModel());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void onError(String message) {
|
||||
view.showError(message);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
|
||||
@Override
|
||||
public void onGameInit(Game model) throws RemoteException {
|
||||
clientController.setModel(model);
|
||||
clientController.view.render();
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +56,7 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
|
||||
System.out.println(event.toString());
|
||||
} else {
|
||||
event.apply(clientController.localController);
|
||||
//clientController.view.update(); TODO
|
||||
clientController.view.render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
|
||||
public interface IView {
|
||||
|
||||
public void render(Game model);
|
||||
public void update(Game game);
|
||||
public void render();
|
||||
public void showMessage(String message);
|
||||
public void showError(String message);
|
||||
|
||||
|
||||
@@ -1,18 +1,31 @@
|
||||
package it.polimi.ingsw.gc14.View.TUI;
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Network.Observer;
|
||||
import it.polimi.ingsw.gc14.View.IView;
|
||||
|
||||
public class TUI implements IView {
|
||||
public class TUI implements IView, Observer {
|
||||
|
||||
// ── dati di stato ───────────────────────────────────────────
|
||||
private BorderStyle style = BorderStyle.UNICODE;
|
||||
private Game model;
|
||||
private String username;
|
||||
public TUI(Game model) {
|
||||
this.model = model;
|
||||
this.username="";
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Game model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
// ── punto di ingresso ───────────────────────────────────────
|
||||
public void render(Game model)
|
||||
public void render()
|
||||
{
|
||||
this.model=model;
|
||||
try{
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
ProcessBuilder pb;
|
||||
@@ -28,7 +41,7 @@ public class TUI implements IView {
|
||||
System.out.println(model.toString());
|
||||
}
|
||||
|
||||
public void renderBoard(Game model)
|
||||
public void renderBoard()
|
||||
{
|
||||
try{
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
@@ -44,7 +57,7 @@ public class TUI implements IView {
|
||||
}
|
||||
System.out.println(model.BoardStamp());
|
||||
}
|
||||
public void renderPlayer(Game model)
|
||||
public void renderPlayer()
|
||||
{
|
||||
try{
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
@@ -60,7 +73,7 @@ public class TUI implements IView {
|
||||
}
|
||||
System.out.println(model.BoardStamp());
|
||||
}
|
||||
public void renderMyHand(Game model,String username)
|
||||
public void renderMyHand()
|
||||
{
|
||||
try{
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
@@ -76,6 +89,7 @@ public class TUI implements IView {
|
||||
}
|
||||
System.out.println(model.getPlayerByUsername(username));
|
||||
}
|
||||
|
||||
|
||||
public void showMessage(String message)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user