Repository navigation
Expand file tree
/
Copy pathSettings.java
More file actions
160 lines (132 loc) · 4.63 KB
/
Copy pathSettings.java
File metadata and controls
160 lines (132 loc) · 4.63 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import city.cs.engine.SoundClip;
import city.cs.engine.World;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/** Settings window
* restart button - restarts the game
* out button - ends the game (system exit)
* exit button - applies the settings and closes settings window
* */
public class Settings {
private JFrame frame;
private GameView view;
private SoundClip clip;
private JButton restart;
private JButton out;
private JButton exit;
private JButton abilities;
private World world;
private JFrame gameFrame;
private Player1 player1;
private Player2 player2;
/**
* @param c - (clip) takes in the current background sound
*/
public Settings(GameView v, SoundClip c, World w, JFrame f, Player1 p1, Player2 p2) {
this.view = v;
this.clip = c;
this.world = w;
this.gameFrame = f;
this.player1 = p1;
this.player2 = p2;
frame = new JFrame("Settings");
JPanel panel = new JPanel();
frame.setSize(400,400);
frame.setLocationByPlatform(true);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
JSlider slider = new JSlider(0,100,50);
slider.setPreferredSize(new Dimension(200,100));
slider.setPaintLabels(true);
slider.setPaintTicks(true);
slider.setMinorTickSpacing(10);
slider.setMajorTickSpacing(50);
slider.setFont(new Font("MV Boli",Font.PLAIN,9));
slider.setOrientation(SwingConstants.HORIZONTAL);
// allows to adjust the volume of the background noise
slider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (slider.getValue() <= 5){
clip.stop();
} else if (slider.getValue() <= 25) {
clip.play();
clip.setVolume(0.3);
} else if (slider.getValue() <= 50){
clip.play();
clip.setVolume(0.6);
} else if (slider.getValue() <= 50){
clip.play();
clip.setVolume(1);
} else if (slider.getValue() <= 75){
clip.play();
clip.setVolume(1.4);
} else if (slider.getValue() <= 100){
clip.play();
clip.setVolume(1.9);
}
}
});
// settings buttons
exit = new JButton("APPLY AND EXIT");
exit.setBounds(210,320,150,20);
frame.add(exit);
JLabel soundL = new JLabel("Sound");
soundL.setBounds(30,30,50,50);
frame.add(soundL);
// abilities window
abilities = new JButton("Abilities");
abilities.setBounds(120,110,150,30);
frame.add(abilities);
// exit game
out = new JButton("Exit game");
out.setBounds(120,170,150,30);
frame.add(out);
// restart
restart = new JButton("RESTART");
restart.setBounds(120,230,150,30);
frame.add(restart);
buttonListeners();
panel.add(slider);
frame.add(panel);
frame.setVisible(true);
}
public void buttonListeners() {
ActionListener exitButton = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.dispose();
}
};
ActionListener restartButton = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.dispose();
gameFrame.dispose();
clip.stop();
world.stop();
new StartUp();
}
};
ActionListener abilitiesButton = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new Abilities();
}
};
ActionListener outButton = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(1);
}
};
restart.addActionListener(restartButton);
exit.addActionListener(exitButton);
out.addActionListener(outButton);
abilities.addActionListener(abilitiesButton);
}
}