/*Wendy Nurton
* wnurton
* 5/5/2009
* CS 160
*/
import java.io.File;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Dungeon {
public String rooms [][] = new String[6][4];
public static void main(String[] args) throws Exception {
Dungeon dun = new Dungeon();
String dungeon = args[0];
char direction = 'p';
int row = 0;
int col = 0;
dun.printWelcomeMessage();
dun.readRoomFile(dungeon);
dun.printRoom(row, col);
Scanner keyboard = new Scanner (System.in);
direction = keyboard.next().charAt(0);
do {
switch (direction)
{
case 'h':
case 'H':
dun.printHelp();
break;
case 'n':
case 'N':
if (dun.checkIsExitValid(row, col, "north"))
row --;
else
System.out.println("This is not a valid exit.");
dun.printRoom(row, col);
break;
case 's':
case 'S':
if (dun.checkIsExitValid(row, col, "south"))
row++;
else
System.out.println("This is not a valid exit.");
dun.printRoom(row, col);
break;
case 'w':
case 'W':
if (dun.checkIsExitValid(row, col, "west"))
col++;
else
System.out.println("This is not a valid exit.");
break;
case 'e':
case 'E':
if (dun.checkIsExitValid(row, col, "east"))
col--;
else
System.out.println("This is not a valid exit.");
break;
case 'l':
case 'L':
dun.printRoom(row, col);
break;
}//if (dun.checkIfPit(row, col))
//System.exit(0);
}
while (keyboard.next().charAt(0) != 'q');
}
// TODO Auto-generated method stub
public String[] args;
public boolean checkIsExitValid(int x, int y, String dun) {
// TODO Auto-generated method stub
// System.out.println(rooms[x][y]+";"+ dun);
if (rooms[x][y].indexOf(dun)!=-1)
return true;
else
return false;
}
public boolean checkIfPit(int x, int y) {
// TODO Auto-generated method stub
return (checkIsExitValid(x, y, "pit"));
}
public String getRoomDescription(int row, int col) {
// TODO Auto-generated method stub
return (rooms[row][col]);
}
public void printRoom(int row, int col) {
// TODO Auto-generated method stub
System.out.println(rooms[row][col]);
}
public void printHelp() {
// TODO Auto-generated method stub
System.out.println("");
System.out.println("Help: to play this game, you can move north, west, south or east.");
System.out.println("Type 'l' to take a look around at the room, or type 'q' to quit the game.");
}
public void printWelcomeMessage() {
// TODO Auto-generated method stub
System.out.println("Welcome to my dungeon!");
System.out.println("We have creepy crawly monsters roaming about.");
System.out.println("Find the escape route and win!");
System.out.println("Or drop to your death in the deep pit.");
System.out.println("Good luck!");
System.out.println(" ");
System.out.println("Menu options: 'h' for help, 'n' for north, 's' for south, 'w' for west, 'e' for east, 'l' to look around, and 'q' for quit.");
}
public void readRoomFile(String dungeon) throws Exception {
File file = new File (dungeon);
Scanner in = new Scanner(file);
int i=0;
while( in.hasNextLine())
{
StringTokenizer tokenizer = new StringTokenizer(in.nextLine(), ";\n");
int x = Integer.parseInt(tokenizer.nextToken());
int y = Integer.parseInt(tokenizer.nextToken());
rooms [x][y] = (tokenizer.nextToken());
}
// TODO Auto-generated method stub
}
}