-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameSettings.java
78 lines (61 loc) · 2.53 KB
/
GameSettings.java
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
package TicTacToe;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class GameSettings extends JFrame {
//Settings window
public GameSettings() {
setTitle("TicTacToe");
setBounds(450, 450, 240, 190);
setResizable(false);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
JLabel jLabelMode = new JLabel("Choose game mod:");
JRadioButton radioButtonModeTwoPlayers = new JRadioButton("Player vs Player");
radioButtonModeTwoPlayers.setSelected(true);
radioButtonModeTwoPlayers.setFocusable(false);
JRadioButton radioButtonModeAgainstAI = new JRadioButton("Player vs AI");
radioButtonModeAgainstAI.setFocusable(false);
ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(radioButtonModeTwoPlayers);
buttonGroup.add(radioButtonModeAgainstAI);
JButton jButtonSetSettings = new JButton("Start game!");
jButtonSetSettings.setFocusable(false);
//add buttons on the panel
add(jLabelMode);
add(radioButtonModeTwoPlayers);
add(radioButtonModeAgainstAI);
add(jButtonSetSettings);
setVisible(true);
GameFunction game = new GameFunction();
//if choose gameMode with AI - show jslider for choose difficult
radioButtonModeAgainstAI.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (radioButtonModeAgainstAI.isSelected()) {
GameFunction.gameMode = 2;
getContentPane().revalidate();
}
}
});
radioButtonModeTwoPlayers.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (radioButtonModeTwoPlayers.isSelected()) {
GameFunction.gameMode = 1;
getContentPane().revalidate();
}
}
});
//by clicking in the start button - will be start MainGame TicTacToe
jButtonSetSettings.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jButtonSetSettings) {
MainFormForGame game = new MainFormForGame();
dispose();
}
}
});
}
}