UX fix
- Made high score dialog modal - Added check for type mismatch when unserializing high scores - Added remaining mines counter refresh on board reset
This commit is contained in:
parent
43d3d94756
commit
b648db6755
@ -87,6 +87,8 @@ public class Board extends JPanel {
|
|||||||
activeTiles = boardWidth * boardHeight;
|
activeTiles = boardWidth * boardHeight;
|
||||||
flaggedTiles = 0;
|
flaggedTiles = 0;
|
||||||
|
|
||||||
|
notifyFlaggedTilesEvent(new FlaggedTilesEvent(this, flaggedTiles));
|
||||||
|
|
||||||
// Initialize board
|
// Initialize board
|
||||||
board = new Tile[boardWidth][boardHeight];
|
board = new Tile[boardWidth][boardHeight];
|
||||||
for (int i = 0; i < boardWidth; i++)
|
for (int i = 0; i < boardWidth; i++)
|
||||||
|
@ -48,15 +48,12 @@ public class Minesweeper {
|
|||||||
* Launch the application.
|
* Launch the application.
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
EventQueue.invokeLater(new Runnable() {
|
EventQueue.invokeLater(() -> {
|
||||||
|
try {
|
||||||
public void run() {
|
Minesweeper window = new Minesweeper();
|
||||||
try {
|
window.mframe.setVisible(true);
|
||||||
Minesweeper window = new Minesweeper();
|
} catch (Exception e) {
|
||||||
window.mframe.setVisible(true);
|
e.printStackTrace();
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -182,14 +179,20 @@ public class Minesweeper {
|
|||||||
mframe.setJMenuBar(menubar);
|
mframe.setJMenuBar(menubar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings(
|
||||||
|
"unchecked"
|
||||||
|
)
|
||||||
private void loadScores() {
|
private void loadScores() {
|
||||||
try (var in = new ObjectInputStream(new FileInputStream(scoresFile))) {
|
try (var in = new ObjectInputStream(new FileInputStream(scoresFile))) {
|
||||||
scores = (TreeSet<Score>) in.readObject();
|
Object obj = in.readObject();
|
||||||
|
if (obj instanceof TreeSet<?>) scores = (TreeSet<Score>) obj;
|
||||||
|
else throw new IOException("Serialized object has the wrong class.");
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
scores = new TreeSet<>();
|
scores = new TreeSet<>();
|
||||||
} catch (IOException | ClassNotFoundException ex) {
|
} catch (IOException | ClassNotFoundException ex) {
|
||||||
JOptionPane.showMessageDialog(mframe, "The score file seems to be corrupted. It will be replaced when closing the game.", "File error", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(mframe,
|
||||||
|
"The score file seems to be corrupted. It will be replaced when closing the game.", "File error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
scores = new TreeSet<>();
|
scores = new TreeSet<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ public class ScoreDialog extends JDialog {
|
|||||||
* Create the dialog.
|
* Create the dialog.
|
||||||
*/
|
*/
|
||||||
public ScoreDialog(Set<Score> scores) {
|
public ScoreDialog(Set<Score> scores) {
|
||||||
|
setModal(true);
|
||||||
setBounds(100, 100, 450, 300);
|
setBounds(100, 100, 450, 300);
|
||||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
getContentPane().setLayout(new BorderLayout(0, 0));
|
getContentPane().setLayout(new BorderLayout(0, 0));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user