Class Party

java.lang.Object
  extended by Party

public class Party
extends java.lang.Object


Field Summary
private  int currentPartySize
          The size of the Party
private  Person[] theParty
          An array of Person which represents the traveling group
 
Constructor Summary
Party()
          Party default constructor.
 
Method Summary
 void addLeader(java.lang.String name)
          Adds a leader (Person) to the party.
 void addPartyMember(java.lang.String name)
          Adds a new party member (Person) to the party
 int getCurrentPartySize()
          Returns the value of currentPartySize
 int getNumberAlive()
          Returns the number of people in the Party who are still alive
 Person getPerson(int position)
          Returns a Person given their position in the Party
private  void increaseCapacity()
          Increases the capacity of theParty array
 boolean isAnybodyAlive()
          Returns if any member of the Party is alive
 Person pickRandomPerson()
          Returns a random person picked from the Party.
 void printPartyStatus()
          Prints the status of the people in the Party.
 void starve()
          Starves the entire Party.
 java.lang.String toString()
          Creates a String that can be used in print statements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

theParty

private Person[] theParty
An array of Person which represents the traveling group


currentPartySize

private int currentPartySize
The size of the Party

Constructor Detail

Party

public Party()
Party default constructor. Allocates an array of DEFAULT_PARTY_SIZE, initially null, Person references.

Method Detail

getCurrentPartySize

public int getCurrentPartySize()
Returns the value of currentPartySize


getPerson

public Person getPerson(int position)
Returns a Person given their position in the Party

Parameters:
position - The position in the Party array
Returns:
Person

addLeader

public void addLeader(java.lang.String name)
Adds a leader (Person) to the party. The leader occupies the first position in the Party. If a leader already exists, then no leader is added. Otherwise, a new Person with their name set to name is created and the currentPartySize is updated.

Parameters:
name - The name of the leader

increaseCapacity

private void increaseCapacity()
Increases the capacity of theParty array


addPartyMember

public void addPartyMember(java.lang.String name)
Adds a new party member (Person) to the party

Parameters:
name - The name of the new Party member

toString

public java.lang.String toString()
Creates a String that can be used in print statements.

Overrides:
toString in class java.lang.Object
Returns:
A String representing the Party members and their alive/dead status.

isAnybodyAlive

public boolean isAnybodyAlive()
Returns if any member of the Party is alive

Returns:
true if any party member is alive, false if no party member is alive

pickRandomPerson

public Person pickRandomPerson()
Returns a random person picked from the Party. Generates a random number between 0 and the size of the party and returns that Person.

Returns:
The randomly chosen person.

starve

public void starve()
Starves the entire Party. The health of each party member is reduced by Game.STARVATION_HEALTH_COST


getNumberAlive

public int getNumberAlive()
Returns the number of people in the Party who are still alive

Returns:
The number of party members who are still alive

printPartyStatus

public void printPartyStatus()
Prints the status of the people in the Party. It prints each Person in the party, one person per line.