import java.util.ArrayList;
import java.util.Scanner;
import java.io.File;

/**
 * Class that models a maze of caves for the "Hunt the Wumpus" game.
 *   @author Dave Reed
 *   @version 11/15/15
 */
public class CaveMaze {
  private ArrayList<Cave> caves;
  private Cave currentCave;
  
  /**
   * Constructs a CaveMaze from the data found in a file. The player starts out in cave 0.
   *   @param filename the name of the cave data file
   */
  public CaveMaze(String filename) throws java.io.FileNotFoundException {
      Scanner infile = new Scanner(new File(filename));
      
      int numCaves = infile.nextInt();
      this.caves = new ArrayList<Cave>();
      for (int i = 0; i < numCaves; i++) {
          this.caves.add(null);
      }
      
      for (int i = 0; i < numCaves; i++) {
          int num1 = infile.nextInt();
          int num2 = infile.nextInt();
          int num3 = infile.nextInt();
          int num4 = infile.nextInt();
          String name = infile.nextLine().trim();
          this.caves.set(num1, new Cave(name, num1, num2, num3, num4));
      }
      
      this.currentCave = this.caves.get(0);
      this.currentCave.markAsVisited();
  }
  
  /**
   * Moves the player from the current cave along the specified tunnel.  The new location is marked
   * as visited.
   *   @param tunnel the number of the tunnel to be traversed (1-3)
   */
  public String move(int tunnel) {
      this.currentCave = this.caves.get(this.currentCave.getAdjNumber(tunnel));
      this.currentCave.markAsVisited();
      
      return "OK";
  }
  
  /**
   * Tosses a grenade (if the player has any) through the specified tunnel.  
   *   @param tunnel the number of the tunnel to be bombed (1-3)
   */
  public String toss(int tunnel) {
	  return "NOT IMPLEMENTED";
  }  
  
  /**
   * Displays the current cave name and the names of adjacent caves (if those caves have * 
   * been visited). Caves that have not yet been visited are displayed as "unknown".  
   */
  public String showLocation() {
    String message = "You are currently in " + this.currentCave.getCaveName();
	for (int i = 1; i <= 3; i++) {
	    Cave adjCave = this.caves.get(this.currentCave.getAdjNumber(i));
	    if (adjCave.hasBeenVisited()) {
	        message += "\n    (" + i + ") " + adjCave.getCaveName();
	    }
	    else {
	        message += "\n    (" + i + ") unknown";
	    }
	}
	return message;
  }
  
  /**
   * Reports whether the player is still alive.
   *   @return true if alive, false otherwise
   */
  public boolean stillAlive() {
      return true;
  }

  /**
   * Reports whether there are any wumpi remaining.
   *   @return true if wumpi reamining in the maze, false otherwise
   */
  public boolean stillWumpi() {
      return true;
  }
}