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.ReadyData;
|
||||
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.GameCharacter;
|
||||
import netwerkprog.game.util.graphics.FrameRate;
|
||||
@@ -254,14 +255,25 @@ public class MainGame extends Game implements ClientCallback {
|
||||
frameRate.update();
|
||||
camera.update();
|
||||
this.gameInputProcessor.update();
|
||||
this.team.update(Gdx.graphics.getDeltaTime());
|
||||
this.enemyTeam.update(Gdx.graphics.getDeltaTime());
|
||||
|
||||
if (this.team.isDead() || this.enemyTeam.isDead()) {
|
||||
this.setGameOver(true);
|
||||
}
|
||||
if (this.isGameOver()) {
|
||||
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
|
||||
@@ -304,10 +316,12 @@ public class MainGame extends Game implements ClientCallback {
|
||||
}
|
||||
|
||||
public void setSelectedCharacter(GameCharacter character) {
|
||||
this.selectedCharacter = character;
|
||||
GameTile characterTile = mapRenderer.getTile(character);
|
||||
Point pos = mapRenderer.getPos(characterTile);
|
||||
mapRenderer.setSurroundedTilesOfCurrentCharacter(pos.x, pos.y);
|
||||
if (!character.isDead()) {
|
||||
this.selectedCharacter = character;
|
||||
GameTile characterTile = mapRenderer.getTile(character);
|
||||
Point pos = mapRenderer.getPos(characterTile);
|
||||
mapRenderer.setSurroundedTilesOfCurrentCharacter(pos.x, pos.y);
|
||||
}
|
||||
}
|
||||
|
||||
public GAMESTATE getGamestate() {
|
||||
@@ -351,6 +365,7 @@ public class MainGame extends Game implements ClientCallback {
|
||||
if (turn == 3) {
|
||||
this.turn = 0;
|
||||
this.setPlayersTurn(false);
|
||||
send(new TurnData());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,7 +378,6 @@ public class MainGame extends Game implements ClientCallback {
|
||||
}
|
||||
|
||||
public void send(Data data) {
|
||||
System.out.println("[MAINGAME] sending data " + data);
|
||||
this.client.writeData(data);
|
||||
}
|
||||
|
||||
@@ -376,43 +390,34 @@ public class MainGame extends Game implements ClientCallback {
|
||||
} else if (data instanceof TeamData) {
|
||||
// check if it is not our own message
|
||||
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
|
||||
TeamData teamData = (TeamData) data;
|
||||
enemyFaction = teamData.getFaction();
|
||||
System.out.println("Got enemy faction: " + enemyFaction);
|
||||
if (this.chosenFaction == null) {
|
||||
if (enemyFaction == Faction.HACKER) {
|
||||
System.out.println("enemy is hacker");
|
||||
this.chosenFaction = Faction.MEGACORPORATION;
|
||||
this.enemyReady = true;
|
||||
this.ready = true;
|
||||
} else {
|
||||
System.out.println("enemy is mega corp");
|
||||
this.chosenFaction = Faction.HACKER;
|
||||
this.enemyReady = 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) {
|
||||
MoveData moveData = (MoveData) data;
|
||||
System.out.println(moveData);
|
||||
if (moveData.getUsername().equals(this.username)) {
|
||||
moveData.getTile().visit(team.get(moveData.getCharacterName()));
|
||||
} else {
|
||||
moveData.getTile().visit(enemyTeam.get(moveData.getCharacterName()));
|
||||
if (!moveData.getUsername().equals(this.username)) {
|
||||
GameTile tile = mapRenderer.getGameTile(moveData.getPos());
|
||||
GameCharacter character = enemyTeam.get(moveData.getCharacterName());
|
||||
gameInputProcessor.removeCharacterFromTile(character);
|
||||
tile.visit(character);
|
||||
}
|
||||
} else if (data instanceof DamageData) {
|
||||
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();
|
||||
camera.translate(-400, 0);
|
||||
|
||||
this.playersTurn = true;
|
||||
setGamestate(GAMESTATE.PLAYING);
|
||||
}
|
||||
|
||||
@@ -433,6 +439,7 @@ public class MainGame extends Game implements ClientCallback {
|
||||
setChosenFaction(Faction.MEGACORPORATION);
|
||||
send(new TeamData(Faction.MEGACORPORATION, getUsername()));
|
||||
initCharacters();
|
||||
this.playersTurn = false;
|
||||
setGamestate(GAMESTATE.PLAYING);
|
||||
}
|
||||
|
||||
|
||||
@@ -120,12 +120,12 @@ public class GameInputProcessor implements InputProcessor {
|
||||
} else if (mainGame.getGamestate() == GAMESTATE.SELECTING_FACTION) {
|
||||
if (keycode == Input.Keys.NUM_1) {
|
||||
System.out.println("choosing mega");
|
||||
mainGame.send(new TeamData(Faction.MEGACORPORATION,mainGame.getUsername()));
|
||||
mainGame.send(new TeamData(Faction.MEGACORPORATION, mainGame.getUsername()));
|
||||
mainGame.chooseMegaCorp();
|
||||
}
|
||||
if (keycode == Input.Keys.NUM_2) {
|
||||
System.out.println("choosing hacker");
|
||||
mainGame.send(new TeamData(Faction.HACKER,mainGame.getUsername()));
|
||||
mainGame.send(new TeamData(Faction.HACKER, mainGame.getUsername()));
|
||||
mainGame.chooseHacker();
|
||||
}
|
||||
|
||||
@@ -160,31 +160,38 @@ public class GameInputProcessor implements InputProcessor {
|
||||
gameTile.visit(mainGame.getSelectedCharacter());
|
||||
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
||||
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
|
||||
if (mainGame.hasCharacterSelected() && gameTile.containsCharacter() && gameTile.getCharacter().getFaction() != mainGame.getChosenFaction()) {
|
||||
if (mainGame.mapRenderer.getSurroundedTilesOfCurrentCharacter().contains(gameTile)) {
|
||||
gameTile.getCharacter().damage(10);
|
||||
mainGame.increaseTurn();
|
||||
mainGame.send(new DamageData(gameTile.getCharacter().getName()));
|
||||
if (!gameTile.getCharacter().isDead()) {
|
||||
gameTile.getCharacter().damage(100);
|
||||
mainGame.increaseTurn();
|
||||
mainGame.send(new DamageData(gameTile.getCharacter().getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// set selected character
|
||||
if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) {
|
||||
if (gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) {
|
||||
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
||||
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
||||
if (!gameTile.getCharacter().isDead()) {
|
||||
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
||||
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// switch character
|
||||
if (gameTile.containsCharacter()
|
||||
&& !mainGame.getSelectedCharacter().equals(gameTile.getCharacter())
|
||||
&& gameTile.getCharacter().getFaction() == mainGame.getChosenFaction()) {
|
||||
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
||||
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
||||
if (!gameTile.getCharacter().isDead()) {
|
||||
mainGame.setSelectedCharacter(gameTile.getCharacter());
|
||||
mainGame.mapRenderer.setSurroundedTilesOfCurrentCharacter(col, row);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -195,7 +202,7 @@ public class GameInputProcessor implements InputProcessor {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void removeCharacterFromTile(GameCharacter character) {
|
||||
public void removeCharacterFromTile(GameCharacter character) {
|
||||
rowLoop:
|
||||
for (int row = 0; row < mainGame.mapRenderer.getGameTiles().length; row++) {
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
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.util.data.Data;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class MoveData extends Data {
|
||||
private final String username;
|
||||
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.setPayload(this);
|
||||
this.username = username;
|
||||
this.characterName = characterName;
|
||||
this.tile = tile;
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
@@ -24,7 +26,7 @@ public class MoveData extends Data {
|
||||
return characterName;
|
||||
}
|
||||
|
||||
public GameTile getTile() {
|
||||
return tile;
|
||||
public Point getPos() {
|
||||
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