This assignment uses the ideas presented in Chapter 5 of the text to create the beginnings of a learning game for children just learning about the alphabet.
If you don't remember how to do any of the steps (like, copying, zipping, etc), please refer back to Lab 1.
First, you will need to copy over the scenario for this assignment. If you are working from home, you can download the scenario here. If you are in lab, the scenario is located in /eng/class/notes/cse113/scenarios/Lab6.
Your final product will be game that has a bunch of "cards" face down on the screen. When the user selects to "Run" the scenario, a card will turn over. The user then needs to guess the first letter of the image on that card. If the user guesses correctly, a "Correct" message appears and they are given another card. If the user guesses incorrectly, a "Keep Guessing" message appears and the user needs to keep guessing. The game continues until the user stops the scenario.
Take note of the following classes in the scenario:
Below is a description of the tasks you need to complete for this scenario.
In the constructor of the LetterGame, create a Message actor and put it on the screen. You should make sure that the image is centered in the x-direction and is near the bottom of the screen (at or below y = 425). Note that there is already an instance variable for a Message in the class. You will need to create your Message object and assign it to this variable or the messages for the game will not work.
Compile the scenario. Note that it may take a few more seconds than normal to compile and for the world to reappear. Make sure the image appears where you thought it would. If you press Run, nothing will happen.
Finish the code in the methods of the message class so that they set the image of the message correctly.
After you complete the methods and ensure that the scenario compiles, you should change the code in the constructor of the Message so that the message displayed is the "guess message". When you run, you should see the "guess message". Now change it to see the "correct" message and run again. After you are sure that calling the two methods for the message work correctly, set the constructor back to the way it was so the "Press Run to Start" message is showing.
Create an instance variable for the face image of the card. Add a parameter to the constructor that is a string and is the filename for the image. Inside the constructor, assign a new GreenfootImage object to the instance variable using the filename passed into the constructor. Now, write the code in the method turnOver to set the image of the card to the face image.
Now write the code to add the cards to the screen. Cards are 100x100 pixels. You may want to space them out so that there is some space between them. If you assume the cards are 120x120, this gives enough room around each card. You should lay out the cards in three rows and three columns. Remember that in order to create a card, you need to pass in values for each of its parameters, a selector object and the name of the image file for the card. After you compile all of this code, set the speed of the scenario to be somewhere between the left hand side and the first marking. When you run, you will see the images flip over slowly.
Write code inside of the act method of card so that it tells the selector that there has been a correct guess whenever the user presses the "z" key. Change the correct "true" value to "false" inside the Selector class at this time. There is a comment where you need to change the value. Changing the value allows the next card only to be shown after the first letter of the word on the previous card has been correctly identified.
After you have seen this work, add code so that after the selector is told of the correct guess, the card turns over (that is, call the turnOver method again). You will need to modify the turnOver method so that the cards actually turn over. In order to do this, you will need to create a boolean instance variable to store whether or not the card is face up. If the card is face up, the background image should be displayed, but if it is not face up, the face image should be displayed. The boolean variable needs to be updated correctly as well. Now, when you run the game and press the z key the images will flip back over before another one is shown. Note that the slower you have the speed indicator set, the more delay you will see. Find a setting that suits you as the game player.
In the LetterGame class, you will need to create arrays to hold the first letters of the pictures in each of the three rows of cards on the screen. You should use the lower case version of the letters. You will need to create an instance variable for the Card to hold onto the first letter, you will pass another String into the constructor of Card that represents this letter, and you will need to make sure that you assign a value to that instance variable inside the constructor of card. You should make sure that all of your classes compile before moving on to the next steps. After this, there will be no changes to how the game runs, but with the number of changes asked for here, you should make sure that everything compiles before moving on.
As you may have noticed, the cards all are "correct" when z is pressed, you need to make the card turn over and be correct when the correct letter is pressed, the letter that is stored in the instance variable that you created in the last step.
There is a weird quirk in the game at this point. No matter which card is shown, if you guess a letter that is any of the correct letters for any of the cards, the "correct" message will show and the cards will turn over. In order to fix this, you need to make sure in the act method of Card, not only that the correct key is being pressed, but that the card is face up. Then, this bug will go away.
Once you have completed the functionality for Lab 6, you will submit the zipped up version of the Lab 6 scenario.
For directions on submitting, please see here.
Please recall that you must achieve a grade of at least 50% on each of the labs to be allowed to take the third practical exam. This lab is technically due on Monday, May 2nd at 11:59:59pm. However, if you want to stay current with the course, I would recommend having this assignment completed within a week. You will need mastery of the skills you learn in this lab to be successful at practical exam 3.
Please make sure to look at your grading information on Web-CAT. See the grading information page for more details about how to interpret Web-CAT grade reports. (At this time, grading for this assignment via Web-CAT is not enabled.)
The following tests were run on your assignment submission. Each test was given equal weight (6.25 points each).
Lab authored by Adrienne Decker