質問編集履歴

1

自分で試したことを追記した。

2023/01/17 19:59

投稿

gmwp
gmwp

スコア0

test CHANGED
File without changes
test CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ### 発生している問題・エラーメッセージ
11
11
 
12
- から書けばよいか分かりません。
12
+ Heroクラスは書いてみたのですが正しいの分かずAbstractHeroクラスについてどう書けばよいか分かりません。
13
13
 
14
14
  ### 該当のソースコード
15
15
 
@@ -71,6 +71,80 @@
71
71
  ```
72
72
  と出力させるHeroクラスなどを作成したい。
73
73
 
74
+ 実際に書いてみたHeroクラス
75
+ ```Java
76
+ package checkpoints;
77
+
78
+ public class Hero {
79
+ private String name;
80
+ private int hp;
81
+ private int job;
82
+ private boolean isAlive;
83
+ private boolean isRunning;
84
+ public final int MAX_HP;
85
+
86
+ public Hero(String name, int hp, int job) {
87
+ this.name = name;
88
+ this.hp = hp;
89
+ this.job = job;
90
+ this.isAlive = true;
91
+ this.isRunning = false;
92
+ this.MAX_HP = hp;
93
+ }
94
+
95
+ public String getName() {
96
+ return this.name;
97
+ }
98
+
99
+ public int getHp() {
100
+ return this.hp;
101
+ }
102
+
103
+ public int getJob() {
104
+ return this.job;
105
+ }
106
+
107
+ public boolean isAlive() {
108
+ return this.isAlive;
109
+ }
110
+
111
+ public boolean isRunning() {
112
+ return this.isRunning;
113
+ }
114
+
115
+ public int gotDamage(int damage) {
116
+ if (damage < 0) {
117
+ damage = 0;
118
+ }
119
+ this.hp -= damage;
120
+ if (this.hp <= 0) {
121
+ this.hp = 0;
122
+ this.isAlive = false;
123
+ }
124
+ return damage;
125
+ }
126
+
127
+ public void rest() {
128
+ this.hp = this.MAX_HP;
129
+ }
130
+
131
+ public void run() {
132
+ this.isRunning = true;
133
+ }
134
+
135
+ public void actionStatus() {
136
+ if (!this.isAlive) {
137
+ System.out.println(this.name + "は倒れた");
138
+ } else if (this.isRunning) {
139
+ System.out.println(this.name + "は逃げ出した");
140
+ } else {
141
+ System.out.println(this.name + "は戦い続ける");
142
+ }
143
+ }
144
+ }
145
+ ```
146
+
147
+
74
148
  ### 補足情報
75
149
  勇者にしか無いメンバ変数やgetterメソッドを追加しましょう
76
150
  • run():逃げる