-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.java
More file actions
65 lines (56 loc) · 1.08 KB
/
Game.java
File metadata and controls
65 lines (56 loc) · 1.08 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
/*
Name: Creighton Young
Date: 9/24/2020
Assigment: Make a bunch of pipes appear
*/
import javax.swing.JFrame;
import java.awt.Toolkit;
public class Game extends JFrame
{
Model model;
View view;
Controller controller;
public Game()
{
model = new Model();
controller = new Controller(model);
view = new View(controller, model);
this.setTitle("Mario Jump");
this.setSize(1200, 600);
this.setFocusable(true);
this.getContentPane().add(view);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
view.addMouseListener(controller);
this.addKeyListener(controller);
}
public static void main(String[] args)
{
Game g = new Game();
g.run();
}
public void run()
{
while(true)
{
controller.update();
model.update();
view.repaint(); // Indirectly calls View.paintComponent
Toolkit.getDefaultToolkit().sync(); // Updates screen
// Go to sleep for 50 miliseconds
try
{
Thread.sleep(50);
}
catch(Exception e)
{
e.printStackTrace();
System.exit(1);
}
}
}
void setModel(Model m)
{
model = m;
}
}