Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package uni.fmi.bachelors;
- import java.util.Random;
- public class Dragon extends Animal {
- private boolean hasMagicImmunity;
- private int hp = 100;
- Random random = new Random();
- public Dragon(String type, int pop) {
- super(type, pop);
- }
- public void seeIfDead() {
- if(hp <= 0) {
- System.err.println("IS NOW DEAD!");
- }
- }
- @Override
- public void moveTo(String to) {
- System.out.println("Flew to " + to);
- if(random.nextInt(10) > 2) {
- System.out.println("Was shot by arrow and "
- + "lost 10 hp");
- hp -= 10;
- seeIfDead();
- }
- }
- @Override
- public void eat() {
- System.out.println("Ate a knight!");
- int ran = random.nextInt(4);
- System.out.println("But the Knight last bath "
- + " was " + ran + " months ago and "
- + " caused poisoning that took "
- + ran*10 + " damage ");
- hp -= ran*10;
- seeIfDead();
- }
- public boolean isHasMagicImmunity() {
- return hasMagicImmunity;
- }
- public void setHasMagicImmunity(boolean hasMagicImmunity) {
- this.hasMagicImmunity = hasMagicImmunity;
- }
- public int getHp() {
- return hp;
- }
- public void setHp(int hp) {
- this.hp = hp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement