Multiplayer capable (STABLE PRESENTATION VERSION)
This commit is contained in:
@@ -63,8 +63,8 @@ public class TicTacToe_Client {
|
||||
break;
|
||||
|
||||
case "userInput":
|
||||
client.sendToServer("test");
|
||||
client.printLog("Waiting for userInput", true, LogType.Log);
|
||||
renderEngine.setMoveAllowed(true);
|
||||
while (!renderEngine.isMouseClicked()) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
@@ -73,6 +73,7 @@ public class TicTacToe_Client {
|
||||
}
|
||||
}
|
||||
renderEngine.setMouseClicked(false);
|
||||
renderEngine.setMoveAllowed(false);
|
||||
isAllowedToMove = false;
|
||||
this.userInput();
|
||||
break;
|
||||
|
||||
@@ -89,6 +89,15 @@ public class Client {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasMessage(){
|
||||
try {
|
||||
return in.available() < 0;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getResponse() {
|
||||
try {
|
||||
String message = in.readUTF();
|
||||
|
||||
@@ -22,6 +22,7 @@ public class Engine extends Application {
|
||||
private static Engine engine = null;
|
||||
private boolean mouseClicked = false;
|
||||
private boolean windowClosed = false;
|
||||
private boolean moveAllowed = false;
|
||||
private Point coordinates = new Point();
|
||||
private Stage primaryStage;
|
||||
|
||||
@@ -37,7 +38,20 @@ public class Engine extends Application {
|
||||
grid.setVgap(75);
|
||||
}
|
||||
|
||||
private Scene setScene() {
|
||||
private Scene setStartingScene(){
|
||||
scene = new Scene(grid, 900, 900);
|
||||
grid.add(new javafx.scene.control.Label("Your Username"), 0, 0);
|
||||
grid.add(new javafx.scene.control.TextField(), 1,0);
|
||||
scene.setOnMousePressed(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent mouseEvent) {
|
||||
|
||||
}
|
||||
});
|
||||
return scene;
|
||||
}
|
||||
|
||||
private Scene setPlayingScene() {
|
||||
scene = new Scene(grid, 900, 900);
|
||||
scene.getStylesheets().add("res/TicTacToe_Client.css");
|
||||
scene.setOnMousePressed(new EventHandler<MouseEvent>() {
|
||||
@@ -104,8 +118,10 @@ public class Engine extends Application {
|
||||
}
|
||||
|
||||
private void onMouseClick(MouseEvent event) {
|
||||
mouseClicked = true;
|
||||
coordinates.setLocation(event.getX(), event.getY());
|
||||
if (moveAllowed) {
|
||||
mouseClicked = true;
|
||||
coordinates.setLocation(event.getX(), event.getY());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isWindowClosed() {return windowClosed;}
|
||||
@@ -122,6 +138,10 @@ public class Engine extends Application {
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
public void setMoveAllowed(boolean isMoveAllowed){
|
||||
moveAllowed = isMoveAllowed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
//initialize window
|
||||
@@ -129,7 +149,7 @@ public class Engine extends Application {
|
||||
primaryStage.setTitle("Test");
|
||||
primaryStage.setResizable(true);
|
||||
this.initializeGrid();
|
||||
primaryStage.setScene(this.setScene());
|
||||
primaryStage.setScene(this.setPlayingScene());
|
||||
primaryStage.sizeToScene();
|
||||
primaryStage.show();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user