diff --git a/.idea/artifacts/Client.xml b/.idea/artifacts/Client.xml deleted file mode 100644 index 43d929f..0000000 --- a/.idea/artifacts/Client.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - $PROJECT_DIR$/out/artifacts/Client - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/artifacts/Client_jar.xml b/.idea/artifacts/Client_jar.xml new file mode 100644 index 0000000..563a75d --- /dev/null +++ b/.idea/artifacts/Client_jar.xml @@ -0,0 +1,14 @@ + + + $PROJECT_DIR$/out/artifacts/Client_jar + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/JavaFx.xml b/.idea/libraries/JavaFx.xml new file mode 100644 index 0000000..58ef7fc --- /dev/null +++ b/.idea/libraries/JavaFx.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 0548357..e0844bc 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/ArcadeMachine.iml b/ArcadeMachine.iml index c90834f..e7b98ac 100644 --- a/ArcadeMachine.iml +++ b/ArcadeMachine.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/Client/Client.iml b/Client/Client.iml index de33418..d46e7d9 100644 --- a/Client/Client.iml +++ b/Client/Client.iml @@ -6,8 +6,8 @@ - + - + \ No newline at end of file diff --git a/Client/src/Launcher.java b/Client/src/Launcher.java new file mode 100644 index 0000000..b2ca47e --- /dev/null +++ b/Client/src/Launcher.java @@ -0,0 +1,7 @@ +import game.TicTacToe_Client; + +public class Launcher { + public static void main(String[] args) { + TicTacToe_Client.main(args); + } +} \ No newline at end of file diff --git a/README.md b/README.md index 96b042c..13cb96c 100644 --- a/README.md +++ b/README.md @@ -1 +1,12 @@ -ArcadeMachine +# ArcadeMachine + +## Requierments +- ### Linux: + - OpenJfx + +- ### Windows: + - + +## Installation +- ### Linux (Debian): + - `sudo apt-get install openjfx` diff --git a/Server/Server.iml b/Server/Server.iml index 17ba59d..2366fd0 100644 --- a/Server/Server.iml +++ b/Server/Server.iml @@ -6,7 +6,7 @@ - + \ No newline at end of file diff --git a/Server/src/networking/Server.java b/Server/src/networking/Server.java deleted file mode 100644 index 9b15e51..0000000 --- a/Server/src/networking/Server.java +++ /dev/null @@ -1,159 +0,0 @@ -package networking; - -import game.TicTacToe_Server; -import logging.LogType; -import logging.ServerLogger; - -import java.io.*; -import java.net.ServerSocket; -import java.net.Socket; -import java.util.HashMap; -import java.util.Scanner; - -public class Server { - private ServerSocket serverSocket; - private HashMap clients; - private HashMap clientNames; - private HashMap outstreams; - private HashMap instreams; - private TicTacToe_Server ticTacToe_server; - private ServerLogger serverLogger; - private Scanner scanner; - private int requiredConnections; - - public Server(int port){ - try { - serverSocket = new ServerSocket(port); - clients = new HashMap<>(); - clientNames = new HashMap<>(); - outstreams = new HashMap<>(); - instreams = new HashMap<>(); - ticTacToe_server = new TicTacToe_Server(); - scanner = new Scanner(System.in); - serverLogger = new ServerLogger(); - requiredConnections = 1; - - serverLogger.printLog("Server started successfully", LogType.Log); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void connectClients(){ - try { - int id = 0; - serverLogger.printLog(String.format("Waiting for %d clients to connect ...", requiredConnections), LogType.Log); - while(clients.size() < requiredConnections) { - Socket momentaryClient = serverSocket.accept(); - clients.put(id, momentaryClient); - outstreams.put(momentaryClient, new DataOutputStream(momentaryClient.getOutputStream())); - instreams.put(momentaryClient, new DataInputStream(momentaryClient.getInputStream())); - id++; - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void handshake(){ - for (Socket client: clients.values()) { - try { - int handshakeValue = instreams.get(client).readInt(); - if (handshakeValue == 165313125) { - outstreams.get(client).writeInt(200); - outstreams.get(client).flush(); - clientNames.put(client, instreams.get(client).readUTF()); - outstreams.get(client).writeUTF(serverSocket.getInetAddress().getHostAddress()+":"+serverSocket.getLocalPort()); - outstreams.get(client).flush(); - serverLogger.printLog(String.format("%s got connected", clientNames.get(client)), LogType.Log); - } else { - outstreams.get(client).writeInt(403); - outstreams.get(client).flush(); - } - - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - public void ticTacToe_gameloop(){ - for (Socket client: clients.values()) { - try { - while (!client.isClosed()) { - String message = instreams.get(client).readUTF(); - serverLogger.printLog(message, clientNames.get(client), LogType.Message); - outstreams.get(client).writeInt(200); - outstreams.get(client).flush(); - serverLogger.printLog("Sent verification code", clientNames.get(client), LogType.Log); - this.gameFlow(message, client); - } - } catch (IOException e) { - e.printStackTrace(); - try { - client.close(); - } catch (IOException ioException) { - ioException.printStackTrace(); - } - } - } - } - - public void gameFlow(String input, Socket client){ - switch (input){ - case "gameState": - try { - outstreams.get(client).writeUTF(ticTacToe_server.getGameState()); - outstreams.get(client).flush(); - serverLogger.printLog("Sent gameState", clientNames.get(client), LogType.Log); - break; - } catch (IOException e) { - e.printStackTrace(); - } - - case "update": - try { - String position = instreams.get(client).readUTF(); - serverLogger.printLog(position, clientNames.get(client), LogType.Message); - outstreams.get(client).writeInt(200); - outstreams.get(client).flush(); - serverLogger.printLog("Sent verification code", clientNames.get(client), LogType.Log); - int verificationCode = ticTacToe_server.makeClientMove(position); - if (verificationCode == 200) { - String gameState = ticTacToe_server.getGameState(); - outstreams.get(client).writeUTF(gameState); - outstreams.get(client).flush(); - serverLogger.printLog(String.format("Sent gameState: %s", gameState), clientNames.get(client), LogType.Log); - break; - } else { - outstreams.get(client).writeUTF(" "); - outstreams.get(client).flush(); - serverLogger.printLog(String.format("Move is not allowed!"), clientNames.get(client), LogType.Error); - break; - } - } catch (IOException e) { - e.printStackTrace(); - } - - case "exit()": - try { - outstreams.get(client).writeInt(200); - outstreams.get(client).flush(); - outstreams.get(client).close(); - instreams.get(client).close(); - client.close(); - serverLogger.printLog(String.format("%s closed the connection",clientNames.get(client)), LogType.Log); - break; - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - public static void main(String[] args) { - Server server = new Server(2589); - server.connectClients(); - server.handshake(); - server.ticTacToe_gameloop(); - } -} \ No newline at end of file diff --git a/out/artifacts/Client/Client.html b/out/artifacts/Client/Client.html deleted file mode 100644 index af4b518..0000000 --- a/out/artifacts/Client/Client.html +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - -

Test page for Client

- Webstart: click to launch this app as webstart


- - -
- diff --git a/out/artifacts/Client/Client.jnlp b/out/artifacts/Client/Client.jnlp deleted file mode 100644 index eff4374..0000000 --- a/out/artifacts/Client/Client.jnlp +++ /dev/null @@ -1,15 +0,0 @@ - - - - Client - Unknown - Client - - - - - - - - - diff --git a/out/production/Server/META-INF/MANIFEST.MF b/out/production/Server/META-INF/MANIFEST.MF index 9ae8574..b764489 100644 --- a/out/production/Server/META-INF/MANIFEST.MF +++ b/out/production/Server/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ Manifest-Version: 1.0 -Main-Class: networking.Server +Main-Class: networking.SinglePlayerServer diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..01f4484 --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,6 @@ +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 +