-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.java
More file actions
580 lines (477 loc) · 19.3 KB
/
Copy pathGUI.java
File metadata and controls
580 lines (477 loc) · 19.3 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
import javax.swing.border.*;
/**
* Write a description of class G here.
*
* @author (Mainuddin Monsur Robin)
* @version (1.0)
*/
public class GUI implements UI
{
private Playable player;
private JFrame frame;
private JLabel background;
private JTextPane title;
private JTextPane gameOutputArea;
private JPanel buttons;
GameHistory gameHistory;
/**
* Constructor for objects of class G
*/
public GUI(Playable game)
{
// initialise instance variables
player = game;
System.out.println(game.getCurrentRoom().getDirections());
this.makeFrame();
this.makeMenuBar();
this.makeBackground();
this.makeGameStartBtn();
gameHistory = new GameHistory(game.playerName());
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
private void makeFrame()
{
frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setTitle("PIZZA DELIVERY");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setSize(580, 620);
frame.setResizable(true);
frame.setVisible(true);
}
private void makeMenuBar()
{
// menu bar -------------------------------------------------------------------->
JMenuBar menubar = new JMenuBar();
frame.setJMenuBar(menubar);
// File Menu ----------------------------------------------------------------->
JMenu file = new JMenu("File");
menubar.add(file);
// file memu items
JMenuItem newGame = new JMenuItem("New Game");
JMenuItem quit = new JMenuItem("Quit");
quit.addActionListener(e -> {
gameHistory.closeWriter();
System.exit(0);
});
file.add(newGame);
file.add(quit);
// Setting menu--------------------------------------------------------------->
JMenu settings = new JMenu("Settings");
menubar.add(settings);
// Settings memu items
JMenuItem muteAudio = new JMenuItem("Mute Audio");
JMenuItem unmuteAudio = new JMenuItem("Unmute Audio");
settings.add(muteAudio);
settings.add(unmuteAudio);
}
private void makeBackground()
{
background = new JLabel (new ImageIcon("//Users//mainuddinrobin//Library//CloudStorage//OneDrive-haw-hamburg.de//02.HAW Hamburg//2nd semester//SO2/lab2022_Renz//lab6//Pizza Delivery//pic//bg-main.jpg"));
background.setLayout(new FlowLayout());
frame.add(background);
title = new JTextPane();
title.setFont(new Font("MV Boli",Font.PLAIN,15));
title.setForeground(new Color(0xffff00));
title.setOpaque(false);
title.setMargin( new Insets(30,0,0,0));
title.setAlignmentX(0);
gameOutputArea = new JTextPane();
gameOutputArea.setFont(new Font("MV Boli",Font.PLAIN,15));
gameOutputArea.setForeground(new Color(0xffff00));
gameOutputArea.setOpaque(false);
gameOutputArea.setMargin( new Insets(5,0,0,0));
gameOutputArea.setAlignmentX(0);
background.add(title);
background.add(gameOutputArea);
title.setText(player.welcome());
}
public void updateBackground()
{
background.setIcon(new ImageIcon(player.getCurrentRoom().getImagePath()));
title.setText(player.getCurrentRoom().getDescription());
background.revalidate();
background.repaint();
}
public void makeGameStartBtn(){
buttons = new JPanel();
buttons.setLayout(new BoxLayout(buttons,BoxLayout.Y_AXIS));
buttons.setPreferredSize(new Dimension(300, 300));
buttons.setOpaque(false);
JButton newGameButton = new JButton("New Game");
buttons.add(newGameButton);
newGameButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
background.remove(buttons);
makeKitchen();
gameOutputArea.setText(null);
}
});
background.add(buttons);
}
public void makeKitchen()
{
updateBackground();
buttons = new JPanel();
buttons.setLayout(new BoxLayout(buttons,BoxLayout.Y_AXIS));
buttons.setPreferredSize(new Dimension(300, 300));
buttons.setOpaque(false);
JButton straightButton = new JButton("Go Straight");
JButton quitButton = new JButton("Quit");
JButton helpButton = new JButton("Help");
JButton pickButton = new JButton("Pick");
buttons.add(straightButton);
buttons.add(pickButton);
buttons.add(helpButton);
buttons.add(quitButton);
background.add(buttons);
//Actions
helpButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
gameHistory.writeHistory("Help");
gameOutputArea.setText(player.getHelp());
}
});
straightButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Command command = new Command("go", "straight");
gameHistory.writeHistory(command.getUserCommand());
player.processCommand(command);
background.remove(buttons);
makeStreet1();
}
});
pickButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
gameHistory.writeHistory("Pick");
gameOutputArea.setText("You have picked pizza for delivery.");
}
});
quitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
gameHistory.writeHistory("Quit");
gameHistory.closeWriter();
gameOutputArea.setFont(new Font("MV Boli",Font.PLAIN,50));
gameOutputArea.setText("GAME OVER");
background.remove(buttons);
makeGameStartBtn();
}
});
}
//Street1
public void makeStreet1(){
updateBackground();
buttons = new JPanel();
buttons.setLayout(new BoxLayout(buttons,BoxLayout.Y_AXIS));
buttons.setPreferredSize(new Dimension(300, 300));
buttons.setOpaque(false);
JButton straightButton = new JButton("Go Straight");
JButton backButton = new JButton("Back");
JButton leftButton = new JButton("GO Left");
JButton rightButton = new JButton("GO Right");
buttons.add(straightButton);
buttons.add(leftButton);
buttons.add(rightButton);
buttons.add(backButton);
background.add(buttons);
//Actions
//go straight button
straightButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Command command = new Command("go", "straight");
gameHistory.writeHistory(command.getUserCommand());
player.processCommand(command);
background.remove(buttons);
makeStreet2();
}
});
//go left button
leftButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Command command = new Command("go", "left");
gameHistory.writeHistory(command.getUserCommand());
player.processCommand(command);
background.remove(buttons);
makeBBlock();
}
});
//go right button
rightButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Command command = new Command("go", "right");
gameHistory.writeHistory(command.getUserCommand());
player.processCommand(command);
background.remove(buttons);
makeABlock();
}
});
backButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Command command = new Command("go", "back");
gameHistory.writeHistory(command.getUserCommand());
player.processCommand(command);
background.remove(buttons);
makeKitchen();
}
});
}
// for street2
public void makeStreet2(){
updateBackground();
buttons = new JPanel();
buttons.setLayout(new BoxLayout(buttons,BoxLayout.Y_AXIS));
buttons.setPreferredSize(new Dimension(300, 300));
buttons.setOpaque(false);
JButton straightButton = new JButton("Go Straight");
JButton backButton = new JButton("Back");
JButton leftButton = new JButton("GO Left");
JButton rightButton = new JButton("GO Right");
buttons.add(straightButton);
buttons.add(leftButton);
buttons.add(rightButton);
buttons.add(backButton);
background.add(buttons);
//Actions
//go straight button
straightButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Command command = new Command("go", "straight");
gameHistory.writeHistory(command.getUserCommand());
player.processCommand(command);
background.remove(buttons);
makeStreet3();
}
});
//go left button
leftButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Command command = new Command("go", "left");
gameHistory.writeHistory(command.getUserCommand());
player.processCommand(command);
background.remove(buttons);
makeDBlock();
}
});
//go right button
rightButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Command command = new Command("go", "right");
player.processCommand(command);
background.remove(buttons);
makeCBlock();
}
});
backButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Command command = new Command("go", "back");
gameHistory.writeHistory(command.getUserCommand());
player.processCommand(command);
background.remove(buttons);
makeStreet1();
}
});
}
public void makeStreet3(){
updateBackground();
buttons = new JPanel();
buttons.setLayout(new BoxLayout(buttons,BoxLayout.Y_AXIS));
buttons.setPreferredSize(new Dimension(300, 300));
buttons.setOpaque(false);
JButton straightButton = new JButton("Go Straight");
JButton backButton = new JButton("Back");
buttons.add(straightButton);
buttons.add(backButton);
background.add(buttons);
//Actions
//go straight button
straightButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Command command = new Command("go", "straight");
gameHistory.writeHistory(command.getUserCommand());
player.processCommand(command);
background.remove(buttons);
makeEBlock();
}
});
backButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Command command = new Command("go", "back");
gameHistory.writeHistory(command.getUserCommand());
player.processCommand(command);
background.remove(buttons);
makeStreet2();
}
});
}
//AState
public void makeABlock()
{
updateBackground();
buttons = new JPanel();
buttons.setLayout(new BoxLayout(buttons,BoxLayout.Y_AXIS));
buttons.setPreferredSize(new Dimension(300, 300));
buttons.setOpaque(false);
JButton backButton = new JButton("Back");
JButton deliverButton = new JButton("Deliver");
buttons.add(backButton);
buttons.add(deliverButton);
background.add(buttons);
//Actions
backButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Command command = new Command("go", "back");
gameHistory.writeHistory(command.getUserCommand());
player.processCommand(command);
background.remove(buttons);
gameOutputArea.setText(null);
makeStreet1();
}
});
deliverButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
gameHistory.writeHistory("Delivered");
gameOutputArea.setFont(new Font("MV Boli",Font.PLAIN,50));
gameOutputArea.setText("Pizza deliverd!");
}
});
}
//For B-Block
public void makeBBlock()
{
updateBackground();
buttons = new JPanel();
buttons.setLayout(new BoxLayout(buttons,BoxLayout.Y_AXIS));
buttons.setPreferredSize(new Dimension(300, 300));
buttons.setOpaque(false);
JButton backButton = new JButton("Back");
JButton deliverButton = new JButton("Deliver");
buttons.add(backButton);
buttons.add(deliverButton);
background.add(buttons);
//Actions
backButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Command command = new Command("go", "back");
gameHistory.writeHistory(command.getUserCommand());
player.processCommand(command);
background.remove(buttons);
gameOutputArea.setText(null);
makeStreet1();
}
});
deliverButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
gameHistory.writeHistory("Deliver");
gameOutputArea.setFont(new Font("MV Boli",Font.PLAIN,50));
gameOutputArea.setText("Pizza deliverd!");
}
});
}
//For C-Block
public void makeCBlock()
{
updateBackground();
buttons = new JPanel();
buttons.setLayout(new BoxLayout(buttons,BoxLayout.Y_AXIS));
buttons.setPreferredSize(new Dimension(300, 300));
buttons.setOpaque(false);
JButton backButton = new JButton("Back");
JButton deliverButton = new JButton("Deliver");
buttons.add(backButton);
buttons.add(deliverButton);
background.add(buttons);
//Actions
backButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Command command = new Command("go", "back");
gameHistory.writeHistory(command.getUserCommand());
player.processCommand(command);
background.remove(buttons);
gameOutputArea.setText(null);
makeStreet2();
}
});
deliverButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
gameHistory.writeHistory("Deliver");
gameOutputArea.setFont(new Font("MV Boli",Font.PLAIN,50));
gameOutputArea.setAlignmentX(Component.RIGHT_ALIGNMENT);
gameOutputArea.setText("\nPizza deliverd!\n");
}
});
}
//For D-Block
public void makeDBlock()
{
updateBackground();
buttons = new JPanel();
buttons.setLayout(new BoxLayout(buttons,BoxLayout.Y_AXIS));
buttons.setPreferredSize(new Dimension(300, 300));
buttons.setOpaque(false);
JButton backButton = new JButton("Back");
JButton deliverButton = new JButton("Deliver");
buttons.add(backButton);
buttons.add(deliverButton);
background.add(buttons);
//Actions
backButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Command command = new Command("go", "back");
gameHistory.writeHistory(command.getUserCommand());
player.processCommand(command);
background.remove(buttons);
gameOutputArea.setText(null);
makeStreet2();
}
});
deliverButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
gameHistory.writeHistory("Deliver");
gameOutputArea.setFont(new Font("MV Boli",Font.PLAIN,50));
gameOutputArea.setText("\nPizza deliverd!\n");
}
});
}
//For E-Block
public void makeEBlock()
{
updateBackground();
buttons = new JPanel();
buttons.setLayout(new BoxLayout(buttons,BoxLayout.Y_AXIS));
buttons.setPreferredSize(new Dimension(300, 300));
buttons.setOpaque(false);
JButton backButton = new JButton("Back");
JButton deliverButton = new JButton("Deliver");
buttons.add(backButton);
buttons.add(deliverButton);
background.add(buttons);
//Actions
backButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Command command = new Command("go", "back");
gameHistory.writeHistory(command.getUserCommand());
player.processCommand(command);
background.remove(buttons);
gameOutputArea.setText(null);
makeStreet3();
}
});
deliverButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
gameHistory.writeHistory("Deliver");
gameOutputArea.setFont(new Font("MV Boli",Font.PLAIN,50));
gameOutputArea.setText("\nPizza deliverd!\n");
}
});
}
}