Skip to content

Commit 10a5595

Browse files
committed
added SimpleBubbleQuiz stubs w/Samantha
1 parent e620c01 commit 10a5595

File tree

5 files changed

+208
-24
lines changed

5 files changed

+208
-24
lines changed
0 Bytes
Binary file not shown.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.teachingkidsprogramming.recipes.quizzes.graders;
2+
3+
public class SimpleBubbleQuizAdapter
4+
{
5+
public static class Pieces
6+
{
7+
public String beginning;
8+
public String middle;
9+
public String end;
10+
}
11+
public String word1;
12+
public String word2;
13+
public String word3;
14+
public String template4;
15+
public void question1(String letter1, String letter3)
16+
{
17+
}
18+
public void question2(String letter1)
19+
{
20+
}
21+
public void question3(String templateText, Object model)
22+
{
23+
}
24+
public void question4(org.teachingkidsprogramming.recipes.quizzes.graders.AdLibsQuizAdapter.Pieces pieces)
25+
{
26+
}
27+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package org.teachingkidsprogramming.recipes.quizzes.graders;
2+
3+
import java.awt.Font;
4+
import java.awt.Graphics2D;
5+
6+
import javax.swing.JPanel;
7+
8+
import org.teachingextensions.logo.Colors;
9+
import org.teachingextensions.logo.Paintable;
10+
import org.teachingextensions.logo.Tortoise;
11+
import org.teachingextensions.simpleparser.Parser;
12+
import org.teachingkidsprogramming.recipes.quizzes.graders.AdLibsQuizAdapter.Pieces;
13+
14+
public class SimpleBubbleQuizGrader implements Paintable
15+
{
16+
private static class Model
17+
{
18+
public String three;
19+
public Model(String three)
20+
{
21+
this.three = three;
22+
}
23+
}
24+
private boolean[] answers;
25+
public static int TURTLE_SPEED = 9;
26+
private SimpleBubbleQuizAdapter quiz;
27+
private void displayScreen()
28+
{
29+
QuizUtils.prepareScoringScreen(answers, this, TURTLE_SPEED);
30+
}
31+
public void grade(SimpleBubbleQuizAdapter quiz)
32+
{
33+
this.quiz = quiz;
34+
answers = new boolean[]{grade1You(), grade2Won(), grade3The(), grade4Game()};
35+
displayScreen();
36+
}
37+
public void paint(Graphics2D g, JPanel caller)
38+
{
39+
QuizUtils.displayScores(g, 300, answers);
40+
Tortoise.hide();
41+
drawRewardShape(g);
42+
}
43+
public void drawRewardShape(Graphics2D g)
44+
{
45+
drawYou(g);
46+
drawWin(g);
47+
drawThe(g);
48+
drawGame(g);
49+
}
50+
private void drawGame(Graphics2D g)
51+
{
52+
quiz.template4 = "";
53+
Pieces pieces = new Pieces();
54+
quiz.question4(pieces);
55+
pieces.middle = "am";
56+
String word = Parser.parse(quiz.template4, pieces);
57+
drawWord(g, word, 0, 4, true);
58+
}
59+
private void drawThe(Graphics2D g)
60+
{
61+
quiz.word3 = "";
62+
Pieces model = new Pieces();
63+
model.middle = "H";
64+
quiz.question3("T{middle}E", model);
65+
drawWord(g, quiz.word3, 3, 2, false);
66+
}
67+
private void drawWin(Graphics2D g)
68+
{
69+
quiz.word2 = "WO";
70+
quiz.question2("n");
71+
drawWord(g, quiz.word2, 1, 0, false);
72+
}
73+
private void drawWord(Graphics2D g, String word, int x, int y, boolean horizontal)
74+
{
75+
char[] letters = word.toUpperCase().toCharArray();
76+
int dx = horizontal ? 1 : 0;
77+
int dy = horizontal ? 0 : 1;
78+
for (int i = 0; i < letters.length; i++)
79+
{
80+
char c = letters[i];
81+
drawLetter(getPosition(x + dx * i), getPosition(y + dy * i), c, g);
82+
}
83+
}
84+
private int getPosition(int i)
85+
{
86+
return 100 + i * 53;
87+
}
88+
private void drawYou(Graphics2D g)
89+
{
90+
quiz.word1 = "NOT";
91+
quiz.question1("y", "u");
92+
drawWord(g, quiz.word1, 0, 1, true);
93+
}
94+
private void drawLetter(int x, int y, char c, Graphics2D g)
95+
{
96+
g.setColor(Colors.Browns.BurlyWood);
97+
g.drawRect(x, y, 50, 50);
98+
g.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 36));
99+
int charWidth = g.getFontMetrics().charWidth(c);
100+
int charHeight = g.getFontMetrics().getAscent();
101+
int textY = y + (40 - charHeight) / 2 + charHeight;
102+
int textX = x + (50 - charWidth) / 2;
103+
g.drawString("" + c, textX, textY);
104+
}
105+
private boolean grade1You()
106+
{
107+
quiz.word1 = "fake";
108+
quiz.question1("f", "o");
109+
return "foo".equals(quiz.word1);
110+
}
111+
private boolean grade2Won()
112+
{
113+
quiz.word2 = "passe";
114+
quiz.question2("d");
115+
return "passed".equals(quiz.word2);
116+
}
117+
private boolean grade3The()
118+
{
119+
quiz.word3 = "fake";
120+
quiz.question3("12{three}4", new Model("3"));
121+
return "1234".equals(quiz.word3);
122+
}
123+
private boolean grade4Game()
124+
{
125+
quiz.template4 = "fake";
126+
quiz.question4(new Pieces());
127+
return "g{middle}e".equals(quiz.template4);
128+
}
129+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.teachingkidsprogramming.section07events;
2+
3+
public class OldSimpleBubbleQuiz
4+
{
5+
//this is the original quiz (from SmallBasic) - need to be translated to Java
6+
//Variables needed for Quiz
7+
// action[1] = 15
8+
// ball = 1
9+
// BubbleQuiz.StartQuizAt = Question2
10+
//--------------------Begin Quiz --------------------
11+
//Question1 - Is At the bottom of this quiz. But do it 1st!
12+
// Sub Question2
13+
// Set the 1st action to 5
14+
// EndSub
15+
// Sub Question3
16+
//Have the timer call Move every 100 milliseconds
17+
// EndSub
18+
// Sub Question4
19+
// Set the 2nd action to -6
20+
// EndSub
21+
// Sub Question5
22+
//Change the color for the next circle to be yellow
23+
//Make the current ball be a circle with a 11 pixel radius
24+
// EndSub
25+
//Question1
26+
//Create a subroutine called Move
27+
// that calls Quiz.DoMovement()
28+
}
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
package org.teachingkidsprogramming.section07events;
22

3-
public class SimpleBubbleQuiz
3+
import org.teachingkidsprogramming.recipes.quizzes.graders.SimpleBubbleQuizAdapter;
4+
import org.teachingkidsprogramming.recipes.quizzes.graders.SimpleBubbleQuizGrader;
5+
6+
public class SimpleBubbleQuiz extends SimpleBubbleQuizAdapter
47
{
5-
//this is the original quiz (from SmallBasic) - need to be translated to Java
6-
//Variables needed for Quiz
7-
// action[1] = 15
8-
// ball = 1
9-
// BubbleQuiz.StartQuizAt = Question2
10-
//--------------------Begin Quiz --------------------
11-
//Question1 - Is At the bottom of this quiz. But do it 1st!
12-
// Sub Question2
13-
// Set the 1st action to 5
14-
// EndSub
15-
// Sub Question3
16-
//Have the timer call Move every 100 milliseconds
17-
// EndSub
18-
// Sub Question4
19-
// Set the 2nd action to -6
20-
// EndSub
21-
// Sub Question5
22-
//Change the color for the next circle to be yellow
23-
//Make the current ball be a circle with a 11 pixel radius
24-
// EndSub
25-
//Question1
26-
//Create a subroutine called Move
27-
// that calls Quiz.DoMovement()
8+
public void question1(String letter1, String letter3)
9+
{
10+
//set current value of word1 to be letter1 + 'o' + letter3
11+
}
12+
public void question2(String letter1)
13+
{
14+
//add the letter1 to the end of word2
15+
}
16+
public void question3(String templateText, Object model)
17+
{
18+
//use the parser to combine the template and the model as word3
19+
}
20+
public void question4(Pieces pieces)
21+
{
22+
//set template4 to the template which does'g' + pieces.middle + 'e'
23+
}
24+
public static void main(String[] args)
25+
{
26+
new SimpleBubbleQuizGrader().grade(new SimpleBubbleQuiz());
27+
}
2828
}

0 commit comments

Comments
 (0)