我正在制作一个扫雷游戏,我希望用户能够在玩游戏之前从初学者,中级和高级中选择。到目前为止,我所拥有的是一个JFrame,当我用每个难度的按钮打开程序时会打开它。
这是我的主要功能和选择难度的功能。我想知道在调用chooseGameDifficulty之后我仍然可以调用main函数中的所有函数,因为现在它们没有被调用。
public static void main(String[] args) {
chooseGameDifficulty();
game.initGame();
initBoard();
getClick();
while (gameOver == false) {
showUserTile();
checkGameWon();
}
}
public static void chooseGameDifficulty() {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame chooseDifficulty = new JFrame("Minesweeper");
chooseDifficulty.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
chooseDifficulty.setPreferredSize(new Dimension(500,500));
chooseDifficulty.setLayout(new GridLayout(1, 3));
JButton B = new JButton("Beginner");
JButton I = new JButton("Intermediate");
JButton E = new JButton("Expert");
chooseDifficulty.add(B);
chooseDifficulty.add(I);
chooseDifficulty.add(E);
B.addMouseListener(
new MouseListener() {
public void mouseClicked(MouseEvent event) {
game.setGameDifficulty("Beginner");
chooseDifficulty.setVisible(false);
}
public void mouseExited(MouseEvent event) {
}
public void mouseEntered(MouseEvent event) {
}
public void mouseReleased(MouseEvent event) {
}
public void mousePressed(MouseEvent event) {
}
}
);
// same thing for the other buttons
chooseDifficulty.pack();
chooseDifficulty.setLocationRelativeTo(null);
chooseDifficulty.setVisible(true);
}
答案 0 :(得分:0)