Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /*
- * Created by Arvind Thambidurai
- * Created: 10-21-2010
- * Last updated: 11-12-2010 by Brandon
- *
- * The Person class is the superclass for any people in my code.
- * It contains many actions that a default person can use.
- * There is a lot of interaction involved, both between other people
- * (such as attack, greet, and sell), as well as between objects
- * (such as attacking WITH, selling, and eating).
- *
- * The person class is also in charge of maintaining the basic statistics
- * and properties of a person, such as name, energy, strength, life, etc.
- *
- * It contains all the functions within it to modify its own properties,
- * which is done either through the person class, or through other classes.
- *
- * The two classes that inherit from Person are FARMER and BLACKSMITH
- *
- */
- public class Person
- {
- //these are all the common properties of a personn
- int height, weight, age, money, energy, strength, life;
- String name, address, weapon, armor, weakness, rank;
- boolean isMale;
- //the constructor for a person, takes in all stats from its subclasses and assigns them as the values
- public Person(int Height, int Weight, int Age, int Money, int Energy, int Strength, String Name, String Address, boolean isMan)
- {
- height=Height;
- weight=Weight;
- age=Age;
- money=Money;
- energy=Energy;
- strength=Strength;
- name=Name;
- address=Address;
- isMale=isMan;
- life=1000;
- }
- //returns the name of a person
- public String getName()
- {
- return name;
- }
- //sets the name of a person to a specific String
- public void setName(String n)
- {
- name=n;
- }
- //allows the person to rest, increasing energy and life
- public void sleep()
- {
- energy++;
- life=life+energy;
- System.out.println(this.getName()+" has slept for a night and rested up.");
- }
- //allows a person to attack another person (with a metal item) to inflict damage on the person
- //first it calculates the amount of damage dealt by factoring the metal used and the person's stats
- //then it applies the damage to the victim
- //then it reduces the stats of the attacker slightly, burning energy and strength
- public void attack(Person p, MetalA m)
- {
- int dmg = this.energy*this.strength*m.getStrength();
- System.out.println(this.getName()+" attacks "+p.getName()+" and deals "+(dmg)+" damage.");
- p.modLife(dmg);
- if (p.getLife() < 0)
- System.out.println(p.getName()+" has died.");
- energy--;
- strength--;
- }
- //returns the current value of life a person has
- public int getLife()
- {
- return life;
- }
- //modifies the current value of life a person has by an integer n
- public void modLife(int n)
- {
- life=life-n;
- System.out.println(this.getName()+ " has " + life + " life remaining");
- }
- //alters the energy value of a person by an integer n
- public void modEnergy(int n)
- {
- this.energy=this.energy+n;
- }
- //returns the current energy value of a person
- public int getEnergy()
- {
- return energy;
- }
- //alters the current strength value of a person by an integer n
- public void modStrength(int n)
- {
- this.strength=this.strength+n;
- }
- //returns the current strength value of the person
- public int getStrength()
- {
- return strength;
- }
- //adds or subtracts a certain integer amount of money from the person
- public void modMoney(int n)
- {
- this.money=this.money+n;
- }
- //returns the amount of money a person has
- public int getMoney()
- {
- return this.money;
- }
- //outputs the current stats on the person, including money, life, energy, and strength
- public void status()
- {
- System.out.println(this.getName()+"'s Money totals "+this.getMoney());
- System.out.println(this.getName()+"'s Life is at "+this.getLife());
- System.out.println(this.getName()+"'s Strength is at "+this.getStrength());
- System.out.println(this.getName()+"'s Energy is at "+this.getEnergy());
- }
- //allows the person to eat an (Plant) object, which increases their stats
- public void eat(Plant p)
- {
- this.modEnergy(p.getNutrition());
- this.modStrength(p.getNutrition());
- this.modLife(p.getNutrition()*p.getHealth());
- }
- //sets the players rank based on number of kills
- public void setRank(int kills)
- {
- if (kills < 5)
- {
- System.out.println("You Have killed less than 5 people, keep on killing! ");
- rank = "noob";
- }
- else if (kills >= 5 && kills < 10)
- {
- System.out.println("You have ordered the killing of 5 people, you have reached the rank of 'Blood Thirsty'");
- rank = "Blood Thirsty";
- }
- else
- {
- System.out.println("You have ordered the killing of 10 people, you have reached the rank of 'Brutal'");
- rank = "Brutal";
- }
- }
- public String getRank()
- {
- return rank;
- }
- public void standDown()
- {
- System.out.println(name+": Soldiers, Stand Down!");
- }
- public int getAge()
- {
- return age;
- }
- public int getHeight()
- {
- return height;
- }
- public int getWeight()
- {
- return weight;
- }
- public String getWeapon()
- {
- return weapon;
- }
- public void setWeapon(String newWeapon)
- {
- weapon = newWeapon;
- }
- public String getArmor()
- {
- return armor;
- }
- public void setArmor(String newArmor)
- {
- armor = newArmor;
- }
- public void command()
- {
- System.out.print("(A)ttack or (S)tand Down?");
- Scanner in = new Scanner(System.in);
- String choice = in.nextLine();
- choice.toLowerCase();
- /*
- if (choice.equals("a"))
- attack();
- else
- standDown();
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement