generated from skills/introduction-to-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
920 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 : 实现你的逻辑 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 : 实现你的逻辑 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public interface Guard { | ||
|
||
boolean fight(Adventurer adventurer); | ||
|
||
String getType(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 : 实现你的逻辑 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public interface Treasure { | ||
void showInfo(); | ||
|
||
void useBy(Adventurer adventurer); | ||
} |
Oops, something went wrong.