Advertisement
Guest User

Player Class

a guest
Aug 23rd, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.31 KB | None | 0 0
  1. public class Player {
  2.  
  3.     private String userName;
  4.     private int healthLevel;
  5.     private int currentHealth;
  6.     private int miningLevel;
  7.     private int miningLevelXP;
  8.  
  9.  
  10.     // Setting Player Constructor
  11.     public Player(String userName) {
  12.         this.userName = userName;
  13.         healthLevel = 10;
  14.         currentHealth = healthLevel;
  15.         miningLevel = 1;
  16.         miningLevelXP = 0;
  17.  
  18.     }
  19.  
  20.     // Getting Player Username and Printing It Out.
  21.     public void getPlayerUsername() {
  22.         System.out.println("Username: " + this.userName);
  23.     }
  24.  
  25.     // Getting Player Health and Printing It Out.
  26.     public void getPlayerHealth() {
  27.         System.out.println("Health Points: " + this.currentHealth + "/" + this.healthLevel);
  28.     }
  29.     // Getting Players Mining XP and Printing It Out.
  30.     public void getPlayerMiningXP() {
  31.         System.out.println("Mining XP: " + miningLevelXP);
  32.     }
  33.  
  34.     // Returning The Integer of The Players Mining Level.
  35.     public void getPlayerMiningLevel() {
  36.         System.out.println("Mining Level: " + miningLevel);
  37.     }
  38.  
  39.     // Returning The Integer of The Players Mining Experience.
  40.     public int getPlayerMiningEXP() {
  41.         return miningLevelXP;
  42.     }
  43.  
  44.  
  45.     // Player Action Methods
  46.  
  47.     // Player Eat Action To Restore Health Points.
  48.     public void eat(int foodHP, String foodName) {
  49.         System.out.println("You ate some " + foodName + ", it healed you for " + foodHP + " health points ");
  50.         currentHealth += foodHP;
  51.  
  52.         if (currentHealth >= healthLevel) {
  53.             currentHealth = healthLevel;
  54.         }
  55.     }
  56.  
  57.     // Player Take Damage Action To Reduce Health Points.
  58.     public void takeDamange(int damangeHP) {
  59.         System.out.println("You've taken damage, you have lost " + damangeHP + " health");
  60.         currentHealth -= damangeHP;
  61.     }
  62.  
  63.     // Method To Calculate The Players Mining Level
  64.     // Based Off of The Players Mining Experience.
  65.     public int getPlayerMiningLEVEL() {
  66.         if (miningLevelXP > 0 & miningLevelXP < 5) {
  67.             miningLevel = 1;
  68.         } else if (miningLevelXP >= 5 & miningLevelXP < 10) {
  69.             miningLevel = 2;
  70.         } else if (miningLevelXP >= 10 & miningLevelXP < 15) {
  71.             miningLevel = 3;
  72.         } else if (miningLevelXP >= 15 & miningLevelXP < 20) {
  73.             miningLevel = 4;
  74.         } else if (miningLevelXP >=20 & miningLevelXP < 25) {
  75.             miningLevel = 5;
  76.         } else if (miningLevelXP >= 25 & miningLevelXP < 30) {
  77.             miningLevel = 6;
  78.         } else {
  79.             miningLevel = 6;
  80.         }
  81.         return miningLevel;
  82.     }
  83.  
  84.     // Player Mine Ore Action To Gain Mining Experience and
  85.     // To Check if Mining Level is High Enough To Mine Certain Ore.
  86.     public void mineOre(String oreName, int oreLevel, int oreXP) {
  87.         if (miningLevel >= oreLevel) {
  88.             System.out.println("\nYou mined a " + oreName + " ore and gained " + oreXP + " experience");
  89.             miningLevelXP += oreXP;
  90.             getPlayerMiningXP();
  91.             getPlayerMiningLEVEL();
  92.         } else if (miningLevel < oreLevel) {
  93.             System.out.println("\nYou do not have a high enough mining level to mine " + oreName + " ore.");
  94.             System.out.println("You need a required level of: " + oreLevel);
  95.         }
  96.     }
  97.    
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement