/
Game.java
87 lines (81 loc) · 2.69 KB
/
Game.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
85
86
87
//////////////////////////////////////////////////////////////////////////
//Karl Cassel & Yuna Choe
//CruzID: kcassel (Karl)
//CruzID: yuchoe (Yuna)
//Date: Nov 7, 2014
// Game.java
// Where the actual game is played and the file is read.
//////////////////////////////////////////////////////////////////////////
import java.io.*;
import java.io.BufferedReader;
import static java.lang.System.*;
import java.util.ArrayList;
class Game {
public static void main(String[] args) throws IOException{
String fileName = null;
String temp = null;
File f;
BufferedReader systemIn;
Room insertedRoom = new Room();
LinkedRoomList adventure = new LinkedRoomList();
if(args.length > 1)
{
System.out.println("Cannot pass more than 1 argument.");
}
else if(args.length == 1)
{
try {
fileName = args[0];
f = new File(fileName);
systemIn = new BufferedReader(new FileReader(f));
temp = systemIn.readLine();
while(temp != null)
{
if(temp.length() > 1) {
if(temp.substring(0,1).equals("r"))
{
insertedRoom.roomName = temp.substring(2,temp.length());
}
else if(temp.substring(0,1).equals("d"))
{
insertedRoom.description.add(temp.substring(2,temp.length()));
}
else if(temp.substring(0,1).equals("o"))
{
insertedRoom.choiceList.add(temp.substring(2,temp.length()));
}
else if(temp.substring(0,1).equals("t"))
{
insertedRoom.roomList.add(temp.substring(2,temp.length()));
}
else
{
// does nothing
}
}
else
{
adventure.insertLast(insertedRoom);
insertedRoom.clearRoom();
}
temp = systemIn.readLine();
}
} catch(RuntimeException e) {
System.out.println("File failed to process.");
} catch(FileNotFoundException b) {
System.out.println("File not found.");
} catch(IOException ex) {
System.out.println("End of file.");
}
}
else
{
System.out.println("No arguments passed.");
}
// when the game begins
while(true)
{
adventure.showRoom();
}
}
}