commit a7e636265804d368a858bb7aaa2b5fbdf04f5af2 Author: Andrew Date: Fri Nov 25 11:49:17 2022 +0200 Initial commit diff --git a/Main/Battlefield.class b/Main/Battlefield.class new file mode 100644 index 0000000..988f483 Binary files /dev/null and b/Main/Battlefield.class differ diff --git a/Main/Battlefield.java b/Main/Battlefield.java new file mode 100644 index 0000000..357f908 --- /dev/null +++ b/Main/Battlefield.java @@ -0,0 +1,73 @@ +package Main; + +import java.util.*; + +public class Battlefield { + protected HashMap battlefield = new HashMap(); + protected int id1, id2, deadLutemon; + protected Lutemon lutemon1, lutemon2, temp; + Scanner scanner; + private Boolean exit = true; + + public Battlefield(Scanner scanner) { + this.scanner = scanner; + } + + public void addLutemon(int id, Lutemon lutemon) { + battlefield.put(id, lutemon); + } + + public void removeLutemon(int id) { + battlefield.remove(id); + } + + public void fight() { + exit = true; + try { + System.out.println("Give the ID of the first fighter:"); + id1 = Integer.parseInt(scanner.nextLine()); + lutemon1 = battlefield.get(id1); + System.out.println("Give the ID of the second fighter:"); + id2 = Integer.parseInt(scanner.nextLine()); + lutemon2 = battlefield.get(id2); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + while (exit) { + System.out.println(lutemon1.printStats()); + System.out.println(lutemon2.printStats()); + lutemon2.defense(lutemon1.attack()); + System.out.println( + lutemon1.getColor() + "(" + lutemon1.getName() + ") attacks " + lutemon2.getColor() + "(" + + lutemon2.getName() + ")"); + if (lutemon2.checkAlive()) { + System.out + .println(lutemon2.getColor() + "(" + lutemon2.getName() + ") manages to escape death."); + temp = lutemon1; + lutemon1 = lutemon2; + lutemon2 = temp; + } else { + System.out.println(lutemon2.getColor() + "(" + lutemon2.getName() + ") gets killed."); + System.out.println("The battle is over."); + if (battlefield.get(id2) == lutemon2) { + battlefield.remove(id2); + lutemon1.train(); + deadLutemon = id2; + } else { + battlefield.remove(id1); + lutemon2.train(); + deadLutemon = id1; + } + exit = false; + } + } + } + + public HashMap getBattlefield() { + return battlefield; + } + + public int deadLutemon() { + return deadLutemon; + } +} diff --git a/Main/Black.class b/Main/Black.class new file mode 100644 index 0000000..9200231 Binary files /dev/null and b/Main/Black.class differ diff --git a/Main/Black.java b/Main/Black.java new file mode 100644 index 0000000..66cc6d7 --- /dev/null +++ b/Main/Black.java @@ -0,0 +1,7 @@ +package Main; + +public class Black extends Lutemon { + public Black(String name, String color, int exp, int attack, int defense, int health) { + super(name, color, exp, attack, defense, health); + } +} diff --git a/Main/Green.class b/Main/Green.class new file mode 100644 index 0000000..b2dc375 Binary files /dev/null and b/Main/Green.class differ diff --git a/Main/Green.java b/Main/Green.java new file mode 100644 index 0000000..56ff67d --- /dev/null +++ b/Main/Green.java @@ -0,0 +1,7 @@ +package Main; + +public class Green extends Lutemon { + public Green(String name, String color, int exp, int attack, int defense, int health) { + super(name, color, exp, attack, defense, health); + } +} diff --git a/Main/Home.class b/Main/Home.class new file mode 100644 index 0000000..1b075b3 Binary files /dev/null and b/Main/Home.class differ diff --git a/Main/Home.java b/Main/Home.java new file mode 100644 index 0000000..8b485f6 --- /dev/null +++ b/Main/Home.java @@ -0,0 +1,28 @@ +package Main; + +import java.util.*; + +public class Home { + protected HashMap home = new HashMap(); + + public Home() { + + } + + public void addLutemon(int id, Lutemon lutemon) { + home.put(id, lutemon); + heal(lutemon); + } + + public void removeLutemon(int id) { + home.remove(id); + } + + public void heal(Lutemon lutemon) { + lutemon.heal(); + } + + public HashMap getHome() { + return home; + } +} diff --git a/Main/Lutemon.class b/Main/Lutemon.class new file mode 100644 index 0000000..4860863 Binary files /dev/null and b/Main/Lutemon.class differ diff --git a/Main/Lutemon.java b/Main/Lutemon.java new file mode 100644 index 0000000..cecda3f --- /dev/null +++ b/Main/Lutemon.java @@ -0,0 +1,88 @@ +package Main; + +public class Lutemon { + protected String name, color; + protected int id, exp, attack, defense, health, maxHealth; + private static int idCounter = 0; + + public Lutemon(String name, String color, int exp, int attack, int defense, int health) { + this.name = name; + this.color = color; + this.exp = 0; + this.attack = attack; + this.defense = defense; + this.health = health; + this.maxHealth = health; + this.id = idCounter; + idCounter++; + } + + public String getName() { + return name; + } + + public String getColor() { + return color; + } + + public int getId() { + return id; + } + + public int getExp() { + return exp; + } + + public int getAttack() { + return attack; + } + + public int getDefense() { + return defense; + } + + public int getMaxHealth() { + return maxHealth; + } + + public int getHealth() { + return health; + } + + public void heal() { + this.health = this.maxHealth; + } + + public void train() { + this.exp++; + } + + public String printStats() { + return (getId() + ": " + getColor() + "(" + getName() + ") " + "att: " + + getAttack() + "; def: " + getDefense() + "; exp:" + + getExp() + "; health: " + getHealth() + "/" + + getMaxHealth()); + + } + + public static int getIdCounter() { + return idCounter; + } + + public int attack() { + return getAttack() + getExp(); + } + + public void defense(int attack) { + this.health -= attack - this.defense; + + } + + public boolean checkAlive() { + if (this.health > 0) { + return true; + } else { + return false; + } + } +} diff --git a/Main/Main.class b/Main/Main.class new file mode 100644 index 0000000..81f4b21 Binary files /dev/null and b/Main/Main.class differ diff --git a/Main/Main.java b/Main/Main.java new file mode 100644 index 0000000..3fac1d8 --- /dev/null +++ b/Main/Main.java @@ -0,0 +1,59 @@ +package Main; + +import java.util.Scanner; + +/** + * + * @author gessle + */ +public class Main { + + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + boolean exit = false; + + System.out.println("Welcome to the Lutemon simulator!"); + Storage storage = new Storage(sc); + while (!exit) { + System.out.println( + "1) Create a Lutemon, 2) List all the Lutemons, 3) Move Lutemons, 4) Train Lutemons, 5) Let them fight, 0) Exit"); + int i = 0; + String si = sc.nextLine(); + try { + i = Integer.parseInt(si); + } catch (NumberFormatException ex) { + ex.printStackTrace(); + } + switch (i) { + case 1: + storage.createLutemon(); + break; + case 2: + storage.listLutemons(); + break; + case 3: + storage.moveLutemons(); + break; + case 4: + storage.trainLutemon(); + break; + case 5: + storage.fightLutemon(); + break; + case 0: + exit = true; + System.out.println( + "The game has closed. In total " + Lutemon.getIdCounter() + + " Lutemons were created."); + break; + default: + System.out.println("Unknown option."); + break; + } + + } + sc.close(); + + } +} \ No newline at end of file diff --git a/Main/Orange.class b/Main/Orange.class new file mode 100644 index 0000000..4dc31fd Binary files /dev/null and b/Main/Orange.class differ diff --git a/Main/Orange.java b/Main/Orange.java new file mode 100644 index 0000000..da8fa87 --- /dev/null +++ b/Main/Orange.java @@ -0,0 +1,8 @@ +package Main; + +public class Orange extends Lutemon { + public Orange(String name, String color, int exp, int attack, int defense, int health) { + super(name, color, exp, attack, defense, health); + } + +} diff --git a/Main/Pink.class b/Main/Pink.class new file mode 100644 index 0000000..2c4fb68 Binary files /dev/null and b/Main/Pink.class differ diff --git a/Main/Pink.java b/Main/Pink.java new file mode 100644 index 0000000..0db03ce --- /dev/null +++ b/Main/Pink.java @@ -0,0 +1,7 @@ +package Main; + +public class Pink extends Lutemon { + public Pink(String name, String color, int exp, int attack, int defense, int health) { + super(name, color, exp, attack, defense, health); + } +} diff --git a/Main/Storage.class b/Main/Storage.class new file mode 100644 index 0000000..26353e0 Binary files /dev/null and b/Main/Storage.class differ diff --git a/Main/Storage.java b/Main/Storage.java new file mode 100644 index 0000000..65d54d2 --- /dev/null +++ b/Main/Storage.java @@ -0,0 +1,155 @@ +package Main; + +import java.util.*; + +public class Storage { + protected HashMap storage = new HashMap(); + private int choice, id; + private String name; + Scanner scanner; + private Home home = new Home(); + private TrainingArea training = new TrainingArea(); + private Battlefield battlefield; + + public Storage(Scanner scanner) { + this.scanner = scanner; + this.battlefield = new Battlefield(scanner); + } + + public void createLutemon() { + try { + System.out.println("Add 1) White, 2) Green, 3) Pink, 4) Orange, 5) Black"); + String a = scanner.nextLine(); + choice = Integer.parseInt(a); + System.out.println("Give it a name:"); + name = scanner.nextLine(); + + } catch (NumberFormatException e) { + e.printStackTrace(); + } + switch (choice) { + case 1: + White white = new White(name, "White", 0, 5, 4, 20); + storage.put(white.getId(), white); + home.addLutemon(white.getId(), white); + break; + case 2: + Green green = new Green(name, "Green", 0, 6, 3, 19); + storage.put(green.getId(), green); + home.addLutemon(green.getId(), green); + break; + case 3: + Pink pink = new Pink(name, "Pink", 0, 7, 2, 18); + storage.put(pink.getId(), pink); + home.addLutemon(pink.getId(), pink); + break; + case 4: + Orange orange = new Orange(name, "Orange", 0, 8, 1, 17); + storage.put(orange.getId(), orange); + home.addLutemon(orange.getId(), orange); + break; + case 5: + Black black = new Black(name, "Black", 0, 9, 0, 16); + storage.put(black.getId(), black); + home.addLutemon(black.getId(), black); + break; + default: + System.out.println("Invalid choice."); + break; + } + } + + public void listLutemons() { + System.out.println("There are the following Lutemons at Home:"); + for (Lutemon lutemon : home.getHome().values()) { + System.out.println(lutemon.printStats()); + } + System.out.println("There are the following Lutemons at Training area:"); + for (Lutemon lutemon : training.getTraining().values()) { + System.out.println(lutemon.printStats()); + } + System.out.println("There are the following Lutemons at Battle field:"); + for (Lutemon lutemon : battlefield.getBattlefield().values()) { + System.out.println(lutemon.printStats()); + } + } + + public void moveLutemons() { + try { + System.out.println("Give the ID of Lutemon that should be moved:"); + id = Integer.parseInt(scanner.nextLine()); + System.out.println( + "Where would the Lutemon be moved? 1) Home, 2) Training area, 3) Battle field"); + choice = Integer.parseInt(scanner.nextLine()); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + if (checkIfExists(id)) { + switch (choice) { + case 1: + if (home.getHome().containsKey(id) == false) { + if (training.getTraining().containsKey(id)) { + training.removeLutemon(id); + home.addLutemon(id, storage.get(id)); + } else if (battlefield.getBattlefield().containsKey(id)) { + battlefield.removeLutemon(id); + home.addLutemon(id, storage.get(id)); + } + } + break; + case 2: + if (training.getTraining().containsKey(id) == false) { + if (home.getHome().containsKey(id)) { + home.removeLutemon(id); + training.addLutemon(id, storage.get(id)); + } else if (battlefield.getBattlefield().containsKey(id)) { + battlefield.removeLutemon(id); + training.addLutemon(id, storage.get(id)); + } + } + break; + case 3: + if (battlefield.getBattlefield().containsKey(id) == false) { + if (home.getHome().containsKey(id)) { + home.removeLutemon(id); + battlefield.addLutemon(id, storage.get(id)); + } else if (training.getTraining().containsKey(id)) { + training.removeLutemon(id); + battlefield.addLutemon(id, storage.get(id)); + } + } + break; + default: + System.out.println("Invalid choice."); + break; + } + } + + } + + public void trainLutemon() { + training.train(); + } + + public void fightLutemon() { + System.out.println("There are the following Lutemons at Battle field:"); + for (Lutemon lutemon : battlefield.getBattlefield().values()) { + System.out.println(lutemon.printStats()); + } + battlefield.fight(); + storage.remove(battlefield.deadLutemon()); + } + + public HashMap getStorage() { + return storage; + } + + public boolean checkIfExists(Integer id) { + if (storage.containsKey(id) == false) { + System.out.println("No Lutemon with ID " + id + " could be found!"); + return false; + } else { + return true; + } + } +} diff --git a/Main/TrainingArea.class b/Main/TrainingArea.class new file mode 100644 index 0000000..b10666f Binary files /dev/null and b/Main/TrainingArea.class differ diff --git a/Main/TrainingArea.java b/Main/TrainingArea.java new file mode 100644 index 0000000..801086b --- /dev/null +++ b/Main/TrainingArea.java @@ -0,0 +1,30 @@ +package Main; + +import java.util.*; + +public class TrainingArea { + protected HashMap training = new HashMap(); + + public TrainingArea() { + + } + + public void addLutemon(int id, Lutemon lutemon) { + training.put(id, lutemon); + } + + public void removeLutemon(int id) { + training.remove(id); + } + + public void train() { + for (Lutemon lutemon : training.values()) { + System.out.println(lutemon.getColor() + "(" + lutemon.getName() + ") trains and gain experience!"); + lutemon.train(); + } + } + + public HashMap getTraining() { + return training; + } +} diff --git a/Main/White.class b/Main/White.class new file mode 100644 index 0000000..6f7a02c Binary files /dev/null and b/Main/White.class differ diff --git a/Main/White.java b/Main/White.java new file mode 100644 index 0000000..c0c9c79 --- /dev/null +++ b/Main/White.java @@ -0,0 +1,8 @@ +package Main; + +public class White extends Lutemon { + public White(String name, String color, int exp, int attack, int defense, int health) { + super(name, color, exp, attack, defense, health); + } + +}