-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathWizard.java
More file actions
69 lines (53 loc) · 1.35 KB
/
Copy pathWizard.java
File metadata and controls
69 lines (53 loc) · 1.35 KB
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
package com.survivalcoding;
public class Wizard {
static final int MAX_MP = 100;
int hp;
int mp = MAX_MP;
Wand wand;
private String name;
public int getHp() {
return hp;
}
public void setHp(int hp) {
if (hp < 0) {
hp = 0;
}
this.hp = hp;
}
public int getMp() {
return mp;
}
public void setMp(int mp) {
if (mp < 0) {
throw new IllegalArgumentException("마법사의 MP는 0이상이어야 함");
}
this.mp = mp;
}
public String getName() {
return name;
}
public void setName(String name) {
if (name == null) {
throw new IllegalArgumentException("이름은 null이 아니어야 함");
}
if(name.length() <= 2){
throw new IllegalArgumentException("이름이 짧음");
}
this.name = name;
}
public Wand getWand() {
return wand;
}
public void setWand(Wand wand) {
if (wand == null) {
throw new IllegalArgumentException("마법사의 지팡이는 null이 아니어야 함");
}
this.wand = wand;
}
void heal(Hero hero) {
int recoverPoint = 20;
int usedPoint = 10;
hero.setHp(hero.getHp() + recoverPoint);
hero.setMp(hero.getMp() - usedPoint);
}
}