Repository navigation
Expand file tree
/
Copy pathGame.java
More file actions
254 lines (214 loc) · 9 KB
/
Copy pathGame.java
File metadata and controls
254 lines (214 loc) · 9 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/**
* Pizza Delivery game. In this game
* the pizza delivery boy will start from
* a center point of a road. The player will
* have to find the correct destination in order
* to deliver the Pizza and win the match.
*
* @author Mainuddin Monsur Robin
* @version 1.0
*/
public class Game implements Playable
{
private Parser parser;
private Room currentRoom;
private boolean item;
private Player player;
private UI ui;
private Environement environment;
/**
* Create the game and initialise its internal map.
*/
public Game(String playerName)
{
createRooms();
player = new Player(playerName);
environment = new Environement();
player.setCurrentLocation(environment.startRoom());
parser = new Parser();
ui = UI.UiStart(this);
item = false;
}
/**
* Create all the rooms and link their exits together.
*/
private void createRooms()
{
Room kitchen,aBlock,bBlock, cBlock, dBlock, eBlock,street1, street2, street3;
kitchen = new Room("You are at kitchen where delicious pizzas are cooked.\n","//Users//mainuddinrobin//Library//CloudStorage//OneDrive-haw-hamburg.de//02.HAW Hamburg//2nd semester//SO2//lab2022_Renz//lab6//Pizza Delivery//pic//kitchen.jpeg");
aBlock = new Room("This is the first block and closest to the restaurant.\n","//Users//mainuddinrobin//Library//CloudStorage//OneDrive-haw-hamburg.de//02.HAW Hamburg//2nd semester//SO2//lab2022_Renz//lab6//Pizza Delivery//pic//ablock.jpg");
bBlock = new Room("This is the Second block and also closest to the restaurant.\n ","//Users//mainuddinrobin//Library//CloudStorage//OneDrive-haw-hamburg.de//02.HAW Hamburg//2nd semester//SO2//lab2022_Renz//lab6//Pizza Delivery//pic//bblock.jpg");
cBlock = new Room("You are at block ´C´.\n","//Users//mainuddinrobin//Library//CloudStorage//OneDrive-haw-hamburg.de//02.HAW Hamburg//2nd semester//SO2//lab2022_Renz//lab6//Pizza Delivery//pic//cblock.jpg");
dBlock = new Room("You are at block ´D´.\n","//Users//mainuddinrobin//Library//CloudStorage//OneDrive-haw-hamburg.de//02.HAW Hamburg//2nd semester//SO2//lab2022_Renz//lab6//Pizza Delivery//pic//dblock.jpg");
eBlock = new Room("You are at block ´E´.\n","//Users//mainuddinrobin//Library//CloudStorage//OneDrive-haw-hamburg.de//02.HAW Hamburg//2nd semester//SO2//lab2022_Renz//lab6//Pizza Delivery//pic//eblock.jpg");
street1 = new Room("You are now at street1.\nBlock A is at your right and Block B is at your left.\nGo straight to go to Street2.","//Users//mainuddinrobin//Library//CloudStorage//OneDrive-haw-hamburg.de//02.HAW Hamburg//2nd semester//SO2//lab2022_Renz//lab6//Pizza Delivery//pic//street1.jpg");
street2 = new Room("You are now at street2.\nBlock C is at your right and Block D is at your left.\nGo straight to go to Street3.","//Users//mainuddinrobin//Library//CloudStorage//OneDrive-haw-hamburg.de//02.HAW Hamburg//2nd semester//SO2//lab2022_Renz//lab6//Pizza Delivery//pic//street2.jpg");
street3 = new Room("You are now at street3.\nGo straight to go to Block E.\nThis is the last Block.","//Users//mainuddinrobin//Library//CloudStorage//OneDrive-haw-hamburg.de//02.HAW Hamburg//2nd semester//SO2//lab2022_Renz//lab6//Pizza Delivery//pic//street3.jpg");
// initialise room exits
kitchen.setExit("straight", street1);
street1.setExit("straight", street2);
street1.setExit("left", bBlock);
bBlock.setExit("back", street1);
street1.setExit("right", aBlock);
aBlock.setExit("back", street1);
street1.setExit("back", kitchen);
street2.setExit("straight", street3);
street2.setExit("left", dBlock);
dBlock.setExit("back", street2);
street2.setExit("right", cBlock);
cBlock.setExit("back", street2);
street2.setExit("back", street1);
eBlock.setExit("back", street3);
street3.setExit("straight", eBlock);
street3.setExit("back", street2);
currentRoom = kitchen; // start game outside
}
/**
* Main play routine. Loops until end of play.
*/
public void play()
{
welcome();
// Enter the main command loop. Here we repeatedly read commands and
// execute them until the game is over.
boolean finished = false;
while (! finished) {
Command command = parser.getCommand();
finished = processCommand(command);
}
System.out.println("Thank you for playing. Good bye.");
}
/**
* Print out the opening message for the player.
*/
public String welcome()
{
return String.format("Welcome to the Pizza Delivery Game! \n" +
"Pizza Delivery is a new, incredibly boring adventure game. \n" +
"Click on 'help' button if you need help. \n");
}
public Room getCurrentRoom()
{
return player.getCurrentLocation();
}
/**
* Given a command, process (that is: execute) the command.
* @param command The command to be processed.
* @return true If the command ends the game, false otherwise.
*/
public boolean processCommand(Command command)
{
boolean wantToQuit = false;
if(command.isUnknown()) {
System.out.println("I don't know what you mean...");
return false;
}
String commandWord = command.getCommandWord();
if (commandWord.equals("help")) {
printHelp();
}
else if (commandWord.equals("go")) {
goRoom(command);
}
else if (commandWord.equals("pick")) {
//pick();
}
else if (commandWord.equals("quit") ) {
wantToQuit = quit(command);
}
// else command not recognised.
return wantToQuit;
}
// implementations of user commands:
/**
* Print out some help information.
* Here we print some stupid, cryptic message and a list of the
* command words.
*/
private void printHelp()
{
System.out.println("Go around the blocks and pick item from packet station.");
System.out.println();
System.out.println("Your command words are:");
parser.showCommands();
}
/**
* Try to in to one direction. If there is an exit, enter the new
* room, otherwise print an error message.
*/
private void goRoom(Command command)
{
if(command.getCommandWord().equals("go"))
{
if(!command.hasSecondWord()) {
// if there is no second word, we don't know where to go...
System.out.println("Go where?");
return;
}
}
String direction = command.getSecondWord();
System.out.println(direction);
System.out.println(currentRoom.getDirections().toString());
// Try to leave current room.
player.setPreviousLocation(currentRoom);
Room nextRoom = currentRoom.getExit(direction);
if (nextRoom == null) {
System.out.println("There is no block!");
}
else {
currentRoom = nextRoom;
System.out.println(currentRoom.getDirections());
player.setCurrentLocation(currentRoom);
/*
if(item){
System.out.println(currentRoom.getDescription());
}else{
System.out.println("Fool you didn't bring the Item. You looser");
}*/
}
}
/**
* "Quit" was entered. Check the rest of the command to see
* whether we really quit the game.
* @return true, if this command quits the game, false otherwise.
*/
private boolean quit(Command command)
{
if(command.hasSecondWord()) {
System.out.println("Quit what?");
return false;
}
else {
return true; // signal that we want to quit
}
}
public String getHelp(){
return "Go around the blocks and pick item from packet station.";
}
public String playerName(){
return this.player.getName();
}
/*
public void loadGame(){
GameSerializer gameDeserializer = new GameSerializer();
Game game = gameDeserializer.deSerialize();
this.player = game.player;
this.environment = game.environment;
ui.gamePlayWindowMaker(player.getName(), player.getCurrentLocation().getRoomName())
}
public void saveGame(){
}
/*
private void pick()
{
if(currentRoom.getRoomNumber().equals("D"))
{
System.out.println("You picked up the item.");
System.out.println(currentRoom.getLongDescription());
item = true;
}else{
System.out.println("This is not a packet station!");
System.out.println(currentRoom.getLongDescription());
}
}*/
}