forked from League-Archive/IntroToJavaWorkshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobotTreasureHunt.java
More file actions
113 lines (86 loc) · 3.12 KB
/
RobotTreasureHunt.java
File metadata and controls
113 lines (86 loc) · 3.12 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package section4;
import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.event.KeyEvent;
import java.net.MalformedURLException;
import java.net.URI;
import javax.swing.JOptionPane;
//import org.teachingextensions.logo.ImageBackground;
//import org.teachingextensions.logo.Paintable;
//import org.teachingextensions.logo.robot;
import org.jointheleague.graphical.robot.Robot;
public class RobotTreasureHunt implements KeyEventDispatcher{
// 1. Create a new mini robot (type "mini" inside the parentheses)
private void goUp() throws InterruptedException {
// 2. Make the robot move up the screen (use setAngle(angle) and microMove(distance))
}
private void goDown() throws InterruptedException{
// 3. make the robot move down the screen (use setAngle(angle) and microMove(distance))
}
private void turnLeft() throws InterruptedException{
// 4. Make the robot turn to the left (use setAngle(angle) and microMove(distance))
}
private void turnRight() throws InterruptedException{
// 5. make the robot turn to the right (use setAngle(angle) and microMove(distance))
}
private void spaceBarWasPressed() {
// 5. Change ROBOTNAME below to match the name of the robot you created in step 1. THEN, remove the slashes at the beginning of the next two lines
//int robotXLocation = ROBOTNAME.getX();
//int robotYLocation = ROBOTNAME.getY();
// 6. Print the robotXLocation and robotYLocation variables to the console
// 7. If robot is at same location as the little girl
// --make a pop-up tell the robot where to go next
// 8. Give the user subsequent clues at different locations on the image
// (pirate robot, swamp, parrots, etc.)
// 9. If the robot is in the final location
// --call the treasureFound() method
}
private void go() {
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);
Robot.setWindowImage("section4/treasure_hunt.jpg");
JOptionPane.showMessageDialog(null, "Ask the girl for help with your quest. Press the space bar to ask.");
}
public boolean dispatchKeyEvent(KeyEvent e) {
if (e.getID() == KeyEvent.KEY_PRESSED) {
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
try {
turnRight();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
else if (e.getKeyCode() == KeyEvent.VK_LEFT)
try {
turnLeft();
} catch (InterruptedException e2) {
e2.printStackTrace();
}
else if (e.getKeyCode() == 38)
try {
goUp();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
else if (e.getKeyCode() == KeyEvent.VK_DOWN)
try {
goDown();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
else if (e.getKeyCode() == KeyEvent.VK_SPACE)
spaceBarWasPressed();
}
return false;
}
static void treasureFound() {
try {
URI uri = new URI("https://www.youtube.com/watch?v=G0aIg4N6aro");
java.awt.Desktop.getDesktop().browse(uri);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main (String[] args) throws MalformedURLException {
new RobotTreasureHunt().go();
}
}