Compare commits
1 Commits
Connection
...
Mick
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f89dbbb6b3 |
Binary file not shown.
|
Before Width: | Height: | Size: 80 KiB After Width: | Height: | Size: 51 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 913 B |
Binary file not shown.
|
Before Width: | Height: | Size: 907 B |
104
core/src/netwerkprog/game/client/Client.java
Normal file
104
core/src/netwerkprog/game/client/Client.java
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
package netwerkprog.game.client;
|
||||||
|
|
||||||
|
import netwerkprog.game.util.application.Controller;
|
||||||
|
import netwerkprog.game.util.data.Data;
|
||||||
|
import netwerkprog.game.util.data.ParserCallback;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class Client extends Controller implements ParserCallback {
|
||||||
|
private final int port;
|
||||||
|
private final String hostname;
|
||||||
|
private final Parser parser;
|
||||||
|
private boolean isConnected = true;
|
||||||
|
private Socket socket;
|
||||||
|
private Thread receiveThread;
|
||||||
|
private DataOutputStream outputStream;
|
||||||
|
|
||||||
|
public Client(String hostname) {
|
||||||
|
this.port = Data.port();
|
||||||
|
this.hostname = hostname;
|
||||||
|
this.parser = new Parser(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the client process.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
this.connect();
|
||||||
|
this.receiveThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connects the client to the server.
|
||||||
|
*/
|
||||||
|
public void connect() {
|
||||||
|
System.out.println("[CLIENT] connecting to server on port " + this.port);
|
||||||
|
try {
|
||||||
|
this.socket = new Socket(this.hostname, this.port);
|
||||||
|
DataInputStream in = new DataInputStream(socket.getInputStream());
|
||||||
|
this.outputStream = new DataOutputStream(socket.getOutputStream());
|
||||||
|
|
||||||
|
this.receiveThread = new Thread( () -> receive(in));
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("[CLIENT] there was an error connecting : " + e.getMessage());
|
||||||
|
StringBuilder sb = new StringBuilder(" Stacktrace : ");
|
||||||
|
Arrays.stream(e.getStackTrace()).forEach(n -> sb.append("\t\t").append(n).append("\n"));
|
||||||
|
System.out.println(sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a message to the server.
|
||||||
|
* @param message The message to send.
|
||||||
|
*/
|
||||||
|
public void send(String message) {
|
||||||
|
try {
|
||||||
|
this.outputStream.writeUTF(message);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receives a message from the server.
|
||||||
|
* @param in The inputStream
|
||||||
|
*/
|
||||||
|
public void receive(DataInputStream in) {
|
||||||
|
while (isConnected) {
|
||||||
|
try {
|
||||||
|
this.parser.parse(in.readUTF());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disconnect() {
|
||||||
|
this.isConnected = false;
|
||||||
|
try {
|
||||||
|
this.receiveThread.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
send("Disconnect");
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.socket.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDataReceived(String data) {
|
||||||
|
System.out.println(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,35 +3,23 @@ package netwerkprog.game.client;
|
|||||||
import com.badlogic.gdx.ApplicationAdapter;
|
import com.badlogic.gdx.ApplicationAdapter;
|
||||||
import com.badlogic.gdx.Files;
|
import com.badlogic.gdx.Files;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.assets.AssetManager;
|
|
||||||
import com.badlogic.gdx.audio.Music;
|
import com.badlogic.gdx.audio.Music;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import netwerkprog.game.client.game.GAMESTATE;
|
|
||||||
import netwerkprog.game.client.game.characters.Agent;
|
|
||||||
import netwerkprog.game.client.game.characters.Hacker;
|
import netwerkprog.game.client.game.characters.Hacker;
|
||||||
import netwerkprog.game.client.game.characters.Team;
|
|
||||||
import netwerkprog.game.client.game.characters.abilities.BodySwap;
|
import netwerkprog.game.client.game.characters.abilities.BodySwap;
|
||||||
import netwerkprog.game.client.game.connections.Client;
|
|
||||||
import netwerkprog.game.client.game.map.GameInputProcessor;
|
|
||||||
import netwerkprog.game.client.game.map.GameTile;
|
|
||||||
import netwerkprog.game.client.game.map.Map;
|
import netwerkprog.game.client.game.map.Map;
|
||||||
import netwerkprog.game.client.game.map.MapRenderer;
|
import netwerkprog.game.client.game.map.MapRenderer;
|
||||||
import netwerkprog.game.util.data.Data;
|
import netwerkprog.game.client.game.map.GameInputProcessor;
|
||||||
import netwerkprog.game.util.data.DataCallback;
|
|
||||||
import netwerkprog.game.util.game.Faction;
|
|
||||||
import netwerkprog.game.util.game.GameCharacter;
|
import netwerkprog.game.util.game.GameCharacter;
|
||||||
import netwerkprog.game.util.graphics.FrameRate;
|
import netwerkprog.game.util.graphics.FrameRate;
|
||||||
import netwerkprog.game.util.graphics.TextRenderer;
|
import netwerkprog.game.util.tree.BST;
|
||||||
|
|
||||||
import java.awt.*;
|
public class MainGame extends ApplicationAdapter {
|
||||||
|
|
||||||
public class MainGame extends ApplicationAdapter implements DataCallback {
|
|
||||||
SpriteBatch batch;
|
SpriteBatch batch;
|
||||||
float screenWidth;
|
float screenWidth;
|
||||||
float screenHeight;
|
float screenHeight;
|
||||||
@@ -40,17 +28,12 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
private OrthographicCamera camera;
|
private OrthographicCamera camera;
|
||||||
private GameInputProcessor gameInputProcessor;
|
private GameInputProcessor gameInputProcessor;
|
||||||
private GameCharacter selectedCharacter;
|
private GameCharacter selectedCharacter;
|
||||||
private Team team;
|
|
||||||
private Team enemyTeam;
|
|
||||||
private TextRenderer textRenderer;
|
|
||||||
private BitmapFont font;
|
|
||||||
private GlyphLayout layout;
|
|
||||||
private GAMESTATE gamestate;
|
|
||||||
private Faction chosenFaction;
|
|
||||||
|
|
||||||
private Map map;
|
private Map map;
|
||||||
public MapRenderer mapRenderer;
|
public MapRenderer mapRenderer;
|
||||||
public AssetManager assets;
|
|
||||||
|
private BST<GameCharacter> tree;
|
||||||
|
public GameCharacter testCharacter;
|
||||||
|
|
||||||
private static MainGame INSTANCE;
|
private static MainGame INSTANCE;
|
||||||
|
|
||||||
@@ -72,20 +55,17 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
screenHeight = Gdx.graphics.getHeight();
|
screenHeight = Gdx.graphics.getHeight();
|
||||||
frameRate = new FrameRate();
|
frameRate = new FrameRate();
|
||||||
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
textRenderer = new TextRenderer();
|
|
||||||
font = new BitmapFont();
|
|
||||||
layout = new GlyphLayout();
|
|
||||||
assets = new AssetManager();
|
|
||||||
|
|
||||||
String[] strings = new String[]{
|
String[] strings = new String[]{
|
||||||
"#########################",
|
"#########################",
|
||||||
"#xxxx #",
|
"#xxxx #",
|
||||||
"# x #",
|
"# x #",
|
||||||
"# xxxx xxxxx #",
|
"# xxxx #",
|
||||||
"# xxxx xxxxx #",
|
"# xx #",
|
||||||
"# xxxx xx xx #",
|
"# x #",
|
||||||
"# x xxxxx #",
|
"# x #",
|
||||||
"# x xxxx #",
|
"# x #",
|
||||||
"# x #",
|
"# x #",
|
||||||
"# xxxxxx #",
|
"# xxxxxx #",
|
||||||
"# x #",
|
"# x #",
|
||||||
@@ -100,39 +80,28 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
camera.viewportWidth = screenWidth / 2;
|
camera.viewportWidth = screenWidth / 2;
|
||||||
camera.viewportHeight = screenHeight / 2;
|
camera.viewportHeight = screenHeight / 2;
|
||||||
camera.update();
|
camera.update();
|
||||||
setGamestate(GAMESTATE.SELECTING_FACTION);
|
this.tree = new BST<>();
|
||||||
|
initCharacters();
|
||||||
// this.tree.insert(new Hacker(,new BodySwap()));
|
// this.tree.insert(new Hacker(,new BodySwap()));
|
||||||
|
|
||||||
|
|
||||||
// playSong();
|
// playSong();
|
||||||
|
|
||||||
|
|
||||||
connectToServer();
|
// connectToServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initCharacters() {
|
private void initCharacters() {
|
||||||
assets.load("core/assets/characters.png", Texture.class);
|
Texture texture = new Texture(Gdx.files.internal("core/assets/characters.png"));
|
||||||
assets.finishLoading();
|
|
||||||
Texture texture = assets.get("core/assets/characters.png");
|
|
||||||
TextureRegion[][] characters = TextureRegion.split(texture, 32, 32);
|
TextureRegion[][] characters = TextureRegion.split(texture, 32, 32);
|
||||||
this.team = new Team();
|
this.testCharacter = new Hacker("harry",characters[1][0], new BodySwap("test"));
|
||||||
|
GameCharacter character2 = new Hacker("test2",characters[2][0], new BodySwap("test"));
|
||||||
for (int i = 1; i <= 5; i++) {
|
// this.tree.insert(testCharacter);
|
||||||
GameCharacter temp = new Hacker("hacker" + i, characters[5][0], new BodySwap("test"));
|
// this.tree.insert(character2);
|
||||||
mapRenderer.getGameTiles()[1][i].visit(temp);
|
// this.tree.insert(new Agent(characters[2][0], new Implant("test")));
|
||||||
if (chosenFaction == Faction.HACKER) {
|
this.setSelectedCharacter(testCharacter);
|
||||||
this.team.addMember(temp);
|
mapRenderer.getGameTiles()[0][1].visit(testCharacter);
|
||||||
}
|
mapRenderer.getGameTiles()[0][2].visit(character2);
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 1; i <= 5; i++) {
|
|
||||||
GameCharacter temp = new Agent("Agent" + i, characters[11][0], new BodySwap("Test"));
|
|
||||||
mapRenderer.getGameTiles()[3][i].visit(temp);
|
|
||||||
if (chosenFaction == Faction.MEGACORPORATION) {
|
|
||||||
this.team.addMember(temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.setSelectedCharacter(this.team.get(0));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +118,7 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
|
|
||||||
|
|
||||||
private void connectToServer() {
|
private void connectToServer() {
|
||||||
client = new Thread(new Client("localhost", this));
|
client = new Thread(new Client("localhost"));
|
||||||
try {
|
try {
|
||||||
client.start();
|
client.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -162,36 +131,12 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
if (this.gamestate == GAMESTATE.PLAYING) {
|
update();
|
||||||
update();
|
// clear screen
|
||||||
// clear screen
|
Gdx.gl.glClearColor(0, 0, 0, 1);
|
||||||
Gdx.gl.glClearColor(0, 0, 0, 1);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
mapRenderer.render();
|
||||||
mapRenderer.render();
|
frameRate.render();
|
||||||
frameRate.render();
|
|
||||||
renderText();
|
|
||||||
} else if (this.gamestate == GAMESTATE.SELECTING_FACTION) {
|
|
||||||
renderString("FACTION SELECT\nPress 1 for mega corporation, press 2 for hackers", Gdx.graphics.getWidth() / 2f, Gdx.graphics.getHeight() / 2f);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderText() {
|
|
||||||
String text = "FACION: " + chosenFaction;
|
|
||||||
text += "\nSelected character: " + selectedCharacter.getName();
|
|
||||||
text += "\nHealth: " + selectedCharacter.getHealth();
|
|
||||||
layout.setText(font, text);
|
|
||||||
textRenderer.render(text, Gdx.graphics.getWidth() - layout.width - 5, Gdx.graphics.getHeight() - 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderString(String text) {
|
|
||||||
layout.setText(font, text);
|
|
||||||
textRenderer.render(text, Gdx.graphics.getWidth() - layout.width - 5, Gdx.graphics.getHeight() - 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderString(String text, float x, float y) {
|
|
||||||
layout.setText(font, text);
|
|
||||||
textRenderer.render(text, x - layout.width / 2f, x - layout.height / 2f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -210,7 +155,6 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
screenWidth = width;
|
screenWidth = width;
|
||||||
frameRate.resize(width, height);
|
frameRate.resize(width, height);
|
||||||
mapRenderer.resize(width, height);
|
mapRenderer.resize(width, height);
|
||||||
textRenderer.resize(width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -221,8 +165,6 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
batch.dispose();
|
batch.dispose();
|
||||||
textRenderer.dispose();
|
|
||||||
assets.dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getScreenWidth() {
|
public float getScreenWidth() {
|
||||||
@@ -241,27 +183,13 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
return map.getWidth();
|
return map.getWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BST<GameCharacter> getTree() {
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
|
||||||
public void setSelectedCharacter(GameCharacter character) {
|
public void setSelectedCharacter(GameCharacter character) {
|
||||||
this.selectedCharacter = character;
|
this.selectedCharacter = character;
|
||||||
GameTile characterTile = mapRenderer.getTile(character);
|
System.out.println("selected character set to : " + character);
|
||||||
Point pos = mapRenderer.getPos(characterTile);
|
|
||||||
mapRenderer.setSurroundedTilesOfCurrentCharacter(pos.x, pos.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GAMESTATE getGamestate() {
|
|
||||||
return gamestate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGamestate(GAMESTATE gamestate) {
|
|
||||||
this.gamestate = gamestate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Faction getChosenFaction() {
|
|
||||||
return chosenFaction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setChosenFaction(Faction chosenFaction) {
|
|
||||||
this.chosenFaction = chosenFaction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameCharacter getSelectedCharacter() {
|
public GameCharacter getSelectedCharacter() {
|
||||||
@@ -271,13 +199,4 @@ public class MainGame extends ApplicationAdapter implements DataCallback {
|
|||||||
public boolean hasCharacterSelected() {
|
public boolean hasCharacterSelected() {
|
||||||
return selectedCharacter != null;
|
return selectedCharacter != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Team getTeam() {
|
|
||||||
return team;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDataReceived(Data data) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
15
core/src/netwerkprog/game/client/Parser.java
Normal file
15
core/src/netwerkprog/game/client/Parser.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package netwerkprog.game.client;
|
||||||
|
|
||||||
|
import netwerkprog.game.util.data.ParserCallback;
|
||||||
|
|
||||||
|
public class Parser {
|
||||||
|
private final ParserCallback callback;
|
||||||
|
|
||||||
|
public Parser(ParserCallback callback) {
|
||||||
|
this.callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void parse(String data) {
|
||||||
|
callback.onDataReceived(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package netwerkprog.game.client.game;
|
|
||||||
|
|
||||||
public enum GAMESTATE {
|
|
||||||
PLAYING,
|
|
||||||
SELECTING_FACTION
|
|
||||||
}
|
|
||||||
15
core/src/netwerkprog/game/client/game/Game.java
Normal file
15
core/src/netwerkprog/game/client/game/Game.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package netwerkprog.game.client.game;
|
||||||
|
|
||||||
|
import netwerkprog.game.util.application.Controller;
|
||||||
|
|
||||||
|
public class Game extends Controller {
|
||||||
|
|
||||||
|
|
||||||
|
public Game() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
14
core/src/netwerkprog/game/client/game/Graphics.java
Normal file
14
core/src/netwerkprog/game/client/game/Graphics.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package netwerkprog.game.client.game;
|
||||||
|
|
||||||
|
import netwerkprog.game.util.application.Controller;
|
||||||
|
|
||||||
|
public class Graphics extends Controller {
|
||||||
|
public Graphics() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ import netwerkprog.game.util.game.Faction;
|
|||||||
import netwerkprog.game.util.game.GameCharacter;
|
import netwerkprog.game.util.game.GameCharacter;
|
||||||
|
|
||||||
public class Agent extends GameCharacter {
|
public class Agent extends GameCharacter {
|
||||||
public Agent(String name, TextureRegion textureRegion, Ability... abilities) {
|
public Agent(TextureRegion textureRegion, Ability... abilities) {
|
||||||
super(name, Faction.MEGACORPORATION, textureRegion, abilities);
|
super("Agent", Faction.MEGACORPORATION, textureRegion, abilities);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package netwerkprog.game.client.game.characters;
|
package netwerkprog.game.client.game.characters;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import netwerkprog.game.util.game.Faction;
|
|
||||||
import netwerkprog.game.util.game.GameCharacter;
|
import netwerkprog.game.util.game.GameCharacter;
|
||||||
|
import netwerkprog.game.util.game.Faction;
|
||||||
|
|
||||||
public class DevTest1 extends GameCharacter {
|
public class DevTest1 extends GameCharacter {
|
||||||
public DevTest1() {
|
public DevTest1() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package netwerkprog.game.client.game.characters;
|
package netwerkprog.game.client.game.characters;
|
||||||
|
|
||||||
import netwerkprog.game.util.game.Faction;
|
|
||||||
import netwerkprog.game.util.game.GameCharacter;
|
import netwerkprog.game.util.game.GameCharacter;
|
||||||
|
import netwerkprog.game.util.game.Faction;
|
||||||
|
|
||||||
public class DevTest2 extends GameCharacter {
|
public class DevTest2 extends GameCharacter {
|
||||||
public DevTest2() {
|
public DevTest2() {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package netwerkprog.game.client.game.characters;
|
package netwerkprog.game.client.game.characters;
|
||||||
|
|
||||||
import netwerkprog.game.util.game.Faction;
|
|
||||||
import netwerkprog.game.util.game.GameCharacter;
|
import netwerkprog.game.util.game.GameCharacter;
|
||||||
|
import netwerkprog.game.util.game.Faction;
|
||||||
|
|
||||||
public class DevTest3 extends GameCharacter {
|
public class DevTest3 extends GameCharacter {
|
||||||
public DevTest3() {
|
public DevTest3() {
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
package netwerkprog.game.client.game.characters;
|
|
||||||
|
|
||||||
import netwerkprog.game.util.game.GameCharacter;
|
|
||||||
import netwerkprog.game.util.tree.BST;
|
|
||||||
|
|
||||||
public class Team {
|
|
||||||
private BST<GameCharacter> members;
|
|
||||||
|
|
||||||
public Team() {
|
|
||||||
this.members = new BST<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Team(BST<GameCharacter> characters) {
|
|
||||||
this.members = characters;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addMember(GameCharacter gameCharacter) {
|
|
||||||
if (this.members.getSize() != 6)
|
|
||||||
this.members.insert(gameCharacter);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BST<GameCharacter> getMembers() {
|
|
||||||
return this.members;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMembers(BST<GameCharacter> members) {
|
|
||||||
this.members = members;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addMember(GameCharacter... characters) {
|
|
||||||
for (GameCharacter gameCharacter : characters) {
|
|
||||||
this.members.insert(gameCharacter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public GameCharacter get(GameCharacter character) {
|
|
||||||
for (GameCharacter cur : this.members) {
|
|
||||||
if (cur.equals(character)) {
|
|
||||||
return cur;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GameCharacter get(int position) {
|
|
||||||
if (position >= this.members.getSize()) {
|
|
||||||
throw new IndexOutOfBoundsException("position out of range");
|
|
||||||
}
|
|
||||||
int i = 0;
|
|
||||||
for (GameCharacter cur : this.members) {
|
|
||||||
if (i == position) return cur;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDead() {
|
|
||||||
int dead = 0;
|
|
||||||
for (GameCharacter character : this.members) {
|
|
||||||
if (character.isDead()) dead++;
|
|
||||||
}
|
|
||||||
return dead >= this.members.getSize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
package netwerkprog.game.client.game.connections;
|
|
||||||
|
|
||||||
import netwerkprog.game.util.application.Controller;
|
|
||||||
import netwerkprog.game.util.data.ConnectionData;
|
|
||||||
import netwerkprog.game.util.data.Data;
|
|
||||||
import netwerkprog.game.util.data.DataCallback;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class Client extends Controller {
|
|
||||||
private final int port;
|
|
||||||
private final String hostname;
|
|
||||||
private boolean isConnected;
|
|
||||||
private Socket socket;
|
|
||||||
private Thread receiveThread;
|
|
||||||
private DataCallback callback;
|
|
||||||
private ObjectOutputStream outputStream;
|
|
||||||
private boolean connecting;
|
|
||||||
|
|
||||||
public Client(String hostname, DataCallback callback) {
|
|
||||||
this.port = Data.port();
|
|
||||||
this.hostname = hostname;
|
|
||||||
this.callback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the client process.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
this.connect();
|
|
||||||
this.receiveThread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Connects the client to the server.
|
|
||||||
*/
|
|
||||||
public void connect() {
|
|
||||||
System.out.println("[CLIENT] connecting to server on port " + this.port);
|
|
||||||
this.connecting = true;
|
|
||||||
try {
|
|
||||||
this.socket = new Socket(this.hostname, this.port);
|
|
||||||
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
|
|
||||||
this.outputStream = new ObjectOutputStream(socket.getOutputStream());
|
|
||||||
register(in);
|
|
||||||
this.receiveThread = new Thread( () -> receive(in));
|
|
||||||
} catch (IOException e) {
|
|
||||||
this.connecting = false;
|
|
||||||
System.out.println("[CLIENT] there was an error connecting : " + e.getMessage());
|
|
||||||
StringBuilder sb = new StringBuilder(" Stacktrace : ");
|
|
||||||
Arrays.stream(e.getStackTrace()).forEach(n -> sb.append("\t\t").append(n).append("\n"));
|
|
||||||
System.out.println(sb.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void register(ObjectInputStream in) {
|
|
||||||
while (connecting) {
|
|
||||||
String username = "DEV";
|
|
||||||
send(new ConnectionData("Connect", username));
|
|
||||||
try {
|
|
||||||
Object object = in.readObject();
|
|
||||||
if (object instanceof Data) {
|
|
||||||
Data data = (Data) object;
|
|
||||||
if (data.getPayload() instanceof ConnectionData) {
|
|
||||||
ConnectionData connectionData = (ConnectionData) data.getPayload();
|
|
||||||
if (connectionData.getAction().equals("Connect") && connectionData.getMessage().equals("Confirm")){
|
|
||||||
this.connecting = false;
|
|
||||||
this.isConnected = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a message to the server.
|
|
||||||
* @param data The message to send.
|
|
||||||
*/
|
|
||||||
public void send(Data data) {
|
|
||||||
try {
|
|
||||||
this.outputStream.writeObject(data);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Receives a message from the server.
|
|
||||||
* @param in The inputStream
|
|
||||||
*/
|
|
||||||
public void receive(ObjectInputStream in) {
|
|
||||||
while (isConnected) {
|
|
||||||
try {
|
|
||||||
Object object = in.readObject();
|
|
||||||
if (object instanceof Data) {
|
|
||||||
callback.onDataReceived((Data) object);
|
|
||||||
}
|
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disconnect() {
|
|
||||||
this.isConnected = false;
|
|
||||||
try {
|
|
||||||
this.receiveThread.join();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
send(new ConnectionData("Disconnect", "DEV"));
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.socket.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,8 +8,6 @@ import com.badlogic.gdx.math.MathUtils;
|
|||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.math.Vector3;
|
||||||
import com.badlogic.gdx.utils.TimeUtils;
|
import com.badlogic.gdx.utils.TimeUtils;
|
||||||
import netwerkprog.game.client.MainGame;
|
import netwerkprog.game.client.MainGame;
|
||||||
import netwerkprog.game.client.game.GAMESTATE;
|
|
||||||
import netwerkprog.game.util.game.Faction;
|
|
||||||
import netwerkprog.game.util.game.GameCharacter;
|
import netwerkprog.game.util.game.GameCharacter;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -91,41 +89,25 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
@Override
|
@Override
|
||||||
public boolean keyUp(int keycode) {
|
public boolean keyUp(int keycode) {
|
||||||
// System.out.println(camera.position.x + " , " + camera.position.y);
|
// System.out.println(camera.position.x + " , " + camera.position.y);
|
||||||
if (mainGame.getGamestate() == GAMESTATE.PLAYING) {
|
if (keysList.contains(keycode)) {
|
||||||
|
if (keycode == keysList.get(0)) {
|
||||||
if (keysList.contains(keycode)) {
|
this.isWPressed = false;
|
||||||
if (keycode == keysList.get(0)) {
|
|
||||||
this.isWPressed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (keycode == keysList.get(1)) {
|
|
||||||
this.isAPressed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (keycode == keysList.get(2)) {
|
|
||||||
this.isSPressed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (keycode == keysList.get(3)) {
|
|
||||||
this.isDPressed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (mainGame.getGamestate() == GAMESTATE.SELECTING_FACTION) {
|
if (keycode == keysList.get(1)) {
|
||||||
if (keycode == Input.Keys.NUM_1) {
|
this.isAPressed = false;
|
||||||
System.out.println("MEGA CORP");
|
return true;
|
||||||
mainGame.setChosenFaction(Faction.MEGACORPORATION);
|
|
||||||
mainGame.initCharacters();
|
|
||||||
mainGame.setGamestate(GAMESTATE.PLAYING);
|
|
||||||
}
|
}
|
||||||
if (keycode == Input.Keys.NUM_2) {
|
if (keycode == keysList.get(2)) {
|
||||||
System.out.println("HACKER");
|
this.isSPressed = false;
|
||||||
mainGame.setChosenFaction(Faction.HACKER);
|
return true;
|
||||||
mainGame.initCharacters();
|
|
||||||
mainGame.setGamestate(GAMESTATE.PLAYING);
|
|
||||||
}
|
}
|
||||||
|
if (keycode == keysList.get(3)) {
|
||||||
|
this.isDPressed = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -140,37 +122,25 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
|
|
||||||
Vector3 touchPoint = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
|
Vector3 touchPoint = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
|
||||||
camera.unproject(touchPoint);
|
camera.unproject(touchPoint);
|
||||||
if (mainGame.getGamestate() == GAMESTATE.PLAYING) {
|
|
||||||
|
|
||||||
|
for (int row = 0; row < mainGame.mapRenderer.getGameTiles().length; row++) {
|
||||||
for (int row = 0; row < mainGame.mapRenderer.getGameTiles().length; row++) {
|
for (int col = 0; col < mainGame.mapRenderer.getGameTiles()[0].length; col++) {
|
||||||
for (int col = 0; col < mainGame.mapRenderer.getGameTiles()[0].length; col++) {
|
GameTile gameTile = mainGame.mapRenderer.getGameTiles()[row][col];
|
||||||
GameTile gameTile = mainGame.mapRenderer.getGameTiles()[row][col];
|
if (gameTile.contains(touchPoint.x, touchPoint.y)) {
|
||||||
if (gameTile.contains(touchPoint.x, touchPoint.y)) {
|
if (button == Input.Buttons.LEFT) {
|
||||||
if (button == Input.Buttons.LEFT) {
|
|
||||||
// System.out.println(gameTile + " row: " + row + ", col: " + col);
|
// System.out.println(gameTile + " row: " + row + ", col: " + col);
|
||||||
if (mainGame.hasCharacterSelected() && !gameTile.containsCharacter()) {
|
if (mainGame.hasCharacterSelected() && !gameTile.containsCharacter()) {
|
||||||
// System.out.println(mainGame.getSelectedCharacter());
|
// System.out.println(mainGame.getSelectedCharacter());
|
||||||
if (gameTile.getSymbol() != '#' && mainGame.mapRenderer.getSurroundedTilesOfCurrentCharacter().contains(gameTile)) {
|
removeCharacterFromTile(mainGame.getSelectedCharacter());
|
||||||
removeCharacterFromTile(mainGame.getSelectedCharacter());
|
gameTile.visit(mainGame.getSelectedCharacter());
|
||||||
gameTile.visit(mainGame.getSelectedCharacter());
|
|
||||||
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) {
|
|
||||||
if (gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) {
|
|
||||||
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
|
||||||
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (gameTile.containsCharacter()
|
|
||||||
&& !mainGame.getSelectedCharacter().equals(gameTile.getCharacter())
|
|
||||||
&& gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) {
|
|
||||||
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
|
||||||
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) {
|
||||||
|
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
||||||
|
}
|
||||||
|
if (gameTile.containsCharacter() && !mainGame.getSelectedCharacter().equals(gameTile.getCharacter())) {
|
||||||
|
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,6 @@ public class GameTile extends Rectangle {
|
|||||||
public boolean visit(GameCharacter character) {
|
public boolean visit(GameCharacter character) {
|
||||||
if (this.character != null) return false;
|
if (this.character != null) return false;
|
||||||
this.character = character;
|
this.character = character;
|
||||||
this.character.setX(this.x);
|
|
||||||
this.character.setY(this.y);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +61,6 @@ public class GameTile extends Rectangle {
|
|||||||
"symbol=" + symbol +
|
"symbol=" + symbol +
|
||||||
", x=" + x +
|
", x=" + x +
|
||||||
", y=" + y +
|
", y=" + y +
|
||||||
", character=" + this.character +
|
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package netwerkprog.game.client.game.map;
|
package netwerkprog.game.client.game.map;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map class to hold a 2d array of tiles which will specify the map
|
* Map class to hold a 2d array of tiles which will specify the map
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,14 +4,9 @@ import com.badlogic.gdx.Gdx;
|
|||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
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 com.badlogic.gdx.graphics.g2d.TextureRegion;
|
|
||||||
import netwerkprog.game.client.MainGame;
|
import netwerkprog.game.client.MainGame;
|
||||||
import netwerkprog.game.util.game.GameCharacter;
|
|
||||||
import netwerkprog.game.util.graphics.Renderable;
|
import netwerkprog.game.util.graphics.Renderable;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import java.awt.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MapRenderer implements Renderable {
|
public class MapRenderer implements Renderable {
|
||||||
private final OrthographicCamera camera;
|
private final OrthographicCamera camera;
|
||||||
@@ -24,8 +19,6 @@ public class MapRenderer implements Renderable {
|
|||||||
private static int y = 0;
|
private static int y = 0;
|
||||||
|
|
||||||
private MainGame mainGame;
|
private MainGame mainGame;
|
||||||
private Texture square;
|
|
||||||
private Texture square2;
|
|
||||||
|
|
||||||
|
|
||||||
public static TextureRegion FLOOR_TILE;
|
public static TextureRegion FLOOR_TILE;
|
||||||
@@ -33,7 +26,6 @@ public class MapRenderer implements Renderable {
|
|||||||
public static TextureRegion PATH_TILE;
|
public static TextureRegion PATH_TILE;
|
||||||
|
|
||||||
private GameTile[][] gameTiles;
|
private GameTile[][] gameTiles;
|
||||||
private List<GameTile> surroundedTilesOfCurrentCharacter;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,14 +50,7 @@ public class MapRenderer implements Renderable {
|
|||||||
* loads all the images for the tiles and adds all the tiles to the array
|
* loads all the images for the tiles and adds all the tiles to the array
|
||||||
*/
|
*/
|
||||||
private void makeTiles() {
|
private void makeTiles() {
|
||||||
mainGame.assets.load("square.png", Texture.class);
|
Texture texture = new Texture(Gdx.files.internal(tilePath));
|
||||||
mainGame.assets.load("square2.png", Texture.class);
|
|
||||||
mainGame.assets.load(tilePath, Texture.class);
|
|
||||||
mainGame.assets.finishLoading();
|
|
||||||
square = mainGame.assets.get("square.png");
|
|
||||||
square2 = mainGame.assets.get("square2.png");
|
|
||||||
|
|
||||||
Texture texture = mainGame.assets.get(tilePath);
|
|
||||||
TextureRegion[][] tileTextures = TextureRegion.split(texture, 32, 32);
|
TextureRegion[][] tileTextures = TextureRegion.split(texture, 32, 32);
|
||||||
|
|
||||||
FLOOR_TILE = tileTextures[1][6];
|
FLOOR_TILE = tileTextures[1][6];
|
||||||
@@ -115,67 +100,18 @@ public class MapRenderer implements Renderable {
|
|||||||
for (int col = 0; col < gameTiles[0].length; col++) {
|
for (int col = 0; col < gameTiles[0].length; col++) {
|
||||||
GameTile cur = gameTileRow[col];
|
GameTile cur = gameTileRow[col];
|
||||||
batch.draw(cur.getTextureRegion(), cur.x, cur.y);
|
batch.draw(cur.getTextureRegion(), cur.x, cur.y);
|
||||||
|
|
||||||
if (cur.containsCharacter()) {
|
if (cur.containsCharacter()) {
|
||||||
batch.draw(cur.getCharacter().getTextureRegion(), cur.x, cur.y);
|
batch.draw(cur.getCharacter().getTextureRegion(), cur.x, cur.y);
|
||||||
if (cur.getCharacter().equals(mainGame.getSelectedCharacter())) {
|
// System.out.println("drawing character at " + cur.x + " " + cur.y);
|
||||||
batch.draw(square, cur.x, cur.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (surroundedTilesOfCurrentCharacter != null && !surroundedTilesOfCurrentCharacter.isEmpty()) {
|
|
||||||
for (GameTile gameTile : surroundedTilesOfCurrentCharacter) {
|
|
||||||
batch.draw(square2, gameTile.x, gameTile.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
batch.end();
|
batch.end();
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[][] directions = new int[][]{{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}};
|
|
||||||
|
|
||||||
public List<GameTile> setSurroundedTilesOfCurrentCharacter(int x, int y) {
|
|
||||||
List<GameTile> res = new ArrayList<GameTile>();
|
|
||||||
for (int[] direction : directions) {
|
|
||||||
int cx = x + direction[0];
|
|
||||||
int cy = y + direction[1];
|
|
||||||
if (cy >= 0 && cy < gameTiles.length)
|
|
||||||
if (cx >= 0 && cx < gameTiles[cy].length)
|
|
||||||
if (gameTiles[cy][cx].getSymbol() != '#')
|
|
||||||
res.add(gameTiles[cy][cx]);
|
|
||||||
}
|
|
||||||
surroundedTilesOfCurrentCharacter = res;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GameTile getTile(GameCharacter character) {
|
|
||||||
for (GameTile[] tiles : this.gameTiles) {
|
|
||||||
for (GameTile tile : tiles) {
|
|
||||||
if (tile.containsCharacter())
|
|
||||||
if (tile.getCharacter().equals(character)) {
|
|
||||||
return tile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Point getPos(GameTile tile) {
|
|
||||||
for (int row = 0; row < this.gameTiles.length; row++) {
|
|
||||||
for (int col = 0; col < this.gameTiles[0].length; col++) {
|
|
||||||
if (gameTiles[row][col].equals(tile)) {
|
|
||||||
return new Point(col, row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new Point(-1, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(double deltaTime) {
|
public void update(double deltaTime) {
|
||||||
|
|
||||||
@@ -191,9 +127,4 @@ public class MapRenderer implements Renderable {
|
|||||||
public GameTile[][] getGameTiles() {
|
public GameTile[][] getGameTiles() {
|
||||||
return gameTiles;
|
return gameTiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GameTile> getSurroundedTilesOfCurrentCharacter() {
|
|
||||||
return surroundedTilesOfCurrentCharacter;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
43
core/src/netwerkprog/game/server/Parser.java
Normal file
43
core/src/netwerkprog/game/server/Parser.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package netwerkprog.game.server;
|
||||||
|
|
||||||
|
import netwerkprog.game.client.game.characters.DevTest1;
|
||||||
|
import netwerkprog.game.client.game.characters.DevTest2;
|
||||||
|
import netwerkprog.game.client.game.characters.DevTest3;
|
||||||
|
import netwerkprog.game.server.controllers.DataController;
|
||||||
|
import netwerkprog.game.util.data.ParserCallback;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Parser {
|
||||||
|
private final ParserCallback callback;
|
||||||
|
private Scanner scanner;
|
||||||
|
|
||||||
|
private final DataController dataController;
|
||||||
|
|
||||||
|
public Parser(ParserCallback callback) {
|
||||||
|
this.callback = callback;
|
||||||
|
this.dataController = new DataController();
|
||||||
|
|
||||||
|
this.dataController.addAllCharacters(new DevTest1(), new DevTest2(), new DevTest3());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void parse(String request) {
|
||||||
|
String data = "";
|
||||||
|
this.scanner = new Scanner(request);
|
||||||
|
scanner.useDelimiter("~");
|
||||||
|
String type = scanner.next();
|
||||||
|
String name = scanner.next();
|
||||||
|
|
||||||
|
if (type.equals("character")) {
|
||||||
|
try {
|
||||||
|
data = dataController.getCharacter(name).toString();
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
data = ex.getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
callback.onDataReceived(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,16 @@
|
|||||||
package netwerkprog.game.server;
|
package netwerkprog.game.server;
|
||||||
|
|
||||||
import netwerkprog.game.server.controllers.DataController;
|
|
||||||
import netwerkprog.game.server.controllers.SessionController;
|
import netwerkprog.game.server.controllers.SessionController;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Server {
|
public class Server {
|
||||||
private SessionController sessionController;
|
private SessionController sessionController;
|
||||||
private DataController dataController;
|
|
||||||
private Thread sessionThread;
|
private Thread sessionThread;
|
||||||
private HashMap<String, Thread> gameThreads;
|
private HashMap<String, Thread> gameThreads;
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
this.sessionController = new SessionController(this);
|
this.sessionController = new SessionController();
|
||||||
this.dataController = new DataController();
|
|
||||||
|
|
||||||
this.gameThreads = new HashMap<>();
|
this.gameThreads = new HashMap<>();
|
||||||
this.sessionThread = new Thread(sessionController);
|
this.sessionThread = new Thread(sessionController);
|
||||||
@@ -35,8 +32,4 @@ public class Server {
|
|||||||
// gameThreads.get(game).start();
|
// gameThreads.get(game).start();
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataController getDataController() {
|
|
||||||
return dataController;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,38 @@
|
|||||||
package netwerkprog.game.server;
|
package netwerkprog.game.server;
|
||||||
|
|
||||||
import netwerkprog.game.server.controllers.DataController;
|
|
||||||
import netwerkprog.game.server.controllers.SessionController;
|
import netwerkprog.game.server.controllers.SessionController;
|
||||||
import netwerkprog.game.util.data.ConnectionData;
|
import netwerkprog.game.util.data.ParserCallback;
|
||||||
import netwerkprog.game.util.data.Data;
|
|
||||||
import netwerkprog.game.util.data.DataCallback;
|
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
import java.net.Socket;
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
|
|
||||||
public class ServerClient implements Runnable {
|
public class ServerClient implements Runnable, ParserCallback {
|
||||||
private ObjectInputStream in;
|
private DataInputStream in;
|
||||||
private ObjectOutputStream out;
|
private DataOutputStream out;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final SessionController server;
|
private final SessionController server;
|
||||||
private final DataCallback callback;
|
private final Parser parser;
|
||||||
private boolean isConnected;
|
private boolean isConnected;
|
||||||
|
|
||||||
public ServerClient(String name, ObjectInputStream in, ObjectOutputStream out, SessionController server, DataController dataController) {
|
public ServerClient(String name, Socket socket, SessionController server) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.callback = dataController;
|
this.parser = new Parser(this);
|
||||||
this.in = in;
|
try {
|
||||||
this.out = out;
|
this.in = new DataInputStream(socket.getInputStream());
|
||||||
this.isConnected = true;
|
this.out = new DataOutputStream(socket.getOutputStream());
|
||||||
|
this.isConnected = true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
this.isConnected = false;
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeData(Data data) {
|
public void writeUTF(String text) {
|
||||||
try {
|
try {
|
||||||
this.out.writeObject(data);
|
this.out.writeUTF(text);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -39,26 +42,14 @@ public class ServerClient implements Runnable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
while (this.isConnected) {
|
while (this.isConnected) {
|
||||||
try {
|
try {
|
||||||
Object object = this.in.readObject();
|
String received = this.in.readUTF();
|
||||||
if (object instanceof Data) {
|
this.parser.parse(received);
|
||||||
Data data = (Data) object;
|
|
||||||
if (data.getPayload() instanceof ConnectionData) {
|
|
||||||
ConnectionData connectionData = (ConnectionData) data.getPayload();
|
|
||||||
if (connectionData.getAction().equals("Disconnect")) {
|
|
||||||
this.isConnected = false;
|
|
||||||
//todo properly remove thread.
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
callback.onDataReceived((Data) this.in.readObject());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("[SERVERCLIENT] caught exception - " + e.getMessage());
|
System.out.println("[SERVERCLIENT] caught exception - " + e.getMessage());
|
||||||
System.out.println("[SERVERCLIENT] terminating failing connection...");
|
System.out.println("[SERVERCLIENT] terminating failing connection...");
|
||||||
this.isConnected = false;
|
this.isConnected = false;
|
||||||
System.out.println("[SERVERCLIENT] done!");
|
System.out.println("[SERVERCLIENT] done!");
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,4 +57,9 @@ public class ServerClient implements Runnable {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDataReceived(String data) {
|
||||||
|
writeUTF(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
package netwerkprog.game.server.controllers;
|
package netwerkprog.game.server.controllers;
|
||||||
|
|
||||||
import netwerkprog.game.util.data.CharacterData;
|
|
||||||
import netwerkprog.game.util.data.Data;
|
|
||||||
import netwerkprog.game.util.data.DataCallback;
|
|
||||||
import netwerkprog.game.util.game.GameCharacter;
|
import netwerkprog.game.util.game.GameCharacter;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
public class DataController implements DataCallback {
|
public class DataController {
|
||||||
private final HashSet<GameCharacter> gameCharacters;
|
private final HashSet<GameCharacter> gameCharacters;
|
||||||
|
|
||||||
public DataController() {
|
public DataController() {
|
||||||
@@ -47,15 +44,4 @@ public class DataController implements DataCallback {
|
|||||||
}
|
}
|
||||||
throw new IllegalArgumentException("The character does not exist.");
|
throw new IllegalArgumentException("The character does not exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDataReceived(Data data) {
|
|
||||||
switch (data.getType()) {
|
|
||||||
case "Character" :
|
|
||||||
if (data.getPayload() instanceof CharacterData) {
|
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package netwerkprog.game.server.controllers;
|
package netwerkprog.game.server.controllers;
|
||||||
|
|
||||||
import netwerkprog.game.server.Server;
|
|
||||||
import netwerkprog.game.server.ServerClient;
|
import netwerkprog.game.server.ServerClient;
|
||||||
import netwerkprog.game.util.application.Controller;
|
import netwerkprog.game.util.application.Controller;
|
||||||
import netwerkprog.game.util.data.ConnectionData;
|
|
||||||
import netwerkprog.game.util.data.Data;
|
import netwerkprog.game.util.data.Data;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
@@ -19,14 +17,12 @@ import java.util.Set;
|
|||||||
* The sessionController manages any connections from new clients and assigns individual threads to said clients.
|
* The sessionController manages any connections from new clients and assigns individual threads to said clients.
|
||||||
*/
|
*/
|
||||||
public class SessionController extends Controller {
|
public class SessionController extends Controller {
|
||||||
private Server server;
|
|
||||||
private ServerSocket serverSocket;
|
private ServerSocket serverSocket;
|
||||||
private final ArrayList<ServerClient> clients = new ArrayList<>();
|
private final ArrayList<ServerClient> clients = new ArrayList<>();
|
||||||
private final HashMap<String, Thread> clientThreads = new HashMap<>();
|
private final HashMap<String, Thread> clientThreads = new HashMap<>();
|
||||||
private boolean listening;
|
private boolean listening;
|
||||||
|
|
||||||
public SessionController(Server server) {
|
public SessionController() {
|
||||||
this.server = server;
|
|
||||||
this.listening = true;
|
this.listening = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,66 +59,43 @@ public class SessionController extends Controller {
|
|||||||
try {
|
try {
|
||||||
System.out.println("[SERVER] got new client on " + socket.getInetAddress().getHostAddress());
|
System.out.println("[SERVER] got new client on " + socket.getInetAddress().getHostAddress());
|
||||||
ObjectOutputStream outputStream = new ObjectOutputStream(socket.getOutputStream());
|
ObjectOutputStream outputStream = new ObjectOutputStream(socket.getOutputStream());
|
||||||
ObjectInputStream inputStream = new ObjectInputStream(socket.getInputStream());
|
DataInputStream inputStream = new DataInputStream(socket.getInputStream());
|
||||||
|
|
||||||
String username = "";
|
outputStream.writeUTF("Enter username: ");
|
||||||
boolean registering = true;
|
String username = inputStream.readUTF();
|
||||||
|
|
||||||
while (registering) {
|
|
||||||
outputStream.writeObject(new ConnectionData("Connect", "Please give a username"));
|
|
||||||
Object object = inputStream.readObject();
|
|
||||||
|
|
||||||
if (object instanceof Data) {
|
|
||||||
Data data = (Data) object;
|
|
||||||
if (data instanceof ConnectionData) {
|
|
||||||
ConnectionData connectionData = (ConnectionData) data.getPayload();
|
|
||||||
if (connectionData.getAction().equals("Connect")) {
|
|
||||||
username = connectionData.getMessage();
|
|
||||||
outputStream.writeObject(new ConnectionData("Connect", "Confirm"));
|
|
||||||
registering = false;
|
|
||||||
} else {
|
|
||||||
//todo error messaging.
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//todo error messaging.
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//todo error messaging.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("[SERVER] got username " + username);
|
System.out.println("[SERVER] got username " + username);
|
||||||
ServerClient serverClient = new ServerClient(username, inputStream, outputStream, this, server.getDataController());
|
ServerClient serverClient = new ServerClient(username, socket, this);
|
||||||
|
|
||||||
Thread t = new Thread(serverClient);
|
Thread t = new Thread(serverClient);
|
||||||
t.start();
|
t.start();
|
||||||
|
|
||||||
this.clientThreads.put(username,t);
|
this.clientThreads.put(username,t);
|
||||||
this.clients.add(serverClient);
|
this.clients.add(serverClient);
|
||||||
} catch (IOException | ClassNotFoundException ex) {
|
} catch (IOException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a server message to all connected clients.
|
* Sends a server message to all connected clients.
|
||||||
* @param data message.
|
* @param text message.
|
||||||
*/
|
*/
|
||||||
public void serverMessage(Data data) {
|
public void serverMessage(String text) {
|
||||||
for (ServerClient serverClient : clients) {
|
for (ServerClient serverClient : clients) {
|
||||||
serverClient.writeData(data);
|
serverClient.writeUTF(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message to a specific user.
|
* Sends a message to a specific user.
|
||||||
* @param name user.
|
* @param name user.
|
||||||
* @param data message.
|
* @param text message.
|
||||||
*/
|
*/
|
||||||
public void personalMessage(String name, Data data) {
|
public void personalMessage(String name, String text) {
|
||||||
for (ServerClient serverClient : clients) {
|
for (ServerClient serverClient : clients) {
|
||||||
if (serverClient.getName().equals(name)) {
|
if (serverClient.getName().equals(name)) {
|
||||||
serverClient.writeData(data);
|
serverClient.writeUTF(text);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,7 +113,7 @@ public class SessionController extends Controller {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
this.clientThreads.remove(serverClient.getName());
|
this.clientThreads.remove(serverClient.getName());
|
||||||
//this.serverMessage(serverClient.getName() + " left!");
|
this.serverMessage(serverClient.getName() + " left!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
package netwerkprog.game.util.data;
|
|
||||||
|
|
||||||
import netwerkprog.game.util.game.GameCharacter;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class CharacterData extends Data implements Serializable {
|
|
||||||
private final String name;
|
|
||||||
private final GameCharacter character;
|
|
||||||
|
|
||||||
public CharacterData(String name, GameCharacter character) {
|
|
||||||
super("Character");
|
|
||||||
super.setPayload(this);
|
|
||||||
this.name = name;
|
|
||||||
this.character = character;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package netwerkprog.game.util.data;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
public class ConnectionData extends Data implements Serializable {
|
|
||||||
private final String action;
|
|
||||||
private final String message;
|
|
||||||
|
|
||||||
public ConnectionData(String action, String message) {
|
|
||||||
super("Connection");
|
|
||||||
super.setPayload(this);
|
|
||||||
this.action = action;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAction() {
|
|
||||||
return action;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +1,7 @@
|
|||||||
package netwerkprog.game.util.data;
|
package netwerkprog.game.util.data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
public class Data {
|
||||||
|
|
||||||
public class Data implements Serializable {
|
|
||||||
public static int port() {
|
public static int port() {
|
||||||
return 8000;
|
return 8000;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String objectType;
|
|
||||||
private Data payload;
|
|
||||||
|
|
||||||
public Data(String type) {
|
|
||||||
this.objectType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setObjectType(String objectType) {
|
|
||||||
this.objectType = objectType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPayload(Data payload) {
|
|
||||||
this.payload = payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return objectType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Data getPayload() {
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
package netwerkprog.game.util.data;
|
|
||||||
|
|
||||||
public interface DataCallback {
|
|
||||||
void onDataReceived(Data data);
|
|
||||||
}
|
|
||||||
@@ -1,35 +1,29 @@
|
|||||||
package netwerkprog.game.util.game;
|
package netwerkprog.game.util.game;
|
||||||
|
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||||
import netwerkprog.game.client.game.map.GameTile;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class GameCharacter extends Actor implements Comparable<GameCharacter>, Serializable {
|
public abstract class GameCharacter extends Actor implements Comparable<GameCharacter> {
|
||||||
protected String name;
|
protected String name;
|
||||||
protected Faction faction;
|
protected Faction faction;
|
||||||
protected HashSet<Ability> abilities;
|
protected HashSet<Ability> abilities;
|
||||||
protected boolean override;
|
protected boolean override;
|
||||||
protected TextureRegion textureRegion;
|
protected TextureRegion textureRegion;
|
||||||
protected int health;
|
|
||||||
protected List<GameTile> allowedToMove;
|
|
||||||
|
|
||||||
public GameCharacter(String name, Faction faction, TextureRegion textureRegion, Ability... abilities) {
|
public GameCharacter(String name, Faction faction, TextureRegion textureRegion, Ability... abilities) {
|
||||||
super();
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.faction = faction;
|
this.faction = faction;
|
||||||
this.abilities = new HashSet<>(Arrays.asList(abilities));
|
this.abilities = new HashSet<>(Arrays.asList(abilities));
|
||||||
this.override = false;
|
this.override = false;
|
||||||
this.textureRegion = textureRegion;
|
this.textureRegion = textureRegion;
|
||||||
this.health = 100;
|
|
||||||
this.allowedToMove = new ArrayList<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -44,28 +38,6 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
|
|||||||
this.abilities.remove(ability);
|
this.abilities.remove(ability);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHealth() {
|
|
||||||
return health;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHealth(int health) {
|
|
||||||
this.health = health;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void heal(int amount) {
|
|
||||||
this.health += amount;
|
|
||||||
if (this.health > 100) this.health = 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void damage(int amount) {
|
|
||||||
this.health -= amount;
|
|
||||||
if (this.health < 0) this. health = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDead() {
|
|
||||||
return this.health <= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void changeControl() {
|
public void changeControl() {
|
||||||
this.override = !this.override;
|
this.override = !this.override;
|
||||||
}
|
}
|
||||||
@@ -97,7 +69,7 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(GameCharacter o) {
|
public int compareTo(GameCharacter o) {
|
||||||
return this.health - o.health;
|
return this.name.compareTo(o.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -105,20 +77,6 @@ public abstract class GameCharacter extends Actor implements Comparable<GameChar
|
|||||||
return "GameCharacter{" +
|
return "GameCharacter{" +
|
||||||
"name='" + name + '\'' +
|
"name='" + name + '\'' +
|
||||||
", faction=" + faction +
|
", faction=" + faction +
|
||||||
", x=" + super.getX() +
|
|
||||||
", y=" + super.getY() +
|
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GameTile> getAllowedToMove() {
|
|
||||||
return allowedToMove;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAllowedToMove(List<GameTile> allowedToMove) {
|
|
||||||
this.allowedToMove = allowedToMove;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Faction getFaction() {
|
|
||||||
return faction;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
package netwerkprog.game.util.graphics;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|
||||||
import com.badlogic.gdx.utils.Disposable;
|
|
||||||
|
|
||||||
public class TextRenderer implements Disposable {
|
|
||||||
private BitmapFont font;
|
|
||||||
private SpriteBatch batch;
|
|
||||||
private OrthographicCamera cam;
|
|
||||||
|
|
||||||
public TextRenderer() {
|
|
||||||
font = new BitmapFont();
|
|
||||||
batch = new SpriteBatch();
|
|
||||||
cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
|
||||||
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void dispose() {
|
|
||||||
font.dispose();
|
|
||||||
batch.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void resize(int screenWidth, int screenHeight) {
|
|
||||||
cam = new OrthographicCamera(screenWidth, screenHeight);
|
|
||||||
cam.translate(screenWidth / 2, screenHeight / 2);
|
|
||||||
cam.update();
|
|
||||||
batch.setProjectionMatrix(cam.combined);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void render(String text, float x, float y) {
|
|
||||||
batch.begin();
|
|
||||||
font.draw(batch, text, x, y);
|
|
||||||
batch.end();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package netwerkprog.game.util.tree;
|
package netwerkprog.game.util.tree;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
public class BST<E extends Comparable<E>> extends AbstractTree<E> {
|
public class BST<E extends Comparable<E>> extends AbstractTree<E> {
|
||||||
protected TreeNode<E> root;
|
protected TreeNode<E> root;
|
||||||
protected int size = 0;
|
protected int size = 0;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class RestartSessionControllerTest {
|
|||||||
SessionController sessionController;
|
SessionController sessionController;
|
||||||
Thread sessionThread;
|
Thread sessionThread;
|
||||||
|
|
||||||
sessionController = new SessionController(null);
|
sessionController = new SessionController();
|
||||||
sessionThread = new Thread(sessionController);
|
sessionThread = new Thread(sessionController);
|
||||||
|
|
||||||
sessionThread.start();
|
sessionThread.start();
|
||||||
|
|||||||
Reference in New Issue
Block a user