11package org .teachingkidsprogramming .section07events ;
22
3+ import java .util .ArrayList ;
4+
35import org .teachingextensions .logo .MultiTurtlePanel ;
46import org .teachingextensions .logo .Turtle ;
57import org .teachingextensions .windows .MouseLeftClickListener ;
@@ -10,30 +12,61 @@ public ManyAnimals()
1012 {
1113 showSomeTurtles ();
1214 }
15+ //create an ArrayList of Turtle Objects
16+ public ArrayList <Turtle > turtles = new ArrayList <Turtle >();
17+ //create a window for many turtles
18+ public MultiTurtlePanel mt = new MultiTurtlePanel ();
1319 private void showSomeTurtles ()
1420 {
15- MultiTurtlePanel mt = new MultiTurtlePanel ();
16- Turtle t1 = new Turtle ();
17- mt .addTurtle (t1 );
18- t1 .setX (100 );
19- t1 .setY (300 );
20- Turtle t2 = new Turtle ();
21- mt .addTurtle (t2 );
22- t1 .setX (300 );
23- t1 .setY (100 );
2421 mt .showPanel ();
22+ //Have SimpleBubble listen for when the left mouse button is clicked in your program window
23+ //mt.addMouseLeftClickListener(this);
24+ int size = 100 ;
25+ //add three turtles
26+ for (int i = 1 ; i <= 3 ; i ++)
27+ {
28+ //create a turtle
29+ Turtle turtle = new Turtle ();
30+ //add the turtles to the turtles
31+ turtles .add (turtle );
32+ }
33+ //add all the turtles to the window
34+ for (Turtle turtle : turtles )
35+ {
36+ //must call addTurtle BEFORE calling other methods
37+ //add the first turtle to the windows
38+ mt .addTurtle (turtle );
39+ }
40+ //set the X, Y - teleport
41+ for (int i = 0 ; i < 3 ; i ++)
42+ {
43+ turtles .get (i ).setX (i * 100 + 350 );
44+ turtles .get (i ).setY (i * 100 + 100 );
45+ }
46+ for (Turtle turtle : turtles )
47+ {
48+ //have the first Turtle draw a star
49+ turtle .setSpeed (7 );
50+ turtle .drawStar (size );
51+ }
2552 }
2653 @ Override
54+ //threading error - Virtual Proctor contention
2755 public void onLeftMouseClick (int x , int y )
2856 {
29- // createTurtles (recipe below) --#8
30- //------------- Recipe for createTurtles --#8
31- // Remove previous Tortoise from your program window --#9
32- // programWindow.removePaintable();
33- // Set the count of Turtles to a random number between 10 and 50 --#2.5
34- // Create a tortoise at 200, 300 --#2.1
35- // Add the circle to your program window --#2.4
36- //------------- End of createTurtles recipe --#8
57+ int size = 200 ;
58+ //create a new Turtle
59+ Turtle turtle = new Turtle ();
60+ //add another turtle to the turtles
61+ turtles .add (turtle );
62+ // the turtle to the window
63+ mt .addTurtle (turtle );
64+ turtle .show ();
65+ // teleport the new turtle to the x and y of the mouse click
66+ turtle .setX (x );
67+ turtle .setY (y );
68+ // have this turtle draw a star
69+ turtle .drawStar (size );
3770 }
3871 public static void main (String [] args )
3972 {
0 commit comments