Game Challenge
public class Human {
private String name;
private int HP;
private int DMG;
private double luck;
private String food;
public String getName() {
return name;
}
public int getHP() {
return HP;
}
public int getDMG() {
return DMG;
}
public String getFood() {
return food;
}
public double getLuck() {
return luck;
}
public boolean isAlive() {
if (this.HP > 0) {
return true;
} else {
return false;
}
}
public void setName(String newName) {
this.name = newName;
}
public void setHP(int newHP) {
this.HP = newHP;
}
public void takeDMG(int takenDamage) {
this.HP -= takenDamage;
}
public void setDMG(int newDMG) {
this.DMG = newDMG;
}
public void setFood(String newFood) {
this.food = newFood;
}
public void setLuck(double newLuck) {
this.luck = newLuck;
}
}
import java.lang.Math;
public class Eating {
public static void eat(Human Human1) {
System.out.println(Human1.getName() + " has an HP of " +Human1.getHP() );
System.out.println(Human1.getName()+ " is eating " + Human1.getFood());
for(int x=0; x<5; x ++ ) {
if (Math.random() < Human1.getLuck()) {
Human1.takeDMG(Human1.getDMG());
System.out.println(Human1.getName() + " is hurt!!");
System.out.println(Human1.getName() + " takes " + Human1.getDMG() + " damage ");
} else {
System.out.println(Human1.getName() + " takes no damage");
System.out.println(Human1.getName() + " takes another bite ");
}
System.out.println(Human1.getName() + " HP: " + Human1.getHP());
System.out.println();
if (!Human1.isAlive()) {
System.out.println(Human1.getName() + " has died " );
}
}
if (Human1.isAlive()) {
System.out.println(Human1.getName() + " stays alive to save the day! ");
}
}
public static void main(String[] args) {
Human Human1 = new Human();
Human1.setName("Batman");
Human1.setHP(15);
Human1.setDMG(1);
Human1.setFood("orange");
Human1.setLuck(0.9);
eat(Human1);
}
}
Eating.main(null);