-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathEnemy.java
More file actions
55 lines (50 loc) · 1.7 KB
/
Copy pathEnemy.java
File metadata and controls
55 lines (50 loc) · 1.7 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
package jp.ac.uryukyu.ie.tnal;
/**
* 敵クラス。
* String name; //敵の名前
* int hitPoint; //敵のHP
* int attack; //敵の攻撃力
* boolean dead; //敵の生死状態。true=死亡。
* Created by tnal on 2016/11/13.
*/
public class Enemy {
public String name;
public int hitPoint;
public int attack;
public boolean dead;
/**
* コンストラクタ。名前、最大HP、攻撃力を指定する。
* @param name モンスター名
* @param maximumHP モンスターのHP
* @param attack モンスターの攻撃力
*/
public Enemy (String name, int maximumHP, int attack) {
this.name = name;
hitPoint = maximumHP;
this.attack = attack;
dead = false;
System.out.printf("%sのHPは%d。攻撃力は%dです。\n", name, maximumHP, attack);
}
/**
* Heroへ攻撃するメソッド。
* attackに応じて乱数でダメージを算出し、hero.wounded()によりダメージ処理を実行。
* @param hero 攻撃対象
*/
public void attack(Hero hero){
int damage = (int)(Math.random() * attack);
System.out.printf("%sの攻撃!%sに%dのダメージを与えた!!\n", name, hero.name, damage);
hero.wounded(damage);
}
/**
* 自身へ攻撃されたときのダメージ処理をするメソッド。
* 指定されたダメージを hitPoint から引き、死亡判定を行う。
* @param damage 受けたダメージ
*/
public void wounded(int damage){
hitPoint -= damage;
if( hitPoint < 0 ) {
dead = true;
System.out.printf("モンスター%sは倒れた。\n", name);
}
}
}