Made the project artifact friendly
Can now be build using IntelliJ artifacts
This commit is contained in:
22
.idea/artifacts/Client.xml
generated
22
.idea/artifacts/Client.xml
generated
@@ -1,22 +0,0 @@
|
|||||||
<component name="ArtifactManager">
|
|
||||||
<artifact type="javafx" name="Client">
|
|
||||||
<output-path>$PROJECT_DIR$/out/artifacts/Client</output-path>
|
|
||||||
<properties id="javafx-properties">
|
|
||||||
<options>
|
|
||||||
<option name="appClass" value="game.TicTacToe_Client" />
|
|
||||||
<option name="description" value="" />
|
|
||||||
<option name="height" value="" />
|
|
||||||
<option name="htmlPlaceholderId" value="" />
|
|
||||||
<option name="title" value="" />
|
|
||||||
<option name="vendor" value="" />
|
|
||||||
<option name="version" value="" />
|
|
||||||
<option name="width" value="" />
|
|
||||||
</options>
|
|
||||||
</properties>
|
|
||||||
<root id="root">
|
|
||||||
<element id="archive" name="Client.jar">
|
|
||||||
<element id="module-output" name="Client" />
|
|
||||||
</element>
|
|
||||||
</root>
|
|
||||||
</artifact>
|
|
||||||
</component>
|
|
||||||
14
.idea/artifacts/Client_jar.xml
generated
Normal file
14
.idea/artifacts/Client_jar.xml
generated
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<component name="ArtifactManager">
|
||||||
|
<artifact name="Client:jar">
|
||||||
|
<output-path>$PROJECT_DIR$/out/artifacts/Client_jar</output-path>
|
||||||
|
<root id="root">
|
||||||
|
<element id="archive" name="Client.jar">
|
||||||
|
<element id="directory" name="META-INF">
|
||||||
|
<element id="file-copy" path="$PROJECT_DIR$/src/META-INF/MANIFEST.MF" />
|
||||||
|
</element>
|
||||||
|
<element id="module-output" name="Client" />
|
||||||
|
</element>
|
||||||
|
<element id="library" level="project" name="JavaFx" />
|
||||||
|
</root>
|
||||||
|
</artifact>
|
||||||
|
</component>
|
||||||
16
.idea/libraries/JavaFx.xml
generated
Normal file
16
.idea/libraries/JavaFx.xml
generated
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="JavaFx">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="file://$USER_HOME$/Libs/javafx-sdk-11.0.2/lib" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<NATIVE>
|
||||||
|
<root url="file://$USER_HOME$/Libs/javafx-sdk-11.0.2/lib" />
|
||||||
|
</NATIVE>
|
||||||
|
<SOURCES>
|
||||||
|
<root url="file://$USER_HOME$/Libs/javafx-sdk-11.0.2/lib" />
|
||||||
|
</SOURCES>
|
||||||
|
<jarDirectory url="file://$USER_HOME$/Libs/javafx-sdk-11.0.2/lib" recursive="false" />
|
||||||
|
<jarDirectory url="file://$USER_HOME$/Libs/javafx-sdk-11.0.2/lib" recursive="false" type="SOURCES" />
|
||||||
|
</library>
|
||||||
|
</component>
|
||||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -6,8 +6,8 @@
|
|||||||
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" exported="" name="JavaFx" level="project" />
|
<orderEntry type="library" name="JavaFx" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
7
Client/src/Launcher.java
Normal file
7
Client/src/Launcher.java
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import game.TicTacToe_Client;
|
||||||
|
|
||||||
|
public class Launcher {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
TicTacToe_Client.main(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
13
README.md
13
README.md
@@ -1 +1,12 @@
|
|||||||
ArcadeMachine
|
# ArcadeMachine
|
||||||
|
|
||||||
|
## Requierments
|
||||||
|
- ### Linux:
|
||||||
|
- OpenJfx
|
||||||
|
|
||||||
|
- ### Windows:
|
||||||
|
-
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
- ### Linux (Debian):
|
||||||
|
- `sudo apt-get install openjfx`
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -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<Integer, Socket> clients;
|
|
||||||
private HashMap<Socket, String> clientNames;
|
|
||||||
private HashMap<Socket, DataOutputStream> outstreams;
|
|
||||||
private HashMap<Socket, DataInputStream> 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
<html><head>
|
|
||||||
<SCRIPT src="http://java.com/js/dtjava.js"></SCRIPT>
|
|
||||||
<script>
|
|
||||||
function launchApplication(jnlpfile) {
|
|
||||||
dtjava.launch( {
|
|
||||||
url : 'Client.jnlp'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
javafx : '8.0+'
|
|
||||||
},
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
function javafxEmbedClient_id() {
|
|
||||||
dtjava.embed(
|
|
||||||
{
|
|
||||||
id : 'Client_id',
|
|
||||||
url : 'Client.jnlp',
|
|
||||||
placeholder : 'javafx-app-placeholder',
|
|
||||||
width : '900',
|
|
||||||
height : '900'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
javafx : '8.0+'
|
|
||||||
},
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
<!-- Embed FX application into web page once page is loaded -->
|
|
||||||
dtjava.addOnloadCallback(javafxEmbedClient_id);
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</head><body>
|
|
||||||
<h2>Test page for <b>Client</b></h2>
|
|
||||||
<b>Webstart:</b> <a href='Client.jnlp' onclick="return launchApplication('Client.jnlp');">click to launch this app as webstart</a><br><hr><br>
|
|
||||||
|
|
||||||
<!-- Applet will be inserted here -->
|
|
||||||
<div id='javafx-app-placeholder'></div>
|
|
||||||
</body></html>
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<jnlp spec="1.0" xmlns:jfx="http://javafx.com" href="Client.jnlp">
|
|
||||||
<information>
|
|
||||||
<title>Client</title>
|
|
||||||
<vendor>Unknown</vendor>
|
|
||||||
<description>Client</description>
|
|
||||||
<offline-allowed/>
|
|
||||||
</information>
|
|
||||||
<resources>
|
|
||||||
<j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
|
|
||||||
<jar href="Client.jar" size="9642" download="eager" />
|
|
||||||
</resources>
|
|
||||||
<jfx:javafx-desc width="900" height="900" main-class="game.TicTacToe_Client" name="Client" />
|
|
||||||
<update check="background"/>
|
|
||||||
</jnlp>
|
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
Manifest-Version: 1.0
|
Manifest-Version: 1.0
|
||||||
Main-Class: networking.Server
|
Main-Class: networking.SinglePlayerServer
|
||||||
|
|
||||||
|
|||||||
6
src/META-INF/MANIFEST.MF
Normal file
6
src/META-INF/MANIFEST.MF
Normal file
@@ -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
|
||||||
|
|
||||||
Reference in New Issue
Block a user