diff --git a/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java b/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java index 061a2f9..a4a65af 100644 --- a/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java +++ b/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java @@ -13,7 +13,6 @@ public class Battle { private WindowOfBattle windowOfBattle; private Timer timer; private BattlePerson turnBelongTo; - private BattlePerson turnWas; private int turnCount; private int delay; @@ -42,12 +41,23 @@ public class Battle { return heroes; } + private boolean checkHealthOfEnemies(){ + return enemies.isEmpty(); + } + + private boolean checkHealthOfHeroes(){ + return heroes.isEmpty(); + } + public void startBattle() { turnBelongTo = heroes.getFirst(); windowOfBattle.getMenuOfActions().setVisible(true); windowOfBattle.getEnemyDescription().setVisible(true); windowOfBattle.repaint(); timer = new Timer(1000, actionEvent -> { + for (Enemy e: enemies) System.out.println(e.health); + if (checkHealthOfEnemies()) endBattle(true); + if (checkHealthOfHeroes()) endBattle(false); if(playerAttack) attackByHero(randomEnemy()); else if (delay != 0) @@ -55,16 +65,24 @@ public class Battle { else if (turnBelongTo == null) nextTurn(); else if (turnBelongTo.getClass().getName().equals(Enemy.class.getName())) - attackByMonster(); + attackByMonster(randomHero()); else { returnControlToPlayer(); } }); } + private void endBattle(boolean b) { + //TODO Return to Map + timer.stop(); + if (b) windowOfBattle.writeToOutput("Win!"); + else windowOfBattle.writeToOutput("Lose!"); + } + private void returnControlToPlayer(){ timer.stop(); windowOfBattle.getMenuOfActions().setVisible(true); + windowOfBattle.getMenuOfActions().getComponents()[0].setEnabled(true); windowOfBattle.getEnemyDescription().setVisible(true); } @@ -73,11 +91,12 @@ public class Battle { windowOfBattle.getMenuOfActions().setVisible(false); windowOfBattle.getEnemyDescription().setVisible(false); windowOfBattle.repaint(); - e.setHealth(e.getHealth() - turnBelongTo.getLevel() * turnBelongTo.getStrength()); + turnBelongTo.attack(e); + //TODO Animation of Death + if (e.health <= 0) enemies.remove(e); windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " to " + e.getName()); playerAttack = false; - turnBelongTo = null; delay = 2; } @@ -89,19 +108,19 @@ public class Battle { LinkedList turns = new LinkedList<>(enemies); turns.addAll(heroes); - + //TODO Check turns (maybe List) Collections.shuffle(turns); turnBelongTo = turns.getFirst(); System.out.println(turnBelongTo.getClass().getName()); } - private void attackByMonster() { + private void attackByMonster(Hero e) { turnCount++; - LinkedList list = getHeroes(); - Random rand = new Random(); - Hero e = (Hero) list.get(rand.nextInt(list.size())); - e.setHealth(e.getHealth() - turnBelongTo.getLevel() * turnBelongTo.getStrength()); + turnBelongTo.attack(e); + //TODO Animation of Death + if (e.health <= 0) heroes.remove(e); + windowOfBattle.writeToOutput(turnBelongTo.getName() + " deal " + turnBelongTo.getLevel() * turnBelongTo.getStrength() + " to " + e.getName()); delay = 2; turnBelongTo = null; @@ -113,6 +132,12 @@ public class Battle { return (Enemy) list.get(rand.nextInt(list.size())); } + private Hero randomHero(){ + LinkedList list = getHeroes(); + Random rand = new Random(); + return (Hero) list.get(rand.nextInt(list.size())); + } + public Timer getTimer() { return timer; } diff --git a/src/main/java/ruscz/game/gameOfProd/Battle/Hero.java b/src/main/java/ruscz/game/gameOfProd/Battle/Hero.java index aa073a4..cf9673f 100644 --- a/src/main/java/ruscz/game/gameOfProd/Battle/Hero.java +++ b/src/main/java/ruscz/game/gameOfProd/Battle/Hero.java @@ -19,7 +19,7 @@ public class Hero extends BattlePerson { @Override public void attack(BattlePerson enemy) { - enemy.setHealth(enemy.getHealth() - (strength)); + enemy.setHealth(enemy.getHealth() - (strength * level)); } @Override diff --git a/src/main/java/ruscz/game/gameOfProd/Game.java b/src/main/java/ruscz/game/gameOfProd/Game.java index 3d7fe30..c45480e 100644 --- a/src/main/java/ruscz/game/gameOfProd/Game.java +++ b/src/main/java/ruscz/game/gameOfProd/Game.java @@ -41,18 +41,18 @@ public class Game extends JFrame { battle = new WindowOfBattle(this); //tohle spustí na začátku menu - add(menu); +// add(menu); //tohle spustí na začátku hru -// add(freeMove); -// freeMove.start(true); +// add(freeMove); +// freeMove.start(true); //tohle spustí na začátku bitvu -// add(battle); -// battle.startBattle(); + add(battle); + battle.startBattle(); //Tohle spustí na začátku tileset overview - new EditorManager(); +// new EditorManager(); setDefaultCloseOperation(EXIT_ON_CLOSE); setUndecorated(true); @@ -64,6 +64,8 @@ public class Game extends JFrame { setExtendedState(MAXIMIZED_BOTH); } - public Game game() {return this;} + public Game game() { + return this; + } } diff --git a/src/main/java/ruscz/game/gameOfProd/LevelEditor/InfoManager.java b/src/main/java/ruscz/game/gameOfProd/LevelEditor/InfoManager.java index 8d767bf..36b900f 100644 --- a/src/main/java/ruscz/game/gameOfProd/LevelEditor/InfoManager.java +++ b/src/main/java/ruscz/game/gameOfProd/LevelEditor/InfoManager.java @@ -11,7 +11,7 @@ public class InfoManager { private JScrollPane scrollInfo; private JLayeredPane view; - LinkedList radioButtons; + private LinkedList radioButtons; public InfoManager(LevelEditor editor) { this.editor = editor; diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java index 604a199..5dae47e 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java @@ -2,6 +2,8 @@ package ruscz.game.gameOfProd.Windows; import ruscz.game.gameOfProd.Battle.*; import ruscz.game.gameOfProd.Game; +import ruscz.game.gameOfProd.Save.LoadManager; +import ruscz.game.gameOfProd.Save.SaveManager; import javax.swing.*; import java.awt.*; @@ -53,6 +55,8 @@ public class WindowOfBattle extends JPanel { private Game game; private Battle battle; + private LoadManager loadManager; + private SaveManager saveManager; public WindowOfBattle(Game game) { this.game = game; @@ -91,11 +95,26 @@ public class WindowOfBattle extends JPanel { menuOfActions.setVisible(false); JButton attack = new JButton("Attack"); attack.addActionListener(e -> { + attack.setEnabled(false); battle.setPlayerAttack(true); battle.getTimer().start(); }); - attack.setLayout(null); + JButton console = new JButton("Console"); + console.addActionListener(e -> { + + }); + JButton inventory = new JButton("Items"); + inventory.addActionListener(e -> { + + }); + JButton escape = new JButton("Run Away"); + escape.addActionListener(e -> { + + }); menuOfActions.add(attack); + menuOfActions.add(console); + menuOfActions.add(inventory); + menuOfActions.add(escape); consoleInput = new JPanel(); consoleInput.setSize(CELL_SIZE * (CANVAS_WIDTH - 4), CELL_SIZE); @@ -133,7 +152,10 @@ public class WindowOfBattle extends JPanel { } public void startBattle() { - Hero hero = new Hero(100, 1, "Mark", 1, 100, 1); + //saveManager.saveGame(); + + //TODO Enemies from Files + Hero hero = new Hero(100, 100, "Mark", 1, 100, 1); Enemy enemy1 = new Enemy(10, 1, "123", 1, 1); Enemy enemy2 = new Enemy(10, 1, "test", 1, 2); @@ -150,13 +172,13 @@ public class WindowOfBattle extends JPanel { Timer t = new Timer(10, actionEvent -> { repaint(); canvas.repaint(); - if (situationText.isVisible()) { - situationText.repaint(); - } + situationText.repaint(); }); t.start(); battle.startBattle(); + + //loadManager.loadSavedGame(); } public Canvas getCanvas() { diff --git a/src/main/resources/save/savedGame/events.txt b/src/main/resources/save/savedGame/events.txt index e69de29..8b367ec 100644 --- a/src/main/resources/save/savedGame/events.txt +++ b/src/main/resources/save/savedGame/events.txt @@ -0,0 +1,65 @@ + + tutorial + + + 11 + 6 + false + + + + + openspace + + + 6 + 4 + true + + + 14 + 16 + false + + + 15 + 7 + true + + + + + office + + + 4 + 2 + false + + + 1 + 9 + false + + + + + boss + + + 4 + 18 + true + + + + + treasure + + + 6 + 1 + true + + + diff --git a/src/main/resources/save/savedGame/inventory.txt b/src/main/resources/save/savedGame/inventory.txt index e69de29..ad81884 100644 --- a/src/main/resources/save/savedGame/inventory.txt +++ b/src/main/resources/save/savedGame/inventory.txt @@ -0,0 +1,6 @@ + + blue-key-card + 1 + 39 + key + diff --git a/src/main/resources/save/savedGame/person.txt b/src/main/resources/save/savedGame/person.txt index e69de29..da4d904 100644 --- a/src/main/resources/save/savedGame/person.txt +++ b/src/main/resources/save/savedGame/person.txt @@ -0,0 +1,6 @@ + + openspace + 8 + 16 + 3 + \ No newline at end of file diff --git a/src/main/resources/save/savedGame/village.txt b/src/main/resources/save/savedGame/village.txt index e69de29..1b4bc7b 100644 --- a/src/main/resources/save/savedGame/village.txt +++ b/src/main/resources/save/savedGame/village.txt @@ -0,0 +1 @@ +TODO: Village \ No newline at end of file