Skip to content

Commit fa52cda

Browse files
committed
working on SuperSoundingTurtles recipe
1 parent 48c6067 commit fa52cda

5 files changed

Lines changed: 65 additions & 67 deletions

File tree

src/main/java/org/teachingextensions/logo/utils/InterfaceUtils/TurtleFrame.java

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,74 @@
11
package org.teachingextensions.logo.utils.InterfaceUtils;
22

3+
import javax.swing.JComponent;
4+
import javax.swing.JFrame;
5+
36
import org.teachingextensions.approvals.lite.util.FrameCloser;
47
import org.teachingextensions.approvals.lite.util.WindowUtils;
58
import org.teachingextensions.virtualproctor.VirtualProctorWeb;
69

7-
import javax.swing.*;
8-
9-
public class TurtleFrame {
10+
public class TurtleFrame
11+
{
1012
public static final String TITLE = "TKPJava Turtle";
11-
private LazyFrame frame;
12-
private String title;
13-
14-
public TurtleFrame(JFrame frame) {
15-
if (frame == null) {
16-
throw new IllegalArgumentException("frame must not be null when creating a TurtleFrame");
17-
}
18-
13+
private LazyFrame frame;
14+
private String title;
15+
public TurtleFrame(JFrame frame)
16+
{
17+
if (frame == null) { throw new IllegalArgumentException(
18+
"frame must not be null when creating a TurtleFrame"); }
1919
this.frame = new LazyFrame(frame);
2020
}
21-
22-
public TurtleFrame(String title) {
23-
if (title == null) {
21+
public TurtleFrame(String title)
22+
{
23+
if (title == null)
24+
{
2425
title = TITLE;
2526
}
26-
2727
this.frame = new LazyFrame(title);
2828
}
29-
30-
public TurtleFrame() {
29+
public TurtleFrame()
30+
{
3131
this(TITLE);
3232
}
33-
34-
public static void createStandardFrame(JFrame frame) {
33+
public static void createStandardFrame(JFrame frame)
34+
{
3535
WindowUtils.testFrame(frame, new VirtualProctorWeb(), new FrameCloser());
3636
}
37-
38-
public TurtleFrame addContent(JComponent panel) {
37+
public TurtleFrame addContent(JComponent panel)
38+
{
3939
this.frame.getValue().getContentPane().add(panel);
4040
return this;
4141
}
42-
43-
public TurtleFrame setVisible(boolean visible) {
42+
public TurtleFrame setVisible(boolean visible)
43+
{
4444
this.frame.getValue().setVisible(visible);
4545
return this;
4646
}
47-
48-
public TurtleFrame setStandardLayout() {
47+
public TurtleFrame setStandardLayout()
48+
{
4949
createStandardFrame(this.frame.getValue());
5050
return this;
5151
}
52-
53-
private class LazyFrame {
52+
private class LazyFrame
53+
{
5454
private String title;
5555
private JFrame frame;
56-
57-
public LazyFrame(String title) {
58-
if (title == null) {
59-
throw new IllegalArgumentException("title must not be null when creating a LazyFrame");
60-
}
61-
56+
public LazyFrame(String title)
57+
{
58+
if (title == null) { throw new IllegalArgumentException(
59+
"title must not be null when creating a LazyFrame"); }
6260
this.title = title;
6361
}
64-
65-
public LazyFrame(JFrame frame) {
62+
public LazyFrame(JFrame frame)
63+
{
6664
this.frame = frame;
6765
}
68-
69-
public JFrame getValue() {
70-
if (this.frame == null) {
66+
public JFrame getValue()
67+
{
68+
if (this.frame == null)
69+
{
7170
this.frame = new JFrame(this.title);
7271
}
73-
7472
return this.frame;
7573
}
7674
}

src/main/java/org/teachingkidsprogramming/recipes/completed/section07objects/SuperSoundingTurtles.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,27 @@ public static void main(String[] args)
1717
}
1818
private void showSomeTurtles()
1919
{
20-
makeSpeedyTurtle();
2120
makeSlowTurtle();
21+
makeSpeedyTurtle();
2222
makeCrazyTurtle();
2323
}
24-
private void makeSpeedyTurtle()
25-
{
26-
Turtle speedyTurtle = new Turtle();
27-
Sound s = new Sound();
28-
s.setSound(Sound.TKPSound.LLCoolJYaKnow);
29-
speedyTurtle.setSound(s);
30-
mtw.addAndShowTurtle(speedyTurtle);
31-
speedyTurtle.setSpeed(10);
32-
speedyTurtle.drawTriangle(100);
33-
speedyTurtle.speak();
34-
}
3524
private void makeSlowTurtle()
3625
{
3726
Turtle slowTurtle = new Turtle();
3827
slowTurtle.setSound(new Sound(Sound.TKPSound.Ahem));
3928
mtw.addAndShowTurtle(slowTurtle);
40-
slowTurtle.drawTriangle(-50);
4129
slowTurtle.speak();
30+
slowTurtle.drawTriangle(-50);
31+
}
32+
private void makeSpeedyTurtle()
33+
{
34+
Turtle speedyTurtle = new Turtle();
35+
// TODO: Event synchronization API needs updating to be able to match events with rendering order
36+
//speedyTurtle.setSound(new Sound(Sound.TKPSound.Gong));
37+
//speedyTurtle.speak();
38+
mtw.addAndShowTurtle(speedyTurtle);
39+
speedyTurtle.setSpeed(10);
40+
speedyTurtle.drawTriangle(100);
4241
}
4342
private void makeCrazyTurtle()
4443
{

src/main/java/org/teachingkidsprogramming/recipes/completed/section07objects/SuperTurtlesKataQuestion.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
//
77
//------------Kata Question---------------//
8-
// How would you add a sound when the crazy turtle draws lightning?
8+
// How would you add a sound before the slow turtle draws a triangle?
99
// Write out the steps in English
1010
// Then translate the steps into code
1111
// Make sure to run after each line
@@ -23,23 +23,23 @@ public static void main(String[] args)
2323
}
2424
private void showSomeTurtles()
2525
{
26-
makeSpeedyTurtle();
2726
makeSlowTurtle();
27+
makeSpeedyTurtle();
2828
makeCrazyTurtle();
2929
}
30+
private void makeSlowTurtle()
31+
{
32+
Turtle slowTurtle = new Turtle();
33+
mtw.addAndShowTurtle(slowTurtle);
34+
slowTurtle.drawTriangle(-50);
35+
}
3036
private void makeSpeedyTurtle()
3137
{
3238
Turtle speedyTurtle = new Turtle();
3339
mtw.addAndShowTurtle(speedyTurtle);
3440
speedyTurtle.setSpeed(10);
3541
speedyTurtle.drawTriangle(100);
3642
}
37-
private void makeSlowTurtle()
38-
{
39-
Turtle slowTurtle = new Turtle();
40-
mtw.addAndShowTurtle(slowTurtle);
41-
slowTurtle.drawTriangle(-50);
42-
}
4343
private void makeCrazyTurtle()
4444
{
4545
Turtle crazyTurtle = new Turtle();

src/main/java/org/teachingkidsprogramming/recipes/completed/section08events/ConnectTheDots.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public ConnectTheDots()
1818
{
1919
setUpTheWindow();
2020
prepareColorPalette();
21+
// NOTE for teachers: Using the Tortoise object here as we are having the Tortoise draw a line (trail) for this recipe
2122
// Listen for left clicks on the window for the tortoise
2223
Tortoise.getBackgroundWindow().addMouseLeftClickListener(this);
2324
// Listen for right clicks on the window for the tortoise

src/main/java/org/teachingkidsprogramming/recipes/completed/section08events/SimpleBubbleVariation.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ public SimpleBubbleVariation()
2222
programWindow.addMouseRightClickListener(this);
2323
prepareColorPalette();
2424
}
25-
private void prepareColorPalette()
26-
{
27-
ColorWheel.addColor(PenColors.Blues.LightSteelBlue);
28-
ColorWheel.addColor(PenColors.Blues.Blue);
29-
ColorWheel.addColor(PenColors.Blues.DarkBlue);
30-
ColorWheel.addColor(PenColors.Purples.Purple);
31-
}
3225
@Override
3326
public void onLeftMouseClick(int x, int y)
3427
{
@@ -61,6 +54,13 @@ private void createBubbles(int x1, int y1)
6154
createBubble(x1 + i * 15, y1 + i * 15);
6255
}
6356
}
57+
private void prepareColorPalette()
58+
{
59+
ColorWheel.addColor(PenColors.Blues.LightSteelBlue);
60+
ColorWheel.addColor(PenColors.Blues.Blue);
61+
ColorWheel.addColor(PenColors.Blues.DarkBlue);
62+
ColorWheel.addColor(PenColors.Purples.Purple);
63+
}
6464
public static void main(String[] args)
6565
{
6666
new SimpleBubbleVariation();

0 commit comments

Comments
 (0)