Multiplayer capable (STABLE PRESENTATION VERSION)
This commit is contained in:
@@ -63,8 +63,8 @@ public class TicTacToe_Client {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "userInput":
|
case "userInput":
|
||||||
client.sendToServer("test");
|
|
||||||
client.printLog("Waiting for userInput", true, LogType.Log);
|
client.printLog("Waiting for userInput", true, LogType.Log);
|
||||||
|
renderEngine.setMoveAllowed(true);
|
||||||
while (!renderEngine.isMouseClicked()) {
|
while (!renderEngine.isMouseClicked()) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
@@ -73,6 +73,7 @@ public class TicTacToe_Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
renderEngine.setMouseClicked(false);
|
renderEngine.setMouseClicked(false);
|
||||||
|
renderEngine.setMoveAllowed(false);
|
||||||
isAllowedToMove = false;
|
isAllowedToMove = false;
|
||||||
this.userInput();
|
this.userInput();
|
||||||
break;
|
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() {
|
public String getResponse() {
|
||||||
try {
|
try {
|
||||||
String message = in.readUTF();
|
String message = in.readUTF();
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public class Engine extends Application {
|
|||||||
private static Engine engine = null;
|
private static Engine engine = null;
|
||||||
private boolean mouseClicked = false;
|
private boolean mouseClicked = false;
|
||||||
private boolean windowClosed = false;
|
private boolean windowClosed = false;
|
||||||
|
private boolean moveAllowed = false;
|
||||||
private Point coordinates = new Point();
|
private Point coordinates = new Point();
|
||||||
private Stage primaryStage;
|
private Stage primaryStage;
|
||||||
|
|
||||||
@@ -37,7 +38,20 @@ public class Engine extends Application {
|
|||||||
grid.setVgap(75);
|
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 = new Scene(grid, 900, 900);
|
||||||
scene.getStylesheets().add("res/TicTacToe_Client.css");
|
scene.getStylesheets().add("res/TicTacToe_Client.css");
|
||||||
scene.setOnMousePressed(new EventHandler<MouseEvent>() {
|
scene.setOnMousePressed(new EventHandler<MouseEvent>() {
|
||||||
@@ -104,9 +118,11 @@ public class Engine extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onMouseClick(MouseEvent event) {
|
private void onMouseClick(MouseEvent event) {
|
||||||
|
if (moveAllowed) {
|
||||||
mouseClicked = true;
|
mouseClicked = true;
|
||||||
coordinates.setLocation(event.getX(), event.getY());
|
coordinates.setLocation(event.getX(), event.getY());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isWindowClosed() {return windowClosed;}
|
public boolean isWindowClosed() {return windowClosed;}
|
||||||
|
|
||||||
@@ -122,6 +138,10 @@ public class Engine extends Application {
|
|||||||
return coordinates;
|
return coordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMoveAllowed(boolean isMoveAllowed){
|
||||||
|
moveAllowed = isMoveAllowed;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
//initialize window
|
//initialize window
|
||||||
@@ -129,7 +149,7 @@ public class Engine extends Application {
|
|||||||
primaryStage.setTitle("Test");
|
primaryStage.setTitle("Test");
|
||||||
primaryStage.setResizable(true);
|
primaryStage.setResizable(true);
|
||||||
this.initializeGrid();
|
this.initializeGrid();
|
||||||
primaryStage.setScene(this.setScene());
|
primaryStage.setScene(this.setPlayingScene());
|
||||||
primaryStage.sizeToScene();
|
primaryStage.sizeToScene();
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
Manifest-Version: 1.0
|
Manifest-Version: 1.0
|
||||||
Main-Class: networking.TicTacToe_Server
|
Main-Class: TicTacToe_Server
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
package networking;
|
|
||||||
|
|
||||||
import logging.LogType;
|
import logging.LogType;
|
||||||
import logging.ServerLogger;
|
import logging.ServerLogger;
|
||||||
import res.TicTacToe_GameRules;
|
import res.TicTacToe_GameRules;
|
||||||
@@ -157,10 +155,17 @@ public class TicTacToe_Server {
|
|||||||
}
|
}
|
||||||
while (clients.size() == requiredConnections) {
|
while (clients.size() == requiredConnections) {
|
||||||
for (Socket client : clients.values()) {
|
for (Socket client : clients.values()) {
|
||||||
|
try {
|
||||||
|
if (instreams.get(client).available() > 0){
|
||||||
gameFlow(handleInput(client), client);
|
gameFlow(handleInput(client), client);
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
System.out.println("Ended");
|
||||||
|
}
|
||||||
|
|
||||||
public void gameFlow(String input, Socket client) {
|
public void gameFlow(String input, Socket client) {
|
||||||
switch (input) {
|
switch (input) {
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
Manifest-Version: 1.0
|
|
||||||
Main-Class: Launcher
|
|
||||||
Class-Path: src.zip javafx-swt.jar javafx.web.jar javafx.base.jar javafx
|
|
||||||
.fxml.jar javafx.media.jar javafx.swing.jar javafx.controls.jar javafx.
|
|
||||||
graphics.jar
|
|
||||||
|
|
||||||
BIN
out/production/Client/res/TicTacToe_Client_UML.png
Normal file
BIN
out/production/Client/res/TicTacToe_Client_UML.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 130 KiB |
@@ -1,3 +1,3 @@
|
|||||||
Manifest-Version: 1.0
|
Manifest-Version: 1.0
|
||||||
Main-Class: networking.TicTacToe_Server
|
Main-Class: TicTacToe_Server
|
||||||
|
|
||||||
|
|||||||
BIN
out/production/Server/TicTacToe_Server_UML.png
Normal file
BIN
out/production/Server/TicTacToe_Server_UML.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 121 KiB |
Reference in New Issue
Block a user