CS105L Introduction to Game Programming Using Alice (Lab)
Fall 2009

LAB 9

Chapter 7 Lists and 6 mouse events & random numbers

Covers material from Chapters 7 & 6 in class text; Starting Out with Alice.

Part 1 . Lists and nested loops. Marcello returns

  1. Create a world with a table and with a character standing behind the table. You can use an old lab or homework. Place any 3 objects on the table. The magician will face each object in turn and the object will disappear. When an object disappears it should flash in and out of visibility 3 times before disappearing.
  2. Requirements:

Part 2 Creating lists: Bottles revisited

  1. Download lab8-bottles.a2w (Scene and dance routines courtesy of Gabrielle Hale)
  2. Open this file in Alice and modify this code to act as below:
  3. Initially no cans to be seen on the table. When the user enters a number, that number of cans appear on the table. As the singer sings the song, a can will disappear from the wall for each number counted. All visible cans must dance.

    HOW-TO:
  4. Create a list allCans containing all the cans (fill this list at creation). You might want to check how the cans are numbered before entering them in the list.
  5. Create an empty list Cans. This list will be populated during run-time.
  6. Create an InitializeCans method such that when the user enters a valid number, the method populates Cans with the correct number of cans. Use a loop to do this by adding an item from the allCans list to the Cans list.
  7. Now that you have a list of cans, make all the cans in the Cans list visible.
  8. Modify the World.sodaRotate method to work with the new list to make the cans dance as required. Hint: use the For all together built-in method.

Add code to make each can disappear at the proper time.

NOTE: Theses list should be global lists, not method variables.

Part 3 – Lists and mouse events

  1. Do exercise #4 on pg 313.
  2. Create a list that contains 5 bugs. Use the web gallery for a better selection.
  3. The main method should create a random value between 0 and 0.75 to be used as a turn value. A random value between 1 and 2 should be used for a move forward value.
  4. While there are bugs left, a random bug will be given a random amount to turn and a random amount to move forward. Then another random bug is selected.
  5. Only bugs (item in the list) should disappear when clicked.

Hint: Look a Table 7-2 on page 290 for List functions that can help.




Last modified: 8/19/09
By: David O'Gwynn