-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCharacterService.java
More file actions
28 lines (25 loc) · 874 Bytes
/
CharacterService.java
File metadata and controls
28 lines (25 loc) · 874 Bytes
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
package structural.facade;
public class CharacterService {
public Character createCharacter(String type, int resource) {
switch (type) {
case "Druid":
return new Druid(resource);
case "Fairy":
return new Fairy(resource);
case "Warrior":
return new Warrior(resource);
default:
throw new RuntimeException("Character type does not exist");
}
}
public void transfer(Character donor, Character receiver, int quantity) {
if (quantity < 0) {
throw new IllegalArgumentException("quantity must be positive");
}
if (donor.down(quantity)) {
receiver.up(quantity);
} else {
throw new RuntimeException("donor have not enough resources to give " + quantity);
}
}
}