Merge branch 'Mick'

* Mick:
  Restructured Util for better usability Moved MainGame from util to client. Moved server port static from serverData to Data
This commit is contained in:
MickWerf
2020-05-18 15:53:27 +02:00
26 changed files with 53 additions and 53 deletions

View File

@@ -1,7 +1,8 @@
package netwerkprog.game.client; package netwerkprog.game.client;
import netwerkprog.game.util.Controller; import netwerkprog.game.util.application.Controller;
import netwerkprog.game.util.ServerData; import netwerkprog.game.util.data.Data;
import netwerkprog.game.util.data.DataParser;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@@ -13,13 +14,20 @@ import java.util.Scanner;
public class Client extends Controller { public class Client extends Controller {
private int port; private int port;
private String hostname; private String hostname;
private DataParser parser;
private boolean isConnected = true; private boolean isConnected = true;
public Client(String hostname) { public Client(String hostname) {
this.port = ServerData.port(); this.port = Data.port();
this.hostname = hostname; this.hostname = hostname;
this.parser = new DataParser();
}
@Override
public void run() {
this.connect();
} }
public void connect() { public void connect() {
@@ -66,15 +74,12 @@ public class Client extends Controller {
while (isConnected) { while (isConnected) {
try { try {
received = in.readUTF(); received = in.readUTF();
System.out.println(received);
} catch (IOException e) { } catch (IOException e) {
System.out.println("exception caught - " + e.getMessage());; System.out.println("exception caught - " + e.getMessage());;
} }
} }
} }
@Override
public void run() {
this.connect();
}
} }

View File

@@ -1,4 +1,4 @@
package netwerkprog.game; package netwerkprog.game.client;
import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Files; import com.badlogic.gdx.Files;
@@ -7,8 +7,7 @@ import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import netwerkprog.game.client.Client; import netwerkprog.game.util.graphics.FrameRate;
import netwerkprog.game.util.FrameRate;
public class MainGame extends ApplicationAdapter { public class MainGame extends ApplicationAdapter {
SpriteBatch batch; SpriteBatch batch;

View File

@@ -1,6 +1,6 @@
package netwerkprog.game.client.game; package netwerkprog.game.client.game;
import netwerkprog.game.util.Controller; import netwerkprog.game.util.application.Controller;
public class Game extends Controller { public class Game extends Controller {

View File

@@ -1,6 +1,6 @@
package netwerkprog.game.client.game; package netwerkprog.game.client.game;
import netwerkprog.game.util.Controller; import netwerkprog.game.util.application.Controller;
public class Graphics extends Controller { public class Graphics extends Controller {
public Graphics() { public Graphics() {

View File

@@ -1,6 +1,6 @@
package netwerkprog.game.client.game.logic; package netwerkprog.game.client.game.logic;
import netwerkprog.game.util.Controller; import netwerkprog.game.util.application.Controller;
public class Logic extends Controller { public class Logic extends Controller {

View File

@@ -2,7 +2,7 @@ package netwerkprog.game.client.game.map;
import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import netwerkprog.game.util.Renderable; import netwerkprog.game.util.graphics.Renderable;
public class MapRenderer implements Renderable { public class MapRenderer implements Renderable {
private int tileWidth; private int tileWidth;

View File

@@ -1,7 +1,7 @@
package netwerkprog.game.server; package netwerkprog.game.server;
import netwerkprog.game.server.controllers.SessionController; import netwerkprog.game.server.controllers.SessionController;
import netwerkprog.game.server.data.Data; import netwerkprog.game.util.data.Data;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;

View File

@@ -1,10 +1,9 @@
package netwerkprog.game.server.controllers; package netwerkprog.game.server.controllers;
import netwerkprog.game.server.ServerClient; import netwerkprog.game.server.ServerClient;
import netwerkprog.game.server.data.Data; import netwerkprog.game.util.data.Data;
import netwerkprog.game.server.data.DataParser; import netwerkprog.game.util.data.DataParser;
import netwerkprog.game.util.Controller; import netwerkprog.game.util.application.Controller;
import netwerkprog.game.util.ServerData;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@@ -46,8 +45,8 @@ public class SessionController extends Controller {
*/ */
public void listen() { public void listen() {
try { try {
this.serverSocket = new ServerSocket(ServerData.port()); this.serverSocket = new ServerSocket(Data.port());
System.out.println("[SERVER] listening on port " + ServerData.port()); System.out.println("[SERVER] listening on port " + Data.port());
registerClient(serverSocket.accept()); registerClient(serverSocket.accept());
this.serverSocket.close(); this.serverSocket.close();
} catch (IOException ex) { } catch (IOException ex) {

View File

@@ -1,4 +0,0 @@
package netwerkprog.game.server.data;
public class Data {
}

View File

@@ -1,4 +0,0 @@
package netwerkprog.game.server.data;
public class Event {
}

View File

@@ -1,4 +0,0 @@
package netwerkprog.game.util;
public enum Faction {
}

View File

@@ -1,5 +0,0 @@
package netwerkprog.game.util;
public interface Renderable extends Updatable {
void render();
}

View File

@@ -1,4 +1,4 @@
package netwerkprog.game.util; package netwerkprog.game.util.application;
public abstract class Controller implements Runnable { public abstract class Controller implements Runnable {

View File

@@ -1,4 +1,4 @@
package netwerkprog.game.util; package netwerkprog.game.util.application;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;

View File

@@ -1,4 +1,4 @@
package netwerkprog.game.util; package netwerkprog.game.util.application;
public class Timer implements Updatable { public class Timer implements Updatable {
private double wait; private double wait;

View File

@@ -1,4 +1,4 @@
package netwerkprog.game.util; package netwerkprog.game.util.application;
public interface Updatable { public interface Updatable {
void update(double deltaTime); void update(double deltaTime);

View File

@@ -1,4 +1,4 @@
package netwerkprog.game.util; package netwerkprog.game.util.data;
public interface Callback { public interface Callback {
void onDataReceived(); void onDataReceived();

View File

@@ -1,7 +1,6 @@
package netwerkprog.game.util; package netwerkprog.game.util.data;
public class ServerData {
public class Data {
public static int port() { public static int port() {
return 8000; return 8000;
} }

View File

@@ -1,4 +1,4 @@
package netwerkprog.game.server.data; package netwerkprog.game.util.data;
public class DataParser { public class DataParser {
public DataParser() { public DataParser() {

View File

@@ -0,0 +1,4 @@
package netwerkprog.game.util.data;
public class Event {
}

View File

@@ -1,4 +1,4 @@
package netwerkprog.game.util; package netwerkprog.game.util.game;
public abstract class Ability { public abstract class Ability {
protected String name; protected String name;

View File

@@ -1,4 +1,4 @@
package netwerkprog.game.util; package netwerkprog.game.util.game;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;

View File

@@ -0,0 +1,4 @@
package netwerkprog.game.util.game;
public enum Faction {
}

View File

@@ -1,4 +1,4 @@
package netwerkprog.game.util; package netwerkprog.game.util.graphics;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;

View File

@@ -0,0 +1,7 @@
package netwerkprog.game.util.graphics;
import netwerkprog.game.util.application.Updatable;
public interface Renderable extends Updatable {
void render();
}

View File

@@ -1,8 +1,8 @@
package netwerkprog.game.desktop; package netwerkprog.game.desktop;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import netwerkprog.game.MainGame; import netwerkprog.game.client.MainGame;
import netwerkprog.game.util.GameApplicationConfiguration; import netwerkprog.game.util.application.GameApplicationConfiguration;
public class DesktopLauncher { public class DesktopLauncher {
public static void main (String[] arg) { public static void main (String[] arg) {