init
This commit is contained in:
46
Question13-Extends/src/common/Animal.java
Normal file
46
Question13-Extends/src/common/Animal.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
package common;
|
||||
|
||||
/**
|
||||
* 動物の情報や行動を持ったクラスです
|
||||
*
|
||||
*/
|
||||
public class Animal {
|
||||
/** 名前 */
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 行動:走る
|
||||
*/
|
||||
public void run() {
|
||||
System.out.println(this.name + "は走りました。");
|
||||
}
|
||||
|
||||
/**
|
||||
* 行動:食べる
|
||||
*/
|
||||
public void eat() {
|
||||
System.out.println(this.name + "は食事をしました。");
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter
|
||||
* @param name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
||||
12
Question13-Extends/src/common/Cat.java
Normal file
12
Question13-Extends/src/common/Cat.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package common;
|
||||
|
||||
/*
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
|
||||
// TODO 同一パッケージのAnimalクラスを継承してください
|
||||
public class Cat {
|
||||
|
||||
}
|
||||
119
Question13-Extends/src/common/Character.java
Normal file
119
Question13-Extends/src/common/Character.java
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
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) {
|
||||
|
||||
boolean deadFlg = false;
|
||||
|
||||
// ダメージ計算
|
||||
int damage = attack - this.endurance;
|
||||
if (damage <= 0) {
|
||||
// 必ず1ダメージは入るようにする
|
||||
damage = 1;
|
||||
}
|
||||
|
||||
// ダメージ分体力を減らす
|
||||
this.hp -= damage;
|
||||
|
||||
// 体力がなくなったかどうかの判定
|
||||
if (this.hp <= 0) {
|
||||
|
||||
// 体力が負の値になったら0に設定する
|
||||
this.hp = 0;
|
||||
|
||||
deadFlg = true;
|
||||
System.out.println(this.name + "は" + damage + "のダメージを受けた。");
|
||||
System.out.println(this.name + "の残り体力は" + this.hp + "。");
|
||||
System.out.println(this.name + "は" + "ちからつきた。");
|
||||
} else {
|
||||
System.out.println(this.name + "は" + damage + "のダメージを受けた。");
|
||||
System.out.println(this.name + "の残り体力は" + this.hp + "。");
|
||||
}
|
||||
|
||||
System.out.println("↓");
|
||||
|
||||
|
||||
return deadFlg;
|
||||
}
|
||||
|
||||
/**
|
||||
* キャラクター情報を表示します
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
16
Question13-Extends/src/common/Dog.java
Normal file
16
Question13-Extends/src/common/Dog.java
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
package common;
|
||||
|
||||
// TODO 同一パッケージのAnimalクラスを継承してください
|
||||
public class Dog {
|
||||
/*
|
||||
* TODO eatメソッドをオーバーライドして以下の内容が出力されるようにしてください。
|
||||
* name はドッグフードを食べました
|
||||
* ※ name には name フィールドの値が入る
|
||||
*/
|
||||
|
||||
}
|
||||
62
Question13-Extends/src/common/Item.java
Normal file
62
Question13-Extends/src/common/Item.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
package common;
|
||||
|
||||
/**
|
||||
* 装備品オブジェクト
|
||||
* @author rhizome
|
||||
*
|
||||
*/
|
||||
public class Item {
|
||||
/** アイテム名 */
|
||||
private String name;
|
||||
|
||||
/** 追加ダメージ量 */
|
||||
private int additionalDamage;
|
||||
|
||||
/**
|
||||
* 装備品の初期値を設定するコンストラクタ
|
||||
* @param name 装備品名
|
||||
* @param additionalDamage 追加ダメージ
|
||||
*/
|
||||
public Item(String name, int additionalDamage) {
|
||||
this.name = name;
|
||||
this.additionalDamage = additionalDamage;
|
||||
}
|
||||
|
||||
/**
|
||||
* アイテム名を取得します
|
||||
* @return アイテム名
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* アイテム名を設定します
|
||||
* @param name 設定したいアイテム名
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 追加ダメージを取得します
|
||||
* @return 追加ダメージ
|
||||
*/
|
||||
public int getAdditionalDamage() {
|
||||
return additionalDamage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 追加ダメージを設定します
|
||||
* @param additionalDamage 設定したい追加ダメージ
|
||||
*/
|
||||
public void setAdditionalDamage(int additionalDamage) {
|
||||
this.additionalDamage = additionalDamage;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user