Labs

Lab 5.3: Game On!

Print
References

In this set of exercises we begin programming in earnest, asking you to add some basic statements and data1 items of your own to the existing code. All of these exercises are to be conducted on your copy of the concert game. In each case, make changes to your file to accomplish the proposed change in the game, and then test your changes out by loading your file into your browser2 and running it.

1pp. 89, 149, 260, 310
2pp. 9, 14–15, 70–71, 143, 146

You should attempt them one at a time (that is, make changes to address one exercise, and work on that until it has been solved), and in the prescribed order (since we've ordered them to reflect their relative difficulty). Feel free to copy and paste sections of code to make your work easier.

  1. Create a global variable3 called "playerName" and initialize it to be an empty string ("").

  2. Add a statement which prompts the user of the program for their name, and saves the name in variable playerName. Place this statement so that it gets executed immediately after the screen is initialized, but before the game (and the clicking) begins.

  3. Now modify some of the messages that are displayed in alert boxes and in the document's status window so that they use the player's name.

  4. You have undoubtedly noticed that whenever the image (or, your "location" in the game) changes, you are put back into "Look" mode. Change the program so that this is not the case. That is, you should change from "Look" to "Action" mode, and vice versa, only when you click on the appropriate radio button.

  5. At present there is a relatively short list of items that you need in order to proceed to the concert. Change this so that you must also have sneakers in your inventory to make it all the way to the concert. Notice that we have provided you with a function4 that will tell you when sneakers have been "clickedOn" when visiting the clothing store.

  6. Speaking of the clothing store, notice how the cashier insists that you have ATM cash before allowing you to leave the store - even when you haven't selected anything to purchase. Change function processBeat so that you are checked for money only if you have actually purchased something at the store. [Hint: A function named inventoryContains is already defined in the program which can be used to tell you whether or not the inventory contains a particular item.]
3pp. 151–152, 220-221,
4pp. 144–146, 179-182, 239–240

Labs

MODULES:


Home Search Resources Objectives Feedback Order Form Credits

Copyright Notice
© 1998 PWS Publishing Company, All Rights Reserved.