戦闘ゲーム(?)

その質問はこちら

修正前

Main.java

public class Main {
    public static void main(String[] args) {
        Hero h1 = new Hero("ミナト");
        Wizard w = new Wizard();
        w.name = "スガワラ";
        w.hp = 50;
        w.heal(h1);
        w.heal(h2);
        System.out.println(h1.hp);
        System.out.println(h2.hp);
        Matango m1 = new Matango();
        m1.hp = 50;
        m1.suffix = 'A';
        Matango m2 = new Matango();
        m2.hp = 48;
        m2.suffix = 'B';
    }
}

Hero.java

public class Hero {
    Sword sword;
    void attack() {
        System.out.println(this.name + "は攻撃した!");
        System.out.println("敵に5ポイントのダメージを与えた!");
    }
    void sleep() {
        this.hp = 100;
        System.out.println(this.name + "は、眠って回復した!");
    }
    void sit(int sec) {
        this.hp += sec;
        System.out.println(this.name + "は、" + sec + "秒座った!");
        System.out.println("HPが" + sec + "ポイント回復した.");
    }
    void slip() {
        this.hp -= 5;
        System.out.println(this.name + "は、転んだ!");
        System.out.println("5のダメージ!");
    }
    void run() {
        System.out.println(this.name + "は、逃げ出した!");
        System.out.println("GAMEOVER");
        System.out.println("最終HPは" + this.hp + "でした");
    }
    Hero(String name) {
        this.hp = 100;
        this.name = name;
    }
}

Wizard.java

public class Wizard {
    String name;
    int hp;
    void heal(Hero h) {
        h.hp += 2;
        System.out.println(h.name + "のHPを10回復した!");
    }
}

Matango.java

public class Matango {
    int hp;
    final int LEVEL = 10;
    char suffix;
    int sleepPoint;
    void run() {
        System.out.println("お化けキノコ" + this.suffix + "は逃げ出した!");
    }
    void sleep(int sleepPoint) {
        hp += sleepPoint;
        System.out.println("お化けキノコ" + this.suffix + "は"
        + sleepPoint + "眠った!"
        + this.hp + "ポイント回復した!");
    }
}

Sword.java

public class Sword {
    String name;
    int damage;
}

修正後

Main.java

public class Main {
	public static void main(String[] args){
		Hero hero = new Hero("ミナト");
		Wizard wizard = new Wizard("スガワラ");
		wizard.heal(hero);
		wizard.heal(wizard);
		System.out.println(hero.characterName + " HP:" + hero.hp);
		System.out.println(wizard.characterName + " HP:" + wizard.hp);
		Matango matangoA = new Matango(50, "A");
		Matango matangoB = new Matango(48, "B");
	}
}

Hero.java

public class Hero {
	int hp, maxHp;
	String characterName;
	Hero(String name){
		this.characterName = name;
		this.hp = 100;
		this.maxHp = 100;
	}
	public void attack(Matango matango) {
		System.out.println(characterName + "は攻撃した!");
		System.out.println("敵に5ポイントのダメージを与えた!");
		matango.hp -= 5;		
	}
	public void sleep() {
		hp = 100;
		System.out.println(characterName + "は、眠って回復した!");
	}
	public void sit(int sec) {
		hp += sec;
		if(hp > maxHp) hp = maxHp;
		System.out.println(characterName + "は、" + sec + "秒座った!");
		System.out.println("HPが" + sec + "ポイント回復した.");
	}
	public void slip() {
		hp -= 5;
		if(hp < 0) hp = 0;
		System.out.println(characterName + "は、転んだ!");
		System.out.println("5のダメージ!");
	}
	public void run() {
		System.out.println(characterName + "は、逃げ出した!");
		System.out.println("GAMEOVER");
		System.out.println("最終HPは" + hp + "でした");
	}
}

Wizard.java

public class Wizard {
	String characterName;
	int hp, maxHp;
	Wizard(String name){
		this.characterName = name;
		this.hp = 50;
		this.maxHp = 50;
	}
	public void heal(Hero hero){
		hero.hp += 10;
		if(hero.hp > hero.maxHp) hero.hp = hero.maxHp;
		System.out.println(hero.characterName + "のHPを10回復した!");
	}
	public void heal(Wizard wizard){
		wizard.hp += 10;
		if(wizard.hp > wizard.maxHp) wizard.hp = wizard.maxHp;
		System.out.println(wizard.characterName + "のHPを10回復した!");
	}
}

Matango.java

public class Matango {
	int hp, maxHp;
	String suffix;
	Matango(int maxHitPoint, String suffixLetter){
		this.suffix = suffixLetter;
		this.hp = maxHitPoint;
	}
	public void run() {
		System.out.println("お化けキノコ" + suffix + "は逃げ出した!");
	}
	public void sleep(int sleepPoint) {
		hp += sleepPoint;
		System.out.println("お化けキノコ" + suffix + "は眠った!\n" + sleepPoint + "ポイント回復した!");
	}
}

たぶん途中なんだろうけど、仕事してないSwordクラスには消えてもらいました。