Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Shalcy authored Nov 10, 2024
1 parent d471185 commit c58e2b0
Show file tree
Hide file tree
Showing 20 changed files with 920 additions and 0 deletions.
501 changes: 501 additions & 0 deletions src/Adventurer.java

Large diffs are not rendered by default.

117 changes: 117 additions & 0 deletions src/AdventurerManager.java
Original file line number Diff line number Diff line change
@@ -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<Integer, Adventurer> adventurers;
private ArrayList<Adventurer> 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<Adventurer> 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());
}
}
}

}
72 changes: 72 additions & 0 deletions src/Bottle.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
62 changes: 62 additions & 0 deletions src/Equipment.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
9 changes: 9 additions & 0 deletions src/Flm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Flm implements Guard {
public boolean fight(Adventurer adventurer) {
return adventurer.getComprehensiveCE() > 2000;
}

public String getType() {
return "Flm";
}
}
11 changes: 11 additions & 0 deletions src/FlmTreasure.java
Original file line number Diff line number Diff line change
@@ -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 : 实现你的逻辑
}
}
17 changes: 17 additions & 0 deletions src/Fragment.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
9 changes: 9 additions & 0 deletions src/Frz.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Frz implements Guard {
public boolean fight(Adventurer adventurer) {
return adventurer.getComprehensiveCE() > 5000;
}

public String getType() {
return "Frz";
}
}
11 changes: 11 additions & 0 deletions src/FrzTreasure.java
Original file line number Diff line number Diff line change
@@ -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 : 实现你的逻辑
}
}
6 changes: 6 additions & 0 deletions src/Guard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public interface Guard {

boolean fight(Adventurer adventurer);

String getType();
}
11 changes: 11 additions & 0 deletions src/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public interface Item {

int getId();

int getCe();

String getName();

String getType();

}
8 changes: 8 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

public class Main {
public static void main(String[] args) {
AdventurerManager manager = new AdventurerManager();
manager.processInput();
manager.operate();
}
}
9 changes: 9 additions & 0 deletions src/Shd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Shd implements Guard {
public boolean fight(Adventurer adventurer) {
return adventurer.getComprehensiveCE() > 1000;
}

public String getType() {
return "Shd";
}
}
11 changes: 11 additions & 0 deletions src/ShdTreasure.java
Original file line number Diff line number Diff line change
@@ -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 : 实现你的逻辑
}
}
9 changes: 9 additions & 0 deletions src/Stn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Stn implements Guard {
public boolean fight(Adventurer adventurer) {
return adventurer.getComprehensiveCE() > 3000;
}

public String getType() {
return "Stn";
}
}
11 changes: 11 additions & 0 deletions src/StnTreasure.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
5 changes: 5 additions & 0 deletions src/Treasure.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public interface Treasure {
void showInfo();

void useBy(Adventurer adventurer);
}
Loading

0 comments on commit c58e2b0

Please sign in to comment.