package project;
import Collection.*;

public class GateToHell extends Location implements Item {
 
  private boolean print;
  
  public GateToHell (ManageText t, Player1 p) {
	player = p;
	text = t;
	StageClear = false;
	count = new countMonsterV();
  } //method GateToHell
  
  public void acceptVisitor(Visitor v) { v.visitMe(this); }
  
  public void start() { 
    GameState = true;
	player.setLocation(1,1);   //starting position
	player.Restore();
    initStage();
	StageIntro();
  } //method start
  
  public void initStage() {
    monsters = new ListC();
	items = new ListC();
	
	Monster flyZombie1 = new FlyingZombie (player, 1, 5);
	Monster flyZombie2 = new FlyingZombie (player, 1, 7);
	Monster fireDragon = new FireDragon (player, 1, 12);
	Monster blackDragon1 = new BlackDragon (player, 1, 10);
	Monster draculaBat = new DraculaBat (player, 1, 16);
	Monster blackDragon2 = new BlackDragon (player, 1, 21);
	
	monsters.add(flyZombie1);
	monsters.add(flyZombie2);
	monsters.add(fireDragon);
	monsters.add(blackDragon1);
	monsters.add(blackDragon2);
	monsters.add(draculaBat);
	
	Weapon gun = new Shotgun (player, 1, 6);
	Weapon rocket = new RocketLauncher (player, 1, 14);
	food apple1 = new PoisonApple (player, 1, 9);
	food apple2 = new PoisonApple (player, 1, 17);
	food orange = new Orange (player, 1, 19);
	items.add(gun);
	items.add(rocket);
	items.add(apple1);
	items.add(apple2);
	items.add(orange);
  } //method initStage
  
  public void update() {
	if (GameState) {
	  try {
	    acceptVisitor(count);
	    count.getCount();
	  } catch (StageClearException exception) {
	     StageClear = true;
		 GameState = false;
	     if (!print) text.println ("The sky bightens suddenly...");
	     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 ("~~The Church collapsed into piles of bricks as you walked out of the exit..."); 
   text.println ("The sky started to turn dark and you're loosing much of the visibility of");
   text.println ("environment you're in~~");
   text.println ("The Last Episode: ~~Gate to Hell~~");
  } 
  
  public boolean StageCleared() { return StageClear; }
  public boolean getGameState() { return GameState; }
  
  public void AttackMe(Player1 p) {
    Monster monster = ( Monster )p.target;
    MonsterAttack = new MonsterBattleMode( monster );
	try { MonsterAttack.Attack();
	} catch (NullTargetException exception) {}
  } //method AttackMe
 
} // class GateToHell