Advertisement
nadejdachitakova

DragonheritedByAnimal

Feb 17th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. package uni.fmi.bachelors;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Dragon extends Animal {
  6.  
  7.     private boolean hasMagicImmunity;
  8.     private int hp = 100;
  9.     Random random = new Random();
  10.    
  11.     public Dragon(String type, int pop) {
  12.         super(type, pop);
  13.     }
  14.    
  15.     public void seeIfDead() {
  16.         if(hp <= 0) {
  17.             System.err.println("IS NOW DEAD!");
  18.         }
  19.     }
  20.  
  21.     @Override
  22.     public void moveTo(String to) {
  23.         System.out.println("Flew to " + to);
  24.        
  25.         if(random.nextInt(10) > 2) {
  26.             System.out.println("Was shot by arrow and "
  27.                     + "lost 10 hp");           
  28.             hp -= 10;
  29.             seeIfDead();           
  30.         }      
  31.     }
  32.  
  33.     @Override
  34.     public void eat() {
  35.         System.out.println("Ate a knight!");
  36.        
  37.         int ran = random.nextInt(4);
  38.        
  39.         System.out.println("But the Knight last bath "
  40.                 + " was " + ran + " months ago and "
  41.                 + " caused poisoning that took "
  42.                 + ran*10 + " damage ");
  43.        
  44.         hp -= ran*10;
  45.        
  46.         seeIfDead();
  47.     }
  48.  
  49.     public boolean isHasMagicImmunity() {
  50.         return hasMagicImmunity;
  51.     }
  52.  
  53.     public void setHasMagicImmunity(boolean hasMagicImmunity) {
  54.         this.hasMagicImmunity = hasMagicImmunity;
  55.     }
  56.  
  57.     public int getHp() {
  58.         return hp;
  59.     }
  60.  
  61.     public void setHp(int hp) {
  62.         this.hp = hp;
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement