Skip to content

Commit d421be0

Browse files
committed
Published new recipe ManyAnimals w/Jim
1 parent d3b210f commit d421be0

File tree

3 files changed

+13
-62
lines changed

3 files changed

+13
-62
lines changed
-6 Bytes
Binary file not shown.

TeachingKidsProgramming/src/org/teachingkidsprogramming/section07events/ConnectTheDots.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class ConnectTheDots implements MouseRightClickListener, MouseLeftClickLi
77
{
88
public static void main(String[] args)
99
{
10-
//Create a new 'Connect The Dots' window. --#1.1
10+
//Create a new 'Connect The Dots' object. --#1.1
1111
}
1212
public ConnectTheDots()
1313
{

TeachingKidsProgramming/src/org/teachingkidsprogramming/section07events/ManyAnimals.java

Lines changed: 12 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,29 @@
11
package org.teachingkidsprogramming.section07events;
22

3-
import java.util.ArrayList;
4-
5-
import org.teachingextensions.logo.MultiTurtlePanel;
6-
import org.teachingextensions.logo.Turtle;
7-
import org.teachingextensions.windows.MouseLeftClickListener;
8-
9-
public class ManyAnimals implements MouseLeftClickListener
3+
public class ManyAnimals
104
{
115
public ManyAnimals()
126
{
137
showSomeTurtles();
148
}
159
//create container for Turtles HINT: Use ArrayList
16-
public ArrayList<Turtle> turtles = new ArrayList<Turtle>();
1710
//create a window for many turtles HINT: Use MultiTurtlePanel
18-
public MultiTurtlePanel mt = new MultiTurtlePanel();
1911
private void showSomeTurtles()
2012
{
2113
//show the panel
22-
mt.showPanel();
23-
//listen for left mouse button click
24-
//mt.addMouseLeftClickListener(this);
2514
//set the size to 100
26-
int size = 100;
27-
//add three turtles HINT: Use a For loop
28-
for (int i = 1; i <= 3; i++)
29-
{
30-
//create a turtle
31-
Turtle turtle = new Turtle();
32-
//add the turtles to the container for turtles
33-
turtles.add(turtle);
34-
}
35-
//add all turtles to the window HINT: Use a FOR loop
36-
for (Turtle turtle : turtles)
37-
{
38-
//NOTE: must call addTurtle BEFORE calling other methods
39-
//add all turtles to the window
40-
mt.addTurtle(turtle);
41-
}
15+
//add three turtles HINT: FOR loop which 'does an action'
16+
//create a turtle
17+
//add the turtles to the container for turtles
18+
//add all turtles to the window HINT: Use a foreach loop
19+
//NOTE: must call addTurtle BEFORE calling other methods
20+
//add all turtles to the window
4221
//teleport all turtles on the window HINT: Use a FOR loop and ZERO
43-
for (int i = 0; i < 3; i++)
44-
{
45-
//set the X position to i*100 + 350
46-
turtles.get(i).setX(i * 100 + 350);
47-
//set the Y position to i*100 + 100
48-
turtles.get(i).setY(i * 100 + 100);
49-
}
50-
//set some values for all turtles HINT: Use a FOR loop
51-
for (Turtle turtle : turtles)
52-
{
53-
//set the speed of all turtle's to 7
54-
turtle.setSpeed(7);
55-
//have every turtle draw a star of the current size
56-
turtle.drawStar(size);
57-
}
58-
}
59-
@Override
60-
//threading error - Virtual Proctor contention
61-
public void onLeftMouseClick(int x, int y)
62-
{
63-
int size = 200;
64-
//create a new Turtle
65-
Turtle turtle = new Turtle();
66-
//add another turtle to the turtles
67-
turtles.add(turtle);
68-
// the turtle to the window
69-
mt.addTurtle(turtle);
70-
turtle.show();
71-
// teleport the new turtle to the x and y of the mouse click
72-
turtle.setX(x);
73-
turtle.setY(y);
74-
// have this turtle draw a star
75-
turtle.drawStar(size);
22+
//set the X position to i*100 + 350
23+
//set the Y position to i*100 + 100
24+
//set some values for all turtles HINT: Use a foreach loop
25+
//set the speed of all turtle's to 7
26+
//have every turtle draw a star of the current size
7627
}
7728
public static void main(String[] args)
7829
{

0 commit comments

Comments
 (0)