-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameOver.java
More file actions
99 lines (82 loc) · 2.65 KB
/
GameOver.java
File metadata and controls
99 lines (82 loc) · 2.65 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
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
@SuppressWarnings("serial")
public class GameOver extends JFrame{
private BackEnd backEnd = null;
private GameScreen gameScreen = null;
public GameOver(){
setLayout(new BorderLayout());
backEnd = FrontEnd.backEnd();
gameScreen = FrontEnd.gameScreen();
int D = backEnd.getD();
int numberOfMines = backEnd.getNumberOfMines();
Minefield field = backEnd.getMinefield();
int[][] mineLocations = field.getMineLocations();
//Sorry message
JPanel sorryPanel = new JPanel(new GridBagLayout());
sorryPanel.setBackground(Color.BLACK);
GridBagConstraints c1 = new GridBagConstraints();
c1.gridx = 0;
c1.gridy = 0;
c1.weightx = 1;
c1.gridwidth = 2;
JLabel sorryMessage = new JLabel("You hit a mine. Sorry, you lose.");
sorryMessage.setHorizontalAlignment(SwingConstants.CENTER);
int fontSize = MinesweeperUtils.roundToInt(4.4 * D);
sorryMessage.setFont(new Font("YouMurderer BB", Font.PLAIN, fontSize));
sorryMessage.setForeground(Color.WHITE);
sorryPanel.add(sorryMessage, c1);
//New game
NewGameButton newGameButton = new NewGameButton(this);
c1.gridx = 0;
c1.gridy = 1;
c1.gridwidth = 1;
c1.weightx = .5;
sorryPanel.add(newGameButton, c1);
//Quit button
QuitButton quitButton = new QuitButton();
c1.gridx = 1;
c1.gridy = 1;
c1.gridwidth = 1;
c1.weightx = .5;
sorryPanel.add(quitButton, c1);
//Grid
JPanel gridPanel = new JPanel();
gridPanel.setBackground(Color.BLACK);
gridPanel.setLayout(new GridLayout(D, D));
gridPanel.setSize(gameScreen.getGameSize());
ButtonNumber[][] button = new ButtonNumber[(D+1)][(D+1)];
for (int x = 1; x <= D; x++){
for (int y = 1; y <= D; y++){
button[x][y] = new ButtonNumber(MinesweeperIcons.NULL);
gridPanel.add(button[x][y]);
button[x][y].setEnabled(false);
}
}
for (int counter = 0; counter < numberOfMines; counter++){
int x = mineLocations[counter][0];
int y = mineLocations[counter][1];
button[x][y].setEnabled(true);
button[x][y].setButtonNumber(MinesweeperIcons.BOMB);
}
add(sorryPanel, BorderLayout.NORTH);
add(gridPanel);
setTitle("Game Over");
setSize(FrontEnd.gameScreen().getGameSize());
setLocation(MinesweeperUtils.getCornerPoint(getSize()));
setDefaultCloseOperation(EXIT_ON_CLOSE);
setBackground(Color.BLACK);
setVisible(true);
if (MusicEnabledCheckbox.musicEnabled()){
Songs.song2.play();
}
}
}