-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
63 lines (54 loc) · 1.23 KB
/
Game.java
File metadata and controls
63 lines (54 loc) · 1.23 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
/*
* Levi Crider
* 2/9/22
* Legend of Zelda
*
*
*
*/
import javax.swing.JFrame;
import java.awt.Toolkit;
//JFrame is the box that surrounds the internal application
public class Game extends JFrame{
//Member variables
Model model;
View view;
Controller controller;
//Constructor
public Game(){
model = new Model();
controller = new Controller(model);
view = new View(controller, model); //Created two new objects. A controller and the view
view.addMouseListener(controller);
this.setTitle("Legend of Zelda");
this.setSize(700, 500);
this.setFocusable(true);
this.getContentPane().add(view);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.addKeyListener(controller);
model.loadFile();
}
//Runs the game
public void run(){
while(true){
controller.update();
model.update();
view.repaint(); // Indirectly calls View.paintComponent
Toolkit.getDefaultToolkit().sync(); // Updates screen
// Go to sleep for 40 miliseconds (25 fps)
try{
Thread.sleep(40);
}
catch(Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}
public static void main(String[] args)
{
Game g = new Game(); //Creating the game object
g.run();
}
}