これ何て呼びますか

public class PTra13_04 のところが分かりません。
誰か助けてください!

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
package practice13.common;

/**
* 登場するキャラクターの情報とデフォルトの行動を設定したクラスです
* @author rhizome
*
*/
public class Character {
/** 名前 */
private String name = "キャラクター";

/** 体力 */
private int hp;

/** 力 */
private int power;

/** 防御力 */
private int endurance;

/**
* 体力、攻撃力、防御力の初期値を設定しつつ、Characterインスタンスを生成します
* @param hp
* @param attack
* @param defence
*/
public Character(int hp, int power, int endurance) {
this.hp = hp;
this.power = power;
this.endurance = endurance;
}

/**
* 名前を設定します
* @param name 設定したい名前
*/
public void setName(String name) {
this.name = name;
}

/**
* 名前を取得します
* @return 名前
*/
public String getName() {
return this.name;
}

/**
* 攻撃を行います
* @return 相手に与えるダメージを返します
*/
public int attack() {
return this.power;
}

/**
* ダメージ判定を行います
* @param attack 攻撃値
* @return 体力が0になったらtrue、まだ体力が残っていたらfalse
*/
public boolean damage(int attack) {
// ダメージ計算
int calc = attack - this.endurance;
if (calc <= 0) {
// 必ず1ダメージは入るようにする
calc = 1;
}

// ダメージ分体力を減らす
this.hp -= calc;

// 体力がなくなったかどうかの判定
if (this.hp <= 0) {
this.hp = 0;
return true;
}

return false;
}

/**
* キャラクター情報を表示します
* @return
*/
public String showParameter() {
StringBuilder str = new StringBuilder();

str.append("名 前:" + this.name);
str.append("\n");
str.append("体 力:" + this.hp);
str.append("\n");
str.append(" 力 :" + this.power);
str.append("\n");
str.append("耐 久:" + this.endurance);

return str.toString();
}
}
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
package practice13.common;

public class Hero extends Character{



public Hero() {
super(25, 10, 7);
}

}
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
package practice13.common;

public class Slime extends Character {

public Slime() {
super(10,5,2);
}
}
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
★ここのところが分からないです。


package practice13.ptra13;

import practice13.common.Hero;
import practice13.common.Slime;

public class PTra13_04 {

/*
* ★ PTra13_02, PTra13_03で作成した、Hero/Slimeクラスを使用します
*/

public static void main(String[] args) {

// ★ HeroインスタンスとSlimeインスタンスを作成し、それぞれの名前に"勇者", "スライム"を設定してください

Hero hero=new Hero();
hero.setName("勇者");

Slime slime=new Slime();
slime.setName("スライム");
/*
* ★ HeroとSlimeを、どちらかが体力0になるまで戦わせます
*
* ●Heroの攻撃 -> ダメージ判定 -> Slimeの攻撃 -> ダメージ判定
* 上記を繰り返し行います
*/


// ★ 勝利した方の出力を行ってください。「○○は■■との戦闘に勝利した」


   }
}
}

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

A 回答 (2件)

eclipseで実際に実行して動作することを確認しています。


面倒なのでpackageは全てcommonにしています。
「PTra13_04、Hero、Slime、Character」は別ファイルです。




package common;

/**
* 登場するキャラクターの情報とデフォルトの行動を設定したクラスです
* @author rhizome
*
*/
public class Character {
/** 名前 */
private String name = "キャラクター";

/** 体力 */
private int hp;

/** 力 */
private int power;

/** 防御力 */
private int endurance;

/**
* 体力、攻撃力、防御力の初期値を設定しつつ、Characterインスタンスを生成します
* @param hp
* @param attack
* @param defence
*/
public Character(int hp, int power, int endurance) {
this.hp = hp;
this.power = power;
this.endurance = endurance;
}

/**
* 名前を設定します
* @param name設定したい名前
*/
public void setName(String name) {
this.name = name;
}

/**
* 名前を取得します
* @return 名前
*/
public String getName() {
return this.name;
}

/**
* 攻撃を行います
* @return 相手に与えるダメージを返します
*/
public int attack() {
return this.power;
}

/**
* ダメージ判定を行います
* @param attack 攻撃値
* @return体力が0になったらtrue、まだ体力が残っていたらfalse
*/
public boolean damage(int attack) {
// ダメージ計算
int calc = attack - this.endurance;
if (calc <= 0) {
// 必ず1ダメージは入るようにする
calc = 1;
}

// ダメージ分体力を減らす
this.hp -= calc;

// 体力がなくなったかどうかの判定
if (this.hp <= 0) {
this.hp = 0;
return true;
}

return false;
}

/**
* キャラクター情報を表示します
* @return
*/
public String showParameter() {
StringBuilder str = new StringBuilder();

str.append("名 前:" + this.name);
str.append("\n");
str.append("体 力:" + this.hp);
str.append("\n");
str.append(" 力 :" + this.power);
str.append("\n");
str.append("耐 久:" + this.endurance);

return str.toString();
}

}



package common;

public class Hero extends Character{

public Hero() {
super(25, 10, 7);
}

}



package common;

public class Slime extends Character {

public Slime() {
super(10,5,2);
}

}



package common;

public class PTra13_04 {

/*
* ★ PTra13_02, PTra13_03で作成した、Hero/Slimeクラスを使用します
*/

public static void main(String[] args) {

// ★ HeroインスタンスとSlimeインスタンスを作成し、それぞれの名前に"勇者", "スライム"を設定してください

Hero hero=new Hero();
hero.setName("勇者");

Slime slime=new Slime();
slime.setName("スライム");
/*
* ★ HeroとSlimeを、どちらかが体力0になるまで戦わせます
*
* ●Heroの攻撃 -> ダメージ判定 -> Slimeの攻撃 -> ダメージ判定
* 上記を繰り返し行います
*/

//★ 勝利した方の出力を行ってください。「○○は■■との戦闘に勝利した」

do{
// デバッグ用表示
// System.out.println(hero.showParameter());
// System.out.println(slime.showParameter());
// System.out.println();
if( slime.damage(hero.attack( )) ){ // HeroがSlimeに攻撃
System.out.println(hero.getName()+"は"+slime.getName()+"との戦闘に勝利した");
break;
}else{
if( hero.damage(slime.attack( )) ){ // SlimeがHeroに攻撃
System.out.println(slime.getName()+"は"+hero.getName()+"との戦闘に勝利した");
break;
}
}
}while ( true );
// デバッグ用表示
// System.out.println(hero.showParameter());
// System.out.println(slime.showParameter());

}

}
    • good
    • 0

具体的にはなにがどうわからない?

    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!