package project;
import Collection.*;

public class ItemEncounter extends Event implements Item {
  
  private ListC WeaponBox;      //a container to put weapons in
  private Weapon weapon;
  private Player1 player;
  private ManageText text;
  
  public ItemEncounter(Player1 p) { 
    player = p;
	WeaponBox = new ListC();
    text = player.text;
  } //constructor ItemEncounter
    
  public void update(){}
  
  //======================================================
  // gets a weapon out of container WeaponBox, and 
  // if there're no more weapon, throws NoWeaponException
  //======================================================
  public Weapon getWeapon() throws NoWeaponException {
    WeaponBox.start(); 
    if (WeaponBox.more()) {
	  weapon = (Weapon)WeaponBox.get();
	  if (weapon instanceof Shotgun) text.println ("You took out the shotgun in your weapon box..");
	  else if (weapon instanceof RocketLauncher) text.println ("You took out the rocketlauncher from your weapon box..");
	  return weapon;
	} //if
	else throw new NoWeaponException();
  } //method getWeapon
  
  public void PickUpWeapon() throws NoWeaponException {
    if (player.weapon!=null) {
	  player.weapon.getPickedUp(this);
	  WeaponBox.add (player.weapon);
      text.println ("and you put it in your weapon box.");
	} //if
	else throw new NoWeaponException();
  } //method PickUpWeapon
  
  public void DropWeapon() throws NoWeaponException {
    WeaponBox.start();
    if (WeaponBox.more()) {
	  text.println ("You've thrown away the weapon!!");
	  WeaponBox.remove();
	  text.println ("and you currently have: " + WeaponBox.getCount() + " weapons left in your Weapon Box.");
	} //if
	else throw new NoWeaponException();
  } //method DropWeapon
  
}//class ItemEncounter
  