Problem 5 Example Solutions This document provides pictures of a working Tynker program for both game options described. Keep in mind that these are example solutions. Problems can be solved computationally in many ways, so the best way to know if the solution is correct is by testing it! This document provides suggested solutions for teachers to refer to. Option 1: Color Confusion Game Stage Program 1. Clear the screen from any previous run of the program. 2. Initialize the score to 0. 3. Welcome the player then broadcast round 1 to begin. Note the wait blocks. If there are no wait blocks, programs will run too fast and the program might look like it missed a step, but it was just executing too quickly! 4. The two scripts about displaying score are a nice option to keep the player up to date with the score after each round (display score) as well as at the end of the game (display final score). PLTW Launch Input/Output: Computer Systems Problem 5 Example Solutions Page 1
First Actor Program The code for the actors will be very similar. In fact, it is a copy/paste with minor edits for round numbers, color selection, and the text displayed. 2. When round 1 is broadcasted, the first actor should respond by going to the center of the screen (or any position the student would like!), becoming visible, and displaying the text of the color name (here it is orange) in a given font color (here it is also orange). Students can pick any color and combinations they like for this game. 3. Wait 1 second then hide again, clear the screen from the text drawn then broadcast to the next actor to start round 2. 4. When clicked the actor should either add a point to the score or subtract one. It depends on the case the student chooses to make for each round. In this case below, the color name matches its font color (orange) so it adds 1 point and broadcasts the display score message, which the Stage responds to. PLTW Launch Input/Output: Computer Systems Problem 5 Example Solutions Page 2
Second Actor Program This is a copy of the previous actor, with minor edits for round numbers, color selection, and the text displayed. 2. When round 2 is broadcasted, the second actor should respond by going to the center of the screen (or any position the student would like!), becoming visible, and displaying the text of the color name (here it is blue) in a given font color (here it is dark red). Students can pick any color and combinations they like for this game. 3. Wait 1 second then hide again, clear the screen from the text drawn then broadcast to the next actor to start round 3. 4. When clicked the actor should either add a point to the score or subtract one. It depends on the case the student chooses to make for each round. In this case below, the color name does not match its font color so it subtracts 1 point and broadcasts the display score message, which the Stage responds to. PLTW Launch Input/Output: Computer Systems Problem 5 Example Solutions Page 3
Third Actor Program This is a copy of the previous actor, with minor edits for round numbers, color selection, and the text displayed. 2. When round 3 is broadcasted, the third actor should respond by going to the center of the screen (or any position the student would like!), becoming visible, and displaying the text of the color name (here it is yellow) in a given font color (here it is blue). Students can pick any color and combinations they like for this game. 3. Wait 1 second then hide again, clear the screen from the text drawn then broadcast to the next actor to start round 4. 4. When clicked the actor should either add a point to the score or subtract one. It depends on the case the student chooses to make for each round. In this case below, the color name does not match its font color so it subtracts 1 point and broadcasts the display score message, which the Stage responds to. PLTW Launch Input/Output: Computer Systems Problem 5 Example Solutions Page 4
Fourth Actor Program This is a copy of the previous actor, with minor edits for round numbers, color selection, and the text displayed. 2. When round 4 is broadcasted, the fourth actor should respond by going to the center of the screen (or any position the student would like!), becoming visible, and displaying the text of the color name (here it is red) in a given font color (here it is also red). Students can pick any color and combinations they like for this game. 3. Wait 1 second then hide again, clear the screen from the text drawn then broadcast to the next actor to start round 5. 4. When clicked the actor should either add a point to the score or subtract one. It depends on the case the student chooses to make for each round. In this case below, the color name matches its font color (red) so it adds 1 point and broadcasts the display score message, which the Stage responds to. PLTW Launch Input/Output: Computer Systems Problem 5 Example Solutions Page 5
Fifth Actor Program This is a copy of the previous actor, with minor edits for round numbers, color selection, and the text displayed. 2. When round 5 is broadcasted, the fifth actor should respond by going to the center of the screen (or any position the student would like!), becoming visible, and displaying the text of the color name (here it is brown) in a given font color (here it is also brown). Students can pick any color and combinations they like for this game. 3. Wait 1 second then hide again, clear the screen from the text drawn then broadcast the display final score message which the Stage will respond to. 4. When clicked the actor should either add a point to the score or subtract one. It depends on the case the student chooses to make for each round. In this case below, the color name matches its font color (brown) so it adds 1 point. There is no need to broadcast the display score message since the display final score is called at the end of the when I receive round 5 script. PLTW Launch Input/Output: Computer Systems Problem 5 Example Solutions Page 6
Option 2: Memory Game In this example solution, the balls will always be displayed in a straight horizontal line (with y = 200). The x positions will be 300, 100, 100, and 300. The actors that display the multiple choice answers will always appear in a vertical fashion (with x = 200). The y positions will be 300, 150, 0, and 150. Recall the game will look like this: Note that each round (aka sequence of balls to memorize) will require a new set of actors (like the four kid actors used here) to display the multiple choice answers so that when touched, it is clear to the actor which sequence was displayed and whether to give the player a point or take one away. This will cause some duplication of effort, which is why limiting this project to two or three rounds is plenty! There is another way to avoid the duplication and only use four actors by using a global variable. The code for Stage and Green Ball is shown at the end of this document. PLTW Launch Input/Output: Computer Systems Problem 5 Example Solutions Page 7
Stage Program 1. Clear the screen from any previous run of the program. 2. Initialize the score to 0. 3. Welcome the player then broadcast round 1 to begin. Note the broadcast and wait blocks are best for this game since the stage will be controlling the entire game flow. So it calls for round 1, waits for it to complete, then calls for round 1 options (multiple choice answers) to appear, and then calls the next round, etc. Note that the extra 1 second waits in between are simply to add a short pause between the switches in display in the game, rather than everything switching quickly from one display to the next. 4. After all rounds have been played (the code below shows only two rounds but students can do more than that if time permits), the score is displayed. PLTW Launch Input/Output: Computer Systems Problem 5 Example Solutions Page 8
Green Ball Program The code for the balls will be very similar. In fact, it is a copy/paste with minor edits for the x- and y-coordinates for each round. 2. When a round number is broadcasted, the ball will go to an x-y position then appear on the screen. It is up to the students to decide on the position of the ball on the screen. The example code below shows green all the way on the left (x = 300) in round 1 and in third position (x = 100) in round 2. 3. Wait 2 seconds then hide again. In this program, there is no need to broadcast to the next round, since the Stage is waiting for a round to complete and will broadcast the next round (difference between using broadcast and broadcast and wait blocks!) PLTW Launch Input/Output: Computer Systems Problem 5 Example Solutions Page 9
Pink, Blue, and Orange Balls Programs The code is a copy of the previous ball with minor edits for the x- and y-coordinates for each round. 2. When a round number is broadcasted, the ball will go to an x-y position then appear on the screen. It is up to the students to decide on the position of the ball on the screen. 3. Wait 2 seconds then hide again. PLTW Launch Input/Output: Computer Systems Problem 5 Example Solutions Page 10
PLTW Launch Input/Output: Computer Systems Problem 5 Example Solutions Page 11
First Actor Program The code for the actors will also be very similar. In fact, it is a copy/paste with minor edits for the y-coordinates, the text displayed, and the score update. 2. When a broadcast for round 1 options is sent, the actor will go to its x-y position (see this game s introduction above) then appear on the screen. 3. The green code blocks show how to select a font color and size and draw the text at a specific x-y position. The key is to move it away from the actor just enough so it is not covered by the actor, but still close enough to be obvious that they go together! The player needs to click on the actor, not the text (the text does not detect the clicking event!) 4. Wait 5 seconds then hide again. 5. When the actor is touched, it will either add 1 point to the score or take away a point. For this specific actor, the answer it displayed was incorrect; therefore it subtracts 1 from the score. PLTW Launch Input/Output: Computer Systems Problem 5 Example Solutions Page 12
Second, Third, and Fourth Actors Programs This is a copy of the previous actor, with minor edits for the text displayed and the y position. 2. When a broadcast for round 1 options is sent, the actor will go to its x-y position (see this game s introduction above) then appear on the screen. 3. Actor displays the text using the Drawing blocks. 4. Wait 5 seconds then hide again. 5. When the actor is touched, it will either add 1 point to the score or take away a point. The answer displayed by actors 2 and 4 are incorrect; therefore they subtract 1 from the score. Actor 3, showing the correct answer, adds 1 to it. PLTW Launch Input/Output: Computer Systems Problem 5 Example Solutions Page 13
PLTW Launch Input/Output: Computer Systems Problem 5 Example Solutions Page 14
Alternative Approach: Using a Global Variable As mentioned in the introduction to this game solution, there is a way to avoid duplicating the actors to display answers for each round. You will need to use a global variable which will be the indicator to the actors what sequence the balls were displayed in. The global variable round number will be created on the Stage and defined as a Global Variable. The stage can set that variable to the round number the game is in (like 1, 2, 3, etc.) Then in each of the four actors used to present the multiple choice answers, use an if-then-else statement that will check which round number it is and, based on that, determine which what action to take on the score. Stage Program The code is the same as the previous approach, except the new step where the stage sets the global variable round number before broadcasting the rounds. PLTW Launch Input/Output: Computer Systems Problem 5 Example Solutions Page 15
Sample Actor Program The code below will be very similar for all four actors in the game. The code is the same as the previous approach, except for dealing with the score update. The actor will now need to check to see which round it is in the game, and decide whether to add or subtract a point. Let s say the sequence displayed in the text for this actor does NOT match the balls in round 1, but matches them in round 2. This code shows how to deal with that situation. The next question would be what if there are more than two rounds? Use as many nested if-then-else statements as needed. Here is an example: PLTW Launch Input/Output: Computer Systems Problem 5 Example Solutions Page 16