Skip to content

Commit 499d63d

Browse files
committed
finished SimpleBubbleQuiz w/Jim
1 parent 4e8817c commit 499d63d

7 files changed

Lines changed: 135 additions & 26 deletions

File tree

src/org/teachingextensions/logo/shapes/Text.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,25 @@ public void paint(Graphics2D g, JPanel caller)
6161
g.setFont(font2);
6262
g.drawString(string, x, y);
6363
}
64-
public void setPenColor(Color color)
64+
public Text setPenColor(Color color)
6565
{
6666
this.color = color;
67+
return this;
68+
}
69+
public String getContent()
70+
{
71+
return this.string;
72+
}
73+
public Color getPenColor()
74+
{
75+
return this.color;
76+
}
77+
public int getX()
78+
{
79+
return this.x;
80+
}
81+
public int getY()
82+
{
83+
return this.y;
6784
}
6885
}

src/org/teachingextensions/windows/ProgramWindow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
@SuppressWarnings({"serial", "deprecation"})
2525
public class ProgramWindow extends JPanel
2626
{
27-
private ArrayList<Paintable> additional = new ArrayList<Paintable>();
27+
public ArrayList<Paintable> additional = new ArrayList<Paintable>();
2828
public ProgramWindow(String title)
2929
{
3030
this();
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.teachingkidsprogramming.recipes.completed;
2+
3+
import org.teachingextensions.logo.PenColors;
4+
import org.teachingextensions.logo.Tortoise;
5+
import org.teachingextensions.logo.shapes.Text;
6+
import org.teachingextensions.windows.MouseLeftClickListener;
7+
import org.teachingextensions.windows.MouseRightClickListener;
8+
import org.teachingkidsprogramming.recipes.quizzes.graders.SimpleBubbleQuizAdapter;
9+
import org.teachingkidsprogramming.recipes.quizzes.graders.SimpleBubbleQuizGrader;
10+
11+
public class SimpleBubbleQuiz extends SimpleBubbleQuizAdapter
12+
implements
13+
MouseLeftClickListener,
14+
MouseRightClickListener
15+
{
16+
public void question1()
17+
{
18+
//code: In the Tortoise background window, have this quiz listen for when the left mouse button is clicked
19+
Tortoise.getBackgroundWindow().addMouseLeftClickListener(this);
20+
//action: YOU must left click on the first base to pass this question
21+
}
22+
public void question2()
23+
{
24+
//code: Write "Single!" on the screen in yellow at position 155,135
25+
new Text("Single!").setPenColor(PenColors.Yellows.Yellow).setTopLeft(155, 135)
26+
.addTo(Tortoise.getBackgroundWindow());
27+
}
28+
public void question3()
29+
{
30+
//code: In the Tortoise background window, have this quiz listen for when the right mouse button is clicked
31+
Tortoise.getBackgroundWindow().addMouseRightClickListener(this);
32+
//action: YOU must right click on the home plate (4th base) to pass this question
33+
}
34+
public void question4()
35+
{
36+
//code: Write "Home Run!" on the screen in lime green at position 105,235
37+
new Text("Home Run!").setPenColor(PenColors.Greens.LimeGreen).setTopLeft(105, 235)
38+
.addTo(Tortoise.getBackgroundWindow());
39+
}
40+
public static void main(String[] args)
41+
{
42+
new SimpleBubbleQuizGrader().grade(new SimpleBubbleQuiz());
43+
}
44+
@Override
45+
public void onLeftMouseClick(int x, int y)
46+
{
47+
if (counter < 3)
48+
{
49+
if (counter == 0)
50+
{
51+
this.answerQuestion1();
52+
question2();
53+
Text baseHit = new Text("Keep Running!");
54+
baseHit.setPenColor(PenColors.Oranges.Orange);
55+
baseHit.setTopLeft(105, 35).addTo(Tortoise.getBackgroundWindow());
56+
}
57+
drawNextBase();
58+
counter = counter + 1;
59+
}
60+
}
61+
@Override
62+
public void onRightMouseClick(int x, int y)
63+
{
64+
if (counter != 3) { return; }
65+
this.answerQuestion3();
66+
question4();
67+
drawNextBase();
68+
}
69+
}

src/org/teachingkidsprogramming/recipes/quizzes/graders/SimpleBubbleQuizAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class SimpleBubbleQuizAdapter
66
{
77
public int counter = 0;
88
public boolean leftClickWiredUp;
9+
public boolean rightClickWiredUp;
910
public void drawNextBase()
1011
{
1112
goToNextBase(100);
@@ -44,4 +45,8 @@ public void answerQuestion1()
4445
{
4546
this.leftClickWiredUp = true;
4647
}
48+
public void answerQuestion3()
49+
{
50+
this.rightClickWiredUp = true;
51+
}
4752
}

src/org/teachingkidsprogramming/recipes/quizzes/graders/SimpleBubbleQuizGrader.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.teachingextensions.logo.Paintable;
88
import org.teachingextensions.logo.PenColors;
99
import org.teachingextensions.logo.Tortoise;
10+
import org.teachingextensions.logo.shapes.Text;
1011

1112
public class SimpleBubbleQuizGrader implements Paintable
1213
{
@@ -32,9 +33,43 @@ public void grade(SimpleBubbleQuizAdapter quiz)
3233
public void paint(Graphics2D g, JPanel caller)
3334
{
3435
this.answers[0] = quiz.leftClickWiredUp;
36+
this.answers[2] = quiz.rightClickWiredUp;
37+
for (Paintable p : Tortoise.getBackgroundWindow().additional)
38+
{
39+
try
40+
{
41+
Text t = (Text) p;
42+
if (isAnswerToQuestion2(t))
43+
{
44+
this.answers[1] = true;
45+
}
46+
else if (isAnswerToQuestion4(t))
47+
{
48+
this.answers[3] = true;
49+
}
50+
}
51+
catch (Exception e)
52+
{
53+
//do nothing
54+
}
55+
}
3556
QuizUtils.displayScores(g, 300, answers);
3657
drawRewardShape(g);
3758
}
59+
private boolean isAnswerToQuestion2(Text t)
60+
{
61+
if (t.getContent() != "Single!") { return false; }
62+
if (t.getPenColor() != PenColors.Yellows.Yellow) { return false; }
63+
if (t.getX() != 155 || t.getY() != 135) { return false; }
64+
return true;
65+
}
66+
private boolean isAnswerToQuestion4(Text t)
67+
{
68+
if (t.getContent() != "Home Run!") { return false; }
69+
if (t.getPenColor() != PenColors.Greens.LimeGreen) { return false; }
70+
if (t.getX() != 105 || t.getY() != 235) { return false; }
71+
return true;
72+
}
3873
public void drawRewardShape(Graphics2D g)
3974
{
4075
}

src/org/teachingkidsprogramming/section06modelviewcontroller/AdLibsQuiz.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.teachingkidsprogramming.section06modelviewcontroller;
22

3-
import org.teachingextensions.simpleparser.Parser;
43
import org.teachingkidsprogramming.recipes.quizzes.graders.AdLibsQuizAdapter;
54
import org.teachingkidsprogramming.recipes.quizzes.graders.AdLibsQuizGrader;
65

@@ -9,22 +8,18 @@ public class AdLibsQuiz extends AdLibsQuizAdapter
98
public void question1(String letter1, String letter3)
109
{
1110
//set current value of word1 to be letter1 + 'o' + letter3
12-
word1 = letter1 + 'o' + letter3;
1311
}
1412
public void question2(String letter1)
1513
{
1614
//add the letter1 to the end of word2
17-
word2 = word2 + letter1;
1815
}
1916
public void question3(String templateText, Object model)
2017
{
2118
//use the parser to combine the template and the model as word3
22-
word3 = Parser.parse(templateText, model);
2319
}
2420
public void question4(Pieces pieces)
2521
{
2622
//set template4 to the template which does'g' + pieces.middle + 'e'
27-
template4 = "g{middle}e";
2823
}
2924
public static void main(String[] args)
3025
{

src/org/teachingkidsprogramming/section07events/SimpleBubbleQuiz.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,23 @@ public class SimpleBubbleQuiz extends SimpleBubbleQuizAdapter
1313
MouseLeftClickListener,
1414
MouseRightClickListener
1515
{
16-
//**THIS QUIZ IS IN PROGRESS
1716
public void question1()
1817
{
19-
//code: wire up left click to draw first base
20-
Tortoise.getBackgroundWindow().addMouseLeftClickListener(this);
21-
//action: tortoise move to corner and draw a base
18+
//code: In the Tortoise background window, have this quiz listen for when the left mouse button is clicked
19+
//action: YOU must left click on the first base to pass this question
2220
}
2321
public void question2()
2422
{
25-
//code: add text 'You got a single'
26-
//action: left click on the first base
27-
//grader: fail first in all case, draw base and pass after click
28-
// Write "Single!" in yellow on the screen at position 155,135
29-
Text baseHit = new Text("Single!");
30-
baseHit.setPenColor(PenColors.Yellows.Yellow);
31-
baseHit.setTopLeft(155, 135).addTo(Tortoise.getBackgroundWindow());
23+
//code: Write "Single!" on the screen in yellow at position 155,135
3224
}
3325
public void question3()
3426
{
35-
//wire up right click to get a home run
36-
Tortoise.getBackgroundWindow().addMouseRightClickListener(this);
37-
//so that when you click the Tortoise will move to home plate and draw it
27+
//code: In the Tortoise background window, have this quiz listen for when the right mouse button is clicked
28+
//action: YOU must right click on the home plate (4th base) to pass this question
3829
}
3930
public void question4()
4031
{
41-
//code: add text 'You got a home run' and then right click on the home plate
42-
//action: fail first in all case, draw base and pass after click
43-
Text baseHit = new Text("Home Run!");
44-
baseHit.setPenColor(PenColors.Greens.LimeGreen);
45-
baseHit.setTopLeft(105, 235).addTo(Tortoise.getBackgroundWindow());
32+
//code: Write "Home Run!" on the screen in lime green at position 105,235
4633
}
4734
public static void main(String[] args)
4835
{
@@ -69,6 +56,7 @@ public void onLeftMouseClick(int x, int y)
6956
public void onRightMouseClick(int x, int y)
7057
{
7158
if (counter != 3) { return; }
59+
this.answerQuestion3();
7260
question4();
7361
drawNextBase();
7462
}

0 commit comments

Comments
 (0)