Subscribe to NeoTifa's Blog of |)00M!!!!        RSS Feed
-----

More class....es

Icon Leave Comment
I started on my Item class. Meh >_> Not anywhere on it yet becasue I was working on Player most of the day.


/**
 *
 * @author Erica Boyer
 * @datecreated 17 May 2009
 * 
 * This class handles the events for using items and such.
 * 
 * >>to be converted to C++ later
 * 
 */
public class Item {

    enum Items {POTION, HIPOTION, ETHER, HIETHER}
    
    private final int potion = 100;                             //How many hit points a potion heals
    private final int hiPotion = 250;                           //How many hit points a hi-potion heals
    private final int ether = 50;                               //How many magic points an ether heals
    private final int hiEther = 100;                            //How many magic points a hi-ether heals
    
    private int potionInvetory;                                 //How many potions are in your invetory
    private int hiPotionInvetory;                               //How many hi-potions are in your invetory
    private int etherInvetory;                                  //How many ethers are in your invetory
    private int hiEtherInvetory;                                //How many hi-ethers are in your invetory
    
    /**useRestorativeItem method
     * 
     * Uses given item on given character
     * 
     * @param item
     * @param character
     */
    public void useItem(Items item, Player character) {
        
        switch(item) {
            
            case POTION: {
                
                character.setHp(character.hp + potion);
                
            }//End potion case
            
            case HIPOTION: {
                
                character.setHp(character.hp + hiPotion);
                
            }//End hi-potion case
            
            case ETHER: {
                
                character.setMp(character.mp + ether);
                
            }//End ether case
            
            case HIETHER: {
                
                character.setMp(character.mp + hiEther);
                
            }//End hi-ether case
             
        }//End switch
        
    }//End useRestorativeItem
    
    public void getItem(Items item) {
        
        switch(item) {
            
            case POTION: {
                
                potionInvetory = potionInvetory + 1;
                
            }//End potion case
            
            case HIPOTION: {
                
                hiPotionInvetory = hiPotionInvetory + 1;
                
            }//End hi-potion case
            
            case ETHER: {
                
                etherInvetory = etherInvetory + 1;
                
            }//End ether case
            
            case HIETHER: {
                
                hiEtherInvetory = hiEtherInvetory + 1;
                
            }//End hi-ether case
             
        }//End switch
        
    }//End getItem
    
}//End Item class








And here's Player updated. <3



/**
 *
 * @author Erica Boyer
 * @datecreated 19 Mar 2009
 * @lastupdate 17 May 2009
 * 
 * This is the class for an rpg character. It can be used for the user's players, 
 * npc's, and  enemies. Basically, it just sets the player up with basic stats, 
 * job (optional), gender, and such.
 * 
 * >>To be converted to C++ later.
 * 
 */

import javax.swing.*;

public class Player {

    ////////////////////////////////////////////////////////////////////////////////////////////////
    public enum Job {WARRIOR, KNIGHT, BMAGE, WMAGE}
    public enum Status {NORMAL, KO, POISON, SLEEP, PETRIFIED, CURSED, BLIND}
    public enum Gender {MALE, FEMALE}
    
    private final int initHp = 15;                      //Initial hit points
    private final int initMp = 5;                       //Initial magic points
    private final int initXp = 0;                       //Initial experience
    private final int initLvl = 1;                      //Initial level
    private final int initMaleStr = 4;                  //Initial male strength
    private final int initFemaleStr = 3;                //Initial female strength
    private final int initMaleEnd = 3;                  //Initial male endurance
    private final int initFemaleEnd = 2;                //Initial female endurance
    private final int initMaleInt = 2;                  //Initial male intelligence
    private final int initFemaleInt = 4;                //Initial female intelligence
    private final int initMaleDex = 2;                  //Initial male dexerity
    private final int initFemaleDex = 4;                //Initial female dexerity
    private final int initLuck = 2;                     //They start out the same luck

    private final int lvlUpFirst5 = 50;                 //Amount of experience needed to level up the first 5 levels
    private final int lvlUp6Thru20 = 100;               //Amount of experience needed to level up levels 6 through 20
    private final int lvlUp21Thru50 = 200;              //Amount of experience needed to level up levels 21 through 50
    private final int lvlUpHp = 4;                      //Amount of hit points gained every level up  
    private final int lvlUpMp = 2;                      //Amount of magic points gained every level up
    private final int lvlUpStat = 1;                    //Amount of str, end, dex, and luck gained every level up
    private final int maxLvl = 50;                      //Max level a character can be
    private final int maxJlvl = 10;                     //Max level a characters job can be

    private int jLvl;                                   //Holds the level of the jobs held by the character
    private int jStr;                                   //Holds the stegth the class gives initially
    private int jEnd;                                   //Holds the endurance the class gives initially
    private int jDex;                                   //Holds the dexterity the class gives initially
    private int jInt;                                   //Holds the intelligence the class gives initially
    private int jLuck;                                  //Holds the luck the class gives initially
    private int jHpBonus;                               //Holds the bonus hit points the characters job gives
    private int jMpBonus;                               //Holds the bonus magic points the characters job gives

    private String name;                                //Holds the characters name
    private Gender gender;                              //Holds the characters gender
    private Job job;                                    //Holds the characters job
    private int hp;                                     //Holds the characters hit points
    private int mp;                                     //Holds the characters magic points
    private int maxHp;                                  //Holds the max hit points the character has
    private int maxMp;                                  //Holds the mas magic points the character has
    private long xp;                                    //Holds the characters experience points
    private int lvl;                                    //Holds the characters level
    private int str;                                    //Holds the characters strength
    private int end;                                    //Holds the characters endurance
    private int Int;                                    //Holds the characters intelligence
    private int dex;                                    //Holds the characters dexterity
    private int luck;                                   //Holds the characters luck
    private Status status;                              //Holds the characters status
    
    private final int poisonDamage = 5;                 //How much damage being poisoned does a turn

    ////////////////////////////////////////////////////////////////////////////////////////////////
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
    ////////////////////////////////////////////////////////////////////////////////////////////////
    /**No-Arg Constructor Player
     * 
     * Sets up all the stats the the character will need.
     * 
     * @param none
     *  
     */
    public Player() {

        setName("New Character");
        setJob(Job.WARRIOR);                    //need to get Job from chooser or other class. Default is warrior
 
        setMaxHp(initHp + end);
        setMaxMp(initMp + Int);
        
        setHp(maxHp);
        setMp(maxMp);
       
        setXp(initXp);
        setLvl(initLvl);

        if (gender.equals(Gender.MALE)) {
            setStr(initMaleStr);
        } else if (gender.equals(Gender.FEMALE)) {
            setStr(initFemaleStr);
        }

        if (gender.equals(Gender.MALE)) {
            setEnd(initMaleEnd);
        } else if (gender.equals(Gender.FEMALE)) {
            setEnd(initFemaleEnd);
        }

        if (gender.equals(Gender.MALE)) {
            setDex(initMaleDex);
        } else if (gender.equals(Gender.FEMALE)) {
            setDex(initFemaleDex);
        }

        setLuck(initLuck);
        
        if (gender.equals(Gender.MALE)) {
            setInt(initMaleInt);
        } else if (gender.equals(Gender.FEMALE)) {
            setInt(initFemaleInt);
        }

        setStatus(Status.NORMAL);

    //INCOMPLETE!!!!!!!!!!!!

    }//End constructor

    /** Level Defined Constructor
     * 
     * Sets the stats up according to the level given
     * 
     * @param lvl The level of the character created
     * 
     */
    public Player(int lvl) {

        setName("");                                        //To be set in main game loop or something
        setJob(Job.WARRIOR);
        setLvl(lvl);      
        setMaxHp(initHp + lvl * lvlUpHp * end);
        setMaxMp(initMp + lvl * lvlUpMp * Int);
        
        setHp(maxHp);
        setMp(maxMp);
  
        if (gender.equals(Gender.MALE)) {
            setStr(initMaleStr);
        } else if (gender.equals(Gender.FEMALE)) {
            setStr(initFemaleStr);
        }

        if (gender.equals(Gender.MALE)) {
            setEnd(initMaleEnd);
        } else if (gender.equals(Gender.FEMALE)) {
            setEnd(initFemaleEnd);
        }

        if (gender.equals(Gender.MALE)) {
            setDex(initMaleDex);
        } else if (gender.equals(Gender.FEMALE)) {
            setDex(initFemaleDex);
        }

        setLuck(initLuck);
        
        if (gender.equals(Gender.MALE)) {
            setInt(initMaleInt);
        } else if (gender.equals(Gender.FEMALE)) {
            setInt(initFemaleInt);
        }

        setStatus(Status.NORMAL);

        
    }//End Level Defined Constructor
    
    /** Name-Level Defined Constructor
     * 
     * Sets the stats up according to the name and level given
     * 
     * @param name Name of the character
     * @param lvl Level of the character
     */

    public Player(String name, int lvl) {
        
        setName(name);                                        //To be set in main game loop or something
        setJob(Job.WARRIOR);
        setLvl(lvl);      
        setMaxHp(initHp + lvl * lvlUpHp * end);
        setMaxMp(initMp + lvl * lvlUpMp * Int);
        
        setHp(maxHp);
        setMp(maxMp);
  
        if (gender.equals(Gender.MALE)) {
            setStr(initMaleStr);
        } else if (gender.equals(Gender.FEMALE)) {
            setStr(initFemaleStr);
        }

        if (gender.equals(Gender.MALE)) {
            setEnd(initMaleEnd);
        } else if (gender.equals(Gender.FEMALE)) {
            setEnd(initFemaleEnd);
        }

        if (gender.equals(Gender.MALE)) {
            setDex(initMaleDex);
        } else if (gender.equals(Gender.FEMALE)) {
            setDex(initFemaleDex);
        }

        setLuck(initLuck);
        
        if (gender.equals(Gender.MALE)) {
            setInt(initMaleInt);
        } else if (gender.equals(Gender.FEMALE)) {
            setInt(initFemaleInt);
        }

        setStatus(Status.NORMAL);
        
    }//End Name-Level Defined Constructor
    
    /** Name-Level-Job Defined Constructor
     * 
     * Sets the stats of the character according to name, level, and job given
     * 
     * @param name Name of the character
     * @param lvl Level of the character
     * @param job Job of the character
     */
    
    public Player(String name, int lvl, Job job){
        
        setName(name);                                        //To be set in main game loop or something
        setJob(job);
        setLvl(lvl);      
        setMaxHp(initHp + lvl * lvlUpHp * end);
        setMaxMp(initMp + lvl * lvlUpMp * Int);
        
        setHp(maxHp);
        setMp(maxMp);
  
        if (gender.equals(Gender.MALE)) {
            setStr(initMaleStr);
        } else if (gender.equals(Gender.FEMALE)) {
            setStr(initFemaleStr);
        }

        if (gender.equals(Gender.MALE)) {
            setEnd(initMaleEnd);
        } else if (gender.equals(Gender.FEMALE)) {
            setEnd(initFemaleEnd);
        }

        if (gender.equals(Gender.MALE)) {
            setDex(initMaleDex);
        } else if (gender.equals(Gender.FEMALE)) {
            setDex(initFemaleDex);
        }

        setLuck(initLuck);
        
        if (gender.equals(Gender.MALE)) {
            setInt(initMaleInt);
        } else if (gender.equals(Gender.FEMALE)) {
            setInt(initFemaleInt);
        }

        setStatus(Status.NORMAL);
        
    }
  
    ////////////////////////////////////////////////////////////////////////////////////////////////
    
    /** setName method
     * 
     * Sets the name of the character
     * 
     * @param name Holds the String with the characters name
     * 
     */
    public void setName(String name) {

        this.name = name;

    }//End setName

    /** getName method
     * 
     * Returns the name of the character
     * 
     * @return name 
     */
    public String getName() {

        return (name);

    }//End getName

    /** setGender method
     * 
     * Sets the gender of the character
     * 
     * Pre-Conditon: Has to be either male or female. If using a wierd 
     * race with 3 genders, this class doesn't support it. lol. 
     * 
     * @param gender
     */
    public void setGender(Gender gender) {

        this.gender = gender;

    }//End setGender

    /** getGender method
     * 
     * Returns the gender of the character
     * 
     * @return gender
     */
    public Gender getGender() {

        return (gender);

    }//End getGender

    /** setHp method
     * 
     * Sets the hit points of the character
     * 
     * @param hp Holds the hit points
     */
    public void setHp(int hp) {

        this.hp = hp;
        this.hp = this.hp + end;

    }//End setHp

    /** getHp method
     * 
     * Returns the hit points of the character
     * 
     * @return hp
     */
    public int getHp() {

        return (hp);

    }//End getHp

    /** setMp method
     * 
     * Sets the magic points of the character
     * 
     * @param mp Holds the magic points of the character
     */
    public void setMp(int mp) {

        this.mp = mp;
        this.mp = this.mp + jInt;

    }//End setMp

    /** getMp method
     * 
     * Returns the magic points of the character
     * 
     * @return mp
     */
    public int getMp() {

        return (mp);

    }//End getMp
    
    /** setMaxHp method
     * 
     * Sets the max hit points the character has
     * 
     * @param maxHp The max hit points
     */

    public void setMaxHp(int maxHp) {
        
        this.maxHp = maxHp;
        
    }//End setMaxHp
    
    /** getMaxHp method
     * 
     * Returns the max hit points of the character
     * 
     * @return maxHp 
     */
    
    public int getMaxHp() {
        
        return (maxHp);
        
    }//End getMaxHp
    
    /** setMaxMp method
     * 
     * Sets the max magic points the character has
     * 
     * @param maxMp
     */
        
    public void setMaxMp(int maxMp) {
        
        this.maxMp = maxMp;
        
    }//End setMaxMp
    
    /** getMaxMp method
     * 
     * Returns the max magic points the character has
     * 
     * @return maxMp
     */
    
    public int getMaxMp() {
        
        return (maxMp);
        
    }//End getMaxHp
    
    /** setXp method
     * 
     * Sets the experience points of the character
     * 
     * @param xp Holds the experience points of the character
     */
    public void setXp(long xp) {

        this.xp = xp;

    }//End setXp

    /** getXp method
     * 
     * Returns the experience points of the character
     * 
     * @return xp
     */
    public long getXp() {

        return (xp);

    }//End getXp

    /** setLvl method
     * 
     * Sets the level of the character
     * 
     * @param lvl Holds the level of the character
     */
    public void setLvl(int lvl) {

        this.lvl = lvl;

    }//End setLvl

    /** getLvl method
     * 
     * Returns the level of the character
     * 
     * @return lvl
     */
    public int getLvl() {

        return (lvl);

    }//End getLvl

    /** setStr method
     * 
     * Sets the strength of the character
     * 
     * @param str Holds the strength of the character
     */
    public void setStr(int str) {

        this.str = str;
        this.str = this.str + jStr;

    }//End setStr

    /** getStr method
     * 
     * Returns the strength of the character
     * 
     * @return str
     */
    public int getStr() {

        return (str);

    }//End getStr

    /** setEnd method
     * 
     * Sets the endurance of the character
     * 
     * @param end Holds the endurance of the character
     */
    public void setEnd(int end) {

        this.end = end;
        this.end = this.end + jEnd;

    }//End setEnd

    /** getEnd method
     * 
     * Returns the endurance of the character
     * 
     * @return end
     */
    public int getEnd() {

        return (end);

    }//End getEnd

    /** setDex method
     * 
     * Sets the dexterity of the character
     * 
     * @param deex Holds the dexterity of the character
     */
    public void setDex(int dex) {

        this.dex = dex;
        this.dex = this.dex + jDex;

    }//End setDex

    /** getDex method
     * 
     * Returns the dexterity of the character
     * 
     * @return dex
     */
    public int getDex() {

        return (dex);

    }//End getDex

    /** setInt method
     * 
     * Sets the characters intelligence
     * 
     * @param Int The intelligence of the character
     */
    
    public void setInt(int Int) {
        
        this.Int = Int;
        this.Int = Int + jInt;
        
    }//End setInt
    
    /** getInt method
     * 
     * Returns the intelligence of the character
     * 
     * @return Int
     */
    
    public int getInt() {
        
        return (Int);
        
    }//End getInt 
    
    /** setLuck method
     * 
     * Sets the luck of the character
     * 
     * @param luck Holds the luck of the character
     */
    public void setLuck(int luck) {

        this.luck = luck;
        this.luck = this.luck + jLuck;

    }//End setLuck

    /** getLuck method
     * 
     * Returns the luck of the character
     * 
     * @return luck
     */
    public int getLuck() {

        return (luck);

    }//End getLuck

    /** lvlUp method
     * 
     * Updates the status of the character when s/he levels up
     * 
     */
    public void lvlUp() {

        while(lvl < maxLvl) {
            maxHp = maxHp + lvlUpHp;
            maxMp = maxMp + lvlUpMp;
            hp = maxHp;                                     //Restores all the characters hp on levelup
            mp = maxMp;                                     //Restores all the characters mp on levelup
            str = str + lvlUpStat;
            end = end + lvlUpStat;
            dex = dex + lvlUpStat;
            luck = luck + lvlUpStat;

            lvl = lvl + 1;
        }//End while
        
        while(lvl == maxLvl){
            
            JOptionPane.showMessageDialog(null, "You are already at the maximum level!!!");      //Display method will change
            
        }//End while
        
    }//End lvlUp

    /** setStatus method
     * 
     * Sets the status of the character
     * 
     * @param status Holds the status of the character
     */
    public void setStatus(Status status) {

        this.status = status;

        if(hp == 0) {
            
            status = Status.KO;
            
        }//End if
        
        switch (status) {

            case NORMAL: {
                
            }//End normal case

            case KO: {
                
            }//End ko case

            case POISON: {
                
                //hp = hp - poisonDamage;
                
            }//End poison case

            case SLEEP: {
                
            }//End sleep case

            case PETRIFIED: {
                
            }//End petrified case

            case CURSED: {
                
            }//End cursed case

            case BLIND: {
                
            }//End blind case
            
            default: {
            }//End default

        }//End switch

    }//End setStatus

    /** getStatus method
     * 
     * Returns the status of the character
     * 
     * @return status
     */
    public Status getStatus() {

        return (status);

    }//End getStatus

    /** setJob method
     * 
     * Sets the job/class of the character
     * 
     * @param job Holds the job/class of the character
     */
    private void setJob(Job job) {

        //this.job = job;


        switch (job) {

            case WARRIOR: {
                
                jStr = 2;
                jEnd = 2;
                jDex = 1;
                jInt = 0;
                jLuck = 0;
                
            }//End WARRIOR case

            case KNIGHT: {
                
                jStr = 4;
                jEnd = 3;
                jDex = -3;
                jInt = 2;
                jLuck = 3;
                                
            }//End KNIGHT case

            case BMAGE: {
                
                jStr = -1;
                jEnd = 1;
                jDex = 3;
                jInt = 4;
                jLuck = 2;
                
            }//End BMAGE case

            case WMAGE: {
                
                jStr = -1;
                jEnd = 1;
                jDex = 3;
                jInt = 4;
                jLuck = 2;
                
            }//End WMAGE case

            default: {
                
                job = Job.WARRIOR;
                
            }//End default

        }//End switch

    }//End setJob method
    
    /** getJob method
     * 
     * Returns the job of the character
     * 
     * @return job
     */
    
    public Job getJob() {
        
        return(job);
        
    }//End getJob
    
}//End Player class


0 Comments On This Entry

 

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

September 2020

S M T W T F S
  12345
6789101112
13141516171819
2021 22 23242526
27282930   

Recent Entries

Search My Blog

1 user(s) viewing

1 Guests
0 member(s)
0 anonymous member(s)