課題2 完成
完成かと思ったけど、オーバーライド使ってませんでした!!
Listもうまく使えてるか、ただ書いてあるだけなのかわかりませんが、いちよう攻撃したらモンスターを倒せるようにはしてあります。
毒蝮ゴブリンにたいして攻撃力であったりを変えようと思ったのですが、うまく動作せず、とりあえず今から出かけるのでここで完成です!!
Main
import java.util.*;
public class Main {
public static void main(String[] args) {
//勇者を作成
Character c = new Character();
c.name = "やっつん";
System.out.println("生物" + c.name + "が第一世界に召喚された。");
Hero h = new Hero();
h.name = "マッサル";
h.hp = 100;
h.power = 20;
Goblin g1 = new Goblin();
g1.name = "ゴブリン";
Goblin g2 = new Goblin();
g2.name = "毒蝮ゴブリン";
List list = new ArrayList();
list.add(g1);
list.add(g2);
g1.hp = 50;
g1.defence = 10;
g1.suffix = 'A';
System.out.println("ゴブリン" + g1.suffix + "が現れた!!");
g2.hp = 50;
g2.defence = 15;
g2.suffix = 'A';
System.out.println("毒蝮ゴブリン" + g2.suffix + "が現れた!!");
g1.dance();
g1.Status();
h.damage = h.power - g1.defence;
h.sleep(10);
h.attack(g1);
h.attack2(g2);
h.finish();
h.Status();
g1.Status();
g2.Status2();
}
public class Main {
public static void main(String[] args) {
//勇者を作成
Character c = new Character();
c.name = "やっつん";
System.out.println("生物" + c.name + "が第一世界に召喚された。");
Hero h = new Hero();
h.name = "マッサル";
h.hp = 100;
h.power = 20;
Goblin g1 = new Goblin();
g1.name = "ゴブリン";
Goblin g2 = new Goblin();
g2.name = "毒蝮ゴブリン";
List
list.add(g1);
list.add(g2);
g1.hp =
g1.defence = 10;
g1.suffix = 'A';
System.out.println("ゴブリン" + g1.suffix + "が現れた!!");
g2.hp = 50;
g2.defence = 15;
g2.suffix = 'A';
System.out.println("毒蝮ゴブリン" + g2.suffix + "が現れた!!");
g1.dance();
g1.Status();
h.damage = h.power - g1.defence;
h.sleep(10);
h.attack(g1);
h.attack2(g2);
h.finish();
h.Status();
g1.Status();
g2.Status2();
}
}
Character
public class Character {
String name;
int hp;
int power;
int damage;
int defence;
int recover;
String name;
int hp;
int power;
int damage;
int defence;
int recover;
}
Hero
public class Hero extends Character {
void sleep(int hour){
recover = 10 * hour;
this.hp += recover;
System.out.println(this.name + "は、" + hour + "時間眠って" + recover + "回復した。");
System.out.println(this.name + "の現在のHPは" + this.hp + "です。");
}
void attack(Goblin g1){
for(int i=0; i<g1.hp; i++){
System.out.println(this.name + "は、" + g1.name + "に" + damage + "ダメージを与えた");
g1.hp -= damage;
System.out.println(g1.name + "の現在のHPは" + g1.hp + "です。");
System.out.println("-----------------------------");
if(g1.hp>0){
System.out.println("激しい戦いは続く");
}else{
System.out.println("ゴブリン死亡\n");
System.out.println("今度はひそひそと隠れている毒蝮ゴブリンに攻撃!!");
}
}
}
void attack2(Goblin g2){
for(int i=0; i<g2.hp; i++){
System.out.println(this.name + "は、" + g2.name + "に" + damage + "ダメージを与えた");
g2.hp -= damage;
System.out.println(g2.name + "の現在のHPは" + g2.hp + "です。");
System.out.println("-----------------------------");
if(g2.hp>0){
System.out.println("激しい戦いは続く");
}else{
System.out.println("毒蝮ゴブリン死亡");
}
}
}
void finish(){
System.out.println("マッサルは次の冒険へと旅立った。");
}
public void Status(){
System.out.println("###ステータス###");
System.out.println("勇者:"+this.name+" HP:"+this.hp);
}
//読み込み可能
public int getHp(){
return this.hp;
}
//書き込み可能
public void setHp(int hp){
this.hp=hp;
}
void sleep(int hour){
recover = 10 * hour;
this.hp += recover;
System.out.println(this.name + "は、" + hour + "時間眠って" + recover + "回復した。");
System.out.println(this.name + "の現在のHPは" + this.hp + "です。");
}
void attack(Goblin g1){
for(int i=0; i<g1.hp; i++){
System.out.println(this.name + "は、" + g1.name + "に" + damage + "ダメージを与えた");
g1.hp -= damage;
System.out.println(g1.name + "の現在のHPは" + g1.hp + "です。");
System.out.println("-----------------------------");
if(g1.hp>0){
System.out.println("激しい戦いは続く");
}else{
System.out.println("ゴブリン死亡\n");
System.out.println("今度はひそひそと隠れている毒蝮ゴブリンに攻撃!!");
}
}
}
void attack2(Goblin g2){
for(int i=0; i<g2.hp; i++){
System.out.println(this.name + "は、" + g2.name + "に" + damage + "ダメージを与えた");
g2.hp -= damage;
System.out.println(g2.name + "の現在のHPは" + g2.hp + "です。");
System.out.println("-----------------------------");
if(g2.hp>0){
System.out.println("激しい戦いは続く");
}else{
System.out.println("毒蝮ゴブリン死亡");
}
}
}
void finish(){
System.out.println("マッサルは次の冒険へと旅立った。");
}
public void Status(){
System.out.println("###ステータス###");
System.out.println("勇者:"+this.name+" HP:"+this.hp);
}
//読み込み可能
public int getHp(){
return this.hp;
}
//書き込み可能
public void setHp(int hp){
this.hp=hp;
}
}
Goblin
public class Goblin extends Character{
//ゴブリン
char suffix;
void dance(){
System.out.println("ゴブリンは無我夢中でダンスした");
}
public void Status(){
System.out.println("###ステータス###");
System.out.println("ゴブリン:"+this.name+" HP:"+this.hp);
}
//読み込み可能
public int getHp(){
return this.hp;
}
//書き込み可能
public void setHp(int hp){
this.hp=hp;
}
public void Status2(){
System.out.println("###ステータス###");
System.out.println("ゴブリン:"+this.name+" HP:"+this.hp);
}
//ゴブリン
char suffix;
void dance(){
System.out.println("ゴブリンは無我夢中でダンスした");
}
public void Status(){
System.out.println("###ステータス###");
System.out.println("ゴブリン:"+this.name+" HP:"+this.hp);
}
//読み込み可能
public int getHp(){
return this.hp;
}
//書き込み可能
public void setHp(int hp){
this.hp=hp;
}
public void Status2(){
System.out.println("###ステータス###");
System.out.println("ゴブリン:"+this.name+" HP:"+this.hp);
}
}