Skip to content

Commit 4e8817c

Browse files
committed
working on SimpleBubble Quiz w/Jim
1 parent 07d2c72 commit 4e8817c

8 files changed

Lines changed: 53 additions & 70 deletions

File tree

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

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

3+
import java.awt.Color;
34
import java.awt.Font;
45
import java.awt.Graphics2D;
56

@@ -17,6 +18,7 @@ public class Text implements Paintable
1718
private final String string;
1819
private int x;
1920
private int y;
21+
private Color color;
2022
public Text(String string)
2123
{
2224
this.string = string;
@@ -52,7 +54,15 @@ public void paint(Graphics2D g, JPanel caller)
5254
{
5355
Font font = g.getFont();
5456
Font font2 = new Font(font.getName(), font.getStyle() | Font.BOLD, font.getSize());
57+
if (this.color != null)
58+
{
59+
g.setColor(this.color);
60+
}
5561
g.setFont(font2);
5662
g.drawString(string, x, y);
5763
}
64+
public void setPenColor(Color color)
65+
{
66+
this.color = color;
67+
}
5868
}

src/org/teachingextensions/windows/ProgramWindow.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
import javax.swing.JFrame;
1010
import javax.swing.JPanel;
1111

12-
import org.teachingextensions.logo.Colors;
1312
import org.teachingextensions.logo.ImageBackground;
1413
import org.teachingextensions.logo.Paintable;
14+
import org.teachingextensions.logo.PenColors;
1515
import org.teachingextensions.logo.VirtualProctorWeb;
1616

1717
import com.spun.util.FrameCloser;
@@ -35,7 +35,7 @@ public ProgramWindow(String title)
3535
public ProgramWindow()
3636
{
3737
setPreferredSize(new Dimension(627, 442));
38-
setColor(Colors.Whites.White);
38+
setColor(PenColors.Whites.White);
3939
}
4040
public static void createStandardFrame(JFrame frame)
4141
{

src/org/teachingkidsprogramming/recipes/completed/Spiral.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static void main(String[] args)
1212
Tortoise.show();
1313
// Make the tortoise go as fast as possible --#4
1414
Tortoise.setSpeed(10);
15-
// Add Blue Violet to the Color Wheel --#7
15+
// Add Blue Violet to the Color Wheel (HINT: Use PenColors)--#7
1616
ColorWheel.addColor(PenColors.Purples.BlueViolet);
1717
// Add Violet to the Color Wheel --#8
1818
ColorWheel.addColor(PenColors.Purples.Violet);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import java.awt.Graphics2D;
66
import java.awt.RenderingHints;
77

8-
import org.teachingextensions.logo.Colors;
98
import org.teachingextensions.logo.Paintable;
9+
import org.teachingextensions.logo.PenColors;
1010
import org.teachingextensions.logo.Tortoise;
1111
import org.teachingextensions.logo.Turtle;
1212
import org.teachingextensions.logo.utils.TortoiseUtils;
@@ -15,7 +15,7 @@ public class QuizUtils
1515
{
1616
public static void displayScores(Graphics2D g, int x, boolean[] answers)
1717
{
18-
g.setColor(Colors.Blues.CornflowerBlue);
18+
g.setColor(PenColors.Blues.CornflowerBlue);
1919
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
2020
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
2121
g.setFont(new Font("Tahoma", Font.BOLD, 14));
@@ -33,16 +33,16 @@ public static void displayScores(Graphics2D g, int x, boolean[] answers)
3333
{
3434
boolean b = answers[i];
3535
y += 25;
36-
g.setColor(Colors.Blues.LightBlue);
36+
g.setColor(PenColors.Blues.LightBlue);
3737
g.drawString(String.format("Question %s - ", i + 1), x, y);
3838
if (b)
3939
{
40-
g.setColor(Colors.Greens.ForestGreen);
40+
g.setColor(PenColors.Greens.ForestGreen);
4141
g.drawString("Pass", x + 90, y);
4242
}
4343
else
4444
{
45-
g.setColor(Colors.Reds.Red);
45+
g.setColor(PenColors.Reds.Red);
4646
g.drawString("Fail", x + 90, y);
4747
}
4848
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
public class SimpleBubbleQuizAdapter
66
{
7-
public int counter = 0;
7+
public int counter = 0;
8+
public boolean leftClickWiredUp;
89
public void drawNextBase()
910
{
1011
goToNextBase(100);
@@ -30,13 +31,17 @@ public void drawDiamond(int size)
3031
public void question1()
3132
{
3233
}
33-
public void question2(String letter1)
34+
public void question2()
3435
{
3536
}
3637
public void question3()
3738
{
3839
}
39-
public void question4(org.teachingkidsprogramming.recipes.quizzes.graders.AdLibsQuizAdapter.Pieces pieces)
40+
public void question4()
4041
{
4142
}
43+
public void answerQuestion1()
44+
{
45+
this.leftClickWiredUp = true;
46+
}
4247
}
Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
package org.teachingkidsprogramming.recipes.quizzes.graders;
22

3-
import java.awt.Font;
43
import java.awt.Graphics2D;
54

65
import javax.swing.JPanel;
76

8-
import org.teachingextensions.logo.Colors;
97
import org.teachingextensions.logo.Paintable;
8+
import org.teachingextensions.logo.PenColors;
109
import org.teachingextensions.logo.Tortoise;
11-
import org.teachingkidsprogramming.recipes.quizzes.graders.AdLibsQuizAdapter.Pieces;
1210

1311
public class SimpleBubbleQuizGrader implements Paintable
1412
{
15-
private static class Model
16-
{
17-
public String three;
18-
public Model(String three)
19-
{
20-
this.three = three;
21-
}
22-
}
2313
private boolean[] answers = new boolean[4];
2414
public static int TURTLE_SPEED = 9;
2515
private SimpleBubbleQuizAdapter quiz;
@@ -29,14 +19,10 @@ private void displayScreen()
2919
Tortoise.show();
3020
Tortoise.setX(150);
3121
Tortoise.setY(200);
32-
Tortoise.setPenColor(Colors.Greens.GreenYellow);
22+
Tortoise.setPenColor(PenColors.Greens.GreenYellow);
3323
quiz.drawDiamond(100);
3424
quiz.question1();
3525
quiz.question3();
36-
/*for (int i = 1; i <= 4; i++)
37-
{
38-
drawNextBase();
39-
}*/
4026
}
4127
public void grade(SimpleBubbleQuizAdapter quiz)
4228
{
@@ -45,48 +31,11 @@ public void grade(SimpleBubbleQuizAdapter quiz)
4531
}
4632
public void paint(Graphics2D g, JPanel caller)
4733
{
34+
this.answers[0] = quiz.leftClickWiredUp;
4835
QuizUtils.displayScores(g, 300, answers);
4936
drawRewardShape(g);
5037
}
5138
public void drawRewardShape(Graphics2D g)
5239
{
53-
drawWin(g);
54-
drawGame(g);
55-
}
56-
private void drawGame(Graphics2D g)
57-
{
58-
Pieces pieces = new Pieces();
59-
quiz.question4(pieces);
60-
pieces.middle = "am";
61-
}
62-
private void drawWin(Graphics2D g)
63-
{
64-
quiz.question2("n");
65-
}
66-
private void drawWord(Graphics2D g, String word, int x, int y, boolean horizontal)
67-
{
68-
char[] letters = word.toUpperCase().toCharArray();
69-
int dx = horizontal ? 1 : 0;
70-
int dy = horizontal ? 0 : 1;
71-
for (int i = 0; i < letters.length; i++)
72-
{
73-
char c = letters[i];
74-
drawLetter(getPosition(x + dx * i), getPosition(y + dy * i), c, g);
75-
}
76-
}
77-
private int getPosition(int i)
78-
{
79-
return 100 + i * 53;
80-
}
81-
private void drawLetter(int x, int y, char c, Graphics2D g)
82-
{
83-
g.setColor(Colors.Browns.BurlyWood);
84-
g.drawRect(x, y, 50, 50);
85-
g.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 36));
86-
int charWidth = g.getFontMetrics().charWidth(c);
87-
int charHeight = g.getFontMetrics().getAscent();
88-
int textY = y + (40 - charHeight) / 2 + charHeight;
89-
int textX = x + (50 - charWidth) / 2;
90-
g.drawString("" + c, textX, textY);
9140
}
9241
}

src/org/teachingkidsprogramming/section01forloops/Spiral.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ public static void main(String[] args)
66
{
77
// Show the tortoise --#1
88
// Make the tortoise go as fast as possible --#4
9-
// Add Purple to the Color Wheel --#7
9+
// Add Blue Violet to the Color Wheel (HINT: Use PenColors)--#7
1010
// Add Violet to the Color Wheel --#8
11-
// Add Blue Violet to the Color Wheel --#9
11+
// Add Purple to the Color Wheel --#9
1212
// Do the following 75 times --#3
1313
// Change the pen color of the line the tortoise draws the next color on the Color Wheel --#6
1414
// Move the tortoise 5 times the current line number you are drawing --#5

src/org/teachingkidsprogramming/section07events/SimpleBubbleQuiz.java

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

3+
import org.teachingextensions.logo.PenColors;
34
import org.teachingextensions.logo.Tortoise;
5+
import org.teachingextensions.logo.shapes.Text;
46
import org.teachingextensions.windows.MouseLeftClickListener;
57
import org.teachingextensions.windows.MouseRightClickListener;
68
import org.teachingkidsprogramming.recipes.quizzes.graders.SimpleBubbleQuizAdapter;
@@ -18,10 +20,15 @@ public void question1()
1820
Tortoise.getBackgroundWindow().addMouseLeftClickListener(this);
1921
//action: tortoise move to corner and draw a base
2022
}
21-
public void question2(String letter1)
23+
public void question2()
2224
{
23-
//code: add text 'You got a single' and then left click on the first base
24-
//action: fail first in all case, draw base and pass after click
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());
2532
}
2633
public void question3()
2734
{
@@ -33,6 +40,9 @@ public void question4()
3340
{
3441
//code: add text 'You got a home run' and then right click on the home plate
3542
//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());
3646
}
3747
public static void main(String[] args)
3848
{
@@ -43,6 +53,14 @@ public void onLeftMouseClick(int x, int y)
4353
{
4454
if (counter < 3)
4555
{
56+
if (counter == 0)
57+
{
58+
this.answerQuestion1();
59+
question2();
60+
Text baseHit = new Text("Keep Running!");
61+
baseHit.setPenColor(PenColors.Oranges.Orange);
62+
baseHit.setTopLeft(105, 35).addTo(Tortoise.getBackgroundWindow());
63+
}
4664
drawNextBase();
4765
counter = counter + 1;
4866
}
@@ -51,6 +69,7 @@ public void onLeftMouseClick(int x, int y)
5169
public void onRightMouseClick(int x, int y)
5270
{
5371
if (counter != 3) { return; }
72+
question4();
5473
drawNextBase();
5574
}
5675
}

0 commit comments

Comments
 (0)