-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameFrame.java
More file actions
executable file
·90 lines (72 loc) · 2.21 KB
/
GameFrame.java
File metadata and controls
executable file
·90 lines (72 loc) · 2.21 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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* Write a description of class GameFrame here.
*
* @Author Dexter Antonio
* @version May 12, 2013
*/
public class GameFrame implements ActionListener {
public static final int FRAME_HEIGHT = 700; //the frame height
public static final int FRAME_LENGTH = 700; //the frame length
private AsteroidGame gameStatus;
private JFrame frame; //the actual frame we'll be showing
private GameWindow court; //the window we'll be drawing
private Timer animator; //a timer to control animation
/**
* Creates a new GameFrame object.
*/
public GameFrame(GameWindow window)
{
frame = new JFrame("Asteroids"); //make the JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
court = window;
court.setPreferredSize(new Dimension(GameFrame.FRAME_LENGTH,GameFrame.FRAME_HEIGHT));
frame.getContentPane().add(court); //put the court in the frame
animator = new Timer(30,this); //create the timer, with this object controlling it
frame.pack(); //make everything the preferred size
frame.setVisible(true); //show the frame
startAnimation(); //start the animation!
}
/**
* Method that controls the animation timer
*/
public void actionPerformed(ActionEvent e)
{
court.repaint();
}
/**
* Starts the animation timer
*/
public void startAnimation()
{
animator.start();
}
/**
* Method gameOver is exicuted when the player loses the game. It exicutes the court/windows gameOver method, and repaints the court one last time before
* stopping the animation.
*
*/
public void gameOver(){
court.gameOver();
court.repaint();
animator.stop();
}
/**
* method reset. Resests the gameWindow object that this animator is animating and starts the animator
*
*/
public void reset()
{
court.resetGame();
animator.start();
}
/**
* Stops the animation timer
*/
public void pauseAnimation()
{
animator.stop();
}
}