Mehr javadoc & remove dice3d ordner

This commit is contained in:
joachimschmidt557 2019-03-20 18:09:32 +01:00
parent 6f8b981cea
commit 6431df6bf4
10 changed files with 104 additions and 541 deletions

View file

@ -24,6 +24,9 @@ public class Game {
private GameInterface gameInterface;
private AttackThread attackThread;
/**
* Initialize a new game
*/
public Game() {
this.isOver = false;
this.hasStarted = false;
@ -31,6 +34,10 @@ public class Game {
this.players = new LinkedList<>();
}
/**
* Add a player to the game
* @param p The new player
*/
public void addPlayer(Player p) {
if(players.contains(p))
throw new IllegalArgumentException("Spieler wurde bereits hinzugefügt");
@ -38,19 +45,34 @@ public class Game {
this.players.add(p);
}
/**
* Sets the goal to achieve
* @param goal The goal
*/
public void setGoal(Goal goal) {
this.goal = goal;
this.goal.setGame(this);
}
/**
* The round this game is currently in
* @return The round
*/
public int getRound() {
return round;
}
/**
* Sets the size of the map
* @param mapSize The size of the map
*/
public void setMapSize(MapSize mapSize) {
this.mapSize = mapSize;
}
/**
* Generates the map
*/
private void generateMap() {
int mapSizeMultiplier = this.mapSize.ordinal() + 1;
@ -70,6 +92,10 @@ public class Game {
this.gameMap = GameMap.generateRandomMap(width, height, 40, numRegions, continents);
}
/**
* Starts the game
* @param gameInterface The interface of the game
*/
public void start(GameInterface gameInterface) {
if(hasStarted)
@ -102,6 +128,13 @@ public class Game {
nextTurn();
}
/**
* Starts an attack
* @param source
* @param target
* @param troopCount
* @return
*/
public AttackThread startAttack(Castle source, Castle target, int troopCount) {
if(attackThread != null)
return attackThread;
@ -115,6 +148,13 @@ public class Game {
return attackThread;
}
/**
* Makes a castle attack another castle
* @param attackerCastle
* @param defenderCastle
* @param rollAttacker
* @param rollDefender
*/
public void doAttack(Castle attackerCastle, Castle defenderCastle, int[] rollAttacker, int[] rollDefender) {
Integer[] rollAttackerSorted = Arrays.stream(rollAttacker).boxed().sorted(Comparator.reverseOrder()).toArray(Integer[]::new);
@ -145,6 +185,12 @@ public class Game {
gameInterface.onUpdate();
}
/**
* Move troops from castle to castle
* @param source
* @param destination
* @param troopCount
*/
public void moveTroops(Castle source, Castle destination, int troopCount) {
if(troopCount >= source.getTroopCount() || source.getOwner() != destination.getOwner())
return;
@ -153,23 +199,46 @@ public class Game {
gameInterface.onUpdate();
}
/**
* Abort the attack
*/
public void stopAttack() {
this.attackThread = null;
this.gameInterface.onAttackStopped();
}
/**
* Rolls the dice
* @param player
* @param dices
* @param fastForward
* @return
*/
public int[] roll(Player player, int dices, boolean fastForward) {
return gameInterface.onRoll(player, dices, fastForward);
}
/**
* Are all castles chosen?
* @return
*/
private boolean allCastlesChosen() {
return gameMap.getCastles().stream().noneMatch(c -> c.getOwner() == null);
}
/**
* The attack thread
* @return
*/
public AttackThread getAttackThread() {
return this.attackThread;
}
/**
* A player chooses this castle
* @param castle
* @param player
*/
public void chooseCastle(Castle castle, Player player) {
if(castle.getOwner() != null || player.getRemainingTroops() == 0)
return;
@ -186,6 +255,12 @@ public class Game {
}
}
/**
* Adds troops to a castle
* @param player
* @param castle
* @param count
*/
public void addTroops(Player player, Castle castle, int count) {
if(count < 1 || castle.getOwner() != player)
return;
@ -195,11 +270,19 @@ public class Game {
player.removeTroops(count);
}
/**
* Gives a player more points
* @param player
* @param score
*/
public void addScore(Player player, int score) {
player.addPoints(score);
gameInterface.onAddScore(player, score);
}
/**
* This is it. The endgame.
*/
public void endGame() {
isOver = true;
Player winner = goal.getWinner();
@ -215,6 +298,9 @@ public class Game {
gameInterface.onGameOver(winner);
}
/**
* Moves on to the next turn
*/
public void nextTurn() {
if(goal.isCompleted()) {
@ -275,18 +361,34 @@ public class Game {
playerQueue.add(currentPlayer);
}
/**
* The currently active player
* @return
*/
public Player getCurrentPlayer() {
return this.currentPlayer;
}
/**
* All players
* @return
*/
public List<Player> getPlayers() {
return this.players;
}
/**
* The game map
* @return
*/
public GameMap getMap() {
return this.gameMap;
}
/**
* Is this game over yet?
* @return
*/
public boolean isOver() {
return this.isOver;
}