-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathWizard.java
More file actions
94 lines (79 loc) · 2.27 KB
/
Copy pathWizard.java
File metadata and controls
94 lines (79 loc) · 2.27 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.survivalcoding;
public class Wizard {
private int hp;
private int mp = 100;
private String name;
private Wand wand;
Wizard(String name, int hp, int mp, Wand wand) {
if (wand == null) {
throw new IllegalArgumentException("지팡이는 필수로 있어야 합니다.");
}
this.wand = wand;
setName(name);
setMp(mp);
if (hp < 0) {
setHp(0);
} else {
setHp(hp);
}
}
Wizard(String name, int hp, int mp) {
setName(name);
setHp(hp);
setMp(mp);
}
public Wand getWand() {
return wand;
}
public void setWand(Wand wand) {
if (wand == null) {
throw new IllegalArgumentException("지팡이는 필수로 있어야 합니다.");
}
this.wand = wand;
}
public int getHp() {
return hp;
}
public void setHp(int hp) {
if (hp < 0) {
throw new IllegalArgumentException("마법사의 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("마법사의 이름을 반드시 입력해야 합니다.");
}
if (name.length() <= 2) {
throw new IllegalArgumentException("마법사의 이름은 반드시 3문자 이상이어야 한다.");
}
this.name = name;
}
void heal(Hero hero) {
if (this.mp < 10) {
System.out.println("마나가 부족합니다.");
} else {
this.mp -= 10;
hero.setHp(hero.getHp() + 20);
System.out.println("힐을 시전했습니다. " + hero.getName() + " HP : " + hero.getHp());
}
}
}
// 이전 heal 메서드
// void heal(Hero hero) {
// int basePoint = 10;
// int recovPoint = (int) (basePoint * this.wand.getPower());
// hero.setHp(hero.getHp() + recovPoint);
// }