-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOutWalkin.java
84 lines (75 loc) · 1.92 KB
/
OutWalkin.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.util.Scanner;
public class OutWalkin {
public static void main(String[] args) {
boolean gameloop = true;
Scanner scanner = new Scanner(System.in);
String cmd;
World world = null;
int cur = 0;
System.out.println("Let's go walking!");
if(args.length == 0)
{
System.out.println("Dear God! There's no world! The world is empty!");
System.out.println("Remember to include the world as an argument next time, like this:");
System.out.println("\tOutWalkin rooms.txt");
scanner.close();
return;
}
try{
String worldfile = args[0];
world = new World(worldfile);
System.out.println("I have a world!");
}
catch (Exception Err){
System.out.println("Uh oh. Looks like the world is malformed.");
Err.printStackTrace(System.out);
scanner.close();
return;
}
System.out.println("Where would you like to go?");
world.longDisplay(cur);
do {
System.out.print("\n>");
cmd = new String(scanner.next());
// TODO: This can still probably be better handled as a hashmap.
switch (cmd) {
case "n":
case "north":
cur = world.goN(cur);
world.longDisplay(cur);
break;
case "s":
case "south":
cur = world.goS(cur);
world.longDisplay(cur);
break;
case "e":
case "east":
cur = world.goE(cur);
world.longDisplay(cur);
break;
case "w":
case "west":
cur = world.goW(cur);
world.longDisplay(cur);
break;
case "l":
case "look":
world.shortDisplay(cur);
break;
case "exits":
System.out.println(world.getExits(cur));
break;
case "quit":
gameloop = false;
break;
default:
System.out.println("I'm sorry. I don't understand what you meant.");
}
}
while (gameloop);
System.out.println("Thanks for walking with me.");
scanner.close();
return;
}
}