-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.java
105 lines (81 loc) · 2.84 KB
/
Game.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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Game implements Runnable {
public static JLabel scores;
public void run() {
// Top-level frame
final JFrame frame = new JFrame("JumpUp!");
frame.setLocation(300,100);
frame.setBackground(Color.WHITE);
// Main playing area
final PongCourt court = new PongCourt();
frame.add(court, BorderLayout.CENTER);
//instructions
final JWindow w1 = new JWindow();
w1.setSize(500, 200);
w1.setBackground(Color.WHITE);
w1.setLocation(350, 200);
JTextPane textPane = new JTextPane();
textPane.setBackground(Color.GREEN);
textPane.setText("Welcome to JumpUp! The goal of this game is to jump...up!! " +
"Use the left and right arrow keys to bounce from paddle to paddle and see how high you can get! " +
"Be careful though, the paddles quickly fall down after you jump, so be sure " +
"to JumpUp! Watch out for the moving paddles! Try to get the yellow powerup, it will help you on your journey up! " +
"Press resume game to go back to your game. You will have 3 seconds to prepare!");
w1.add(textPane);
//resume game button
final JButton resume= new JButton("Resume game");
resume.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
w1.setVisible(false);
try {
Thread.sleep(3000);
court.restartTimer();
court.requestFocus();
resume.setVisible(false);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
});
//Instruction button
final JPanel panel = new JPanel();
frame.add(panel, BorderLayout.NORTH);
final JButton instructions= new JButton("Instructions");
instructions.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
court.stopTimer();
w1.setVisible(true);
resume.setVisible(true);
}
});
// Reset button
final JButton reset = new JButton("New Game");
reset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
court.startTimer();
court.reset();
}
});
panel.add(resume);
resume.setVisible(false);
panel.add(instructions);
panel.add(reset);
scores= new JLabel();
scores.setText("Score " + court.score);
panel.add(scores);
// Put the frame on the screen
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
// Start the game running
court.reset();
}
/*
* Get the game started!
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Game());
}
}