-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeam.java
82 lines (66 loc) · 2.21 KB
/
Team.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;
import java.util.stream.Collectors;
public abstract class Team
{
private String name;
private ArrayList<Character> members;
public Team(String name){
this.name = name;
this.members = new ArrayList<Character>();
}
public String getName(){
return name;
}
public Character[] getMembers(){
return members.toArray(new Character[members.size()]);
}
public int addMember(Character member){
if(members.contains(member)){
return -1;
}
else if(members.size()>= 5){
return -2;
}
else{
members.add(member);
return members.size();
}
}
public ArrayList<Character> getAliveMembers() {
ArrayList<Character> aliveMembers = (ArrayList<Character>) this.members
.stream()
.filter(m -> m.isAlive())
.collect(Collectors.toList());
return aliveMembers;
}
public Character getAliveMemberByLeastHP() {
return Collections.min(this.getAliveMembers(), Comparator.comparing(m -> m.getHP()));
}
public Character getAliveMemberByHighestAttack(){
return Collections.max(this.getAliveMembers(), Comparator.comparing(m -> m.getAttack()));
}
public int getAliveMembersCount(){
int aliveMembers = (int)this.members
.stream()
.filter(m -> m.isAlive())
.count();
return aliveMembers;
}
public int getDeadMembersCount(){
int deadMembers = this.members.size() - this.getAliveMembersCount();
return deadMembers;
}
public Character getRandomAliveMember(){
ArrayList<Character> aliveMembers = this.getAliveMembers();
Random random = new Random();
int randomIndex = random.nextInt(aliveMembers.size());
return aliveMembers.get(randomIndex);
}
public int getMembersCount(){
return members.size();
}
public abstract void move(Character member, Team enemyTeam) throws Exception;
}