-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.java
More file actions
84 lines (73 loc) · 1.71 KB
/
Copy pathController.java
File metadata and controls
84 lines (73 loc) · 1.71 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
//Name: Jacob Smith
//Date: 9/11/20
//Description: This is the where the controls for the turle are held. Where
//the user can click or use the arroe keys to move the turle in all directions
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
class Controller implements ActionListener, MouseListener, KeyListener
{
View view;
Model model;
boolean keyLeft;
boolean keyRight;
boolean keyUp;
boolean keyDown;
Controller(Model m)
{
model = m;
}
public void actionPerformed(ActionEvent e)
{
view.removeButton();
}
void setView(View v)
{
view = v;
}
public void mousePressed(MouseEvent e)
{
model.setDestination(e.getX(), e.getY());
}
public void mouseReleased(MouseEvent e) { }
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
public void mouseClicked(MouseEvent e) { }
public void keyPressed(KeyEvent e)
{
switch(e.getKeyCode())
{
case KeyEvent.VK_RIGHT: keyRight = true; break;
case KeyEvent.VK_LEFT: keyLeft = true; break;
case KeyEvent.VK_UP: keyUp = true; break;
case KeyEvent.VK_DOWN: keyDown = true; break;
}
}
public void keyReleased(KeyEvent e)
{
switch(e.getKeyCode())
{
case KeyEvent.VK_RIGHT: keyRight = false; break;
case KeyEvent.VK_LEFT: keyLeft = false; break;
case KeyEvent.VK_UP: keyUp = false; break;
case KeyEvent.VK_DOWN: keyDown = false; break;
}
}
public void keyTyped(KeyEvent e)
{
}
void update()
{
if(keyRight)
model.dest_x++;
if(keyLeft)
model.dest_x--;
if(keyDown)
model.dest_y++;
if(keyUp)
model.dest_y--;
}
}