完了済
This commit is contained in:
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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user