diff --git a/src/Adventurer.java b/src/Adventurer.java new file mode 100644 index 0000000..8a54893 --- /dev/null +++ b/src/Adventurer.java @@ -0,0 +1,501 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; + +public class Adventurer { + private final int id; + private final String name; + private final HashMap> bottles; + private final HashMap> takenBottles; + private final HashMap> equipments; + private final HashMap takenEquipments; + private final HashMap items; + private final HashMap> fragments; + private int atk; + private int def; + private int hp; + private final HashMap allAdventurers; + private final HashMap employees; + private static final ArrayList guards = new ArrayList<>(); + private int hpBeforeBattle; + private final ArrayList treasures; + private final TreasureFactory treasureFactory; + + public Adventurer(HashMap adventurers, int id, String name) { + this.allAdventurers = adventurers; + this.id = id; + this.name = name; + this.bottles = new HashMap<>(); + this.equipments = new HashMap<>(); + this.takenEquipments = new HashMap<>(); + this.takenBottles = new HashMap<>(); + this.items = new HashMap<>(); + this.fragments = new HashMap<>(); + this.employees = new HashMap<>(); + this.treasures = new ArrayList<>(); + this.treasureFactory = new TreasureFactory(); + this.atk = 1; + this.def = 0; + this.hp = 500; + this.hpBeforeBattle = this.hp; + } + + public static void createGuard() { + guards.add(new Shd()); + guards.add(new Flm()); + guards.add(new Stn()); + guards.add(new Wnd()); + guards.add(new Frz()); + } + + public HashMap getAllAdventurers() { + return allAdventurers; + } + + public TreasureFactory getTreasureFactory() { + return treasureFactory; + } + + public int getHpBoreBattle() { + return hpBeforeBattle; + } + + public static ArrayList getGuards() { + return guards; + } + + public HashMap> getTakenBottles() { + return takenBottles; + } + + public HashMap getTakenEquipments() { + return this.takenEquipments; + } + + public HashMap getItems() { + return this.items; + } + + public HashMap> getFragments() { + return fragments; + } + + public HashMap> getEquipments() { + return equipments; + } + + public HashMap> getBottles() { + return bottles; + } + + public int getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public int getHp() { + return this.hp; + } + + public void setHp(int hp) { + this.hp = hp; + } + + public int getAtk() { + return this.atk; + } + + public int getRealAtk(String eqName) { + return this.atk + takenEquipments.get(eqName).getCe(); + } + + public void setHpBeforeBattle() { + this.hpBeforeBattle = this.hp; + } + + public int getDef() { + return this.def; + } + + public int getCe() { + return this.atk + this.def; + } + + public int getMaxBottles() { + return (this.getAtk() + this.getDef()) / 5 + 1; + } + + public int getComprehensiveCE() { + int btlCE = takenBottles.values().stream() + .flatMap(List::stream) + .mapToInt(Bottle::getCe) + .sum(); + int eqCE = takenEquipments.values().stream() + .mapToInt(Equipment::getCe) + .sum(); + int emCE = employees.keySet().stream() + .mapToInt(Adventurer::getCe) + .sum(); + return this.atk + this.def + btlCE + eqCE + emCE; + } + + private int getHpBeforeBattle() { + return this.hpBeforeBattle; + } + + public HashMap getEmployees() { + return this.employees; + } + + public int[] getEmployeeIds() { + return employees.keySet().stream() + .mapToInt(Adventurer::getId) + .toArray(); + } + + public void addFragment(int id, String name) { + this.fragments.computeIfAbsent(name, k -> new ArrayList<>()).add(new Fragment(id, name)); + } + + public void addDurability(int equipmentID) { + Equipment targetEquipment = (Equipment) items.get(equipmentID); + if (targetEquipment != null) { + targetEquipment.equipmentAddDurability(); + System.out.println(targetEquipment.getName() + " " + targetEquipment.getDurability()); + } + + } + + public void addItem(int sign, int id, String name, int property, String type,int ce) { + if (sign == 2) { + Bottle newBtl = new Bottle(this, id, name, property, type, ce); + this.bottles.computeIfAbsent(newBtl.getName(), k -> new ArrayList<>()).add(newBtl); + this.items.put(id, newBtl); + } else { + Equipment newEq = new Equipment(this, id, name, property, type, ce); + this.equipments.computeIfAbsent(name, k -> new ArrayList<>()).add(newEq); + this.items.put(id, newEq); + } + } + + public void addItem(Item item) { + if (item instanceof Bottle) { + Bottle newBtl = (Bottle) item; + this.bottles.computeIfAbsent(newBtl.getName(), k -> new ArrayList<>()).add(newBtl); + this.items.put(item.getId(), newBtl); + } else if (item instanceof Equipment) { + Equipment newEq = (Equipment) item; + this.equipments.computeIfAbsent(name, k -> new ArrayList<>()).add(newEq); + this.items.put(item.getId(), newEq); + } + } + + public void removeItem(int id) { + Item itemToRemove = items.get(id); + if (itemToRemove != null) { + items.remove(id); + if (itemToRemove instanceof Bottle) { + Bottle b = (Bottle) itemToRemove; + switch (b.getType()) { + case "HpBottle" : + System.out.println( + "HpBottle" + " " + b.getName() + " " + b.getCapacity()); + break; + case "AtkBottle" : + System.out.println( + "AtkBottle" + " " + b.getName() + " " + b.getCapacity()); + break; + case "DefBottle" : + System.out.println( + "DefBottle" + " " + b.getName() + " " + b.getCapacity()); + break; + default : + break; + } + bottles.entrySet().removeIf(entry -> { + entry.getValue().removeIf(bottle -> bottle.equals(b)); + return entry.getValue().isEmpty(); + }); + takenBottles.entrySet().removeIf(entry -> { + entry.getValue().removeIf(bottle -> bottle.equals(b)); + return entry.getValue().isEmpty(); + }); + } else if (itemToRemove instanceof Equipment) { + Equipment eq = (Equipment) itemToRemove; + System.out.println("Equipment" + " " + eq.getName() + " " + eq.getDurability()); + equipments.entrySet().removeIf(entry -> { + entry.getValue().removeIf(equipment -> equipment.equals(eq)); + return entry.getValue().isEmpty(); + }); + takenEquipments.entrySet().removeIf(entry -> entry.getValue().equals(eq)); + + } + } + } + + public void breakEq(Equipment eq) { + equipments.entrySet().removeIf(entry -> { + entry.getValue().removeIf(equipment -> equipment.equals(eq)); + return entry.getValue().isEmpty(); + }); + takenEquipments.entrySet().removeIf(entry -> entry.getValue().equals(eq)); + } + + public void takeItem(int id) { + Item itemToTake = items.get(id); + if (itemToTake != null) { + if (itemToTake instanceof Bottle) { + Bottle b = (Bottle) itemToTake; + b.take(); + takenBottles.computeIfAbsent(b.getName(), k -> new ArrayList<>()).add(b); + if (takenBottles.get(b.getName()).size() > getMaxBottles()) { + takenBottles.get(b.getName()).remove(b); + } + } else if (itemToTake instanceof Equipment) { + Equipment eq = (Equipment) itemToTake; + takenEquipments.put(eq.getName(), eq); + } + } + } + + public void useBottle(int id) { + Bottle bottle = (Bottle) items.get(id); + if (takenBottles.get(bottle.getName()).contains(bottle)) { + switch (bottle.getType()) { + case "HpBottle" : + this.hp += bottle.getCapacity(); + break; + case "AtkBottle" : + this.atk += bottle.getCe() + bottle.getCapacity() / 100; + break; + case "DefBottle" : + this.def += bottle.getCe() + bottle.getCapacity() / 100; + break; + default : + break; + } + removeItem(id); + System.out.println(this); + } else { + System.out.println(this.getName() + " fail to use " + bottle.getName()); + } + } + + public void useTreasure(Treasure treasure) { + if (treasure instanceof ShdTreasure) { + this.def += 40; + for (Adventurer adventurer : employees.keySet()) { + adventurer.def += 40; + } + } else if (treasure instanceof FlmTreasure) { + this.atk += 40; + for (Adventurer adventurer : employees.keySet()) { + adventurer.atk += 40; + } + } else if (treasure instanceof StnTreasure) { + this.def += 40; + for (Adventurer adventurer : employees.keySet()) { + adventurer.def += 40; + } + } else if (treasure instanceof WndTreasure) { + this.def += 30; + for (Adventurer adventurer : employees.keySet()) { + adventurer.def += 30; + } + } else if (treasure instanceof FrzTreasure) { + this.atk += 50; + for (Adventurer adventurer : employees.keySet()) { + adventurer.atk += 50; + } + } + } + + public void redeem(String name, int welfareId) { + Item itemToRedeem = items.get(welfareId); + if (fragments.get(name) != null) { + if (fragments.get(name).size() >= 5) { + if (itemToRedeem != null) { + if (itemToRedeem instanceof Bottle) { + Bottle b = (Bottle) itemToRedeem; + if (b.ifEmpty()) { + b.restock(); + System.out.println(b.getName() + " " + b.getCapacity()); + } + } else if (itemToRedeem instanceof Equipment) { + Equipment eq = (Equipment) itemToRedeem; + eq.equipmentAddDurability(); + System.out.println(eq.getName() + " " + eq.getDurability()); + } + } else { + bottles.computeIfAbsent(name, k -> new ArrayList<>()) + .add(new Bottle(this, welfareId, name, 100, "HpBottle", 0)); + System.out.println("Congratulations! HpBottle " + name + " acquired"); + } + + Iterator iterator = fragments.get(name).iterator(); + for (int i = 0; i < 5; i++) { + iterator.next(); + iterator.remove(); + } + } else { + System.out.println(fragments.get(name).size() + + ": Not enough fragments collected yet"); + } + } else { + System.out.println(0 + + ": Not enough fragments collected yet"); + } + } + + public void attack(String eqName, ArrayList targetAdventurers, int sign) { + + int defMax = 0; + boolean success = false; + for (Adventurer adventurer : targetAdventurers) { + adventurer.setHpBeforeBattle(); + } + + for (Adventurer targetAdventurer : targetAdventurers) { + int defTmp = targetAdventurer.getDef(); + if (defTmp > defMax) { + defMax = defTmp; + } + } + Equipment atkEq = takenEquipments.get(eqName); + if (atkEq != null) { + if (getRealAtk(eqName) > defMax) { + finishAttacking(atkEq, targetAdventurers, sign); + success = true; + } + } + if (success) { + atkEq.equipmentSubDurability(); + } + if (!success) { + System.out.println("Adventurer " + getId() + " defeated"); + } + } + + public void employ(int id) { + Adventurer adventurer = allAdventurers.get(id); + employees.putIfAbsent(adventurer, 4); + } + + private void help(Adventurer adventurer) { + AtomicBoolean dismiss = new AtomicBoolean(false); + if (adventurer.getHp() <= adventurer.getHpBeforeBattle() / 2) { + if (!takenEquipments.isEmpty()) { + for (Equipment equipment : takenEquipments.values()) { + equipment.transfer(adventurer); + } + takenEquipments.clear(); + } + adventurer.getEmployees().compute(this, (key, oldValue) -> { + int newValue = Optional.ofNullable(oldValue).orElse(0) - 1; + if (newValue == 0) { + dismiss.set(true); + return null; + } + return newValue; + }); + } + if (dismiss.get()) { + dismissedBy(adventurer); + } + } + + public void dismissedBy(Adventurer adventurer) { + adventurer.getEmployees().remove(this); + } + + public void challenge() { + createGuard(); + for (Guard guard : guards) { + if (guard.fight(this)) { + Treasure treasure = treasureFactory.createTreasure(guard.getType()); + treasures.add(treasure); + useTreasure(treasure); + } else { + break; + } + } + for (Treasure treasure : treasures) { + treasure.showInfo(); + } + } + + private void finishAttacking(Equipment eq, ArrayList targetAdventurers, int sign) { + switch (eq.getType()) { + case "Axe" : + for (Adventurer targetAdventurer : targetAdventurers) { + targetAdventurer.setHp(targetAdventurer.getHp() / 10); + } + break; + case "Sword" : + for (Adventurer targetAdventurer : targetAdventurers) { + int decreaseHp = eq.getCe() + this.getAtk() - targetAdventurer.getDef(); + targetAdventurer.setHp(targetAdventurer.getHp() - decreaseHp); + } + break; + case "Blade" : + for (Adventurer targetAdventurer : targetAdventurers) { + int decreaseHp = eq.getCe() + this.getAtk(); + targetAdventurer.setHp(targetAdventurer.getHp() - decreaseHp); + } + break; + default : + break; + + } + for (Adventurer targetAdventurer : targetAdventurers) { + for (Adventurer helper : targetAdventurer.getEmployees().keySet()) { + helper.help(targetAdventurer); + } + } + if (sign == 1) { + for (Adventurer targetAdventurer : targetAdventurers) { + System.out.println(targetAdventurer.getName() + " " + targetAdventurer.getHp()); + } + } else if (sign == 2) { + switch (eq.getType()) { + case "Axe" : + int decrease = 0; + for (Adventurer targetAdventurer : targetAdventurers) { + decrease += targetAdventurer.getHpBeforeBattle() - targetAdventurer.getHp(); + } + System.out.println(decrease); + break; + case "Sword" : + int a = 0; + for (Adventurer targetAdventurer : targetAdventurers) { + a += targetAdventurer.getHpBeforeBattle() - targetAdventurer.getHp(); + } + System.out.println(a); + break; + case "Blade" : + System.out.println((eq.getCe() + this.getAtk()) * targetAdventurers.size()); + break; + default : + break; + } + } + } + + public String toString() { + return name + " " + hp + " " + atk + " " + def; + } + + public void setAtk(int i) { + this.atk = i; + } + + public void setDef(int i) { + this.def = i; + } +} diff --git a/src/AdventurerManager.java b/src/AdventurerManager.java new file mode 100644 index 0000000..e343f68 --- /dev/null +++ b/src/AdventurerManager.java @@ -0,0 +1,117 @@ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Scanner; + +public class AdventurerManager { + private int opsNumber; + private final String[] lines; + private final HashMap adventurers; + private ArrayList attackedAdventurers; + + public AdventurerManager() { + adventurers = new HashMap<>(); + attackedAdventurers = new ArrayList<>(); + lines = new String[999999]; + } + + public void processInput() { + Scanner scanner = new Scanner(System.in); + opsNumber = Integer.parseInt(scanner.nextLine()); + for (int i = 0; i < opsNumber; i++) { + this.lines[i] = scanner.nextLine(); + } + scanner.close(); + } + + public void operate() { + for (int i = 0; i < opsNumber; i++) { + String[] op = lines[i].split(" "); + switch (Integer.parseInt(op[0])) { + case 1 : + addAdventurer(new Adventurer(adventurers, Integer.parseInt(op[1]), op[2])); + break; + case 2 : + adventurers.get(Integer.parseInt(op[1])).addItem(2, Integer.parseInt(op[2]), + op[3], Integer.parseInt(op[4]), op[5], Integer.parseInt(op[6])); + break; + case 3 : + adventurers.get(Integer.parseInt(op[1])).addItem(3, Integer.parseInt(op[2]), + op[3], Integer.parseInt(op[4]), op[5], Integer.parseInt(op[6])); + break; + case 4 : + adventurers.get(Integer.parseInt(op[1])).addDurability(Integer.parseInt(op[2])); + break; + case 5 : + adventurers.get(Integer.parseInt(op[1])).removeItem(Integer.parseInt(op[2])); + break; + case 6 : + adventurers.get(Integer.parseInt(op[1])).takeItem(Integer.parseInt(op[2])); + break; + case 7 : + adventurers.get(Integer.parseInt(op[1])).useBottle(Integer.parseInt(op[2])); + break; + case 8 : + adventurers.get(Integer.parseInt(op[1])).addFragment(Integer.parseInt(op[2]), + op[3]); + break; + case 9 : + adventurers.get(Integer.parseInt(op[1])).redeem(op[2], Integer.parseInt(op[3])); + break; + case 10 : + int[] atkIds = new int[Integer.parseInt(op[4])]; + int chain; + for (int j = 0, k = 5; j < Integer.parseInt(op[4]); j++, k++) { + atkIds[j] = Integer.parseInt(op[k]); + } + if (op[3].equals("chain")) { + chainAttack(atkIds); + chain = 2; + } else { + normalAttack(atkIds); + chain = 1; + } + if (!attackedAdventurers.isEmpty()) { + adventurers.get(Integer.parseInt(op[1])).attack(op[2], + attackedAdventurers, chain); + } + attackedAdventurers.clear(); + break; + case 11 : + adventurers.get(Integer.parseInt(op[1])).employ(Integer.parseInt(op[2])); + break; + case 12 : + adventurers.get(Integer.parseInt(op[1])).challenge(); + break; + default : + break; + } + } + } + + private void addAdventurer(Adventurer adventurer) { + this.adventurers.put(adventurer.getId(), adventurer); + } + + private void normalAttack(int[] atkIds) { + for (Integer atkId : atkIds) { + attackedAdventurers.add(adventurers.get(atkId)); + } + } + + private void chainAttack(int[] atkIds) { + recursiveAttack(0, atkIds); + LinkedHashSet tmpList = new LinkedHashSet<>(attackedAdventurers); + attackedAdventurers = new ArrayList<>(tmpList); + } + + private void recursiveAttack(int depth, int... targetIds) { + if (depth < 5) { + for (Integer targetId : targetIds) { + attackedAdventurers.add(adventurers.get(targetId)); + recursiveAttack(depth + 1, adventurers.get(targetId).getEmployeeIds()); + } + } + } + +} diff --git a/src/Bottle.java b/src/Bottle.java new file mode 100644 index 0000000..7955717 --- /dev/null +++ b/src/Bottle.java @@ -0,0 +1,72 @@ +public class Bottle implements Item { + private final int id; + private final String name; + private final int capacity; + private final int ce; + private final String type; + private boolean empty; + private boolean taken; + + public Bottle(Adventurer adventurer, int id, String name, int capacity, String type, int ce) { + this.id = id; + this.name = name; + this.capacity = capacity; + this.ce = ce; + this.type = type; + this.empty = false; + } + + public void setEmpty(boolean empty) { + this.empty = empty; + } + + public void restock() { + this.empty = false; + } + + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public int getCapacity() { + return capacity; + } + + public int getId() { + return id; + } + + public int getCe() { + return ce; + } + + public boolean ifEmpty() { + return empty; + } + + @Override + public String toString() { + return type + " " + name + " " + capacity; + } + + public boolean equals(Bottle bottle) { + return id == bottle.id + && name.equals(bottle.name) + && capacity == bottle.capacity + && ce == bottle.ce + && type.equals(bottle.type); + } + + public void take() { + taken = true; + } + + public boolean ifTaken() { + return taken; + } + +} diff --git a/src/Equipment.java b/src/Equipment.java new file mode 100644 index 0000000..be27bcc --- /dev/null +++ b/src/Equipment.java @@ -0,0 +1,62 @@ +public class Equipment implements Item { + private final int id; + private final String name; + private int durability; + private final int ce; + private final String type; + private final Adventurer adventurer; + + public Equipment(Adventurer adventurer, int id, String name, + int durability, String type, int ce) { + this.adventurer = adventurer; + this.id = id; + this.name = name; + this.durability = durability; + this.ce = ce; + this.type = type; + } + + public String getType() { + return type; + } + + public int getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public int getDurability() { + return this.durability; + } + + public void equipmentAddDurability() { + this.durability += 1; + } + + public void equipmentSubDurability() { + this.durability -= 1; + if (this.durability == 0) { + adventurer.breakEq(this); + } + } + + public int getCe() { + return this.ce; + } + + public String toString() { + return type + " " + name + " " + durability; + } + + public void transfer(Adventurer adventurer) { + adventurer.addItem(this); + } + + public boolean equals(Equipment equipment) { + return this.id == equipment.getId() && this.name.equals(equipment.getName()) + && this.durability == equipment.getDurability() && this.ce == equipment.getCe(); + } +} diff --git a/src/Flm.java b/src/Flm.java new file mode 100644 index 0000000..14dbaf5 --- /dev/null +++ b/src/Flm.java @@ -0,0 +1,9 @@ +public class Flm implements Guard { + public boolean fight(Adventurer adventurer) { + return adventurer.getComprehensiveCE() > 2000; + } + + public String getType() { + return "Flm"; + } +} diff --git a/src/FlmTreasure.java b/src/FlmTreasure.java new file mode 100644 index 0000000..32ee67b --- /dev/null +++ b/src/FlmTreasure.java @@ -0,0 +1,11 @@ +public class FlmTreasure implements Treasure { + @Override + public void showInfo() { + System.out.println("Flamebrand Sword"); + } + + @Override + public void useBy(Adventurer adv) { + adv.useTreasure(this);// TODO : 实现你的逻辑 + } +} diff --git a/src/Fragment.java b/src/Fragment.java new file mode 100644 index 0000000..92bfc14 --- /dev/null +++ b/src/Fragment.java @@ -0,0 +1,17 @@ +public class Fragment { + private final int id; + private final String name; + + public Fragment(int id, String name) { + this.id = id; + this.name = name; + } + + public String getName() { + return name; + } + + public boolean equals(Fragment f) { + return id == f.id && name.equals(f.name); + } +} diff --git a/src/Frz.java b/src/Frz.java new file mode 100644 index 0000000..e533ac6 --- /dev/null +++ b/src/Frz.java @@ -0,0 +1,9 @@ +public class Frz implements Guard { + public boolean fight(Adventurer adventurer) { + return adventurer.getComprehensiveCE() > 5000; + } + + public String getType() { + return "Frz"; + } +} diff --git a/src/FrzTreasure.java b/src/FrzTreasure.java new file mode 100644 index 0000000..4b8ddb2 --- /dev/null +++ b/src/FrzTreasure.java @@ -0,0 +1,11 @@ +public class FrzTreasure implements Treasure { + @Override + public void showInfo() { + System.out.println("Frostbite Staff"); + } + + @Override + public void useBy(Adventurer adv) { + adv.useTreasure(this);// TODO : 实现你的逻辑 + } +} diff --git a/src/Guard.java b/src/Guard.java new file mode 100644 index 0000000..d169166 --- /dev/null +++ b/src/Guard.java @@ -0,0 +1,6 @@ +public interface Guard { + + boolean fight(Adventurer adventurer); + + String getType(); +} diff --git a/src/Item.java b/src/Item.java new file mode 100644 index 0000000..18e9b47 --- /dev/null +++ b/src/Item.java @@ -0,0 +1,11 @@ +public interface Item { + + int getId(); + + int getCe(); + + String getName(); + + String getType(); + +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..9b86413 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,8 @@ + +public class Main { + public static void main(String[] args) { + AdventurerManager manager = new AdventurerManager(); + manager.processInput(); + manager.operate(); + } +} \ No newline at end of file diff --git a/src/Shd.java b/src/Shd.java new file mode 100644 index 0000000..05dc48f --- /dev/null +++ b/src/Shd.java @@ -0,0 +1,9 @@ +public class Shd implements Guard { + public boolean fight(Adventurer adventurer) { + return adventurer.getComprehensiveCE() > 1000; + } + + public String getType() { + return "Shd"; + } +} diff --git a/src/ShdTreasure.java b/src/ShdTreasure.java new file mode 100644 index 0000000..216f69a --- /dev/null +++ b/src/ShdTreasure.java @@ -0,0 +1,11 @@ +public class ShdTreasure implements Treasure { + @Override + public void showInfo() { + System.out.println("Cloak of Shadows"); + } + + @Override + public void useBy(Adventurer adv) { + adv.useTreasure(this);// TODO : 实现你的逻辑 + } +} diff --git a/src/Stn.java b/src/Stn.java new file mode 100644 index 0000000..1df37bf --- /dev/null +++ b/src/Stn.java @@ -0,0 +1,9 @@ +public class Stn implements Guard { + public boolean fight(Adventurer adventurer) { + return adventurer.getComprehensiveCE() > 3000; + } + + public String getType() { + return "Stn"; + } +} diff --git a/src/StnTreasure.java b/src/StnTreasure.java new file mode 100644 index 0000000..6df6aa2 --- /dev/null +++ b/src/StnTreasure.java @@ -0,0 +1,11 @@ +public class StnTreasure implements Treasure { + @Override + public void showInfo() { + System.out.println("Stoneheart Amulet"); + } + + @Override + public void useBy(Adventurer adv) { + adv.useTreasure(this); + } +} diff --git a/src/Treasure.java b/src/Treasure.java new file mode 100644 index 0000000..c8db5fc --- /dev/null +++ b/src/Treasure.java @@ -0,0 +1,5 @@ +public interface Treasure { + void showInfo(); + + void useBy(Adventurer adventurer); +} diff --git a/src/TreasureFactory.java b/src/TreasureFactory.java new file mode 100644 index 0000000..c4b8d38 --- /dev/null +++ b/src/TreasureFactory.java @@ -0,0 +1,21 @@ +public class TreasureFactory { + public TreasureFactory() { + } + + public Treasure createTreasure(String guard) { + switch (guard) { + case "Shd" : + return new ShdTreasure(); + case "Flm" : + return new FlmTreasure(); + case "Stn" : + return new StnTreasure(); + case "Wnd" : + return new WndTreasure(); + case "Frz" : + return new FrzTreasure(); + default : + return null; + } + } +} diff --git a/src/Wnd.java b/src/Wnd.java new file mode 100644 index 0000000..d53e2e4 --- /dev/null +++ b/src/Wnd.java @@ -0,0 +1,9 @@ +public class Wnd implements Guard { + public boolean fight(Adventurer adventurer) { + return adventurer.getComprehensiveCE() > 4000; + } + + public String getType() { + return "Wnd"; + } +} diff --git a/src/WndTreasure.java b/src/WndTreasure.java new file mode 100644 index 0000000..3a68791 --- /dev/null +++ b/src/WndTreasure.java @@ -0,0 +1,11 @@ +public class WndTreasure implements Treasure { + @Override + public void showInfo() { + System.out.println("Windrunner Boots"); + } + + @Override + public void useBy(Adventurer adv) { + adv.useTreasure(this); + } +}