diff --git a/src/main/java/BattleSimulation/Army.java b/src/main/java/BattleSimulation/Army.java deleted file mode 100644 index 147483b1f4458e07f1ce4beabfba13076c773f20..0000000000000000000000000000000000000000 --- a/src/main/java/BattleSimulation/Army.java +++ /dev/null @@ -1,182 +0,0 @@ -package BattleSimulation; -import SpecificUnits.*; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -/** - * Class representing a full army, with different methods for handling the mechanics of an army - */ -public class Army { - - private List<Unit> units; - private String name; - - /** - * A constructor with a list, and the name of that list - * @param name army name - */ - public Army(String name) { - units = new ArrayList<>(); - this.name = name; - } - - /** - * A constructor created with a list and a name of the army object created - * @param name name of army - * @param units list of units - */ - public Army(String name, List<Unit> units){ - this.name = name; - this.units = units; - } - - /** - * the get method for the name of the army - * @return String with the name of the army - */ - public String getName() { - return name; - } - - /** - * method for adding a unit to the army - * @param unit chosen unit to add to army - */ - public void add(Unit unit){ - units.add(unit); - } - - /** - * method for adding multiple units at one - * @param newUnits the list of the new units - */ - public void addAll(List<Unit> newUnits){ - units.addAll(newUnits); - } - - /** - * method for removing a specific unit in the army - * @param unit the unit to remove - */ - public void remove(Unit unit){ - units.remove(unit); - } - - /** - * method that return true if a list is empty or not - * @return true if the list is empty, false if it has units - */ - public boolean hasUnits(){ - if(units.size() > 0){ - return true; - } - return false; - } - - /** - * method for getting all units - * @return a list of the unit - */ - public List<Unit> getAllUnits(){ - return units; - } - - /** - * method for getting a random unit for a list - * @return a random unit - */ - public Unit getRandom(){ - java.util.Random random = new java.util.Random(); - int randomNum = random.nextInt(units.size()); - return units.get(randomNum); - } - - /** - * this is a getmethod for getting the list of all units in an army - * @return list of unit in the army - */ - public List<Unit> getUnits() { - return units; - } - - /** - * methods for getting all infantryUnits in a army - * @return a new list of all infantryUnits - */ - public List<Unit> getInfantryUnits(){ - return getUnits().stream() - .filter(u -> u instanceof InfantryUnit) - .collect(Collectors.toCollection(ArrayList::new)); - } - - /** - * methods for getting all RangeUnitsUnits in a army - * @return a new list of all RangeUnits - */ - public List<Unit> getRangeUnits(){ - return getUnits().stream() - .filter(u -> u instanceof RangedUnit) - .collect(Collectors.toCollection(ArrayList::new)); - } - - /** - * methods for getting all CavalryUnits in a army - * @return a new list of all CavalryUnits - */ - public List<Unit> getCavalryUnits(){ - return getUnits().stream() - .filter(u -> u instanceof CavalryUnit && !(u instanceof CommanderUnit)) - .collect(Collectors.toCollection(ArrayList::new)); - } - - /** - * methods for getting all CommanderUnits in a army - * @return a new list of all CommanderUnits - */ - public List<Unit> getCommanderUnits(){ - return getUnits().stream() - .filter(u -> u instanceof CommanderUnit) - .collect(Collectors.toCollection(ArrayList::new)); - } - - - /** - * if a object is the same as a different unit - * @param o object to check - * @return true if the units are equal, false if not - */ - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Army)) return false; - - Army army = (Army) o; - - if (!Objects.equals(units, army.units)) return false; - return getName() != null ? getName().equals(army.getName()) : army.getName() == null; - } - - /** - * method that makes a hashcode for an object - * @return int as a hashcode for the different objects - */ - @Override - public int hashCode() { - int result = units != null ? units.hashCode() : 0; - result = 31 * result + (getName() != null ? getName().hashCode() : 0); - return result; - } - - /** - * a toString method for printing a units list - * @return a string of units - */ - @Override - public String toString() { - return name + - "\nunits=" + units; - } -} diff --git a/src/main/java/BattleSimulation/Battle.java b/src/main/java/BattleSimulation/Battle.java deleted file mode 100644 index 9964db7b495da622c40e848382cdb71210f28b50..0000000000000000000000000000000000000000 --- a/src/main/java/BattleSimulation/Battle.java +++ /dev/null @@ -1,90 +0,0 @@ -package BattleSimulation; -import SpecificUnits.Unit; -import java.util.Random; - -/** - * this class represents the simulation of a battle - * the battle is going to be between two armies from the army class - * this class consists of different methods and variables - */ -public class Battle { - - Army attackingArmy; - Army defendingArmy; - Army armyOne; - Army armyTwo; - - /** - * this is a constructor for the battle class that takes two classes. - * @param armyOne - * @param armyTwo - */ - public Battle(Army armyOne, Army armyTwo) { - this.armyOne = armyOne; - this.armyTwo = armyTwo; - } - - /** - * this method is the simulation of the battle, two armies attack each other, and one wins - * @return return the winning army as an Army object - */ - public Army simulate(){ - Army winningArmy; - - Random random = new Random(); - boolean randomBool = random.nextBoolean(); - - if (randomBool){ - attackingArmy = armyOne; - defendingArmy = armyTwo; - } else { - attackingArmy = armyTwo; - defendingArmy = armyOne; - } - - boolean winner; - while (armyOne.hasUnits() && armyTwo.hasUnits()){ - - Unit attackingUnit = attackingArmy.getRandom(); - Unit defendingUnit = defendingArmy.getRandom(); - - winner = false; - while (!winner){ - attackingUnit.attack(defendingUnit); - if (defendingUnit.getHealth() <= 0){ - defendingArmy.remove(defendingUnit); - winner = true; - } - else { - defendingUnit.attack(attackingUnit); - if (attackingUnit.getHealth() <= 0){ - attackingArmy.remove(attackingUnit); - winner = true; - } - } - } - } - if(armyOne.hasUnits()){ - winningArmy = armyOne; - } else { - winningArmy = armyTwo; - } - return winningArmy; - } - - /** - * this method chooses the starting/attacking and defending army - */ - public void whoStarts(){ - } - - /** - * the toString method that print out both armies - * @return both armies units - */ - @Override - public String toString() { - return armyOne.getName() +"\n"+ armyOne.getAllUnits() + - "\n\n" + armyTwo.getName() +"\n"+ armyTwo.getAllUnits(); - } -} \ No newline at end of file diff --git a/src/main/java/BattleSimulation/armyFiles.java b/src/main/java/BattleSimulation/armyFiles.java deleted file mode 100644 index 4ba4ab7970dcb2071bf170596554d0738f88c834..0000000000000000000000000000000000000000 --- a/src/main/java/BattleSimulation/armyFiles.java +++ /dev/null @@ -1,119 +0,0 @@ -package BattleSimulation; - -import SpecificUnits.*; - -import java.io.*; -import java.nio.file.Files; -import java.nio.file.NoSuchFileException; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Objects; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class armyFiles { - - /** - * method that takes a unit and converts it to a string of csv type - * @param u the unit you want to convert - * @return string of csv type of the specific unit - */ - public static String makeCSVString(Unit u){ - return u.getClass().getSimpleName() +","+ u.getName()+","+u.getHealth()+","+u.getAttack()+","+u.getArmor() - +","+u.getMelee()+"\n"; - } - - /** - * method that creates a file from an army with the armys name - * @param army the army you want to create a file of - * @return File with the new army - * @throws IOException if file not found, or file is wrong throws exception - */ - public static File makeCSVFile(Army army) throws IOException{ - //makes a new file in the armyFile folder with the army name - File armyFile = new File("src/main/resources/armyFiles/"+army.getName().trim()); - - //checks if file is already in registry - if(armyFile.exists() && !armyFile.isDirectory()) { - throw new IllegalArgumentException("This ArmyFile is already in the registry"); - } - - Writer writer = new FileWriter(armyFile.getAbsolutePath()); - writer.write(armyFile.getName()+"\n"); - - // puts all units in a army to a specific list - army.getUnits() - .forEach(unit -> { - try { - writer.write(makeCSVString(unit)); - } catch (IOException e) { - e.printStackTrace(); - } - }); - - writer.close(); - return armyFile; - } - - /** - * method that takes a file and creates an army form its context - * @param armyName the file you are looking for also the name of the army - * @return the new Army created from the file - * @throws IOException any mistakes with the file will throw an exception - */ - public static Army readFromCSV(String armyName) throws IOException { - // finds path to wanted file - Path path = Path.of("src/main/resources/armyFiles/"+armyName); - if(Path.of("src/main/resources/armyFiles/"+armyName).getFileName() == null) throw new NoSuchFileException("File not found"); - - Army newArmy = new Army(armyName); - ArrayList<Unit> newUnits = new ArrayList<>(); - Files.lines(path) - .skip(1) - .forEach(line -> { - //checkForCharacters(line); - checkForUnit(line, newUnits); - }); - if (newUnits.size() == 0){ - throw new NullPointerException("This file doesnt contain any units"); - } - newArmy.addAll(newUnits); - return newArmy; - } - - /** - * method that checks which unitType a line from a file is - * @param line line from a file - * @param newUnits arrayList with the new Units created - */ - public static void checkForUnit(String line, ArrayList<Unit> newUnits){ - String[] column = line.split(","); - if(column.length < 6) throw new IllegalArgumentException("File is not readable"); - - // all 4 different unit types passed to an arraylist of units - String unitType = column[0]; - if(Objects.equals(unitType, "InfantryUnit")){ - newUnits.add(new InfantryUnit(column[1], Integer.parseInt(column[2]), Integer.parseInt(column[2]) - ,Integer.parseInt(column[3]),Integer.parseInt(column[4]))); - } else if(Objects.equals(unitType, "RangedUnit")){ - newUnits.add(new RangedUnit(column[1], Integer.parseInt(column[2]), Integer.parseInt(column[2]) - ,Integer.parseInt(column[3]),Integer.parseInt(column[4]))); - } else if(Objects.equals(unitType, "CavalryUnit")){ - newUnits.add(new CavalryUnit(column[1], Integer.parseInt(column[2]), Integer.parseInt(column[2]) - ,Integer.parseInt(column[3]),Integer.parseInt(column[4]))); - }else if(Objects.equals(unitType, "CommanderUnit")){ - newUnits.add(new CommanderUnit(column[1], Integer.parseInt(column[2]), Integer.parseInt(column[2]) - ,Integer.parseInt(column[3]),Integer.parseInt(column[4]))); - } - } - - /* - public static void checkForCharacters(String lines) throws IllegalArgumentException{ - String removeCharacters = "[\\d]"; - Pattern pt = Pattern.compile(removeCharacters); - Matcher mt = pt.matcher(lines); - boolean result = mt.matches(); - if (result) throw new IllegalArgumentException("Illegal characters found in file"); - } - */ -} \ No newline at end of file diff --git a/src/main/java/GameHub.java b/src/main/java/GameHub.java deleted file mode 100644 index b60f6a43d4f33d4858b59c107183bb8581f37418..0000000000000000000000000000000000000000 --- a/src/main/java/GameHub.java +++ /dev/null @@ -1,228 +0,0 @@ -import SpecificUnits.*; -import BattleSimulation.*; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import static javax.swing.JOptionPane.*; - -/** - * this is the client for my warGame - */ -public class GameHub { - - public static List<Unit> unitList = new ArrayList<>(); - public static List<Army> armyList = new ArrayList<>(); - - /** - * the main method that starts the game - * @param args - */ - public static void main(String[] args) { - start(); - } - - public static boolean finished = true; - - /** - * the start f the game, where you can choose what you want to do in the game - */ - public static void start() { - List<Army> armyList = new ArrayList<>(); - while(finished){ - try { - String[] menuInput = - { - "Register new Unit", - "Register new Army", - "Add all units", - "Multiply unit count", - "Remove all units registered", - "Run simulation", - "See all Units", - "End Game", - }; - final int REGISTER_NEW = 0; - final int REGISTER_ARMY = 1; - final int ADD_ALL = 2; - final int MULTIPY_UNIT = 3; - final int REMOVE_ALL = 4; - final int RUN_SIMULATION = 5; - final int SHOW_ALL_UNITS = 6; - final int EXIT = 7; - - int menuSelection = showOptionDialog(null, "****WarGames****" + "\n Choose function", - "Project Idatt2001", YES_NO_OPTION, INFORMATION_MESSAGE, null, menuInput, menuInput[0]); - - switch (menuSelection) { - case REGISTER_NEW -> { - REGISTERNEW(); - } - case REGISTER_ARMY -> { - REGISTERARMY(); - } - case ADD_ALL -> { - ADDALL(); - } - case MULTIPY_UNIT -> { - MULTIPYUNIT(); - } - case REMOVE_ALL -> { - REMOVEALL(); - } - case RUN_SIMULATION -> { - RUNSIMULATION(); - } - case SHOW_ALL_UNITS -> { - SHOWALLUNITS(); - } - - case EXIT -> { - System.out.println(""" - Thanks of using this Game - Bye - """); - finished = false; - } - } - - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - /** - * method where you register new units - */ - private static void REGISTERNEW() { - String typeRead = showInputDialog("what type of unit is it\n" + - "1. Infantry" + - "\n2. Range" + - "\n3. Cavalry" + - "\n4. Commander"); - int type = Integer.parseInt(typeRead); - String newName = showInputDialog("What is the name of the unit"); - String newDamageRead = showInputDialog("How much damage does it deal"); - int newDamage = Integer.parseInt(newDamageRead); - String newArmorRead = showInputDialog("How much Armor does it have"); - int newArmor = Integer.parseInt(newArmorRead); - String newHealthRead = showInputDialog("How much health does it have"); - int newHealth = Integer.parseInt(newHealthRead); - String newMeleeRead = showInputDialog("How much melee damage does it deal"); - int newMelee = Integer.parseInt(newMeleeRead); - - if (type == 1){ - unitList.add(new InfantryUnit(newName, newHealth, newDamage, newArmor, newMelee)); - } - else if(type == 2){ - unitList.add(new RangedUnit(newName, newHealth, newDamage, newArmor, newMelee)); - } - else if(type == 3){ - unitList.add(new CavalryUnit(newName, newHealth, newDamage, newArmor, newMelee)); - } - else if(type == 4){ - unitList.add(new CommanderUnit(newName, newHealth, newDamage, newArmor, newMelee)); - } - - } - - /** - * method for registering new army - */ - private static void REGISTERARMY() { - String newName = showInputDialog("Write the name of the army"); - Army army = new Army(newName); - armyList.add(army); - } - - /** - * method for adding all units to an army - */ - private static void ADDALL() { - String armyName = showInputDialog("what is the name of the army you want to add all these units to"); - for (Army a:armyList) { - if(Objects.equals(a.getName(), armyName)){ - a.addAll(unitList); - } - } - } - - /** - * method for multiplying a specific unit based on type - */ - private static void MULTIPYUNIT() { - String typeRead = showInputDialog("what type of unit is it\n" + - "1. Infantry" + - "\n2. Range" + - "\n3. Cavalry" + - "\n4. Commander"); - int type = Integer.parseInt(typeRead); - - String nameMultiple = showInputDialog("What is the name of unit you want to multiple"); - String howManyTimes = showInputDialog("How many do you want"); - int multipleNum = Integer.parseInt(howManyTimes); - - if (type == 1) { - for (Unit inf : unitList) { - if (Objects.equals(inf.getName(), nameMultiple)) { - for (int i = 0; i <= multipleNum; i++) { - unitList.add(new InfantryUnit(inf.getName(), inf.getHealth(), inf.getAttack(), inf.getArmor(), inf.getMelee())); - } - } - } - } - - else if (type == 2){ - for (Unit rng: unitList) { - if (Objects.equals(rng.getName(), nameMultiple)){ - for (int i = 0; i < multipleNum; i++) { - unitList.add(new RangedUnit(rng.getName(), rng.getHealth(), rng.getAttack(), rng.getArmor(), rng.getMelee())); - } - } - } - } - - else if (type == 3){ - for (Unit cav : unitList){ - if (Objects.equals(cav.getName(), nameMultiple)){ - for (int i = 0; i <= multipleNum; i++) { - unitList.add(new CavalryUnit(cav.getName(), cav.getHealth(), cav.getAttack(), cav.getArmor(), cav.getMelee())); - } - } - } - } - - else if (type == 4){ - for (Unit com : unitList){ - if (Objects.equals(com.getName(), nameMultiple)){ - for (int i = 0; i <= multipleNum; i++) { - unitList.add(new CommanderUnit(com.getName(), com.getHealth(), com.getAttack(), com.getArmor(), com.getMelee())); - } - } - } - } - } - - /** - * remove all units in the list, so you can make a new army - */ - private static void REMOVEALL() { - unitList.clear(); - } - - /** - * mathod that runs the simulation of the battle - */ - private static void RUNSIMULATION() { - Battle battle = new Battle(armyList.get(0), armyList.get(1)); - System.out.println(battle.simulate()); - } - - - /** - * shows all units registered - */ - private static void SHOWALLUNITS() { - System.out.println(unitList); - } - } diff --git a/src/main/java/SpecificUnits/CavalryUnit.java b/src/main/java/SpecificUnits/CavalryUnit.java deleted file mode 100644 index c193652f78c84b319cedbd4ae4c99d1065b79687..0000000000000000000000000000000000000000 --- a/src/main/java/SpecificUnits/CavalryUnit.java +++ /dev/null @@ -1,58 +0,0 @@ -package SpecificUnits; - -/** - * Cavalry class that represents the cavalry unit with special features - */ -public class CavalryUnit extends Unit { -private boolean firstCharge = true; - /** - * this is the constructor for all units - * @param name - * @param health - * @param attack damage - * @param armor protection - * @param melee melee damage - * @throws IllegalArgumentException if health sett < 0 or name is empty thr exception - */ - public CavalryUnit(String name, int health, int attack, int armor,int melee) throws IllegalArgumentException { - super(name, health, attack, armor, melee); - } - - /** - * an easier constructor with predefined attack and armor and melee - * @param name - * @param health - * @throws IllegalArgumentException if health sett < 0 or name is empty thr exception - */ - public CavalryUnit(String name, int health) throws IllegalArgumentException { - this(name, health, 20, 12, 2); - } - - - /** - *this method represents the attackBonuses of a cavalry unit - * the first attack of this unit will it will get a charge bonus +3 - * later on it will only have the melee attack as main attackBonus - * @return ether +5 or +2 as a attackBonus, depends on the firstCharge bonus - */ - @Override - int getAttackBonus() { - int charge = 3; - if(firstCharge){ - firstCharge = false; - return this.getMelee() + charge; - } - - return this.getMelee(); - } - - /** - * this unit has a better protection than basic infantry, and has a bonus of +3 to resistance - * @return bonus of 3 as resistance - */ - @Override - int getResistBonus() { - int cavalry = 3; - return cavalry; - } -} diff --git a/src/main/java/SpecificUnits/CommanderUnit.java b/src/main/java/SpecificUnits/CommanderUnit.java deleted file mode 100644 index 5e16c6fa2a93235a78fbd98fb26703b9e8edaf50..0000000000000000000000000000000000000000 --- a/src/main/java/SpecificUnits/CommanderUnit.java +++ /dev/null @@ -1,50 +0,0 @@ -package SpecificUnits; - -/** - * Commander class that represents all the variables and methods of a commander unit - */ -public class CommanderUnit extends CavalryUnit{ - - /** - * this is the constructor for all units - * @param name - * @param health - * @param attack damage - * @param armor protection - * @param melee melee damage - * @throws IllegalArgumentException if health sett < 0 or name is empty thr exception - */ - public CommanderUnit(String name, int health, int attack, int armor, int melee) throws IllegalArgumentException { - super(name, health, attack, armor, melee); - } - - /** - * an easier constructor with predefined attack and armor - * @param name - * @param health - * @throws IllegalArgumentException if health sett < 0 or name is empty thr exception - */ - public CommanderUnit(String name, int health) throws IllegalArgumentException { - this(name, health, 25, 15, 2); - } - - /** - *this method represents the attackBonuses of a cavalry unit - * the first attack of this unit will it will get a charge bonus +3 - * later on it will only have the melee attack as main attackBonus - * @return ether +5 or +2 as a attackBonus, depends on the firstCharge bonus - */ - @Override - int getAttackBonus() { - return super.getAttackBonus(); - } - - /** - * this unit has a better protection than basic infantry, and has a bonus of +3 to resistance - * @return bonus of 3 as resistance - */ - @Override - int getResistBonus() { - return super.getResistBonus(); - } -} diff --git a/src/main/java/SpecificUnits/InfantryUnit.java b/src/main/java/SpecificUnits/InfantryUnit.java deleted file mode 100644 index 2e52bec3e591566b94407f111f045d7820ebcb3e..0000000000000000000000000000000000000000 --- a/src/main/java/SpecificUnits/InfantryUnit.java +++ /dev/null @@ -1,48 +0,0 @@ -package SpecificUnits; - -/** - * Infantry class that represents all the variables and methods of an infantry unit - */ -public class InfantryUnit extends Unit{ - - /** - * this is the constructor for all units - * @param name - * @param health - * @param attack damage - * @param armor protection - * @param melee melee damage - * @throws IllegalArgumentException if health sett < 0 or name is empty thr exception - */ - public InfantryUnit(String name, int health, int attack, int armor, int melee) throws IllegalArgumentException { - super(name, health, attack, armor, melee); - } - - /** - * a constructor with predefined attack and armor - * @param name - * @param health - * @throws IllegalArgumentException if health sett < 0 or name is empty thr exception - */ - public InfantryUnit(String name, int health) throws IllegalArgumentException { - this(name, health, 15, 10, 2); - } - - /** - * this unit is a melee unit - * @return which means that it gets a +2 as a AttackBonus - */ - @Override - int getAttackBonus() { - return this.getMelee(); - } - - /** - * infantry unit has only a small armor bonus - * @return because of small armor bonus add 1 as a ResistBonus - */ - @Override - int getResistBonus() { - return 1; - } -} diff --git a/src/main/java/SpecificUnits/RangedUnit.java b/src/main/java/SpecificUnits/RangedUnit.java deleted file mode 100644 index 6c991a8ce25564d91a6dcbaebc4710aff5f07cdb..0000000000000000000000000000000000000000 --- a/src/main/java/SpecificUnits/RangedUnit.java +++ /dev/null @@ -1,59 +0,0 @@ -package SpecificUnits; - -/** - * Range class that represents all the variables and methods of a ranger unit - */ -public class RangedUnit extends Unit { - private int distanceDamage = 0; - private int distanceResist = 0; - - /** - * this is the constructor for all units - * @param name - * @param health - * @param attack damage - * @param armor protection - * @param melee melee damage - * @throws IllegalArgumentException if health sett < 0 or name is empty thr exception - */ - public RangedUnit(String name, int health, int attack, int armor, int melee) throws IllegalArgumentException { - super(name, health, attack, armor, melee); - } - - /** - * an easier constructor with predefined attack and armor - * @param name - * @param health - * @throws IllegalArgumentException if health sett < 0 or name is empty thr exception - */ - public RangedUnit(String name, int health) throws IllegalArgumentException { - this(name, health, 15, 8, 2); - } - - /** - * Range unit has a range attack bonus - * @return because this unit is range, this unit gets +3 as AttackBonus - */ - @Override - int getAttackBonus() { - if(distanceDamage >= 3){ - return this.getMelee(); - } - distanceDamage++; - return 3; - } - - /** - * Range units has an uniq resistantBonus that works as distance between him and his opponent - * @return because of this the range unit returns a bonus based on the variable multiplier (distance) - */ - @Override - int getResistBonus() { - int resistBonus = 6 - 2 * distanceResist; - if(resistBonus <= 2){ - resistBonus = 2; - } - distanceResist++; - return resistBonus; - } -} diff --git a/src/main/java/SpecificUnits/Unit.java b/src/main/java/SpecificUnits/Unit.java deleted file mode 100644 index 9ede60a9d35b67dfdbac4ac26a1a24ca701d6108..0000000000000000000000000000000000000000 --- a/src/main/java/SpecificUnits/Unit.java +++ /dev/null @@ -1,134 +0,0 @@ -package SpecificUnits; - -/** - * SpecificUnits.Unit class that works as a blueprint for all future specific unitclasses - * <p> - * has variables as name, health, DP and CP and to abstract methods - * which talks about bonus Damage or Armor - * </p> - */ -public abstract class Unit { - private String name; - private int health; - private int attack; - private int armor; - private int melee; - - - /** - * this is the constructor for all units - * @param name - * @param health - * @param attack damage - * @param armor protection - * @param melee this is implemented as all my units will be using this melee variable - * @throws IllegalArgumentException if health sett < 0 thr or name is empty exception - */ - public Unit(String name, int health, int attack, int armor, int melee) throws IllegalArgumentException { - if(name.isBlank()){ - throw new IllegalArgumentException("Name no blank bad"); - } - this.name = name; - - if(health < 0){ - throw new IllegalArgumentException("health less zero bad"); - } - this.health = health; - - //I think that attack and armor can be < 0 because in a war something can go wrong or very well - // Eg: a catapult can malfunction, or a units armor can ble less and less efficient - this.attack = attack; - this.armor = armor; - this.melee = melee; - } - - /** - * this is a attack method that takes simulates a unit attacking the opponent - * @param opponent the one this unit attacks - */ - public void attack(Unit opponent){ - int newHealth = opponent.health - (this.attack + this.getAttackBonus()) + (opponent.armor + opponent.getResistBonus()); - if(newHealth < opponent.getHealth()){ - opponent.setHealth(newHealth); - } - } - - /** - * get method for name of the unit - * @return the name of this unit - */ - public String getName() { - return name; - } - - /** - * get method for health of the unit - * @return the health of this unit - */ - public int getHealth() { - return health; - } - - /** - * get method for attacking damage of this unit - * @return the damage or DP of this unit - */ - public int getAttack() { - return attack; - } - - /** - * get method for armor protection of the unit - * @return the protection or AP of this unit - */ - public int getArmor() { - return armor; - } - - /** - * get method for when a unit changes to melee combat - * @return the bonus of using melee - */ - public int getMelee() { - return melee; - } - - /** - * set method that changes the health of a unit if it gets damaged - * @param newHealth the newhealth of this unit after it gets damaged - */ - public void setHealth(int newHealth) { - this.health = newHealth; - } - - /** - * an abstract method for showing an attacking bonus - * <p> - * an abstract method which wil be declared,and further used in subclasses - * </p> - * @return attackBonus as an int - */ - abstract int getAttackBonus(); - - /** - * an abstract method for showing an armor bonus - * <p> - * an abstract method which wil be declared,and further used in subclasses - * </p> - * @return ResistBonus as an int - */ - abstract int getResistBonus(); - - - /** - * a to string method that print out a units statistics in an order - * @return a string of all statistics - */ - @Override - public String toString() { - return "\n\nThe statistics of unit: \n" +name+ - "\nHealth:\n" + health+ - "\nDamage/DP:\n" + attack+ - "\nArmor/AP \n" + armor; - } -} diff --git a/src/main/resources/WarGames_del2/IDATx2001 - Wargames - Del 2.pdf b/src/main/resources/WarGames_del2/IDATx2001 - Wargames - Del 2.pdf deleted file mode 100644 index 18ca0a5d2b82457f2bc6c89f98a8d4e814f128b4..0000000000000000000000000000000000000000 Binary files a/src/main/resources/WarGames_del2/IDATx2001 - Wargames - Del 2.pdf and /dev/null differ diff --git a/src/main/resources/Wargame_del1/IDATx2001 - Wargames - Del 1.pdf b/src/main/resources/Wargame_del1/IDATx2001 - Wargames - Del 1.pdf deleted file mode 100644 index cd190a0afec76373aa2a20b7e221882cd1304377..0000000000000000000000000000000000000000 Binary files a/src/main/resources/Wargame_del1/IDATx2001 - Wargames - Del 1.pdf and /dev/null differ diff --git a/src/test/java/BattleSimulation/ArmyTest.java b/src/test/java/BattleSimulation/ArmyTest.java deleted file mode 100644 index 9553ffbdd5ab056984ff34371ec525a6eff9af2a..0000000000000000000000000000000000000000 --- a/src/test/java/BattleSimulation/ArmyTest.java +++ /dev/null @@ -1,165 +0,0 @@ -package BattleSimulation; - -import SpecificUnits.*; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -class ArmyTest { - - public Army armyTest; - - @BeforeEach - void Initiate_army_with_units(){ - String testName = "Human Army"; - armyTest = new Army(testName); - - List<Unit> listTest = new ArrayList<>(); - Unit infantryTest = new InfantryUnit("Knight", 10); - Unit RangeTest = new RangedUnit("Bowmen", 10); - Unit CavalryTest = new CavalryUnit("Rider", 10); - Unit CommanderUnit = new CommanderUnit("Commander", 10); - - listTest.add(infantryTest); - listTest.add(RangeTest); - listTest.add(CavalryTest); - listTest.add(CommanderUnit); - - armyTest.addAll(listTest); - - } - - @Test - void Test_if_constructor_Works_as_expected(){ - Army armyTest = new Army("Human Army"); - assertEquals("Human Army", armyTest.getName()); - } - - @Test - void Test_to_see_if_other_constructor_also_works(){ - ArrayList<Unit> unitList = new ArrayList<>(); - unitList.add(new InfantryUnit("name",1,1,1,1)); - Army armyTest = new Army("Human Army", unitList); - assertEquals(unitList.get(0), armyTest.getUnits().get(0)); - } - - @Test - void getName() { - assertEquals("Human Army", armyTest.getName()); - } - - @Test - void add() { - String testName = "Human Army"; - Army armies = new Army(testName); - - Unit infantryTest = new InfantryUnit("Knight", 10); - armies.add(infantryTest); - - assertEquals(infantryTest,armies.getUnits().get(0)); - } - - @Test - void addAll() { - assertEquals(3, armyTest.getUnits().size()); - } - - @Test - void remove() { - String testName = "Human Army"; - Army armies = new Army(testName); - - Unit infantryTest = new InfantryUnit("Knight", 10); - armies.add(infantryTest); - - armies.remove(infantryTest); - - assertEquals(0,armies.getUnits().size()); - - } - - @Test - void hasUnits() { - assertTrue(armyTest.hasUnits()); - } - - @Test - void getAllUnits() { - assertEquals(2, armyTest.getAllUnits().size()); - } - - @Test - void getRandom() { - assertNotNull(armyTest.getRandom()); - } - - @Nested - public class Test_for_GetMethods_for_different_object_from_one_list { - - @Test - public void Test_if_getInfantry_units_only_has_all_infantry_units_in_a_army(){ - assertTrue(armyTest.getInfantryUnits().get(0) instanceof InfantryUnit); - } - - @Test - public void Test_if_getRange_units_only_has_all_range_units_in_a_army(){ - assertTrue(armyTest.getRangeUnits().get(0) instanceof RangedUnit); - } - - @Test - public void Test_if_getCavalry_units_only_has_all_cavalry_units_in_a_army(){ - assertTrue(armyTest.getCavalryUnits().get(0) instanceof CavalryUnit); - } - - @Test - public void Test_if_getCommander_units_only_has_all_commander_units_in_a_army(){ - assertTrue(armyTest.getCommanderUnits().get(0) instanceof CommanderUnit); - } - - @Test - public void Test_to_see_if_commander_unit_can_be_accessed_from_getCavalryUnits(){ - assertNotEquals(2, armyTest.getCavalryUnits().size()); - } - } - - @Test - void testEquals() { - String testName1 = "Human Army"; - String testName2 = "Orc Army"; - - Army armyTest1 = new Army(testName1); - Army armyTest2 = new Army(testName2); - Army armyTest3 = armyTest1; - Army armyTest4 = new Army(testName1); - - assertNotEquals(armyTest1, armyTest2); - assertTrue(armyTest1.equals(armyTest3)); - assertTrue(armyTest1.equals(armyTest4)); - - } - - @Test - void testHashCode() { - String testName1 = "Human Army"; - String testName2 = "Orc Army"; - - Army armyTest1 = new Army(testName1); - Army armyTest2 = new Army(testName2); - Army armyTest3 = armyTest1; - - assertNotEquals(armyTest1.hashCode(), armyTest2.hashCode()); - assertEquals(armyTest1.hashCode(), armyTest3.hashCode()); - } - - @Test - void testToString() { - String testName1 = "Human Army"; - Army armyTest1 = new Army(testName1); - - assertEquals("Human Army\nunits=[]", armyTest1.toString()); - } -} \ No newline at end of file diff --git a/src/test/java/BattleSimulation/BattleTest.java b/src/test/java/BattleSimulation/BattleTest.java deleted file mode 100644 index 00060af370b06392e8274362a641a1bd397dc08b..0000000000000000000000000000000000000000 --- a/src/test/java/BattleSimulation/BattleTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package BattleSimulation; - -import SpecificUnits.*; -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; -class BattleTest { - - @Test - void simulate() { - Army armyTest1 = new Army("A"); - Army armyTest2 = new Army("B"); - Battle battleTest = new Battle(armyTest1, armyTest2); - - List<Unit> listTest1 = new ArrayList<>(); - Unit infantryTest1 = new InfantryUnit("Knight", 10); - Unit RangeTest1 = new RangedUnit("Bowmen", 10); - Unit CavalryTest1 = new CavalryUnit("Rider", 10); - - listTest1.add(infantryTest1); - listTest1.add(RangeTest1); - listTest1.add(CavalryTest1); - - - List<Unit> listTest2 = new ArrayList<>(); - Unit infantryTest2 = new InfantryUnit("Orc", 10); - Unit RangeTest2 = new RangedUnit("Orc crossbow", 10); - Unit CavalryTest2 = new CavalryUnit("Wolf Rider", 10); - - listTest2.add(infantryTest2); - listTest2.add(RangeTest2); - listTest2.add(CavalryTest2); - - - armyTest1.addAll(listTest1); - armyTest2.addAll(listTest2); - - String result = battleTest.simulate().toString(); - System.out.println(result); - } - - @Test - void testToString() { - Army test1 = new Army("A"); - Army test2 = new Army("B"); - Battle battle = new Battle(test1, test2); - battle.whoStarts(); - - assertEquals("A\n[]\n\nB\n[]", battle.toString()); - } -} - diff --git a/src/test/java/BattleSimulation/armyFilesTest.java b/src/test/java/BattleSimulation/armyFilesTest.java deleted file mode 100644 index b3fdef535b5ab234487185fb052eb9bfd0ee95d0..0000000000000000000000000000000000000000 --- a/src/test/java/BattleSimulation/armyFilesTest.java +++ /dev/null @@ -1,101 +0,0 @@ -package BattleSimulation; - -import SpecificUnits.InfantryUnit; -import SpecificUnits.RangedUnit; -import SpecificUnits.Unit; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; -import java.io.File; -import java.io.IOException; -import java.nio.file.NoSuchFileException; -import static org.junit.jupiter.api.Assertions.*; - -public class armyFilesTest { - - @Test - public void Test_if_createCSVString_creates_string_of_a_Unit(){ - Unit InfantryTest = new InfantryUnit("Footman", 10); - assertEquals("InfantryUnit,Footman,10,15,10,2"+"\n", armyFiles.makeCSVString(InfantryTest)); - } - - //TODO: check for corrupt files - - @Nested - public class Test_makeCVSFile_method_and_exceptions { - - @Test - public void Test_if_makeCSVFile_makes_a_file_in_armyFile_in_CSV_format() throws IOException { - Unit InfantryTest = new InfantryUnit("Footman", 10); - Unit RangeTest = new RangedUnit("Bowman", 10); - Army armyTest = new Army("Human Army"); - armyTest.add(InfantryTest); - armyTest.add(RangeTest); - - File file = armyFiles.makeCSVFile(armyTest); - assertNotNull(file); - file.delete(); - } - - @Test - public void Test_if_makeCVSFile_throws_IllegalArgumentException_when_a_file_already_exists(){ - Army armyFileExisting = new Army("ExsistingFiletest"); - assertThrows(IllegalArgumentException.class, () -> { - armyFiles.makeCSVFile(armyFileExisting); - }); - } - } - - @Nested - public class Test_readFromCVS_method_and_exceptions{ - - @Test - public void Test_if_readFromCSV_creates_a_army_of_a_wanted_file() throws IOException { - Army armyFileTest = armyFiles.readFromCSV("HumanArmyTest"); - assertEquals(2, armyFileTest.getUnits().size()); - } - - @Test - public void Test_if_readFromCSV_throws_IO_exception(){ - assertThrows(IOException.class, () -> { - armyFiles.readFromCSV(""); - }); - } - - @Test - public void Test_if_readFromCSV_throws_NullPointerException_when_file_has_no_units(){ - assertThrows(NullPointerException.class, () -> { - armyFiles.readFromCSV("NullArmyTest"); - }); - } - - @Test - public void Test_if_readFromCSV_throws_IllegalArgumentException_when_file_not_readable(){ - assertThrows(IllegalArgumentException.class, () -> { - armyFiles.readFromCSV("NotReadableFile"); - }); - } - - @Test - public void Test_if_readFromCSV_throws_NoSuchFileException_when_a_file_doenst_exits(){ - assertThrows(NoSuchFileException.class, () -> { - armyFiles.readFromCSV("NoFileExist"); - }); - } - - @Test - public void Test_if_file_has_units_and_throws_if_not(){ - assertThrows(NullPointerException.class, () -> { - armyFiles.readFromCSV("NullArmyTest"); - }); - } - - /* - @Test - public void Test_if_file_is_corrupt_or_has_illegal_characters_throw_IllegalArgumentException(){ - assertThrows(IllegalArgumentException.class, () -> { - armyFiles.readFromCSV("IllegalCharacters"); - }); - } - */ - } -} diff --git a/src/test/java/SpecificUnits/CavalryUnitTest.java b/src/test/java/SpecificUnits/CavalryUnitTest.java deleted file mode 100644 index f883fa52330c4a007cb7ab1be46f5352e14b40ed..0000000000000000000000000000000000000000 --- a/src/test/java/SpecificUnits/CavalryUnitTest.java +++ /dev/null @@ -1,114 +0,0 @@ -package SpecificUnits; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class CavalryUnitTest { - - @Test - void attack() { - Unit test1 = new Unit("Rider", 0, 1, 0, 0) { - @Override - int getAttackBonus() { - return 0; - } - - @Override - int getResistBonus() { - return 0; - } - }; - Unit test2 = new Unit("Knight", 10, 0, 0, 0) { - @Override - int getAttackBonus() { - return 0; - } - - @Override - int getResistBonus() { - return 0; - } - }; - - test1.attack(test2); - - assertEquals(9, test2.getHealth()); - } - - @Test - void getName() { - Unit test = new CavalryUnit("Rider",10); - assertEquals("Rider",test.getName()); - } - - @Test - void getHealth() { - Unit test = new CavalryUnit("Rider",1); - assertEquals(1,test.getHealth()); - } - - @Test - void getAttack() { - Unit test = new CavalryUnit("Rider",1,2,3,4); - assertEquals(2,test.getAttack()); - } - - @Test - void getArmor() { - Unit test = new CavalryUnit("Rider",1,2,3,4); - assertEquals(3,test.getArmor()); - } - - @Test - void getMelee() { - Unit test = new CavalryUnit("Rider",1,2,3,4); - assertEquals(4,test.getMelee()); - } - - @Test - void setHealth() { - Unit test = new CavalryUnit("Rider",1,2,3,4); - test.setHealth(2); - assertEquals(2,test.getHealth()); - } - - @Test - void testToString() { - Unit test = new CavalryUnit("Rider",1,2,3,4); - assertEquals("\n\n"+ """ - The statistics of unit:\s - Rider - Health: - 1 - Damage/DP: - 2 - Armor/AP\s - 3""",test.toString()); - } - - @Test - void getAttackBonus() { - Unit test1 = new CavalryUnit("Rider",0,2,0,2); - Unit test2 = new InfantryUnit("Knight",20,0,0,0); - - test1.attack(test2); - test1.attack(test2); - test1.attack(test2); - -//test alle - assertEquals(8, test2.getHealth()); - } - - @Test - void getResistBonus() { - Unit test1 = new CavalryUnit("Rider",10,0,0,0); - Unit test2 = new InfantryUnit("Knight",0,2,0,2); - - test2.attack(test1); - test2.attack(test1); - - assertEquals(8, test1.getHealth()); - - } -} \ No newline at end of file diff --git a/src/test/java/SpecificUnits/CommanderUnitTest.java b/src/test/java/SpecificUnits/CommanderUnitTest.java deleted file mode 100644 index 58397e8cb393da28703823981f8d017914d322b7..0000000000000000000000000000000000000000 --- a/src/test/java/SpecificUnits/CommanderUnitTest.java +++ /dev/null @@ -1,113 +0,0 @@ -package SpecificUnits; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class CommanderUnitTest { - @Test - void attack() { - Unit test1 = new Unit("Commander", 0, 1, 0, 0) { - @Override - int getAttackBonus() { - return 0; - } - - @Override - int getResistBonus() { - return 0; - } - }; - Unit test2 = new Unit("Knight", 10, 0, 0, 0) { - @Override - int getAttackBonus() { - return 0; - } - - @Override - int getResistBonus() { - return 0; - } - }; - - test1.attack(test2); - - assertEquals(9, test2.getHealth()); - } - - @Test - void getName() { - Unit test = new CommanderUnit("Commander",10); - assertEquals("Commander",test.getName()); - } - - @Test - void getHealth() { - Unit test = new CommanderUnit("Commander",1); - assertEquals(1,test.getHealth()); - } - - @Test - void getAttack() { - Unit test = new CommanderUnit("Commander",1,2,3,4); - assertEquals(2,test.getAttack()); - } - - @Test - void getArmor() { - Unit test = new CavalryUnit("Rider",1,2,3,4); - assertEquals(3,test.getArmor()); - } - - @Test - void getMelee() { - Unit test = new CommanderUnit("Commander",1,2,3,4); - assertEquals(4,test.getMelee()); - } - - @Test - void setHealth() { - Unit test = new CommanderUnit("Commander",1,2,3,4); - test.setHealth(2); - assertEquals(2,test.getHealth()); - } - - @Test - void testToString() { - Unit test = new CommanderUnit("Commander",1,2,3,4); - assertEquals("\n\n"+ """ - The statistics of unit:\s - Commander - Health: - 1 - Damage/DP: - 2 - Armor/AP\s - 3""",test.toString()); - } - - @Test - void getAttackBonus() { - Unit test1 = new CommanderUnit("Commander",0,2,0,2); - Unit test2 = new InfantryUnit("Knight",20,0,0,0); - - test1.attack(test2); - test1.attack(test2); - test1.attack(test2); - - - assertEquals(8, test2.getHealth()); - } - - @Test - void getResistBonus() { - Unit test1 = new CommanderUnit("Commander",10,0,0,0); - Unit test2 = new InfantryUnit("Knight",0,2,0,2); - - test2.attack(test1); - test2.attack(test1); - - assertEquals(8, test1.getHealth()); - - } -} \ No newline at end of file diff --git a/src/test/java/SpecificUnits/InfantryUnitTest.java b/src/test/java/SpecificUnits/InfantryUnitTest.java deleted file mode 100644 index 4838edbc152bfca5ffc8b79b5247f931166ade80..0000000000000000000000000000000000000000 --- a/src/test/java/SpecificUnits/InfantryUnitTest.java +++ /dev/null @@ -1,109 +0,0 @@ -package SpecificUnits; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class InfantryUnitTest { - - @Test - void attack() { - Unit test1 = new Unit("knight",0, 1, 0, 0) { - @Override - int getAttackBonus() { - return 0; - } - - @Override - int getResistBonus() { - return 0; - } - }; - Unit test2 = new Unit("Orc", 10, 0, 0, 0) { - @Override - int getAttackBonus() { - return 0; - } - - @Override - int getResistBonus() { - return 0; - } - }; - - test1.attack(test2); - assertEquals(9, test2.getHealth()); - - } - - @Test - void getName() { - Unit test = new InfantryUnit("Knight",10); - assertEquals("Knight",test.getName()); - } - - @Test - void getHealth() { - Unit test = new InfantryUnit("Knight", 10); - assertEquals(10,test.getHealth()); - } - - @Test - void getAttack() { - Unit test = new InfantryUnit("knight",1,2,3,4); - assertEquals(2,test.getAttack()); - } - - @Test - void getArmor() { - Unit test = new InfantryUnit("knight",1,2,3,4); - assertEquals(3,test.getArmor()); - } - - @Test - void getMelee() { - Unit test = new InfantryUnit("knight",1,2,3,4); - assertEquals(4,test.getMelee()); - } - - @Test - void setHealth() { - Unit test = new InfantryUnit("knight",1,2,3,4); - test.setHealth(10); - assertEquals(10,test.getHealth()); - } - - @Test - void testToString() { - Unit test = new InfantryUnit("knight",1,2,3,4); - assertEquals("\n\n"+ """ - The statistics of unit:\s - knight - Health: - 1 - Damage/DP: - 2 - Armor/AP\s - 3""",test.toString()); - } - - @Test - void getAttackBonus() { - Unit test1 = new InfantryUnit("knight",1,0,0,2); - Unit test2 = new InfantryUnit("Orc",10,0,0,0); - - test1.attack(test2); - - assertEquals(9, test2.getHealth()); - } - - @Test - void getResistBonus() { - Unit test1 = new InfantryUnit("knight",1,0,0,2); - Unit test2 = new InfantryUnit("Orc",10,0,0,0); - - test1.attack(test2); - - assertEquals(9, test2.getHealth()); - } -} \ No newline at end of file diff --git a/src/test/java/SpecificUnits/RangedUnitTest.java b/src/test/java/SpecificUnits/RangedUnitTest.java deleted file mode 100644 index fefe9ab4bdb68787fbd72fcd23bb9d9ef782c4e4..0000000000000000000000000000000000000000 --- a/src/test/java/SpecificUnits/RangedUnitTest.java +++ /dev/null @@ -1,118 +0,0 @@ -package SpecificUnits; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.*; - -class RangedUnitTest { - - @Test - void attack() { - Unit test1 = new Unit("Bowman", 10, 1, 0, 0) { - @Override - int getAttackBonus() { - return 0; - } - - @Override - int getResistBonus() { - return 0; - } - }; - Unit test2 = new Unit("Knight", 10, 0, 0, 0) { - @Override - int getAttackBonus() { - return 0; - } - - @Override - int getResistBonus() { - return 0; - } - }; - - test1.attack(test2); - - assertEquals(9, test2.getHealth()); - } - - @Test - void getName() { - Unit test = new RangedUnit("Bowmen",10); - assertEquals("Bowmen",test.getName()); - } - - @Test - void getHealth() { - Unit test = new RangedUnit("Bowmen",1); - assertEquals(1,test.getHealth()); - } - - @Test - void getAttack() { - Unit test = new RangedUnit("Bowmen",1,2,3,4); - assertEquals(2,test.getAttack()); - } - - @Test - void getArmor() { - Unit test = new RangedUnit("Bowmen",1,2,3,4); - assertEquals(3,test.getArmor()); - } - - @Test - void getMelee() { - Unit test = new RangedUnit("Bowmen",1,2,3,4); - assertEquals(4,test.getMelee()); - } - - @Test - void setHealth() { - Unit test = new RangedUnit("Bowmen",1,2,3,4); - test.setHealth(2); - assertEquals(2,test.getHealth()); - } - - @Test - void testToString() { - Unit test = new RangedUnit("Bowmen",1,2,3,4); - assertEquals("\n\n"+ """ - The statistics of unit:\s - Bowmen - Health: - 1 - Damage/DP: - 2 - Armor/AP\s - 3""",test.toString()); - } - - @Test - void getAttackBonus() { - Unit test1 = new RangedUnit("Bowman",10,2,1,1); - Unit test2 = new InfantryUnit("Knight",20,1,1,1); - - test1.attack(test2); - test1.attack(test2); - test1.attack(test2); - test1.attack(test2); - test1.attack(test2); - - assertEquals(9, test2.getHealth()); - } - - @Test - void getResistBonus() { - Unit test1 = new RangedUnit("Bowman",15,0,0,0); - Unit test2 = new InfantryUnit("Knight",0,3,0,2); - - test2.attack(test1); - test2.attack(test1); - test2.attack(test1); - test2.attack(test1); - test2.attack(test1); - - assertEquals(5, test1.getHealth()); - - } -} \ No newline at end of file