/*
 * Skeleton class file for WumpusMaze objects
 */

import java.io.*;

class WumpusMaze {

    private WumpusCave[] caves;        // caves that make up the maze
    
    private int numCaves;              // actual number of caves
    private int numWumpi;              // number of live wumpi remaining
    private int numGrenades;           // number of remaining grenades
    private int currentCave;           // index of the current cave
    private boolean stillAlive;       // is player still alive?


    // field to be used by the methods below that read data from the
    // caves.dat input file
    private StreamTokenizer inputFile;

    
    /** 
     * Construct a new WumpusMaze according to the data contained
     * in the "caves.dat" file. This includes creating the
     * WumpusCave objects and indicating how these caves are 
     * connected.  This constructor also randomly places wumpi, 
     * bats and pits in the maze and picks a random starting cave 
     * for the player.  The player will always be started in an 
     * empty cave.
     */
    public WumpusMaze() {

	// The following lines setup the input file so that
	// the caveFileReadInt and caveFileReadLine will work.
	// They do not need to be modified in any way!
        try {
            inputFile = new StreamTokenizer(new FileReader("caves.dat"));
	    inputFile.wordChars('\'','\'');
        } catch (IOException e) {
            System.out.println("Error opening caves.dat");
            return;
        }

        
        
	// Your code to construct and initialize the maze
	// goes here!	
	// ...


    }
    
    

    /* Return a string representation of the maze for debugging and/or 
       testing purposes. This method can simply return a String that
       lists information about each of the caves in the maze 
    */
    public String toString() {
	String str = "";
	return str;
    }



    /* Move through a tunnel into an adjacent cave */
    public void move(int tunnel) {
	// fill in...
    }



    /* Toss a grenade through a tunnel into an adjacent cave in an 
       attempt to kill a wumpus
    */
    public void tossGrenade(int tunnel) {
	// fill in...
    }



    /* Feel the air for a breeze that would be coming from a pit in 
       any of the adjacent caves 
    */
    public boolean feelDraft() {
	return false;    // fix this...
    }


    /* Listen to see if the flapping of bats can be heard coming from
       any of the adjacent caves 
    */
    public boolean hearBats() {
	return false;    // fix this...
    }

    /* Smell the air to see if a wumpus is nearby */
    public boolean smellWumpus() {
	return false;    // fix this...
    }



    /* Print out information about the player's current location in
     * the maze, including the name of the cave and whether a
     * something bad can be heard (like bats), felt (like a draft), or
     * smelt (like a wumpus). It should also print out the names of
     * the three caves that are along the adjacent tunnels (remember,
     * the name should print out as "unknown" if the cave hasn't been
     * visited previously).
     */
    public void displayCurrentLocation() {
	// fill in...
    }


    /* Check to see if the player in the maze is still alive */
    public boolean isAlive() {
	return true;  // fix this...
    }

    /* Check to see if there are still more wumpi romping around that
     * need eliminating
     */
    public boolean liveWumpi() {
	return true;  // fix this...
    }

    

    
    /*********************************************************************
     * You do not need to understand or modify how the methods below
     * work. Just use them in your constructor to read integers from
     * the caves.dat file, or to read up till the end of the line
     */

    /* Read the next integer from the cave.dat file. */
    private int caveFileReadInt() {
        try {
            inputFile.nextToken();
        } catch (IOException e) {
            System.out.println("Error reading integer from caves.dat");
            System.exit(-1);
        }
        return (int)inputFile.nval;
    }
    
    
    /* Read the characters from the current point to 
     * the end of the line into a String.
     */
    private String caveFileReadLine() {
        String ret = "";
        try {
            inputFile.eolIsSignificant(true);
            inputFile.nextToken();
            while(inputFile.ttype != StreamTokenizer.TT_EOL) {
                ret = ret + inputFile.sval + " ";
                inputFile.nextToken();
            }
            inputFile.eolIsSignificant(false);
        }
        catch (final IOException e) {
            System.out.println("Error reading line from caves.dat");
            System.exit(-1);
        }
    
        return ret.trim();
    }
    
    
}