/*
 * WumpusGame.java
 * This is the main application file for the "Hunt the Wumpus" game
 * program
 *
 * It contains a simple main method that just loops around displaying
 * the maze's current status and asking the player to enter input.
 * Depending on the input, it calls the appropriate methods of the 
 * WumpusMaze class.
 *
 * Nadeem Abdul Hamid
 * CS 120 - Fall 2004
 */


public class WumpusGame {

    public static void main(String[] args) {
	WumpusMaze maze = new WumpusMaze();

	System.out.println("\n\nHUNT THE WUMPUS: Your mission is to explore the maze of caves\nand destroy all of the wumpi (without getting yourself killed).");
	printhelp();

	while (!maze.gameOver()) {
	    //	    System.out.println(maze);
	    maze.displayCurrentLocation();
	    
	    System.out.print("What do you want to do? ");
	    String line = Keyboard.readString();
	    if (line.length() >= 3) {
		char cmd = line.toLowerCase().charAt(0);
		int tunnel = line.charAt(2) - '0';
		if (cmd == 'm') maze.move(tunnel);       // moving 
		else if (cmd == 't') maze.toss(tunnel);  // tossing a grenade
		else printhelp();
	    }
	    else if (line.toLowerCase().equals("q")) { // quitting the game
		System.out.println("\nWimp!");
		maze.printStats();
		break;
	    }
	    else if (line.toLowerCase().equals("?")) {  // "cheat" function
		System.out.println(maze);
		maze.printStats();
	    }
	    else 
		printhelp();
	}

	System.out.println("GAME OVER");

    }


    /* 
     * Prints a menu of the possible commands a player can make
     */ 
    static void printhelp() {
	System.out.println();
        System.out.println("To move to an adjacent cave, enter 'M' and the tunnel number.");
	System.out.println("To toss a grenade into a cave, enter 'T' and the tunnel number.");
	System.out.println("To quit like a coward, enter 'Q'.");
	System.out.println();
    }


}