Guest User

PKMN.java

a guest
Jan 7th, 2019
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.87 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. /**
  4.  * A class to represent all the different types of Pokemon
  5.  */
  6. public class PKMN {
  7.  
  8.     /** public static array for tracking PKMN that have been constructed */
  9.     public static ArrayList<PKMN> allPKMN = new ArrayList<>();
  10.     /** PKMNs Name (String) */
  11.     private String name;
  12.     /** int representation of PKMNS current stats */
  13.     private int level, XP, XP2LVL, hp, maxHp, attack, defense, spAttack, spDefense, speed;
  14.     /** If PKMN has lost a fight or hp less than 0 */
  15.     private boolean faint;
  16.     /** PKMNs current Location (Place OBJ)*/
  17.     private Place currentLoc;
  18.     /** PKMNs Elemental Type */
  19.     private TYPE type;
  20.  
  21.     /**
  22.      * Constructor for PKMN
  23.      *
  24.      * @param name PKMN's name
  25.      * @param level PKMN's level
  26.      */
  27.     public PKMN(String name, int level, TYPE type) {
  28.         this.name = name;
  29.         this.level = level;
  30.         this.hp = 10;
  31.         this.maxHp = 10;
  32.         this.attack = 5;
  33.         this.defense = 5;
  34.         this.spAttack = 5;
  35.         this.spDefense = 5;
  36.         this.speed = 5;
  37.         this.type = type;
  38.         allPKMN.add(this);
  39.     }
  40.  
  41.     /**
  42.      * @return String PKMNs Name
  43.      */
  44.     public String name() {
  45.         return this.name;
  46.     }
  47.  
  48.     /**
  49.      * @return int PKMNs level
  50.      */
  51.     public int level() {
  52.         return this.level;
  53.     }
  54.    
  55.     /**
  56.      * @return int current xp
  57.      */
  58.     public int XP(){
  59.         return this.XP;
  60.     }
  61.     /**
  62.      * @return int xp required to level up
  63.      */
  64.     public int XP2LVL(){
  65.         return this.XP2LVL;
  66.     }
  67.  
  68.     /**
  69.      * @return int PKMNs hp
  70.      */
  71.     public int hp() {
  72.         return this.hp;
  73.     }
  74.  
  75.     /**
  76.      * @return int PKMNs max hp
  77.      */
  78.     public int maxHp() {
  79.         return this.maxHp;
  80.     }
  81.  
  82.     /**
  83.      * @return int PKMNs attack
  84.      */
  85.     public int attack() {
  86.         return this.attack;
  87.     }
  88.  
  89.     /**
  90.      * @return int PKMNs defense
  91.      */
  92.     public int defense() {
  93.         return this.defense;
  94.     }
  95.  
  96.     /**
  97.      * @return int PKMNs sp attack
  98.      */
  99.     public int spAttack() {
  100.         return this.spAttack;
  101.     }
  102.  
  103.     /**
  104.      * @return int PKMNs sp defense
  105.      */
  106.     public int spDefense() {
  107.         return this.spDefense;
  108.     }
  109.  
  110.     /**
  111.      * @return int PKMNs speed
  112.      */
  113.     public int speed() {
  114.         return this.speed;
  115.     }
  116.  
  117.     /**
  118.      * @return TYPE The PKMNs type (element)
  119.      */
  120.     public TYPE type() {
  121.         return this.type;
  122.     }
  123.  
  124.     /**
  125.      * @Override toString
  126.      */
  127.     public String toString() {
  128.         return this.name;
  129.     }
  130.  
  131.     /**
  132.      * @return bool PKMN faint status
  133.      */
  134.     public boolean faint() {
  135.         return this.faint;
  136.     }
  137.  
  138.     /**
  139.      * String set PKMNs name
  140.      */
  141.     public void setName(String n) {
  142.         this.name = n;
  143.     }
  144.  
  145.     /**
  146.      * int set PKMNs level
  147.      */
  148.     public void setLevel(int l) {
  149.         this.level = l;
  150.     }
  151.    
  152.     /**
  153.      * int add or remove xp from PKMNs current XP
  154.      */
  155.     public void modXP(int x){
  156.         this.XP += x;
  157.     }
  158.    
  159.     /**
  160.      * int set the maximum XP required for the PKMN to reach the next level
  161.      */
  162.     public void setXP2LVL(int xp){
  163.         this.XP2LVL = xp;
  164.     }
  165.  
  166.     /**
  167.      * int modifies PKMNs hp
  168.      */
  169.     public void modHp(int h) {
  170.         this.hp += h;
  171.         if (this.hp < 0) {
  172.             this.hp = 0;
  173.         }
  174.     }
  175.  
  176.     /**
  177.      * int set PKMNs max hp
  178.      */
  179.     public void setMaxHp(int m) {
  180.         this.maxHp = m;
  181.     }
  182.  
  183.     /**
  184.      * int set PKMNs attack
  185.      */
  186.     public void setAttack(int a) {
  187.         this.attack = a;
  188.     }
  189.  
  190.     /**
  191.      * int set PKMNs defense
  192.      */
  193.     public void setDefense(int d) {
  194.         this.defense = d;
  195.     }
  196.  
  197.     /**
  198.      * int set PKMNs sp attack
  199.      */
  200.     public void setSpAttack(int sa) {
  201.         this.spAttack = sa;
  202.     }
  203.  
  204.     /**
  205.      * int set PKMNs sp defense
  206.      */
  207.     public void setSpDefense(int sd) {
  208.         this.spDefense = sd;
  209.     }
  210.  
  211.     /**
  212.      * int set PKMNs Speed
  213.      */
  214.     public void setSpeed(int s) {
  215.         this.speed = s;
  216.     }
  217.  
  218.     /**
  219.      * @param f boolean which sets PKMN faint status
  220.      */
  221.     public void setFaint(boolean f) {
  222.         this.faint = f;
  223.     }
  224.     /**
  225.      * @param p Place where the PKMN currently is
  226.      */
  227.     public void setLoc(Place p){
  228.         this.currentLoc = p;
  229.     }
  230.  
  231.     /**
  232.      * Prints out the PKMNs info and stats as a block of Strings
  233.      */
  234.     public void info() {
  235.         System.out.println(String.format("\n%s Type: %s", this.name(), this.type.toString()));
  236.         System.out.println(String.format("Level: %d HP: %d/%d ", this.level(), this.hp(), this.maxHp()));
  237.         System.out.println(String.format("ATK: %d DEF: %d SPD: %d", this.attack(), this.defense(), this.speed()));
  238.         System.out.println(String.format("SP ATK: %d SP DEF: %d", this.spAttack(), this.spDefense()));
  239.     }
  240.  
  241.     /**
  242.      *
  243.      * @param target the PKMN being targeted
  244.      * @return if this PKMN is Strong to target PKMNs type
  245.      */
  246.     public boolean counterTypes(PKMN target) {
  247.         if (this.type() == type.Normal || target.type() == TYPE.Normal) {
  248.             return false;
  249.         } else if (this.type() == type.Water && target.type() == type.Fire) {
  250.             return true;
  251.         } else if (this.type() == type.Nature && target.type() == type.Water) {
  252.             return true;
  253.         } else if (this.type() == type.Fire && target.type() == type.Nature) {
  254.             return true;
  255.         } else if (this.type() == type.Electric && target.type() == type.Water) {
  256.             return true;
  257.         }
  258.         return false;
  259.     }
  260.  
  261.     /**
  262.      * Different elemental types for the PKMN
  263.      */
  264.     public enum TYPE {
  265.         Normal,
  266.         Fire,
  267.         Nature,
  268.         Water,
  269.         Electric
  270.     }
  271. }
Advertisement
Add Comment
Please, Sign In to add comment