CSE 113 - Fall 2010 - Banner
  • CSE 113 - Fall 2010
CSE 113 - Fall 2010 - Navigation
CSE 113 - Fall 2010 - Lab 5

Lab 5
Last modified: December 01 2010 04:19:01 PM

CSE 113 - Fall 2010 - 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/Lab5.

Take note of the following classes in the scenario:

  • LearningGame - the world for this scenario
  • Message - an actor that will display a "keep trying" or "congrats" message during the play of the game
  • Letter - an actor that represents a letter of the alphabet - there will be one for each letter
  • Recorder - an actor that is part of the scenario, but does not have a physical representation in the world view. It will help us to keep track of the keys that the user has pressed. 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 LearningGame, create a Message actor and put it on the screen. The image for the message is 600 pixels wide and 103 pixels tall. Use this information along with the size of the world to place the message at the bottom of the screen. Note that the Message constructor takes as a parameter a Recorder. There is a recorder object available in the World constructor - use it as the value to pass into the Message.

Compile and Run and Fix

Compile the scenario. Make sure the image appears where you thought it would. Now Run - you shouldn't notice a difference.

Make the message react to the "winning" of the game

Write the code inside the Message's act method so that when the Recorder's allPressed() method returns true, the message changes to the "win" message. Otherwise, it displays the "not won" message. Remember that you can find the names to images by trying to create a new subclass and seeing all the images in the scenario. You can also go into the images directory inside the scenario and look at the files in a file explorer on your computer.

Compile and Run Again

After you compile and run the scenario, notice that the message changes even though we haven't done anything with the game yet. This is because the Recorder is programmed incorrectly to enable you to test that you have completed the message part of the functionality. You will fix the Recorder next.

Fix the Recorder

Open up the source code for the recorder. Inside the allPressed() method, you will see a line that says "return true;". This is why the message flipped to the "won" message. This method is programmed to always return true no matter what. We need to fix it so it behaves in the correct way. There is a commented-out line of code above "return true;". Un-comment that line and remove the "return true;" line. Now compile this file and run again.

Letters

Letters should react when the user clicks on the proper key on the keyboard by changing their image to the proper "Pressed" image. You should not create multiple letter classes, but rather make the letter class' constructor accept a String that represents the letter from the keyboard so that the letter knows which letter it is supposed to react to. You can use that information (the string containing the letter) to construct the names of the image files you will need to display.

Create some sample letters

In order to test out your letter buttons, it will probably be easiest to put the code right in the LearningGame constructor. Try out a few different letters and place them anywhere on the screen. Make sure their images change when you click on them. We will work on positioning all the letters in a moment.

Letter Images

Each letter image is 77x77. Given the size of the world, you will only be able to put at most 7 letters across the screen before running out of room. Therefore, we will need 4 rows to place the letters into the world.

Use loops to place the letters

Since we will have four rows of letters, we will need four loops. Begin setting up the loops so that each one executes 7 times (except for the last one which will only execute 5 times). Inside the body of the loop, add a letter to the world. Have them all react to the same key on the keyboard for now (or a different key for each row if you'd like), but set up the placement of the letters so that they appear in rows and are not placed on top of each other. Run the program frequently during this stage to ensure that the world looks like you want it to.

Create arrays

Create four arrays to hold the letters from each of the visual rows on the screen. Use the information from the array inside the loop body so that all the letters of the alphabet are placed on the screen. Run the program to be sure it is working.

One more thing...

If you play the "game" at this point, you will notice that even if you type all the letters of the alphabet, the message never changes. This is because when the key is pressed, we never tell the recorder about it. Insert the code inside the act() method of key to tell the recorder that the letter was pressed. You will be calling the keyPressed(String key) method and passing in the appropriate information to the recorder.

Compile an Run One Last Time

Now when you run and press all the keys of the alphabet, you should get the congratulatory message.


Submitting the Assignment

Once you have completed your work, you will submit the zipped up version of the Lab 5 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 second practical exam. This means, that your labs are technically all due by the last day of class (December 10th). However, if you want to stay current with the course, I would recommend having this assignment completed within a week, but definitely before the first practical, which will be during the weeks of October 18th and October 25th.


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.

The following tests were run on your assignment submission.

  1. [5 points] The message is positioned correctly on the screen.
  2. [10 points] The message has the correct message (not won yet) when the scenario is started.
  3. [10 points] The message changes properly when the recorder is full of all the letters of the alphabet
  4. [15 points] The recorder should not always return true when asked if it is all full
  5. [10 points] The placement of all the letters is correct on the screen - they do not overlap each other.
  6. [10 points] All of the letters are placed on the screen
  7. [15 points] The letters change images appropriately when the user clicks on them
  8. [15 points] The letters communicate with the recorder appropriately when clicked upon
  9. [10 points] There is only one letter class, not one class for each letter

Lab authored by Adrienne Decker

 

CSE 113 - Fall 2010 - Footer

Page maintained by Adrienne Decker

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