-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode
More file actions
162 lines (121 loc) · 5.73 KB
/
Copy pathCode
File metadata and controls
162 lines (121 loc) · 5.73 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
161
162
import javax.sound.sampled.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
public class SlotMachine extends MouseAdapter {
public static void main(String[] args) {
JPanel panel = new JPanel(null);
JFrame frame = new JFrame("SlotMachine");
frame.setVisible(true);
frame.setSize(550,300);
frame.setLocation(600,250);
frame.add(panel);
JLabel one = new JLabel(String.valueOf(0));
one.setSize(100, 100);
one.setLocation(40, 50);
one.setFont((new Font("Arial", Font.PLAIN, 30)));
one.setVisible(true);
panel.add(one);
JLabel two = new JLabel(String.valueOf(0));
two.setSize(100, 100);
two.setLocation(100, 50);
two.setFont((new Font("Arial", Font.PLAIN, 30)));
two.setVisible(true);
panel.add(two);
JLabel three = new JLabel(String.valueOf(0));
three.setSize(100, 100);
three.setLocation(160, 50);
three.setFont((new Font("Arial", Font.PLAIN, 30)));
three.setVisible(true);
panel.add(three);
JTextField Bet = new JTextField(String.valueOf(1));
Bet.setVisible(true);
Bet.setSize(50,20);
Bet.setLocation(370,230);
panel.add(Bet);
JCheckBox box = new JCheckBox("Always win");
box.setVisible(true);
box.setSize(90,45);
box.setLocation(350,-5);
panel.add(box);
JLabel credits = new JLabel(String.valueOf(100));
credits.setVisible(true);
credits.setSize(90,90);
credits.setLocation(350, 150);
credits.setFont((new Font("Clarendon Bold", Font.BOLD, 50)));
panel.add(credits);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JButton Spin = new JButton("Play");
Spin.setSize(180,90);
Spin.setLocation(300,50);
Spin.setVisible(true);
panel.add(Spin);
Spin.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
int x = (int) Math.round(Math.random()*10);
int y = (int) Math.round(Math.random()*10);
int z = (int) Math.round(Math.random()*10);
if(Integer.parseInt(Bet.getText()) > Integer.parseInt(credits.getText())&& !box.isSelected()){
return;
}
if(e.getButton() == MouseEvent.BUTTON1){
one.setText((String.valueOf(x)));
two.setText(String.valueOf(y));
three.setText(String.valueOf(z));
//Always win
if(box.isSelected()){
two.setText(one.getText());
}
credits.setText(String.valueOf(Integer.parseInt(credits.getText()) - Integer.parseInt(Bet.getText())));
if (one.getText().equals(two.getText())&& !one.getText().equals(three.getText())) {
credits.setText(String.valueOf(Integer.parseInt(credits.getText()) + 2*(Integer.parseInt(Bet.getText()))));
try {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("C:\\Users\\bener\\Downloads\\mixkit-coins-handling-1939.wav").getAbsoluteFile());
Clip clip = AudioSystem.getClip( );
clip.open(audioInputStream);
clip.start( );
} catch (UnsupportedAudioFileException | LineUnavailableException | IOException ex) {
throw new RuntimeException(ex);
}
}else if(one.getText().equals(two.getText())&& one.getText().equals(three.getText())){
credits.setText(String.valueOf(Integer.parseInt(credits.getText()) + 10*(Integer.parseInt(Bet.getText()))));
try {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("C:\\Users\\bener\\Downloads\\mixkit-magical-coin-win-1936.wav").getAbsoluteFile());
Clip clip = AudioSystem.getClip( );
clip.open(audioInputStream);
clip.start( );
} catch (UnsupportedAudioFileException | LineUnavailableException | IOException ex) {
throw new RuntimeException(ex);
}
}else{
try {
//MUSIC
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("C:\\Users\\bener\\Downloads\\vibrating-thud-39536.wav").getAbsoluteFile());
Clip clip = AudioSystem.getClip( );
clip.open(audioInputStream);
clip.start( );
} catch (UnsupportedAudioFileException | LineUnavailableException | IOException ex) {
throw new RuntimeException(ex);
}
}
if(Integer.parseInt(credits.getText()) < 0) {
credits.setText(String.valueOf(1));
}
}
}
@Override
public void mousePressed(MouseEvent e) {}
@Override
public void mouseReleased(MouseEvent e) {}
@Override
public void mouseEntered(MouseEvent e) {}
@Override
public void mouseExited(MouseEvent e) {}
});
}
}