/**
*
* @author Erica Boyer
* @datecreated 19 Mar 2009
* @lastupdate 30 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 = 3; //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 jLvlUp = 10; //Amount of job experience needed to level up a job
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 jp; //Holds the characters job points (experience for jobs)
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 (double due to Warriors focus ability)
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 xpGained = lvl * 2; //The amount of experience given per victory (enemies lvl * 2);
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);
setJp(0);
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);
setJp(0);
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);
setJp(0);
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);
setJp(jLvl * jLvlUp);
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-Job Defined constructor
////////////////////////////////////////////////////////////////////////////////////////////////
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
////////////////////////////////////////////////////////////////////////////////////////////////
/** 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
/** setJp method
*
* Sets the job points the character has
*
* @param jp The amount of job experience the player has
*/
public void setJp(int jp) {
this.jp = jp;
}//End setJp
/** getJp method
*
* Returns the amount of job points a character has
*
* @return jp Job points
*/
public int getJp() {
return (jp);
}//End getJp
/** 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) {
http://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 = -2;
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