-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathController.java
65 lines (55 loc) · 1.75 KB
/
Controller.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
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
import java.util.*;
//Input new arguments to the call to model object's updateLocationAndDirection to pass in new info from View to Model
/**
* Group 11-5 Andrew Riegner, Arnav Bindra, Sumeet Kothare, Tong Zhao, Woody Hu
* @author skothare
*
*/
public class Controller {
private Model model;
private View view;
public Controller(){
view = new View();
model = new Model(view.picSize, view.picSize, view.getWidth(), view.getHeight());
}
public static void main(String[] args) { //this was the only thing we changed, it's basically just the main of Animation4Thread
Controller c = new Controller();
EventQueue.invokeLater(new Runnable(){
// Create a new Action here- gameAction
Action gameAction = new AbstractAction(){
public void actionPerformed(ActionEvent event){
if(!c.view.isStopped()){
if(c.view.getChangeDir()) {
Random r = new Random();
c.model.setDirect(r.nextInt(7));
c.view.setChangeDir(false);
}
c.model.updateLocationAndDirection(c.view.viewUpdate,c.view.numDirection,c.view.jump,c.view.fire);
c.view.update(c.model.getX(),c.model.getY(),c.model.getDirect());
c.view.viewUpdate = false;
}
}
};
public void run(){
// Have an update method
Timer t = new Timer(c.view.drawDelay, gameAction);
t.start();
}
});
}
}