Battle.java



/** 生命体どおしの戦闘を表すクラス */
public class Battle {

  /** 戦う生命体(先攻) */
    public Attacker attacker1;

  /** 戦う生命体(後攻) */
    public Attacker attacker2;

  /** コンストラクタ */
    public Battle( Attacker attacker1, Attacker attacker2 ) {
        this.attacker1 = attacker1;
        this.attacker2 = attacker2;
    }

  /** 戦闘の処理の開始 */
    public void start() {
        while( true ) {
            System.out.println( attacker1.name + "が"
                              + attacker2.name + "を"
                              + "攻撃した" );
            attacker1.attack( attacker2 );
            if( !attacker2.isAlive() ) {
                System.out.println( attacker1.name + "は"
                                  + attacker2.name + "を"
                                  + "倒した" );
                break;
            }
            else {
                System.out.println( attacker2.name + "の生命力は"
                                  + attacker2.lifePoint
                                  + "に減った" );
            }
            System.out.println( attacker2.name + "が"
                              + attacker1.name + "を"
                              + "攻撃した" );
            attacker2.attack( attacker1 );
            if( !attacker1.isAlive() ) {
                System.out.println( attacker2.name + "は"
                                  + attacker1.name + "を"
                                  + "倒した" );
                break;
            }
            else {
                System.out.println( attacker1.name + "の生命力は"
                                  + attacker1.lifePoint
                                  + "に減った" );
            }
        }
    }
}