モンスター

package monster;

import java.util.ArrayList;
import java.util.List;

import hero.Hero;

public abstract class Monster {
protected static List monsters = new ArrayList();
protected String name;
protected int hp;
protected int power;
private boolean life = true;

//コンストラク
public Monster(String name, int hp, int power) {
this.name = name;
this.setHp(hp);
this.power = power;
}

//getter
public String getName() {
return this.name;
}

public int getHp() {
return this.hp;
}

public int getPower() {
return this.power;
}
public boolean isLife() {
return life;
}

//setter
public void setName(String namae) {
this.name = namae;
}

public void setHp(int hp) {
this.hp = hp;
}

//メソッド
//攻撃
public void attack(Hero heros) {
int target = new java.util.Random().nextInt(3);
System.out.println(this.name + "は、攻撃した!\n"
+ heros[target - 1].getName() + "に、"
+ heros[target - 1].damage(this.power)
+ "のダメージを与えた");
}

//死亡
public void die() {
System.out.println(this.name + "を倒した!");
this.life=false;
}

//ダメージ量を受け取り ダメージを受ける
public int damage(int damage) {
this.hp -= damage;
if (this.hp < 0) {
this.die();
}
return damage;
}

//行動を選択する抽象メソッド
public abstract void action(Hero heros);
}

package monster;

import hero.Hero;

public class Slime extends Monster {
//コンストラクタ
public Slime() {
super("スライム", 50, 10);
}
public void action(Hero heros) {
if (this.isLife() == true) {
this.attack(heros);
}
}
}

package monster;

import hero.Hero;

public class Matango extends Monster {

//コンストラクタ
public Matango() {
super("おばけきのこ", 300, 40);
}

//追加メソッド
public void housi(Hero heros) {
System.out.println(this.getName() + "は、胞子をばらまいた!味方全員がダメージを受けた");
for (Hero h : heros) {
h.damage(25);
}
}

public void action(Hero heros) {
if (this.isLife() == true) {
int pattern = new java.util.Random().nextInt(2);
switch (pattern) {
case 1:
this.attack(heros);
break;
case 2:
this.housi(heros);
default:
}
}
}
}

package monster;

import hero.Hero;

public class Dragon extends Monster {

//コンストラクタ
public Dragon() {
super("ドラゴン", 350, 50);
}

//追加メソッド
public void fire(Hero heros) {
System.out.println(this.getName() + "は、炎を吐いた!味方全員がダメージを受けた");
for (Hero hhp : heros) {
hhp.damage(30);
}
}

public void action(Hero heros) {
if (this.isLife() == true) {
int pattern = new java.util.Random().nextInt(2);
switch (pattern) {
case 1:
this.attack(heros);
break;
case 2:
this.fire(heros);
default:
}
}
}
}

package monster;

import hero.Hero;

public class Boss extends Monster{

public Boss(String name, int hp, int power) {
super("ぼす", 1000, 40);
}
//新規メソッド
public void fubuki(Hero heros) {
System.out.println(this.getName()+"は、吹雪を吐いた!味方全員がダメージを受けた");
for(Hero hhp:heros) {
hhp.damage(50);
}
}
public void meisou() {
System.out.println(this.getName()+"は、瞑想して回復した");
this.setHp(getHp()+200);
}
public void warau() {
System.out.println(this.getName()+"は、不敵に笑っている");
}


public void action(Hero[] heros) {
int pattern = new java.util.Random().nextInt(2);
switch(pattern) {
case 1:
this.attack(heros);
break;
case 2:
this.fubuki(heros);
break;
case 3:
this.meisou();
break;
case 4:
this.warau();
default:
}
}
}