diff --git a/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java b/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java index 76b81ac..77eebc2 100644 --- a/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java +++ b/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java @@ -2,6 +2,7 @@ package ruscz.game.gameOfProd.Battle; import ruscz.game.gameOfProd.Cells.InteractionCell; import ruscz.game.gameOfProd.Dialog.Dialog; +import ruscz.game.gameOfProd.Sounds.SoundManager; import ruscz.game.gameOfProd.Windows.WindowOfBattle; import ruscz.game.gameOfProd.Windows.WindowOfFreeMove; @@ -17,9 +18,7 @@ public class Battle { private final WindowOfBattle windowOfBattle; private Timer timer; - public void setTurnBelongTo(BattlePerson turnBelongTo) { - this.turnBelongTo = turnBelongTo; - } + private final SoundManager soundManager; private BattlePerson turnBelongTo; @@ -42,10 +41,6 @@ public class Battle { private boolean timerStopped; - public BattlePerson getTurnBelongTo() { - return turnBelongTo; - } - public void setPlayerAttack(boolean playerAttack) { windowOfBattle.getMenuOfActions().setVisible(false); windowOfBattle.getEnemyDescription().setVisible(false); @@ -56,6 +51,7 @@ public class Battle { this.heroes = heroes; this.enemies = enemies; this.windowOfBattle = window; + soundManager = new SoundManager(); } public LinkedList getEnemies() { @@ -81,7 +77,6 @@ public class Battle { windowOfBattle.repaint(); turnOrder = new LinkedList<>(); timer = new Timer(1000, actionEvent -> { - for (Enemy e: enemies) System.out.println(e.health); if (checkHealthOfEnemies()) endBattle(true); if (checkHealthOfHeroes()) endBattle(false); if(playerAttack) @@ -134,9 +129,9 @@ public class Battle { turnCount++; windowOfBattle.repaint(); turnBelongTo.attack(e); + if (windowOfBattle.getHitSound() != null) soundManager.playSound(windowOfBattle.getHitSound(), 6.0f); - windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " to " + e.getName()); - //TODO Animation of Attack + windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " damage to " + e.getName()+"!"); //TODO Animation of Death if (e.health <= 0) enemies.remove(e); @@ -154,26 +149,27 @@ public class Battle { LinkedList turns = new LinkedList<>(enemies); turns.addAll(heroes); - if (checkIfTurnOrderIsFull(turns)) + BattlePerson last = turnOrder.getLast(); + if (checkIfTurnOrderIsFull(turns)) { turnOrder = new LinkedList<>(); + } Collections.shuffle(turns); turnBelongTo = turns.getFirst(); - while (turnOrder.contains(turnBelongTo)){ + while (turnOrder.contains(turnBelongTo) || turnBelongTo.equals(last)){ + turns.remove(turnBelongTo); Collections.shuffle(turns); turnBelongTo = turns.getFirst(); } - - System.out.println(turnBelongTo.getClass().getName()); } private void attackByMonster(Hero e) { turnCount++; turnBelongTo.attack(e); + if (windowOfBattle.getHitSound() != null) soundManager.playSound(windowOfBattle.getHitSound(), 6.0f); - windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " to " + e.getName()); - //TODO Animation of Attack + windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() + " damage to " + e.getName()+"!"); //TODO Animation of Death if (e.health <= 0) heroes.remove(e); @@ -198,8 +194,8 @@ public class Battle { return timer; } - public boolean isPlayerAttack() { - return playerAttack; + public void setTurnBelongTo(BattlePerson turnBelongTo) { + this.turnBelongTo = turnBelongTo; } private boolean checkIfTurnOrderIsFull(LinkedList allBattlePerson){ diff --git a/src/main/java/ruscz/game/gameOfProd/BattleUI/EnemyDescription.java b/src/main/java/ruscz/game/gameOfProd/BattleUI/EnemyDescription.java index 3f89d6b..4dcca40 100644 --- a/src/main/java/ruscz/game/gameOfProd/BattleUI/EnemyDescription.java +++ b/src/main/java/ruscz/game/gameOfProd/BattleUI/EnemyDescription.java @@ -48,18 +48,21 @@ public class EnemyDescription extends JPanel { setLayout(new GridLayout (he.size() + 1, 3)); for (BattlePerson person: he){ + Font f = new Font(Font.DIALOG, Font.BOLD, 20); + JPanel jPanel = new JPanel(); JLabel name = new JLabel(person.getName()); + name.setFont(f); JLabel level = new JLabel("Level: " + person.getLevel()); + level.setFont(f); JLabel health = new JLabel("Health: " + person.getHealth() + "/" + person.getMaxHealth()); + health.setFont(f); jPanel.add(name); jPanel.add(level); jPanel.add(health); add(jPanel); } - - System.out.println(Arrays.toString(getComponents())); } private void deletePreviousDescription() { diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java index c94965b..b7d9427 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java @@ -54,15 +54,15 @@ public class WindowOfBattle extends JPanel { return itemsInventory; } - private Canvas canvas; - private SituationText situationText; - private EnemyDescription enemyDescription; - private MenuOfActions menuOfActions; - private ConsoleInput consoleInput; - private CommandList commandList; - private ItemsInventory itemsInventory; + private final Canvas canvas; + private final SituationText situationText; + private final EnemyDescription enemyDescription; + private final MenuOfActions menuOfActions; + private final ConsoleInput consoleInput; + private final CommandList commandList; + private final ItemsInventory itemsInventory; - private Game game; + private final Game game; private Battle battle; private MusicManager musicManager; @@ -71,6 +71,8 @@ public class WindowOfBattle extends JPanel { private String loseCutscene; private String name; + private String hitSound; + public Battle getBattle() { return battle; } @@ -152,6 +154,9 @@ public class WindowOfBattle extends JPanel { else if (data[0].equals("")) { loseCutscene = data[1]; } + else if (data[0].equals("")){ + hitSound = data[1]; + } } } catch (FileNotFoundException e) { e.printStackTrace(); @@ -213,6 +218,10 @@ public class WindowOfBattle extends JPanel { return name; } + public String getHitSound() { + return hitSound; + } + class Canvas extends JPanel { private LinkedList images; private BufferedImage image; diff --git a/src/main/resources/battles/storageroombattle.txt b/src/main/resources/battles/storageroombattle.txt index 1ca86d2..61c5937 100644 --- a/src/main/resources/battles/storageroombattle.txt +++ b/src/main/resources/battles/storageroombattle.txt @@ -1,6 +1,7 @@ 100 10 Mark 1 10 1 main-battle - 1 1 Karen 1 1 monster-battle hover + 120 10 Karen 10 1 monster-battle hover Fight_Music.wav -10.0f + hit.wav battle1 battle2 flicker 500 diff --git a/src/main/resources/save/savedGame/events.txt b/src/main/resources/save/savedGame/events.txt index e69de29..02fad9d 100644 --- a/src/main/resources/save/savedGame/events.txt +++ b/src/main/resources/save/savedGame/events.txt @@ -0,0 +1,80 @@ + + tutorial + + + 11 + 6 + false + + + + + openspace + + + 6 + 4 + true + + + 14 + 16 + false + + + 1 + 2 + true + + + 15 + 7 + true + + + + + office + + + 4 + 2 + false + + + 1 + 9 + true + + + + + boss + + + 4 + 18 + true + + + + + treasure + + + 6 + 1 + true + + + + + storageroom + + + 6 + 2 + true + + + diff --git a/src/main/resources/save/savedGame/person.txt b/src/main/resources/save/savedGame/person.txt index e69de29..ec0fcae 100644 --- a/src/main/resources/save/savedGame/person.txt +++ b/src/main/resources/save/savedGame/person.txt @@ -0,0 +1,6 @@ + + storageroom + 6 + 2 + 0 + \ No newline at end of file diff --git a/src/main/resources/sounds/hit.wav b/src/main/resources/sounds/hit.wav new file mode 100644 index 0000000..bb8f467 Binary files /dev/null and b/src/main/resources/sounds/hit.wav differ