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
-
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.
-
Requirements:
-
Place all code in the my first method. This will make the
nested loop more obvious.
-
The objects are to be in a list.
-
A loop will make the magician face an object in the list and
make the object disappear. The loop index will be the index
into the list.
-
A nested loop will be used to make the object flash in and
out of visibility.
Part 2 Creating lists: Bottles revisited
-
Download lab8-bottles.a2w
(Scene and dance routines courtesy of Gabrielle Hale)
-
Open this file in Alice and modify this code to act as below:
-
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:
-
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.
-
Create an empty list Cans. This list will be populated during
run-time.
-
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.
-
Now that you have a list of cans, make all the cans in the Cans
list visible.
-
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
-
Do exercise #4 on pg 313.
-
Create a list that contains 5 bugs. Use the web gallery for a
better selection.
-
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.
-
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.
-
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.