Merge branch 'master' of https://github.com/SemvdH/netwerk-programming-eindopdracht
# Conflicts: # core/src/netwerkprog/game/client/MainGame.java
This commit is contained in:
@@ -29,6 +29,7 @@ import netwerkprog.game.util.data.character.MoveData;
|
|||||||
import netwerkprog.game.util.data.connection.NameData;
|
import netwerkprog.game.util.data.connection.NameData;
|
||||||
import netwerkprog.game.util.data.connection.ReadyData;
|
import netwerkprog.game.util.data.connection.ReadyData;
|
||||||
import netwerkprog.game.util.data.connection.TeamData;
|
import netwerkprog.game.util.data.connection.TeamData;
|
||||||
|
import netwerkprog.game.util.data.connection.TurnData;
|
||||||
import netwerkprog.game.util.game.Faction;
|
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;
|
||||||
@@ -254,14 +255,25 @@ public class MainGame extends Game implements ClientCallback {
|
|||||||
frameRate.update();
|
frameRate.update();
|
||||||
camera.update();
|
camera.update();
|
||||||
this.gameInputProcessor.update();
|
this.gameInputProcessor.update();
|
||||||
this.team.update(Gdx.graphics.getDeltaTime());
|
|
||||||
this.enemyTeam.update(Gdx.graphics.getDeltaTime());
|
|
||||||
if (this.team.isDead() || this.enemyTeam.isDead()) {
|
if (this.team.isDead() || this.enemyTeam.isDead()) {
|
||||||
this.setGameOver(true);
|
this.setGameOver(true);
|
||||||
}
|
}
|
||||||
if (this.isGameOver()) {
|
if (this.isGameOver()) {
|
||||||
this.setGamestate(GAMESTATE.ENDED);
|
this.setGamestate(GAMESTATE.ENDED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (selectedCharacter.isDead()) {
|
||||||
|
nextCharacter(selectedCharacter);
|
||||||
|
}
|
||||||
|
this.team.update(Gdx.graphics.getDeltaTime());
|
||||||
|
this.enemyTeam.update(Gdx.graphics.getDeltaTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void nextCharacter(GameCharacter c) {
|
||||||
|
for (GameCharacter character : this.team.getMembers()) {
|
||||||
|
if (!character.equals(c)) this.setSelectedCharacter(character);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -304,10 +316,12 @@ public class MainGame extends Game implements ClientCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setSelectedCharacter(GameCharacter character) {
|
public void setSelectedCharacter(GameCharacter character) {
|
||||||
this.selectedCharacter = character;
|
if (!character.isDead()) {
|
||||||
GameTile characterTile = mapRenderer.getTile(character);
|
this.selectedCharacter = character;
|
||||||
Point pos = mapRenderer.getPos(characterTile);
|
GameTile characterTile = mapRenderer.getTile(character);
|
||||||
mapRenderer.setSurroundedTilesOfCurrentCharacter(pos.x, pos.y);
|
Point pos = mapRenderer.getPos(characterTile);
|
||||||
|
mapRenderer.setSurroundedTilesOfCurrentCharacter(pos.x, pos.y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GAMESTATE getGamestate() {
|
public GAMESTATE getGamestate() {
|
||||||
@@ -351,6 +365,7 @@ public class MainGame extends Game implements ClientCallback {
|
|||||||
if (turn == 3) {
|
if (turn == 3) {
|
||||||
this.turn = 0;
|
this.turn = 0;
|
||||||
this.setPlayersTurn(false);
|
this.setPlayersTurn(false);
|
||||||
|
send(new TurnData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,7 +378,6 @@ public class MainGame extends Game implements ClientCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void send(Data data) {
|
public void send(Data data) {
|
||||||
System.out.println("[MAINGAME] sending data " + data);
|
|
||||||
this.client.writeData(data);
|
this.client.writeData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,43 +390,34 @@ public class MainGame extends Game implements ClientCallback {
|
|||||||
} else if (data instanceof TeamData) {
|
} else if (data instanceof TeamData) {
|
||||||
// check if it is not our own message
|
// check if it is not our own message
|
||||||
if (!((TeamData) data).getUsername().equals(this.username)) {
|
if (!((TeamData) data).getUsername().equals(this.username)) {
|
||||||
System.out.println(username + "got team data: " + ((TeamData) data).getFaction());
|
|
||||||
// if we have already chosen a faction, so we were first
|
// if we have already chosen a faction, so we were first
|
||||||
TeamData teamData = (TeamData) data;
|
TeamData teamData = (TeamData) data;
|
||||||
enemyFaction = teamData.getFaction();
|
enemyFaction = teamData.getFaction();
|
||||||
System.out.println("Got enemy faction: " + enemyFaction);
|
|
||||||
if (this.chosenFaction == null) {
|
if (this.chosenFaction == null) {
|
||||||
if (enemyFaction == Faction.HACKER) {
|
if (enemyFaction == Faction.HACKER) {
|
||||||
System.out.println("enemy is hacker");
|
|
||||||
this.chosenFaction = Faction.MEGACORPORATION;
|
this.chosenFaction = Faction.MEGACORPORATION;
|
||||||
this.enemyReady = true;
|
this.enemyReady = true;
|
||||||
this.ready = true;
|
this.ready = true;
|
||||||
} else {
|
} else {
|
||||||
System.out.println("enemy is mega corp");
|
|
||||||
this.chosenFaction = Faction.HACKER;
|
this.chosenFaction = Faction.HACKER;
|
||||||
this.enemyReady = true;
|
this.enemyReady = true;
|
||||||
this.ready = true;
|
this.ready = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (data instanceof ReadyData) {
|
|
||||||
ReadyData readyData = (ReadyData) data;
|
|
||||||
if (!readyData.getUsername().equals(this.username)) {
|
|
||||||
this.enemyReady = true;
|
|
||||||
System.out.println("enemy is ready");
|
|
||||||
}
|
|
||||||
} else if (data instanceof MoveData) {
|
} else if (data instanceof MoveData) {
|
||||||
MoveData moveData = (MoveData) data;
|
MoveData moveData = (MoveData) data;
|
||||||
System.out.println(moveData);
|
if (!moveData.getUsername().equals(this.username)) {
|
||||||
if (moveData.getUsername().equals(this.username)) {
|
GameTile tile = mapRenderer.getGameTile(moveData.getPos());
|
||||||
moveData.getTile().visit(team.get(moveData.getCharacterName()));
|
GameCharacter character = enemyTeam.get(moveData.getCharacterName());
|
||||||
} else {
|
gameInputProcessor.removeCharacterFromTile(character);
|
||||||
moveData.getTile().visit(enemyTeam.get(moveData.getCharacterName()));
|
tile.visit(character);
|
||||||
}
|
}
|
||||||
} else if (data instanceof DamageData) {
|
} else if (data instanceof DamageData) {
|
||||||
DamageData damageData = (DamageData) data;
|
DamageData damageData = (DamageData) data;
|
||||||
team.get(damageData.getName()).damage(10);
|
team.get(damageData.getName()).damage(100);
|
||||||
|
} else if (data instanceof TurnData) {
|
||||||
|
this.playersTurn = !this.playersTurn;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -425,6 +430,7 @@ public class MainGame extends Game implements ClientCallback {
|
|||||||
initCharacters();
|
initCharacters();
|
||||||
camera.translate(-400, 0);
|
camera.translate(-400, 0);
|
||||||
|
|
||||||
|
this.playersTurn = true;
|
||||||
setGamestate(GAMESTATE.PLAYING);
|
setGamestate(GAMESTATE.PLAYING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,6 +439,7 @@ public class MainGame extends Game implements ClientCallback {
|
|||||||
setChosenFaction(Faction.MEGACORPORATION);
|
setChosenFaction(Faction.MEGACORPORATION);
|
||||||
send(new TeamData(Faction.MEGACORPORATION, getUsername()));
|
send(new TeamData(Faction.MEGACORPORATION, getUsername()));
|
||||||
initCharacters();
|
initCharacters();
|
||||||
|
this.playersTurn = false;
|
||||||
setGamestate(GAMESTATE.PLAYING);
|
setGamestate(GAMESTATE.PLAYING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -120,12 +120,12 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
} else if (mainGame.getGamestate() == GAMESTATE.SELECTING_FACTION) {
|
} else if (mainGame.getGamestate() == GAMESTATE.SELECTING_FACTION) {
|
||||||
if (keycode == Input.Keys.NUM_1) {
|
if (keycode == Input.Keys.NUM_1) {
|
||||||
System.out.println("choosing mega");
|
System.out.println("choosing mega");
|
||||||
mainGame.send(new TeamData(Faction.MEGACORPORATION,mainGame.getUsername()));
|
mainGame.send(new TeamData(Faction.MEGACORPORATION, mainGame.getUsername()));
|
||||||
mainGame.chooseMegaCorp();
|
mainGame.chooseMegaCorp();
|
||||||
}
|
}
|
||||||
if (keycode == Input.Keys.NUM_2) {
|
if (keycode == Input.Keys.NUM_2) {
|
||||||
System.out.println("choosing hacker");
|
System.out.println("choosing hacker");
|
||||||
mainGame.send(new TeamData(Faction.HACKER,mainGame.getUsername()));
|
mainGame.send(new TeamData(Faction.HACKER, mainGame.getUsername()));
|
||||||
mainGame.chooseHacker();
|
mainGame.chooseHacker();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,31 +160,38 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
gameTile.visit(mainGame.getSelectedCharacter());
|
gameTile.visit(mainGame.getSelectedCharacter());
|
||||||
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
||||||
mainGame.increaseTurn();
|
mainGame.increaseTurn();
|
||||||
mainGame.send(new MoveData(mainGame.getUsername(),mainGame.getSelectedCharacter().getName(),gameTile));
|
mainGame.send(new MoveData(mainGame.getUsername(), mainGame.getSelectedCharacter().getName(), mainGame.mapRenderer.getPos(gameTile)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// clicking on enemy
|
// clicking on enemy
|
||||||
if (mainGame.hasCharacterSelected() && gameTile.containsCharacter() && gameTile.getCharacter().getFaction() != mainGame.getChosenFaction()) {
|
if (mainGame.hasCharacterSelected() && gameTile.containsCharacter() && gameTile.getCharacter().getFaction() != mainGame.getChosenFaction()) {
|
||||||
if (mainGame.mapRenderer.getSurroundedTilesOfCurrentCharacter().contains(gameTile)) {
|
if (mainGame.mapRenderer.getSurroundedTilesOfCurrentCharacter().contains(gameTile)) {
|
||||||
gameTile.getCharacter().damage(10);
|
if (!gameTile.getCharacter().isDead()) {
|
||||||
mainGame.increaseTurn();
|
gameTile.getCharacter().damage(100);
|
||||||
mainGame.send(new DamageData(gameTile.getCharacter().getName()));
|
mainGame.increaseTurn();
|
||||||
|
mainGame.send(new DamageData(gameTile.getCharacter().getName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// set selected character
|
// set selected character
|
||||||
if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) {
|
if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) {
|
||||||
if (gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) {
|
if (gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) {
|
||||||
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
if (!gameTile.getCharacter().isDead()) {
|
||||||
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
||||||
|
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// switch character
|
// switch character
|
||||||
if (gameTile.containsCharacter()
|
if (gameTile.containsCharacter()
|
||||||
&& !mainGame.getSelectedCharacter().equals(gameTile.getCharacter())
|
&& !mainGame.getSelectedCharacter().equals(gameTile.getCharacter())
|
||||||
&& gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) {
|
&& gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) {
|
||||||
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
if (!gameTile.getCharacter().isDead()) {
|
||||||
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
||||||
|
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -195,7 +202,7 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeCharacterFromTile(GameCharacter character) {
|
public void removeCharacterFromTile(GameCharacter character) {
|
||||||
rowLoop:
|
rowLoop:
|
||||||
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++) {
|
||||||
|
|||||||
@@ -193,6 +193,17 @@ public class MapRenderer implements Renderable {
|
|||||||
return new Point(-1, -1);
|
return new Point(-1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GameTile getGameTile(Point pos) {
|
||||||
|
for (int row = 0; row < this.gameTiles.length; row++) {
|
||||||
|
for (int col = 0; col < this.gameTiles[0].length; col++) {
|
||||||
|
if (row == pos.y && col == pos.x) {
|
||||||
|
return this.gameTiles[row][col];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(double deltaTime) {
|
public void update(double deltaTime) {
|
||||||
|
|
||||||
|
|||||||
@@ -3,17 +3,19 @@ package netwerkprog.game.util.data.character;
|
|||||||
import netwerkprog.game.client.game.map.GameTile;
|
import netwerkprog.game.client.game.map.GameTile;
|
||||||
import netwerkprog.game.util.data.Data;
|
import netwerkprog.game.util.data.Data;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
|
||||||
public class MoveData extends Data {
|
public class MoveData extends Data {
|
||||||
private final String username;
|
private final String username;
|
||||||
private final String characterName;
|
private final String characterName;
|
||||||
private final GameTile tile;
|
private final Point pos;
|
||||||
|
|
||||||
public MoveData(String username, String characterName, GameTile tile) {
|
public MoveData(String username, String characterName, Point pos) {
|
||||||
super("Move");
|
super("Move");
|
||||||
super.setPayload(this);
|
super.setPayload(this);
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.characterName = characterName;
|
this.characterName = characterName;
|
||||||
this.tile = tile;
|
this.pos = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
@@ -24,7 +26,7 @@ public class MoveData extends Data {
|
|||||||
return characterName;
|
return characterName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameTile getTile() {
|
public Point getPos() {
|
||||||
return tile;
|
return pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package netwerkprog.game.util.data.connection;
|
||||||
|
|
||||||
|
import netwerkprog.game.util.data.Data;
|
||||||
|
|
||||||
|
public class TurnData extends Data {
|
||||||
|
public TurnData() {
|
||||||
|
super("turn");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user