forked from League-Archive/IntroToJavaWorkshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeed_meeee.java
More file actions
90 lines (70 loc) · 1.99 KB
/
feed_meeee.java
File metadata and controls
90 lines (70 loc) · 1.99 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
public class feed_meeee {
// Copyright Wintriss Technical Schools 2013
/****** MUST BE USED WITH JAVA 1.6 *****/
import java.awt.Component;
import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.Label;
import java.awt.event.KeyEvent;
import org.teachingextensions.logo.Tortoise;
import org.teachingextensions.logo.TurtlePanel;
public class FeedTheTortoise implements KeyEventDispatcher
{
private void feedTheTortoise()
{
// 1. use the addFood() method to add food for the tortoise
addFood()
}
private void goUp()
{
// 2. Print “going up”. Test it out by running your code and pressing the up key
// 3. Make the tortoise move up the screen
}
private void goDown()
{
// 4. make the tortoise move down the screen
}
private void goLeft()
{
// 5. make the tortoise move left
}
private void goRight()
{
// 6. make the tortoise move right
}
private void checkIfFoodFound() throws Exception
{
int tortoiseLocationX = Tortoise.getX();
int tortoiseLocationY = Tortoise.getY();
// 7. Print out the variables for tortoiseLocationX and tortoiseLocationY
// 8. if tortoise is at same location as food
// print "chomp"
// say “chomp” with Runtime.getRuntime().exec("say chomp");
// call the eatFood() method
}
private void eatFood() {
component.setText("");
}
private void addFood(int x, int y)
{
component.setLocation(x, y);
window.add(component);
}
TurtlePanel window = Tortoise.getBackgroundWindow();
Label component = new Label("*");
public static void main(String[] args)
{
FeedTheTortoise feeder = new FeedTheTortoise();
feeder.controlTheTortoise();
feeder.feedTheTortoise();
}
private void controlTheTortoise()
{
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);
Tortoise.show();
Tortoise.setSpeed(10);
}
public boolean dispatchKeyEvent(KeyEvent e)
{
if (e.getID() == KeyEvent.KEY_PRESSED)
}