package project;

public class Player1 extends BattleEntities {
  
  protected ManageText text;
  protected food snack;
  protected Weapon weapon;
  protected boolean inBattle = false;
  
  public Player1(ManageText t) { 
    super(1, 1, PlayerAttackPower, PlayerHealth); 
    text = t;
  } //constructor Player1
  
  public void acceptVisitor(Visitor v) { v.visitMe(this); }
  
  public void beAttacked(Attackable a) {
     try {
  	    healthDw(a.getAttackPower());
  	} catch (NoHealthException exception) {
	 text.println ("and you have lost your conciousness before");
	 text.println ("the pain starts...");
	 text.println ("~~Game Over~~");
	} //catch
  } //method beAttacked

  public void update() {
    text.println ("Player's current status: Alive:" + Alive);
	text.println ("Player's health:" + health + "units");
  } //method update  
     
  public void healthDw(int x) throws NoHealthException {
    if(health-x > 0)
  	  health = health - x;
  	else {
  	   Disable();
  	   throw new NoHealthException();
  	} //else
  } //method healthDw
 
  public void moveFwd() throws inBattleException { 
    if (!inBattle) {    
	  setLocation(Xaxis, Yaxis+1); 
      text.println ("Walking...");
	} //if
	else throw new inBattleException();
  } //method moveFwd
  
  public void moveBk() throws NoPassageException { 
    if (Yaxis > 1 && !inBattle) {
	  setLocation(Xaxis, Yaxis-1);
	  text.println ("You turned back...");
	} //if
	else throw new NoPassageException();
  } //method moveBk
  
  public void get( Monster m ) { target = m; }
  public void get( food f ) { snack = f;  }
  public void get( Weapon w ) { weapon = w; }
  
  public void eat() throws NoFoodToEatException {
    if (snack!=null) snack.beEaten(this);
	else throw new NoFoodToEatException();
  } //method eat
  
} //class Player1