-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameover.java
115 lines (98 loc) · 3.34 KB
/
gameover.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
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
package mao;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class gameover extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
gameover frame = new gameover();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public gameover() throws InterruptedException, UnsupportedAudioFileException, IOException, LineUnavailableException {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int width = (int)screenSize.getWidth();
int height = (int)screenSize.getHeight();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(0, 0, 1500, 800);
contentPane = new JPanel();
contentPane.setLayout(null);
setContentPane(contentPane);
setExtendedState(JFrame.MAXIMIZED_BOTH);
setUndecorated(true);
Scanner x = new Scanner(new File("src/userdata/currentaccount.txt"));
Scanner in = new Scanner(new File("src/userdata/" + x.nextLine() + ".txt"));
in.nextLine();
in.nextLine();
String scorenum = in.nextLine();
float volume = Float.parseFloat(in.nextLine())/100;
System.out.println(volume);
in.reset();
File soundFile = new File("audio/walk.wav");
AudioInputStream audioIn = AudioSystem.getAudioInputStream(soundFile);
Clip clip = AudioSystem.getClip();
clip.open(audioIn);
FloatControl gainControl = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
float range = gainControl.getMaximum() - gainControl.getMinimum()/2;
float gain = (range * volume) + gainControl.getMinimum()/2;
gainControl.setValue(gain);
if(volume == 0) {
gainControl.setValue(gainControl.getMinimum());
}
else {
gainControl.setValue(gain);
}
Toolkit toolkit = Toolkit.getDefaultToolkit();
MediaTracker tracker = new MediaTracker(this);
Image backgroundimg = toolkit.getImage("images/gameover.png");
tracker.addImage(backgroundimg, 0);
tracker.waitForAll();
backgroundimg = backgroundimg.getScaledInstance(width,height, Image.SCALE_SMOOTH);
ImageIcon backgroundicon = new ImageIcon(backgroundimg);
JLabel background = new JLabel("");
background.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
titlescreen.main(null);
dispose();
}
});
background.setIcon(backgroundicon);
background.setBounds(0, 0, width, height);
contentPane.add(background);
}
}