package project;
import Collection.*;

public class GardenOfHorror extends Location implements Item {
  
  private boolean print;
  
  public GardenOfHorror(ManageText t, Player1 p) {
	player = p;
	text = t;
	StageClear = false;
	count = new countMonsterV();
  } //method GardenOfHorror
  
  public void acceptVisitor(Visitor v) { v.visitMe(this); }
  
  public void start() { 
    GameState = true;
    player.Restore();
	player.setLocation (1, 1);
    StageIntro();
	initStage();
  } //method start
  
  public void initStage() {
    monsters = new ListC();
	items = new ListC();
    Monster zombie = new Zombie(player, 1, 4);
	Monster rat = new Rat (player, 1, 8);
	Monster fireDragon = new FireDragon (player, 1, 11);
	Monster draculaBat = new DraculaBat (player, 1, 15);
	Monster blackDragon = new BlackDragon (player, 1, 17);
	monsters.add(zombie);
	monsters.add(rat);
	monsters.add(fireDragon);
	monsters.add(draculaBat);
	monsters.add(blackDragon);
	Weapon gun = new Shotgun(player, 1, 7);
	food orange = new Orange(player, 1, 9);
	food apple = new PoisonApple (player, 1, 13);
	items.add(gun);
	items.add(orange);
	items.add(apple);
  } //method initStage
  
  public void update() {
	if (GameState) {
	  try {
	    acceptVisitor(count);
	    count.getCount();
	  } catch (StageClearException exception) {
	     GameState = false;
		 StageClear = true;
	     if (!print) text.println ("You've found the exit..existing..");
	     print = true;   //prevents overprinting messages
	  } //catch
	  updateMonster();
	  updateItem();
      if (!player.Alive) GameState = false;
	} //if
  } //method StageUpdate
   
  public void updateMonster() {
	 monsters.start();
     while(monsters.more()) {
	   Monster currentMonster = (Monster)monsters.get();
       currentMonster.update();
     } //while
  } //method updateMonster
  
  public void updateItem() {
    items.start();
	while(items.more()) {
	  StageItem currentItem = ( StageItem ) items.get();
	  currentItem.update();
    } //while
  } //method updateItem
  
  public void StageIntro() { text.println ("~~You've entered the Garden of Horror...the gate shutted as you walked in~~"); }
  
  public boolean getGameState() { return GameState; }
  public boolean StageCleared() { return StageClear; }
  
  public void AttackMe(Player1 p) {
    Monster monster = ( Monster )p.target;
    MonsterAttack = new MonsterBattleMode( monster );
	try { MonsterAttack.Attack();
	} catch (NullTargetException exception) {}
  } //method AttackMe
 
} // class GardenOfHorror