Skip to content

Commit 84cfc02

Browse files
committed
added QuizBuzz stub w/Samantha
1 parent 10a5595 commit 84cfc02

File tree

5 files changed

+186
-0
lines changed

5 files changed

+186
-0
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 QuizBuzzAdapter
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 QuizBuzzGrader 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 QuizBuzzAdapter quiz;
27+
private void displayScreen()
28+
{
29+
QuizUtils.prepareScoringScreen(answers, this, TURTLE_SPEED);
30+
}
31+
public void grade(QuizBuzzAdapter 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+
}

TeachingKidsProgramming/src/org/teachingkidsprogramming/section07events/SimpleBubbleQuiz.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
public class SimpleBubbleQuiz extends SimpleBubbleQuizAdapter
77
{
8+
//**THIS QUIZ IS IN PROGRESS
89
public void question1(String letter1, String letter3)
910
{
1011
//set current value of word1 to be letter1 + 'o' + letter3
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.teachingkidsprogramming.section08tdd;
2+
3+
import org.teachingkidsprogramming.recipes.quizzes.graders.QuizBuzzAdapter;
4+
import org.teachingkidsprogramming.recipes.quizzes.graders.QuizBuzzGrader;
5+
6+
public class QuizBuzz extends QuizBuzzAdapter
7+
{
8+
//**THIS QUIZ IS IN PROGRESS
9+
public void question1(String letter1, String letter3)
10+
{
11+
//set current value of word1 to be letter1 + 'o' + letter3
12+
}
13+
public void question2(String letter1)
14+
{
15+
//add the letter1 to the end of word2
16+
}
17+
public void question3(String templateText, Object model)
18+
{
19+
//use the parser to combine the template and the model as word3
20+
}
21+
public void question4(Pieces pieces)
22+
{
23+
//set template4 to the template which does'g' + pieces.middle + 'e'
24+
}
25+
public static void main(String[] args)
26+
{
27+
new QuizBuzzGrader().grade(new QuizBuzz());
28+
}
29+
}

0 commit comments

Comments
 (0)