From 414a6602ed46fb4175b63f69f2de14c97192216c Mon Sep 17 00:00:00 2001 From: iryupnik Date: Wed, 29 Apr 2020 14:14:46 +0200 Subject: [PATCH] Battle fix --- .../gameOfProd/Windows/WindowOfBattle.java | 42 ++++++------ src/main/resources/save/savedGame/events.txt | 65 +++++++++++++++++++ .../resources/save/savedGame/inventory.txt | 6 ++ src/main/resources/save/savedGame/person.txt | 6 ++ src/main/resources/save/savedGame/village.txt | 1 + 5 files changed, 98 insertions(+), 22 deletions(-) diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java index ea9daf0..604a199 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfBattle.java @@ -132,10 +132,10 @@ public class WindowOfBattle extends JPanel { }); } - public void startBattle(){ + public void startBattle() { Hero hero = new Hero(100, 1, "Mark", 1, 100, 1); Enemy enemy1 = new Enemy(10, 1, "123", 1, 1); - Enemy enemy2 = new Enemy(10, 1, "test", 1, 2); + Enemy enemy2 = new Enemy(10, 1, "test", 1, 2); LinkedList a = new LinkedList<>(); a.add(hero); @@ -147,16 +147,14 @@ public class WindowOfBattle extends JPanel { battle = new Battle(a, b, this); isReadyToPaint = true; - Thread repainting = new Thread(() -> { - Timer t = new Timer(10, actionEvent -> { - canvas.repaint(); - if (situationText.isVisible()){ - situationText.repaint(); - } - }); - t.start(); + Timer t = new Timer(10, actionEvent -> { + repaint(); + canvas.repaint(); + if (situationText.isVisible()) { + situationText.repaint(); + } }); - repainting.start(); + t.start(); battle.startBattle(); } @@ -168,13 +166,13 @@ public class WindowOfBattle extends JPanel { public void writeToOutput(String s) { System.out.println(s); Font f = new Font(Font.SERIF, Font.BOLD, 20); - if (situationText.getComponents().length != 0) - situationText.remove(0); - JLabel text = new JLabel(); - text.setText(s); - text.setFont(f); - situationText.add(text); - situationText.getComponents()[0].repaint(); + if (situationText.getComponents().length == 0) { + JLabel text = new JLabel(); + situationText.add(text); + } + JLabel jLabel = (JLabel) situationText.getComponents()[0]; + jLabel.setText(s); + jLabel.setFont(f); repaint(); } @@ -182,11 +180,11 @@ public class WindowOfBattle extends JPanel { @Override public void paint(Graphics g) { super.paint(g); - if (isReadyToPaint){ - for (Enemy battlePerson: battle.getEnemies()){ - battlePerson.paint(g, CELL_SIZE * 2, CELL_SIZE *3 * battlePerson.getId()); + if (isReadyToPaint) { + for (Enemy battlePerson : battle.getEnemies()) { + battlePerson.paint(g, CELL_SIZE * 2, CELL_SIZE * 3 * battlePerson.getId()); } - for (BattlePerson battlePerson: battle.getHeroes()){ + for (BattlePerson battlePerson : battle.getHeroes()) { battlePerson.paint(g, CELL_SIZE * 12, CELL_SIZE * 4); } } diff --git a/src/main/resources/save/savedGame/events.txt b/src/main/resources/save/savedGame/events.txt index e69de29..24d3470 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 + false + + + + + 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..5c77ce0 100644 --- a/src/main/resources/save/savedGame/inventory.txt +++ b/src/main/resources/save/savedGame/inventory.txt @@ -0,0 +1,6 @@ + + white-key-card + 1 + 19 + key + diff --git a/src/main/resources/save/savedGame/person.txt b/src/main/resources/save/savedGame/person.txt index e69de29..d7aae53 100644 --- a/src/main/resources/save/savedGame/person.txt +++ b/src/main/resources/save/savedGame/person.txt @@ -0,0 +1,6 @@ + + office + 8 + 6 + 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