refactor method
This commit is contained in:
Binary file not shown.
@@ -162,7 +162,7 @@ public class MainGame extends Game implements ClientCallback {
|
|||||||
|
|
||||||
private void playSong() {
|
private void playSong() {
|
||||||
// play music
|
// play music
|
||||||
Music music = Gdx.audio.newMusic(Gdx.files.getFileHandle("core/assets/beat.mp3", Files.FileType.Internal));
|
Music music = Gdx.audio.newMusic(Gdx.files.getFileHandle("core/assets/sound/beat.mp3", Files.FileType.Internal));
|
||||||
music.setVolume(.1f);
|
music.setVolume(.1f);
|
||||||
music.play();
|
music.play();
|
||||||
music.setLooping(true);
|
music.setLooping(true);
|
||||||
@@ -205,7 +205,8 @@ public class MainGame extends Game implements ClientCallback {
|
|||||||
renderTurnText();
|
renderTurnText();
|
||||||
} else if (this.gamestate == GAMESTATE.SELECTING_FACTION) {
|
} else if (this.gamestate == GAMESTATE.SELECTING_FACTION) {
|
||||||
clearRender(67, 168, 186, 1);
|
clearRender(67, 168, 186, 1);
|
||||||
renderString("FACTION SELECT\nYou are: " + username + "\nPress 1 for mega corporation, press 2 for hackers", Gdx.graphics.getWidth() / 2f, Gdx.graphics.getHeight() / 2f);
|
String text = username == null ? "Connecting to server..." : "FACTION SELECT\nYou are: " + username + "\nPress 1 for mega corporation, press 2 for hackers";
|
||||||
|
renderString(text, Gdx.graphics.getWidth() / 2f, Gdx.graphics.getHeight() / 2f);
|
||||||
if (this.ready && this.enemyReady) {
|
if (this.ready && this.enemyReady) {
|
||||||
if (this.chosenFaction == Faction.HACKER) {
|
if (this.chosenFaction == Faction.HACKER) {
|
||||||
chooseHacker();
|
chooseHacker();
|
||||||
@@ -410,7 +411,7 @@ public class MainGame extends Game implements ClientCallback {
|
|||||||
if (!moveData.getUsername().equals(this.username)) {
|
if (!moveData.getUsername().equals(this.username)) {
|
||||||
GameTile tile = mapRenderer.getGameTile(moveData.getPos());
|
GameTile tile = mapRenderer.getGameTile(moveData.getPos());
|
||||||
GameCharacter character = enemyTeam.get(moveData.getCharacterName());
|
GameCharacter character = enemyTeam.get(moveData.getCharacterName());
|
||||||
gameInputProcessor.removeCharacterFromTile(character);
|
mapRenderer.removeCharacterFromTile(character);
|
||||||
tile.visit(character);
|
tile.visit(character);
|
||||||
}
|
}
|
||||||
} else if (data instanceof DamageData) {
|
} else if (data instanceof DamageData) {
|
||||||
|
|||||||
@@ -94,7 +94,6 @@ 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);
|
|
||||||
if (mainGame.getGamestate() == GAMESTATE.PLAYING) {
|
if (mainGame.getGamestate() == GAMESTATE.PLAYING) {
|
||||||
|
|
||||||
if (keysList.contains(keycode)) {
|
if (keysList.contains(keycode)) {
|
||||||
@@ -156,14 +155,14 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
if (mainGame.hasCharacterSelected() && !gameTile.containsCharacter()) {
|
if (mainGame.hasCharacterSelected() && !gameTile.containsCharacter()) {
|
||||||
|
|
||||||
if (gameTile.getSymbol() != '#' && mainGame.mapRenderer.getSurroundedTilesOfCurrentCharacter().contains(gameTile)) {
|
if (gameTile.getSymbol() != '#' && mainGame.mapRenderer.getSurroundedTilesOfCurrentCharacter().contains(gameTile)) {
|
||||||
removeCharacterFromTile(mainGame.getSelectedCharacter());
|
mainGame.mapRenderer.removeCharacterFromTile(mainGame.getSelectedCharacter());
|
||||||
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(), mainGame.mapRenderer.getPos(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)) {
|
||||||
if (!gameTile.getCharacter().isDead()) {
|
if (!gameTile.getCharacter().isDead()) {
|
||||||
@@ -202,18 +201,7 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
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++) {
|
|
||||||
GameTile gameTile = mainGame.mapRenderer.getGameTiles()[row][col];
|
|
||||||
if (gameTile.containsCharacter() && gameTile.getCharacter().equals(character)) {
|
|
||||||
gameTile.removeCharacter();
|
|
||||||
break rowLoop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||||
|
|||||||
@@ -240,6 +240,23 @@ public class MapRenderer implements Renderable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove character from tile
|
||||||
|
* @param character the character to remove
|
||||||
|
*/
|
||||||
|
public void removeCharacterFromTile(GameCharacter character) {
|
||||||
|
rowLoop:
|
||||||
|
for (int row = 0; row < getGameTiles().length; row++) {
|
||||||
|
for (int col = 0; col < getGameTiles()[0].length; col++) {
|
||||||
|
GameTile gameTile = getGameTiles()[row][col];
|
||||||
|
if (gameTile.containsCharacter() && gameTile.getCharacter().equals(character)) {
|
||||||
|
gameTile.removeCharacter();
|
||||||
|
break rowLoop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* resize the screen
|
* resize the screen
|
||||||
* @param screenWidth the width of the screen
|
* @param screenWidth the width of the screen
|
||||||
|
|||||||
Reference in New Issue
Block a user