-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameOverScreen.java
More file actions
114 lines (95 loc) · 3.44 KB
/
GameOverScreen.java
File metadata and controls
114 lines (95 loc) · 3.44 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
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
/**
* Displays the Game-Over Screen after a win or loss
*
* @Avi and Amar Ruthen
* @12.22.2020
*/
public class GameOverScreen extends JFrame implements ActionListener
{
JPanel buttonPanel;
JPanel textPanel;
JPanel picPanel;
JButton replayButton, exitButton;
JLabel gameResult;
JLabel backgroundPic;
BufferedImage titlePic;
final Color DARK_BLUE = new Color(0, 0, 204);
int WIDTH;
int HEIGHT;
/**
* Constructor for creating the Game-Over Screen
*
* @param win displays different text based on whether the user
* has won or lost
*/
public GameOverScreen(boolean win)
{
super("Game Over!");
// the JFrame/Graphics Window size:
WIDTH = 1000;
HEIGHT = 700;
Font font = new Font("Verdana", Font.BOLD, 32);
this.setLayout(new BorderLayout());
//Creating the panel to display text
textPanel = new JPanel();
textPanel.setBackground(DARK_BLUE);
gameResult = new JLabel();
if(win)
gameResult.setText("You found the enemy base first! Congrats!");
else
gameResult.setText("Sorry, the Drones found your base!");
gameResult.setFont(font);
gameResult.setForeground(Color.WHITE);
//Add text to the top panel
textPanel.add(gameResult);
//Creating the panel for the buttons
buttonPanel = new JPanel();
buttonPanel.setBackground(DARK_BLUE);
replayButton = new JButton("REPLAY");
replayButton.addActionListener(this);
replayButton.setActionCommand("replay");
exitButton = new JButton("EXIT");
exitButton.addActionListener(this);
exitButton.setActionCommand("exit");
//Add buttons to the front panel
buttonPanel.add(replayButton);
buttonPanel.add(exitButton);
//Create the picture panel
picPanel = new JPanel();
picPanel.setBackground(DARK_BLUE);
//Establish picture from files and add to bottom panel
ImageIcon titlePic = new ImageIcon("resources/TitleBackground.png");
backgroundPic = new JLabel(titlePic);
picPanel.add(backgroundPic);
//Construct and arrange panels on full screen
this.add(buttonPanel, BorderLayout.CENTER);
this.add(textPanel, BorderLayout.NORTH);
this.add(picPanel, BorderLayout.SOUTH);
//Fine-tuning the screen
this.setPreferredSize(new Dimension(WIDTH, HEIGHT));
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.pack();
this.setVisible(true);
}
/**
* Actionperformed: when a button is pressed, this is automatically called:
*/
public void actionPerformed(ActionEvent e) {
//Transfer screen to powerup selection
if (e.getActionCommand().equals("replay")) {
PowerupScreen ps = new PowerupScreen();
this.setVisible(false);
}
//Quite out of game
if (e.getActionCommand().equals("exit")) {
JOptionPane.showMessageDialog(null, "HAVE A NICE DAY", "Game Over",
JOptionPane.PLAIN_MESSAGE, null);
System.exit(0);
}
}
}