diff --git a/gameOfProd.iml b/gameOfProd.iml
index e16d728..6e66935 100644
--- a/gameOfProd.iml
+++ b/gameOfProd.iml
@@ -11,6 +11,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java b/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java
index eb57b3c..5ebc877 100644
--- a/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java
+++ b/src/main/java/ruscz/game/gameOfProd/Battle/Battle.java
@@ -20,11 +20,23 @@ public class Battle {
private boolean playerAttack;
+ public boolean isTimerStopped() {
+ return timerStopped;
+ }
+
+ public void setTimerStopped(boolean timerStopped) {
+ this.timerStopped = timerStopped;
+ }
+
+ private boolean timerStopped;
+
public BattlePerson getTurnBelongTo() {
return turnBelongTo;
}
public void setPlayerAttack(boolean playerAttack) {
+ windowOfBattle.getMenuOfActions().setVisible(false);
+ windowOfBattle.getEnemyDescription().setVisible(false);
this.playerAttack = playerAttack;
}
@@ -42,11 +54,11 @@ public class Battle {
return heroes;
}
- private boolean checkHealthOfEnemies(){
+ public boolean checkHealthOfEnemies(){
return enemies.isEmpty();
}
- private boolean checkHealthOfHeroes(){
+ public boolean checkHealthOfHeroes(){
return heroes.isEmpty();
}
@@ -76,12 +88,14 @@ public class Battle {
private void endBattle(boolean b) {
//TODO Return to Map
timer.stop();
+ timerStopped = true;
if (b) windowOfBattle.writeToOutput("Win!");
else windowOfBattle.writeToOutput("Lose!");
}
private void returnControlToPlayer(){
timer.stop();
+ timerStopped = true;
windowOfBattle.getMenuOfActions().setVisible(true);
for (Component e: windowOfBattle.getMenuOfActions().getComponents()) e.setEnabled(true);
windowOfBattle.getEnemyDescription().setVisible(true);
@@ -89,8 +103,6 @@ public class Battle {
private void attackByHero(Enemy e) {
turnCount++;
- windowOfBattle.getMenuOfActions().setVisible(false);
- windowOfBattle.getEnemyDescription().setVisible(false);
windowOfBattle.repaint();
turnBelongTo.attack(e);
diff --git a/src/test/java/ruscz/game/gameOfProd/Battle/BattleTest.java b/src/test/java/ruscz/game/gameOfProd/Battle/BattleTest.java
new file mode 100644
index 0000000..f00aa14
--- /dev/null
+++ b/src/test/java/ruscz/game/gameOfProd/Battle/BattleTest.java
@@ -0,0 +1,63 @@
+package ruscz.game.gameOfProd.Battle;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import ruscz.game.gameOfProd.Game;
+import ruscz.game.gameOfProd.Windows.WindowOfBattle;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedList;
+
+import static ruscz.game.gameOfProd.Windows.WindowOfFreeMove.sleep;
+
+public class BattleTest {
+
+ @Test
+ public void startBattle_battleWithAMightHero_winOfHero(){
+ //Arrange
+ Battle battle;
+ Hero h;
+ Enemy e1, e2;
+ LinkedList llh;
+ LinkedList lle;
+ Game game;
+
+ //Act
+ game = new Game();
+ game.setVisible(false);
+
+ h = new Hero(100, 100, "123", 100, 100, 100);
+ e1 = new Enemy(1, 1,"1", 1, 1);
+ e2 = new Enemy(2,2,"2", 2, 2);
+
+ llh = new LinkedList<>(Collections.singleton(h));
+ lle = new LinkedList<>(Arrays.asList(e1, e2));
+
+ battle = new Battle(llh, lle, new WindowOfBattle(game));
+ battle.startBattle();
+
+ battle.setPlayerAttack(true);
+ battle.setTimerStopped(false);
+ battle.getTimer().start();
+
+ timerOfWaiting(battle);
+
+ battle.setPlayerAttack(true);
+ battle.setTimerStopped(false);
+ battle.getTimer().start();
+
+ timerOfWaiting(battle);
+
+ //Assertion
+ Assertions.assertFalse(battle.checkHealthOfHeroes());
+ Assertions.assertTrue(battle.checkHealthOfEnemies());
+
+ }
+
+ private void timerOfWaiting(Battle battle){
+ while (!battle.isTimerStopped()){
+ sleep(1000);
+ }
+ }
+}