Skip to content

Commit 4011aab

Browse files
committed
Update ChooseYourOwnAdv w/@samanthalangit
1 parent 2709eff commit 4011aab

2 files changed

Lines changed: 116 additions & 199 deletions

File tree

src/main/java/org/teachingkidsprogramming/recipes/completed/section03ifs/ChooseYourOwnAdventure.java

Lines changed: 34 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -11,180 +11,99 @@ public class ChooseYourOwnAdventure
1111
{
1212
public static void main(String[] args)
1313
{
14-
// startStory (recipe below) --#1
15-
// ------------- Recipe for startStory --#1
1614
startStory();
17-
// ------------- End of startStory recipe --#1
1815
}
1916
private static void startStory()
2017
{
21-
//Tell the user "One morning the Tortoise woke up in a dream."
22-
MessageBox.showMessage("One morning the Tortoise woke up in a dream.");
23-
// animateStartStory (recipe below) --#1
24-
// ------------- Recipe for animateStartStory --#1
18+
tellMoreStory("One morning the Tortoise woke up in a dream.");
2519
animateStartStory();
26-
// ------------- End of animateStartStory recipe --#1
27-
// Ask the user "Do you want to 'wake up' or 'explore' the dream?"
28-
String action = MessageBox.askForTextInput("Do you want to 'wake up' or 'explore' the dream?");
29-
// If they answer "wake up" --#4
20+
String action = askAQuestion("Do you want to 'wake up' or 'explore' the dream?");
3021
if ("wake up".equalsIgnoreCase(action))
3122
{
32-
// wakeUp (recipe below) --#1
33-
// ------------- Recipe for wakeUp --#1
34-
wakeUp();
35-
// ------------- End of wakeUp recipe --#1
23+
tellMoreStory("You Wake up and have a boring day. The End.");
3624
}
37-
//Otherwise, if they answer "explore"
3825
else if ("explore".equalsIgnoreCase(action))
3926
{
40-
// approachOoze (recipe below) --#1
41-
// ------------- Recipe for approachOoze --#1
4227
approachOoze();
43-
// ------------- End of approachOoze recipe --#1
4428
}
45-
//Otherwise, if they answer anything else
4629
else
4730
{
48-
// badAnswer (recipe below) --#1
49-
// ------------- Recipe for badAnswer --#1
50-
badAnswer();
51-
// ------------- End of badAnswer recipe --#1
31+
endStory();
5232
}
5333
}
54-
private static void badAnswer()
34+
private static void endStory()
5535
{
56-
//Tell the user "You don't know how to read directions. You can't play this game. The End."
57-
MessageBox.showMessage("You don't know how to read directions. You can't play this game. The End.");
58-
}
59-
private static void wakeUp()
60-
{
61-
//Tell the user "You Wake up and have a boring day. The End."
62-
MessageBox.showMessage("You Wake up and have a boring day. The End.");
36+
tellMoreStory("You don't know how to read directions. You can't play this game. The End.");
6337
}
6438
private static void approachOoze()
6539
{
66-
//Tell the user "You approach a glowing, green bucket of ooze, worried that you will get in trouble, you pick up the bucket."
67-
MessageBox
68-
.showMessage("You approach a glowing, green bucket of ooze, worried that you will get in trouble, you pick up the bucket.");
69-
//
70-
// Ask the user "Do you want to pour the ooze into the 'backyard' or 'toilet'?"
71-
String pourTo = MessageBox.askForTextInput(" Do you want to pour the ooze into the 'backyard' or 'toilet'?");
72-
// If they answer "toilet" --#4
40+
tellMoreStory("You approach a glowing, green bucket of ooze, worried that you will get in trouble, you pick up the bucket.");
41+
String pourTo = askAQuestion(" Do you want to pour the ooze into the 'backyard' or 'toilet'?");
7342
if ("toilet".equalsIgnoreCase(pourTo))
7443
{
75-
// pourIntoToilet (recipe below) --#1
76-
// ------------- Recipe for pourIntoToilet --#1
7744
pourIntoToilet();
78-
// ------------- End of pourIntoToilet recipe --#1
7945
}
80-
// Otherwise, if they answer "backyard" --#4
8146
else if ("backyard".equalsIgnoreCase(pourTo))
8247
{
83-
// pourIntoBackyard (recipe below) --#1
84-
// ------------- Recipe for pourIntoBackyard --#1
8548
pourIntoBackyard();
86-
// ------------- End of pourIntoBackyard recipe --#1
8749
}
88-
//Otherwise, if they answer anything else
8950
else
9051
{
91-
// badAnswer (recipe below) --#1
92-
// ------------- Recipe for badAnswer --#1
93-
badAnswer();
94-
// ------------- End of badAnswer recipe --#1
52+
endStory();
9553
}
9654
}
97-
private static void pourIntoBackyard()
55+
private static void pourIntoToilet()
9856
{
99-
//Tell the user "As you walk into the backyard a net scoops you up and a giant takes you to a boiling pot of water."
100-
MessageBox
101-
.showMessage("As you walk into the backyard a net scoops you up and a giant takes you to a boiling pot of water.");
102-
//Ask the user "As the man starts to prepare you as soup, do you... 'Scream' or 'Faint'?"
103-
String action = MessageBox
104-
.askForTextInput("As the man starts to prepare you as soup, do you... 'Scream' or 'Faint'?");
105-
// If they answer "faint" --#4
106-
if ("faint".equalsIgnoreCase(action))
57+
tellMoreStory("As you pour the ooze into the toilet it backs up, gurgles and explodes covering you in radio-active waste.");
58+
String pourTo = askAQuestion("Do you want to train to be a NINJA? 'Yes' or 'HECK YES'?");
59+
if ("yes".equalsIgnoreCase(pourTo))
10760
{
108-
// tortoiseSoup (recipe below) --#1
109-
// ------------- Recipe for tortoiseSoup --#1
110-
tortoiseSoup();
111-
// ------------- End of tortoiseSoup recipe --#1
61+
tellMoreStory("Awesome Dude! You live out the rest of your life fighting crimes and eating pizza!");
11262
}
113-
// Otherwise, if they answer "scream" --#4
114-
else if ("scream".equalsIgnoreCase(action))
63+
else if ("heck yes".equalsIgnoreCase(pourTo))
11564
{
116-
// startStory (recipe below) --#1
117-
// ------------- Recipe for startStory --#1
118-
startStory();
119-
// ------------- End of startStory recipe --#1
65+
tellMoreStory("Awesome Dude! You live out the rest of your life fighting crimes and eating pizza!");
12066
}
121-
//Otherwise, if they answer anything else
12267
else
12368
{
124-
// badAnswer (recipe below) --#1
125-
// ------------- Recipe for badAnswer --#1
126-
badAnswer();
127-
// ------------- End of badAnswer recipe --#1
69+
endStory();
12870
}
12971
}
130-
private static void tortoiseSoup()
131-
{
132-
//Tell the user "You made a delicious soup! Yum! The End."
133-
MessageBox.showMessage("You made a delicious soup! Yum! The End.");
134-
}
135-
private static void pourIntoToilet()
72+
private static void pourIntoBackyard()
13673
{
137-
//Tell the user "As you pour the ooze into the toilet it backs up, gurgles and explodes covering you in radio-active waste."
138-
MessageBox
139-
.showMessage("As you pour the ooze into the toilet it backs up, gurgles and explodes covering you in radio-active waste.");
140-
//Ask the user "Do you want to train to be a NINJA? 'Yes' or 'HECK YES'?"
141-
String pourTo = MessageBox.askForTextInput("Do you want to train to be a NINJA? 'Yes' or 'HECK YES'?");
142-
// If they answer "yes" --#4
143-
if ("yes".equalsIgnoreCase(pourTo))
74+
tellMoreStory("As you walk into the backyard a net scoops you up and a giant takes you to a boiling pot of water.");
75+
String action = askAQuestion("As the man starts to prepare you as soup, do you... 'Scream' or 'Faint'?");
76+
if ("faint".equalsIgnoreCase(action))
14477
{
145-
// ninjaTortoise (recipe below) --#1
146-
// ------------- Recipe for ninjaTortoise --#1
147-
ninjaTortoise();
148-
// ------------- End of ninjaTortoise recipe --#1
78+
tellMoreStory("You made a delicious soup! Yum! The End.");
14979
}
150-
// Otherwise, if they answer "heck yes" --#4
151-
else if ("heck yes".equalsIgnoreCase(pourTo))
80+
else if ("scream".equalsIgnoreCase(action))
15281
{
153-
// ninjaTortoise (recipe below) --#1
154-
// ------------- Recipe for ninjaTortoise --#1
155-
ninjaTortoise();
156-
// ------------- End of ninjaTortoise recipe --#1
82+
startStory();
15783
}
158-
//Otherwise, if they answer anything else
15984
else
16085
{
161-
// badAnswer (recipe below) --#1
162-
// ------------- Recipe for badAnswer --#1
163-
badAnswer();
164-
// ------------- End of badAnswer recipe --#1
86+
endStory();
16587
}
16688
}
167-
private static void ninjaTortoise()
168-
{
169-
//Tell the user "Awesome Dude! You live out the rest of your life fighting crimes and eating pizza!"
170-
MessageBox.showMessage("Awesome Dude! You live out the rest of your life fighting crimes and eating pizza!");
171-
}
17289
private static void animateStartStory()
17390
{
174-
//Show the Tortoise
17591
Tortoise.show();
176-
// The current pen color is black
17792
Color color = PenColors.Grays.Black;
178-
// Do the following 25 times --#5.1
17993
for (int i = 0; i < 25; i++)
18094
{
181-
// Turn the background black --#22
18295
Tortoise.getBackgroundWindow().setColor(color);
183-
// lighten the current pen color
18496
color = PenColors.lighten(color);
185-
// wait for 100 milliseconds
18697
ThreadUtils.sleep(100);
187-
// Repeat --#5.2
18898
}
18999
}
100+
private static void tellMoreStory(String message)
101+
{
102+
MessageBox.showMessage(message);
103+
}
104+
private static String askAQuestion(String question)
105+
{
106+
String answer = MessageBox.askForTextInput(question);
107+
return answer;
108+
}
190109
}
Lines changed: 82 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,90 @@
11
package org.teachingkidsprogramming.section03ifs;
22

3+
import java.awt.Color;
4+
5+
import org.teachingextensions.approvals.lite.util.ThreadUtils;
6+
import org.teachingextensions.logo.Tortoise;
7+
import org.teachingextensions.logo.utils.ColorUtils.PenColors;
8+
import org.teachingextensions.logo.utils.EventUtils.MessageBox;
9+
310
public class ChooseYourOwnAdventure
411
{
512
public static void main(String[] args)
613
{
7-
// startStory (recipe below) --#2.1
8-
//
9-
// ------------- Recipe for startStory --#2.2
10-
// Tell the user "One morning the Tortoise woke up in a dream." --#1
11-
//
12-
// animateStartStory (recipe below) --#38.1
13-
//
14-
// ------------- Recipe for animateStartStory --#38.2
15-
// Show the Tortoise --#37
16-
// The current pen color is black --#39.2
17-
// Do the following 25 times --#41.1
18-
// Turn the background to the current pen color --#39.1
19-
// Lighten the current pen color --#42
20-
// Wait for 100 milliseconds --#40
21-
// Repeat --#41.2
22-
// ------------- End of animateStartStory recipe --#38.3
23-
//
24-
// Ask the user "Do you want to 'wake up' or 'explore' the dream?" --#3
25-
// If they answer "wake up" --#6
26-
// wakeUp (recipe below) --#5.1
27-
//
28-
// ------------- Recipe for wakeUp --#5.2
29-
// Tell the user "You Wake up and have a boring day. The End." --#4
30-
// ------------- End of wakeUp recipe --#5.3
31-
// Otherwise, if they answer "explore" --#9
32-
// approachOoze (recipe below) --#8.1
33-
//
34-
// ------------- Recipe for approachOoze --#8.2
35-
// Tell the user "You approach a glowing, green bucket of ooze, worried that you will get in trouble, you pick up the bucket." --#7
36-
// Ask the user "Do you want to pour the ooze into the 'backyard' or 'toilet'?" --#13
37-
// If they answer "toilet" --#16
38-
// pourIntoToilet (recipe below) --#15.1
39-
//
40-
// ------------- Recipe for pourIntoToilet --#15.2
41-
// Tell the user "As you pour the ooze into the toilet it backs up, gurgles and explodes covering you in radio-active waste." --#14
42-
// Ask the user "Do you want to train to be a NINJA? 'Yes' or 'HECK YES'?" --#29
43-
// If they answer "yes" --#32
44-
// ninjaTortoise (recipe below) --#31.1
45-
//
46-
// ------------- Recipe for ninjaTortoise --#31.2
47-
// Tell the user "Awesome Dude! You live out the rest of your life fighting crimes and eating pizza!" --#30
48-
// ------------- End of ninjaTortoise recipe --#31.3
49-
//
50-
// Otherwise, if they answer "heck yes" --#34
51-
// ninjaTortoise (recipe below) --#33
52-
//
53-
// Otherwise, if they answer anything else --#36
54-
// badAnswer (recipe below) --#35
55-
//
56-
// ------------- End of pourIntoToilet recipe --#15.3
57-
//
58-
// Otherwise, if they answer "backyard" --#19
59-
// pourIntoBackyard (recipe below) --#18.1
60-
//
61-
// ------------- Recipe for pourIntoBackyard --#18.2
62-
// Tell the user "As you walk into the backyard a net scoops you up and a giant takes you to a boiling pot of water." --#17
63-
// Ask the user "As the man starts to prepare you as soup, do you... 'Scream' or 'Faint'?" --#21
64-
// If they answer "faint" --#24
65-
//
66-
// tortoiseSoup (recipe below) --#23.1
67-
//
68-
// ------------- Recipe for tortoiseSoup --#23.2
69-
// Tell the user "You made a delicious soup! Yum! The End." --#22
70-
// ------------- End of tortoiseSoup recipe --#23.3
71-
//
72-
// Otherwise, if they answer "scream" --#26
73-
// startStory (recipe below) --#25.1
74-
//
75-
// Otherwise, if they answer anything else --#28
76-
// badAnswer (recipe below) --#27
77-
//
78-
// ------------- End of pourIntoBackyard recipe --#18.3
79-
// Otherwise, if they answer anything else --#20
80-
// badAnswer (recipe below) --#19
81-
// ------------- End of approachOoze recipe --#8.3
82-
//
83-
// Otherwise, if they answer anything else --#12
84-
// badAnswer (recipe below) --#11.1
85-
//
86-
// ------------- Recipe for badAnswer --#11.2
87-
// Tell the user "You don't know how to read directions. You can't play this game. The End." --#10
88-
// ------------- End of badAnswer recipe --#11.3
89-
//
90-
// ------------- End of startStory recipe --#2.3
14+
startStory();
15+
}
16+
private static void startStory()
17+
{
18+
tellMoreStory("One morning the Tortoise woke up in a dream.");
19+
animateStartStory();
20+
String action = askAQuestion("Do you want to 'wake up' or 'explore' the dream?");
21+
if ("wake up".equalsIgnoreCase(action))
22+
{
23+
// wakeUp (recipe below) --#2.1
24+
// ------------- Recipe for wakeUp --#2.2
25+
// Tell the user "You Wake up and have a boring day. The End." --#1
26+
// ------------- End of wakeUp recipe --#2.3
27+
}
28+
else if ("explore".equalsIgnoreCase(action))
29+
{
30+
// approachOoze (recipe below) --#4.1
31+
// ------------- Recipe for approachOoze --#4.2
32+
// Tell the user "You approach a glowing, green bucket of ooze, worried that you will get in trouble, you pick up the bucket." --#3
33+
// Ask the user "Do you want to pour the ooze into the 'backyard' or 'toilet'?" --#7
34+
// If they answer "toilet" --#8.1
35+
// pourIntoToilet (recipe below) --#12.1
36+
// ------------- Recipe for pourIntoToilet --#12.2
37+
// Tell the user "As you pour the ooze into the toilet it backs up, gurgles and explodes covering you in radio-active waste." --#10
38+
// Ask the user "Do you want to train to be a NINJA? 'Yes' or 'HECK YES'?" --#11
39+
// If they answer "yes" --#13.1
40+
// Tell the user "Awesome Dude! You live out the rest of your life fighting crimes and eating pizza!" --#14
41+
// Otherwise, if they answer "heck yes" --#13.2
42+
// Tell the user "Awesome Dude! You live out the rest of your life fighting crimes and eating pizza!" --#15
43+
// Otherwise, if they answer anything else --#13.3
44+
// endStory --#16
45+
// ------------- End of pourIntoToilet recipe --#12.3
46+
// Otherwise, if they answer "backyard" --#8.2
47+
// pourIntoBackyard (recipe below) --#19.1
48+
// ------------- Recipe for pourIntoBackyard --#19.2
49+
// Tell the user "As you walk into the backyard a net scoops you up and a giant takes you to a boiling pot of water." --#17
50+
// Ask the user "As the man starts to prepare you as soup, do you... 'Scream' or 'Faint'?" --#18
51+
// If they answer "faint" --#20.1
52+
// Tell the user "You made a delicious soup! Yum! The End." --#21
53+
// Otherwise, if they answer "scream" --#20.2
54+
// startStory --#22
55+
// Otherwise, if they answer anything else --#20.3
56+
// endStory --#23
57+
// ------------- End of pourIntoBackyard recipe --#19.3
58+
// Otherwise, if they answer anything else --#8.3
59+
// endStory --#9
60+
// ------------- End of approachOoze recipe --#4.3
61+
}
62+
else
63+
{
64+
// endStory (recipe below) --#6.1
65+
// ------------- Recipe for endStory --#6.2
66+
// Tell the user "You don't know how to read directions. You can't play this game. The End." --#5
67+
// ------------- End of endStory recipe --#6.3
68+
}
69+
}
70+
private static void animateStartStory()
71+
{
72+
Tortoise.show();
73+
Color color = PenColors.Grays.Black;
74+
for (int i = 0; i < 25; i++)
75+
{
76+
Tortoise.getBackgroundWindow().setColor(color);
77+
color = PenColors.lighten(color);
78+
ThreadUtils.sleep(100);
79+
}
80+
}
81+
private static void tellMoreStory(String message)
82+
{
83+
MessageBox.showMessage(message);
84+
}
85+
private static String askAQuestion(String question)
86+
{
87+
String answer = MessageBox.askForTextInput(question);
88+
return answer;
9189
}
9290
}

0 commit comments

Comments
 (0)