CSE 113 - Spring 2011 - Banner
  • CSE 113 - Spring 2011
CSE 113 - Spring 2011 - Navigation
CSE 113 - Spring 2011 - Lab 6

Lab 6
Last modified: April 25 2011 10:16:18 AM

CSE 113 - Spring 2011 - Announcements

Beginnings of a Learning Game

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:

  • LetterGame - the world for this scenario
  • Message - an actor that will display a "guess a letter" or "correct" message during the play of the game
  • Card - an actor that represents a flash card for the game
  • Selector - an actor that is part of the scenario, but does not have a physical representation in the world view. It will help us with game play. This class has been written for you, but you do have to make a few changes to it as you work on the assignment.

Below is a description of the tasks you need to complete for this scenario.

Create and place the message on the screen

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 and Run and Fix

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 Message Class

Finish the code in the methods of the message class so that they set the image of the message correctly.

Compile and Run Again

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.

Modify the Card Class (part 1)

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.

Add the cards to the Screen

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.

Cards react when correct letter is pressed

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.

Cards flip over

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.

Cards reacting to the correct first letters

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.

Cards react to the proper letters

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.

One more thing...

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.


Submitting the Assignment

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.


Grading Information

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).

  1. Message object positioned on screen correctly.
  2. When scenario loaded, "Press Run to Start" message appears.
  3. When method showGuessMessage called, the message on the screen changes appropriately.
  4. Whem method showCorrectAnswerMessage called, the message on the screen changes appropriately.
  5. There is an instance variable in the Card class whose type is GreenfootImage and holds onto the information about the face image of the card.
  6. Constructor of the Card class takes as a parameter a String that represents the name of the image for the face of the card.
  7. When the scenario loads, cards appear on the screen in 3 rows and 3 columns.
  8. The Card class has an instance variable whose type is boolean and holds onto the information about whether or not the card is face up.
  9. There is an instance variable in the Card class that holds onto the first letter of the name of the image on the card.
  10. The first letter of the name of the image of the card is passed into the Card as a parameter to the constructor.
  11. If the user presses the correct key the message on the screen will display the "correct guess" message to the screen. (Repeated 3 times for a total of 18.75 points)
  12. If the user presses the correct key the card will turn over. (Repeated 3 times for a total of 18.75 points)

Lab authored by Adrienne Decker

CSE 113 - Spring 2011 - Footer

Page maintained by Adrienne Decker

Contact: adrienne@buffalo.edu | 130 Bell Hall | (716)645-3184