完了済
This commit is contained in:
6
Question13-Extends/.classpath
Normal file
6
Question13-Extends/.classpath
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"/>
|
||||
<classpathentry kind="src" path="src/main/java"/>
|
||||
<classpathentry kind="output" path="build/classes"/>
|
||||
</classpath>
|
||||
1
Question13-Extends/.gitignore
vendored
Normal file
1
Question13-Extends/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build/
|
||||
23
Question13-Extends/.project
Normal file
23
Question13-Extends/.project
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Question13-Extends</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
9
Question13-Extends/.settings/org.eclipse.jdt.core.prefs
Normal file
9
Question13-Extends/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,9 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
|
||||
org.eclipse.jdt.core.compiler.compliance=21
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=21
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<installed facet="java" version="21"/>
|
||||
</faceted-project>
|
||||
22
Question13-Extends/src/main/java/Animal.java
Normal file
22
Question13-Extends/src/main/java/Animal.java
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
public class Animal {
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void Run() {
|
||||
System.out.println(this.getName()+"走りました。");
|
||||
}
|
||||
|
||||
public void Eat() {
|
||||
System.out.println(this.getName()+"は食事をしました。");
|
||||
}
|
||||
|
||||
}
|
||||
4
Question13-Extends/src/main/java/Cat.java
Normal file
4
Question13-Extends/src/main/java/Cat.java
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
public class Cat extends Animal {
|
||||
|
||||
}
|
||||
84
Question13-Extends/src/main/java/Character.java
Normal file
84
Question13-Extends/src/main/java/Character.java
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
public class Character {
|
||||
|
||||
private String name;
|
||||
private int hp;
|
||||
private int power;
|
||||
private int defense;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public int getHP() {
|
||||
return hp;
|
||||
}
|
||||
public void setHP(int HP) {
|
||||
hp = HP;
|
||||
}
|
||||
public int getPower() {
|
||||
return power;
|
||||
}
|
||||
public void setPower(int power) {
|
||||
this.power = power;
|
||||
}
|
||||
public int getDefense() {
|
||||
return defense;
|
||||
}
|
||||
public void setDefense(int defense) {
|
||||
this.defense = defense;
|
||||
}
|
||||
|
||||
public Character() {
|
||||
|
||||
}
|
||||
|
||||
public Character(int HP, int power, int defense) {
|
||||
this.hp = HP;
|
||||
this.power = power;
|
||||
this.defense = defense;
|
||||
}
|
||||
|
||||
public int attack() {
|
||||
return this.getPower();
|
||||
}
|
||||
|
||||
public boolean dameged(int enemypower) {
|
||||
|
||||
boolean isDead = false;
|
||||
|
||||
int damage = 0;
|
||||
if (enemypower-this.getDefense()<0) {
|
||||
damage = 1;
|
||||
} else {
|
||||
damage = enemypower-this.getDefense();
|
||||
}
|
||||
|
||||
if (this.getHP()-damage<0) {
|
||||
this.setHP(0);
|
||||
isDead = true;
|
||||
} else {
|
||||
this.setHP(this.getHP()-damage);
|
||||
}
|
||||
|
||||
System.out.println(this.getName()+"は"+damage+"のダメージを受けた。");
|
||||
System.out.println(this.getName()+"の残り体力は"+this.getHP()+"。");
|
||||
if(isDead) {
|
||||
System.out.println(this.getName()+"はちからつきた。");
|
||||
}
|
||||
System.out.println("↓");
|
||||
|
||||
return isDead;
|
||||
}
|
||||
|
||||
public String display() {
|
||||
String str = "名 前:"+this.getName()+"\n"
|
||||
+"体 力:"+this.getHP()+"\n"
|
||||
+" 力 :"+this.getPower()+"\n"
|
||||
+"耐 久:"+this.getDefense();
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
||||
6
Question13-Extends/src/main/java/Dog.java
Normal file
6
Question13-Extends/src/main/java/Dog.java
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
public class Dog extends Animal {
|
||||
public void Eat() {
|
||||
System.out.println(this.getName()+"はドッグフードを食べました。");
|
||||
}
|
||||
}
|
||||
9
Question13-Extends/src/main/java/Hero.java
Normal file
9
Question13-Extends/src/main/java/Hero.java
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
public class Hero extends Character {
|
||||
public Hero() {
|
||||
this.setName("");
|
||||
this.setHP(25);
|
||||
this.setPower(10);
|
||||
this.setDefense(7);
|
||||
}
|
||||
}
|
||||
25
Question13-Extends/src/main/java/Item.java
Normal file
25
Question13-Extends/src/main/java/Item.java
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
public class Item {
|
||||
|
||||
private String name;
|
||||
private int add;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public int getAdd() {
|
||||
return add;
|
||||
}
|
||||
public void setAdd(int add) {
|
||||
this.add = add;
|
||||
}
|
||||
|
||||
public Item(String name,int add) {
|
||||
this.setName(name);
|
||||
this.setAdd(add);
|
||||
}
|
||||
|
||||
}
|
||||
14
Question13-Extends/src/main/java/Question13_1.java
Normal file
14
Question13-Extends/src/main/java/Question13_1.java
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
public class Question13_1 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
Cat cat = new Cat();
|
||||
cat.setName("タマ");
|
||||
cat.Run();
|
||||
cat.Eat();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
14
Question13-Extends/src/main/java/Question13_2.java
Normal file
14
Question13-Extends/src/main/java/Question13_2.java
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
public class Question13_2 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
Dog dog = new Dog();
|
||||
dog.setName("ポチ");
|
||||
dog.Run();
|
||||
dog.Eat();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
13
Question13-Extends/src/main/java/Question13_3.java
Normal file
13
Question13-Extends/src/main/java/Question13_3.java
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
public class Question13_3 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
Hero hero = new Hero();
|
||||
hero.setName("勇者");
|
||||
System.out.println(hero.display());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
13
Question13-Extends/src/main/java/Question13_4.java
Normal file
13
Question13-Extends/src/main/java/Question13_4.java
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
public class Question13_4 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
Slime slime = new Slime();
|
||||
slime.setName("スライム");
|
||||
System.out.println(slime.display());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
28
Question13-Extends/src/main/java/Question13_5.java
Normal file
28
Question13-Extends/src/main/java/Question13_5.java
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
public class Question13_5 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
Hero hero = new Hero();
|
||||
hero.setName("勇者");
|
||||
// System.out.println(hero.display());
|
||||
|
||||
Slime slime = new Slime();
|
||||
slime.setName("スライム");
|
||||
// System.out.println(slime.display());
|
||||
|
||||
while (true) {
|
||||
if ( slime.dameged(hero.attack()) ) {
|
||||
System.out.println(hero.getName()+"は"+slime.getName()+"との戦闘に勝利した");
|
||||
break;
|
||||
}
|
||||
if ( hero.dameged(slime.attack()) ) {
|
||||
System.out.println(slime.getName()+"は"+hero.getName()+"との戦闘に勝利した");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
21
Question13-Extends/src/main/java/Question13_6.java
Normal file
21
Question13-Extends/src/main/java/Question13_6.java
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
public class Question13_6 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
SuperHero superhero = new SuperHero();
|
||||
superhero.setName("勇者(装備あり)");
|
||||
System.out.println(superhero.display());
|
||||
|
||||
Slime slime = new Slime();
|
||||
slime.setName("スライム");
|
||||
|
||||
Item item = new Item("こんぼう",5);
|
||||
|
||||
superhero.setItem(item);
|
||||
System.out.println(superhero.attack());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
29
Question13-Extends/src/main/java/Question13_7.java
Normal file
29
Question13-Extends/src/main/java/Question13_7.java
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
public class Question13_7 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO 自動生成されたメソッド・スタブ
|
||||
|
||||
SuperHero superhero = new SuperHero();
|
||||
superhero.setName("勇者(装備あり)");
|
||||
|
||||
Slime slime = new Slime();
|
||||
slime.setName("スライム");
|
||||
|
||||
Item item = new Item("ロングソード",20);
|
||||
superhero.setItem(item);
|
||||
|
||||
while (true) {
|
||||
if ( slime.dameged(superhero.attack()) ) {
|
||||
System.out.println(superhero.getName()+"は"+slime.getName()+"との戦闘に勝利した");
|
||||
break;
|
||||
}
|
||||
if ( superhero.dameged(slime.attack()) ) {
|
||||
System.out.println(slime.getName()+"は"+superhero.getName()+"との戦闘に勝利した");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
9
Question13-Extends/src/main/java/Slime.java
Normal file
9
Question13-Extends/src/main/java/Slime.java
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
public class Slime extends Character {
|
||||
public Slime() {
|
||||
this.setName("");
|
||||
this.setHP(10);
|
||||
this.setPower(5);
|
||||
this.setDefense(2);
|
||||
}
|
||||
}
|
||||
23
Question13-Extends/src/main/java/SuperHero.java
Normal file
23
Question13-Extends/src/main/java/SuperHero.java
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
public class SuperHero extends Hero {
|
||||
|
||||
private Item item;
|
||||
|
||||
public SuperHero() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Item getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(Item item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public int attack() {
|
||||
this.setPower(this.getPower()+this.getItem().getAdd());
|
||||
return this.getPower();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user