package javaEffect.characters;
import java.util.ArrayList;
import javaEffect.ErrNotFountOrMistake;
import javaEffect.weapon.Weapon;
/**
* This class is a model to create a character with a race.
*
* @author Jack OUTRAN & Thibaut LOCQUET
* @version 0.1
*/
public abstract class Character implements Attack {
/**
* This ArrayList contain the all references to the characters
*/
static protected ArrayList<Character> characterList;
static {
characterList = new ArrayList<Character>();
}
protected String firstName;
protected String lastName;
protected ArrayList<String> text;
protected int health;
protected int startHealth;
protected int attack;
protected int credit;
ArrayList<Weapon> weaponList;
/**
* This method is called to set the character.
*
* @param firstName
* The first name of the character
* @param lastName
* The last name of the character
*/
public Character(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
text = new ArrayList<String>();
this.health = 100;
this.startHealth = this.health;
this.attack = 10;
weaponList = new ArrayList<Weapon>();
characterList.add(this);
this.setCredit((int) (Math.random() * 1000));// credit between 10 and
// 1000
}
/**
* This method is called to set the character.
*
* @param firstName
* The first name of the character
* @param lastName
* The last name of the character
* @param health
* The health of the character
*/
public Character(String firstName, String lastName, int health) {
this(firstName, lastName);
this.health = health;
this.startHealth = this.health;
}
/**
* Put the health of the character at the initial state
*/
public void setInitialHealth(){
this.health = this.startHealth;
}
/**
* This method is called to say the character's name.
*
* @return A sentence with the character's name and the way of speaking
* depend on the race.
*/
public String toString() {
return this.firstName + " " + this.lastName;
}
/**
* Remove the character from the list if he is dead
*/
protected void beatHealth() {
if (this.health < 0) {
this.health = 0;
characterList.remove(this);
}
}
/**
* @return The first name of the character.
*/
public String getFirstName() {
return firstName;
}
/**
*
* @return The last name of the character.
*/
public String getLastName() {
return lastName;
}
/**
*
* @return The health of the character.
*/
public int getHealth() {
return health;
}
/**
*
* @return Print the health (and shield) of the character.
*/
public abstract String printHealth();
/**
*
* @return The strength of the character.
*/
public int getStrength() {
return this.attack;
}
/**
* @return The credit that the character have.
*/
public int getCredit() {
return credit;
}
/**
* @param credit
* the credit to set
*/
public void setCredit(int credit) {
this.credit = credit;
}
/**
* The character get the money of the enemy.
*/
public void stealCredit(Character victim) {
this.credit += victim.getCredit();
victim.setCredit(0);
}
/**
*
* @return The race of the character.
*/
public abstract String getRace();
/**
*
* @param text
* the text the character have to say.
*/
public void setText(String text) {
this.text.add(text);
}
/**
*
* @return The text of character.
*/
public String getText() {
String text = "";
for (int i = 0; i < this.text.size(); i++) {
text += this.text.get(i) + "\n";
}
return text;
}
/**
*
* @param newWeapon
* add new weapon to character
*/
public void addWeapon(Weapon newWeapon) {
this.weaponList.add(newWeapon);
// if new weapon is better, the character will equip it
if (newWeapon.getAttack() > this.attack) {
this.equip(newWeapon);
}
}
/**
* Equip the character with the weapon
*
* @param w The weapon to equip
*/
public void equip(Weapon w) {
this.attack = w.getAttack();
}
/**
* show all weapons owned by character
*/
public void showWeaponList() {
for (Weapon w : weaponList) {
System.out.println("\t->" + w.toString());
}
if (weaponList.size() == 0) {
System.out.println("\t->Empty");
}
}
/**
* Print the first name and the last name of every character.
*/
public static void printAllCharacter() {
for (Character c : characterList) {
System.out.println(c.getFirstName() + " " + c.getLastName());
}
}
/**
* Look if a character in the list of character
*
* @param firstName
* The fist name of the character to find
* @param lastName
* His last name
* @return true if the character exist else false
*/
public static boolean isInList(String firstName, String lastName) {
for (Character c : characterList) {
if (c.firstName.equals(firstName) && c.lastName.equals(lastName)) {
return true;
}
}
return false;
}
/**
* Search a character in the list of character
*
* @param firstName
* The fist name of the character to find
* @param lastName
* His last name
* @return A reference to the character to find
* @throws ErrNotFountOrMistake
*/
public static Character getCharacter(String firstName, String lastName)
throws ErrNotFountOrMistake {
for (Character c : characterList) {
if (c.firstName.equalsIgnoreCase(firstName)
&& c.lastName.equalsIgnoreCase(lastName)) {
return c;
}
}
throw new ErrNotFountOrMistake("Character not found");
}
/**
*
* @return A reference to the list of character
*/
public static ArrayList<Character> getList() {
return characterList;
}
/**
* Remove a list of characters from the main list of characters
*
* @param charactersToRemove
* The list to remove
*/
public static void removeInList(ArrayList<Character> charactersToRemove) {
characterList.removeAll(charactersToRemove);
}
/**
* This character attack a character
*
* @param attackedCharacter
* The character to attack
*/
public void attack(Character attackedCharacter) {
}
/**
* This character is attack by an other character
*
* @param damages
* The damages to remove from the health of the character
*/
public void beAttack(int damages) {
}
/**
* Set the attack of the character
*
* @param attack
*/
public void setAttack(int attack) {
}
}