Guest User

PKMN.java

a guest
Jan 7th, 2019
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.16 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.    
  9.     public static ArrayList<PKMN> allPKMN = new ArrayList<>();
  10.     private String name;
  11.     private int level, CurrentXp, XpRequiredToLevel, hp, maxHp, atkVal, defVal, spAtkVal, spDefVal, speed;
  12.     private boolean faint;
  13.     private Place currentLoc;
  14.     private ElementalType type;
  15.    
  16.     /**
  17.      * Constructor for PKMN
  18.      */
  19.     public PKMN(String name, int level, ElementalType type) {
  20.         this.name = name;
  21.         this.level = level;
  22.         this.hp = 10;
  23.         this.maxHp = 10;
  24.         this.atkVal = 5;
  25.         this.defVal = 5;
  26.         this.spAtkVal = 5;
  27.         this.spDefVal = 5;
  28.         this.speed = 5;
  29.         this.type = type;
  30.         allPKMN.add(this);
  31.     }
  32.  
  33.     public String toString()                 {return this.name;}
  34.     public String getName()                  {return this.name;}
  35.     public int getLevel()                    {return this.level;}    
  36.     public int getCurrentXp()                {return this.CurrentXp;}
  37.     public int getXpRequiredToLevel()        {return this.XpRequiredToLevel;}
  38.     public int getHp()                       {return this.hp;}
  39.     public int getMaxHp()                    {return this.maxHp;}
  40.     public int getAtkVal()                   {return this.atkVal;}
  41.     public int getDefVal()                   {return this.defVal;}    
  42.     public int getSpAtkVal()                 {return this.spAtkVal;}
  43.     public int getSpDefVal()                 {return this.spDefVal;}
  44.     public int getSpeed()                    {return this.speed;}
  45.     public ElementalType getElemType()       {return this.type;}
  46.     public boolean isFaint()                 {return this.faint;}
  47.    
  48.     public void setName(String n)            {this.name = n;}
  49.     public void setLevel(int l)              {this.level = l;}
  50.     public void modXp(int x)                 {this.CurrentXp += x;}
  51.     public void setXp(int x)                 {this.CurrentXp = x;}
  52.     public void setXpRequiredToLevel(int xp) {this.XpRequiredToLevel = xp;}
  53.     public void setHp(int h)                 {this.hp = h;}
  54.     public void modHp(int h)                 {this.hp += h;if (this.hp < 0) {this.hp = 0;}}      
  55.     public void setMaxHp(int m)              {this.maxHp = m;}
  56.     public void setAtkValue(int a)           {this.atkVal = a;}
  57.     public void setDefValue(int d)           {this.defVal = d;}    
  58.     public void setSpAtkValue(int sa)        {this.spAtkVal = sa;}
  59.     public void setSpDefValue(int sd)        {this.spDefVal = sd;}
  60.     public void setSpeed(int s)              {this.speed = s;}
  61.     public void setFaint(boolean f)          {this.faint = f;}
  62.     public void setLoc(Place p)              {this.currentLoc = p;}
  63.    
  64.    
  65.     public void info() {
  66.         System.out.println(String.format("\n%s Type: %s", this.getName(), this.type.toString()));
  67.         System.out.println(String.format("Level: %d HP: %d/%d ", this.getLevel(), this.getHp(), this.getMaxHp()));
  68.         System.out.println(String.format("ATK: %d DEF: %d SPD: %d", this.getAtkVal(), this.getDefVal(), this.getSpeed()));
  69.         System.out.println(String.format("SP ATK: %d SP DEF: %d", this.getSpAtkVal(), this.getSpDefVal()));
  70.     }
  71.  
  72.     /**
  73.      *  Determines if the pokemon attacking crits against the pokemon defending
  74.      */
  75.     public boolean counterTypes(PKMN target) {
  76.         if (this.getElemType() == type.Normal || target.getElemType() == type.Normal) {
  77.             return false;
  78.         } else if (this.getElemType() == type.Water && target.getElemType() == type.Fire) {
  79.             return true;
  80.         } else if (this.getElemType() == type.Nature && target.getElemType() == type.Water) {
  81.             return true;
  82.         } else if (this.getElemType() == type.Fire && target.getElemType() == type.Nature) {
  83.             return true;
  84.         } else if (this.getElemType() == type.Electric && target.getElemType() == type.Water) {
  85.             return true;
  86.         }
  87.         return false;
  88.     }
  89.  
  90.    
  91.     public enum ElementalType {
  92.         Normal,
  93.         Fire,
  94.         Nature,
  95.         Water,
  96.         Electric
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment