Advertisement
vladimirVenkov

Untitled

Jun 29th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.94 KB | None | 0 0
  1. package junglesurvival.participants;
  2.  
  3. import junglesurvival.Dice;
  4. import junglesurvival.items.Consumable;
  5. import junglesurvival.items.Item;
  6. import junglesurvival.items.Jewel;
  7. import junglesurvival.items.Weapon;
  8.  
  9. import java.util.ArrayList;
  10. import java.util.List;
  11.  
  12. public abstract class Hero extends Participant {
  13.  
  14.     //Sample constants
  15.     private static final int EXPERIENCE_FOR_LEVELING_UP = 50;
  16.     private static final int BONUS_ATTACK_FOR_LEVELING_UP = 10;
  17.     private static final int BONUS_LIFE_ON_LEVELING_UP = 50;
  18.  
  19.     private Gender gender;
  20.     private int experience;
  21.     private List<Item> bag;
  22.     private List<Jewel> bribAbility;
  23.     private int currentAttack; //TODO lets consider spiting attack from super and this to be set only a bonus attack from items?
  24.  
  25.     public Hero(String name) { //}, int lifepoints, int attack, Gender gender) {
  26.         super(name);
  27.         this.gender = gender;
  28.         bag = new ArrayList<>();
  29.         bribAbility = new ArrayList<>();
  30.         currentAttack = super.getAttack();
  31.     }
  32.  
  33.     public void pickItem(Item item) {
  34.         bag.add(item);
  35.         if (item instanceof Weapon)
  36.             currentAttack += ((Weapon) item).getBonusAttack();//Implemented some logic for Weapon. - older code+comment: currentAttack++; //TODO change when weapon is finished!!!
  37.         if (item instanceof Jewel) bribAbility.add((Jewel) item);
  38.     }
  39.  
  40.     public abstract void attackEnemy(Enemy enemy);
  41.  
  42.  
  43.     private void levelUp() {
  44.         super.setLifepoints(getLifepoints() + BONUS_LIFE_ON_LEVELING_UP); //TODO set to constant at some point - added a sample constant
  45.         super.setAttack(getAttack() + BONUS_ATTACK_FOR_LEVELING_UP); //TODO DOESNT SEEM TO WORK ?-should work now/ set to constant at some point - added a sample constant
  46.         currentAttack += BONUS_ATTACK_FOR_LEVELING_UP;
  47.     }
  48.  
  49.     public void status() {
  50.         System.out.printf("This %s hero %s has %d lifepoints, %d experience \n" +
  51.                         " %d current attack and a bag with following items:\n", gender, super.getName(),
  52.                 super.getLifepoints(), experience, currentAttack);
  53.         bag.forEach(System.out::println);
  54. //        bag.stream().filter(x -> x instanceof Consumable).forEach(System.out::println);
  55.     }
  56.  
  57.     public int getExperience() {
  58.         return experience;
  59.     }
  60.  
  61.     public void setExperience(int bonusExperience) { //this method now works with bonus experience and solves leveling up -> making private
  62.  
  63.         int leftoverExperience = experience + bonusExperience;
  64.         while (leftoverExperience >= EXPERIENCE_FOR_LEVELING_UP) {
  65.             leftoverExperience -= EXPERIENCE_FOR_LEVELING_UP;
  66.             levelUp();
  67.         }
  68.         this.experience = leftoverExperience;
  69.     }
  70.  
  71.     public void eats(Consumable consumable) {
  72.         consumable.beingConsumed(this);
  73.     }
  74.  
  75.     public  int throwDice(){
  76.         Dice dice=new Dice();
  77.         return dice.getValue();
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement