COSC 123 - Computer Creativity
Lab 2: Methods


In this lab, we will practice with methods, expressions, and variables. The tutorials in the lab will be presented by the TA step-by-step. However, you are free to work at your own pace on the lab. The lab assignment questions will not be presented by the TA.

Initial Step: Partner Selection

You must hand in this assignment with a partner.

Tutorial #1

This part of the lab is a tutorial to cover the ideas of creating worlds, adding objects, and basic method calls.

Step #1: Create a World

Open Alice and create an empty world with a Sand template.

Step #2: Add Object

Click on the green Add Object button. Navigate through the galleries until you find the Objects gallery that contains the lock class. Click on the lock class and then click on the Add Instance to World button (or just hold the left mouse button and drag into the world). Rotate the lock, so it is facing the camera. Click on the Done button to go back to editing the story.

Step #3: Call a Method

We will turn the lock right to the number 20. In the object tree, click on the comboLock object in the object tree and then the plus sign beside it. Click on the dial sub-object. The dial object has a method called roll. Drag the method into the method builder. The parameters are roll right 1/2 revolution.

Step #4: Finish Code

See if you can finish the code so that the dial turns left to 30 and then right to 5 (combination is 20-30-5). Answer file: Lock Problem Answer.

Tutorial #2

Step #1: Setup World

Open Alice and create an empty world with a Water template. Add a few boats from the Vehicle gallery.

Step #2: Move Boats

Make each boat move one direction, turn, then move another direction. You can make turns look smooth by going forward and turning at the same time. Start off with having them move in order then modify to having them move at the same time. Answer file: Boats Problem Answer

Lab Question #1

Create a world with three beetles (Animal->Bugs gallery) that scurry around. Create one beetle object and create a new method called scurry. This method should make the beetle turn left a random amount between 0 and 1 full turn and then move a random distance between 1 and 5 meters. After you write the method, duplicate the object to create two more beetles. Call the scurry method for each beetle twice. Make sure all beetles scurry at the same time. It should look something like this video.

Lab Question #2

Create a wild west shoot out with a cowboy and sheriff from the Old West gallery. Create a draw method for both the cowboy and sheriff that will make them take out their gun and shoot. Make it so the sheriff always wins and raises his arms in victory while the cowboy falls to the ground. Bonus: +2 marks if you make the draw method take a parameter which is a random amount of time and the person who draws fastest wins. Make sure to change the end scene accordingly. (You will need an if statement for this.) Note that the Old West Terrain is only accessible using the Web Gallery. Videos: Basic Version, Bonus Sheriff Wins, Bonus cowboy wins

Note: To make the gun move with the hand, set the Vehicle of the gun to be the hand under the gun's properties.


Submission Instructions and Marking

For this lab assignment, only one person has to submit using Connect the two Alice world files for the questions. Make sure to identify both members of the team.

Grading (20 Marks Total)

Question #1 (10 marks)

  1. +1 - basic world with scenery
  2. +2 - create 3 beetles
  3. +3 - create scurry method
  4. +2 - method calls to make 3 beetles move using scurry method
  5. +2 - make sure beetles move at the same time (all beetles should scurry twice)

Question #2 (10 marks)

  1. +2 - basic world with scenery
  2. +2 - sheriff draw method
  3. +2 - cowboy draw method
  4. +2 - make sheriff/cowboy draw guns at same time
  5. +2 - cowboy falls over/sheriff raises arms in victory
  6. bonus +2 - modify both draw methods to accept a time parameter (how long it takes to draw). Modify methods to make the draw take that long. Generate random time for cowboy/sheriff to draw. In end scene, make cowboy or sheriff die/celebrate depending who shot their gun the fastest.

*Home