CS101: Introduction to Computers and Computing
CS101: Introduction to Computers and Computing

Programming Lab 2: Learning About Methods, Events, Functions, and Algorithms

There are 3 parts to this lab:

Part 1: Boot computer into Ubuntu operating system and printout grade sheet.

Part 2:  Create game using Alice programming environment.

Part 3: Check all tasks are complete, email assignment to instructor and self, shut down computer, and staple together and turn in grade sheet and code printouts.

Introduction:
A computer program is a set of instructions for the computer to follow to accomplish a task.  An example of a computer program is Microsoft Word.  When Microsoft Word is running on a computer the computer is executing the Microsoft Word program instructions.  When a program such as Word is running the instructions the computer follows must be in binary form (also called machine language) since a computer can only process zeros and ones. 

Programming is the creation of instructions for computers.  When computers were first invented computer programmers had to write computer programs in machine language (zeros and ones).  This proved to be very difficult since humans do not usually write instructions as a series of zeros and ones.  To make programming easier computer programming languages were invented.  High level programming languages allow computer programmers to write the instructions for the computer using human based language principles such as letters, words, base ten numbers, and mathematical symbols instead of just zeros and ones.  Later, when the instructions are run on a computer, another program turns the instructions written by the programmer into the zeros and ones needed by the computer. 

Alice is a tool that can be used to create programs without having to learn a programming language.  This allow users to learn about problem solving skills and programming concepts without the burden of also learning a programming language.

Lab Directions:
Part 1: Boot computer into Ubuntu operating system and printout grade sheet.

When you first start your computer it will be running the MacOS operating system and your screen will look like this: Current Desktop

For our project we will be using the Ubuntu operating system running in a virtualization environment called VMware Fusion.  In a moment we will be starting the VMware Fusion software.  Once VMware Fusion starts running your screen will look like this:

Ubuntu in pause mode.

To unsuspend Ubuntu just click the white arrow in the middle of the screen. Once Ubuntu is
unsuspend then on the left side of the screen click on the Firefox web browser icon as shown below ...

Click the Firefox icon.

... and once the web browser is running reopen these directions.

To start the software running click on the dock icon called VMware Fusion shown below:


Fusion Icon


Once your computer is running Ubuntu and you have opened today's lab directions in Firefox your screen should similar to the one below:

Drag
                        the lab directions window to the right side of                        the Desktop.

To setup your computer to work more efficiently drag the directions to right side of the screen as shown below:

move directions to
                        right side of screen

For this lab, and each of the remaining labs that require you to complete a project, there will be a grade sheet.  The grade sheet informs you of the tasks you are required to complete in that day's lab and how many points each of the tasks are worth towards the 100 points available for the project.

You are about to download and open the Prog2GradeSheet.xls spreadsheet file using LibreOffice Calc.  When it opens in Calc your screen will look like this:

 Type
                        your name in cell B1 and lab section number in                        celll f1.

To download today's grade sheet click on the following link: 


In the now open spreadsheet click in cell B1, type your name, and press return on your keyboard.  Next click in cell F1, type your lab section number, and press the return key on your keyboard.   The spreadsheet should now contain your name and lab section number similar to the spreadsheet below:

Type your name in
                        cell B1 and lab section number in celll f1.

Now click once on the grade sheet window to make Calc the active program. 
At the top of the Calc window  select File menu > Print as shown below...

file menu print

... to open the following dialog box:


print box


Select either the By Cabinet or the By Door printer and then click on the OK button.

Now walk up to the printer you selected and place one piece of paper at a time into the manual feed tray and retrieve your printout of the grade sheet.

Close the grade sheet by clicking the red close window button in the upper left corner of the window as shown below...

click red button

... and when the following dialog box appears...

click the don't
                        save button


... select Close without saving.


Your screen should now look like this:

Drag
                          the lab directions window to the right side of                          the Desktop.

Look over grade sheet printout to find the requirements for today's lab.  If you have any questions about the grading ask your instructor.

Part 2: Create game using Alice programming environment.

Learning computer programming is a challenging task for most people.   Beginning programmers are trying to learn many things at the same time.  Usually a new computer programmer must learn basic programming concepts, algorithm skills (how to solve problems), a particular programming environment, and a particular programming language.   With this thought in mind the Stage 3 Research Group at Carnegie Mellon University developed the Alice programming environment.  The Alice programming environment allows beginning programmers to learn basic programming concepts, algorithm skills, and write programs for the computer without having to also learn a programming language.  This is accomplished by using a graphical user interface with drag and drop to create programs.  This means the users of Alice are free to concentrate on learning the basic concepts of programming and algorithm skills. 

Once you have created the game you will use the skills learned in the previous Alice lab, and in today's lab, to add new elements to the game.

WARNING: Alice has many features.  Normally we would encourage you to try out as many of the features as possible in a new program.  In fact, playing with a new programming editor and language can be a great way to learn a new computer programming language.  However, it is highly recommended that you follow the directions below exactly as written.  Clicking on the wrong feature in Alice can have drastic consequences to your program and decrease your ability to finish today's lab in the time allotted.  When you are finished with today's lab you can reopen Alice and create without worrying about a grade.

In a moment you will be starting a program called Alice.  When Alice starts it will fill the whole screen as shown below...

alice take up whole screen

... to get back to these directions just click on the Firefox icon on the Launcher on the left side of the screen as shown below:

Firefox icon

To start Alice click once on the Alice icon found on the Launcher on the left side of the screen as shown below:

Alice launched from application
                    menu.

Once Alice loads up, you should see the following:

alice take up whole screen

In the Welcome to Alice! dialog box...

click the cancel
                    button

... click on the Cancel button to close the dialog box and accept the default Alice world.

Next move your mouse to the upper left corner of the large Alice window and resize the window by clicking the window resize button as shown below....

click on the window
                    resize button

 ... your screen should now look like the one shown below (if not resize your windows to look like the ones below):

click the green
                    button

Alice calls the programs you create in it world's.  When you create a world in Alice you are creating a program.  When you run a world you have created in Alice you watch the world's instructions take place in a window.  To see our world (or program) as it exists now click on the Play button near the upper left corner of the Alice window as shown below...

click the play button to run
                    your world.

...to open a window that will play your world as shown below:

empty world window

Since we have not created any instructions in our world (program) yet we just have a very boring world with just a blue sky and green grass where nothing is happening.  Click the Click the stop button button at the top of the Alice World window to stop the world (program) from running and also close the window.

Alice is a object oriented program language (or OOP).  Object oriented programming is a modern programming concept.  Among the many advantages of object oriented programming is that it allows programmers to easily reuse code in other programs.  Since code can be easily reused in other programs creating programs becomes quicker.  Reusing code is accomplished partly by having objects.  Our project today is made easier by the fact we already have four objects in our Alice world.  When we canceled the Welcome to Alice dialog box our Alice world defaulted to the grass template to start our world.  If you look below where you clicked on the Play button you will see the Object Tree panel as shown below:

this is a image

Objects can be shared among programs through the use of object libraries.  We will now bring one of the pre-made objects into our world from the object library.  Alice calls these object libraries galleries.  In the world viewer panel click once on the green ADD OBJECTS button as shown below:

click add objects
                      button

The Local Gallery (objects stored on this computer) will appear at the bottom of the Alice window (your local gallery will load in a non alphabetical order this is OK):

the local gallery will appear
                    at the bottom off the screen.

Scroll to the right in the Local Gallery and click on the Vehicles gallery as shown below:

click on the vehichels gallery

Each item the Vehicles gallery consists of a Class of objects.  Scroll the the right until you find the class of objects called Car.  Each class is a blueprint that tells Alice exactly how to create and display an object from that class. When an object is created and displayed, we call this instantiating the class because an object is an instance of that class. 

In the Vehicles gallery click on the Class Car as shown below:

select the car

When the following window appears...

Click on the vehicle to add to
                    the world.

... click once on the Add instance to world button and watch as the Class Car object is added to the world as shown below:

click the done button

When you add an object, such as the car class, to a world you can control its initial placement and size using the object controls.  To demonstrate this we will move our car to the correct starting location.  Near the top right corner of the Alice project window are the Move Objects Freely buttons.  These buttons are used to move objects in the world.  To move our car into the correct starting position click on the Turn Objects Left or Right button as shown below:

select the turn
                    objects left or right button

Now click and hold on the car to spin it so that it is pointing away for viewer as shown below:

click and drag
                    the car to spin it and point it away from the viewr


Now to complete adding the Car Class to the world click the green Done button underneath the move object buttons...

click the green done button

...to close the object galleries (libraries) and return the Alice window to its default view as shown below:

click the green done button to
                    complete added the car object to the world

Since we have actually added something to our world now would be a good time to save the world with the following process (and how often do you get to save the world).  Select File menu > Save World as shown below:

select file menu save
                    world

We need to save our project into our folder, however, the Save World As.. dialog box is already setup to save your project on the Ubuntu Desktop as shown below:

saving to desktop

All we need to do is provide a name for our world.  In the File Name: box type in the name of the project using the following naming strategy:

lastname_firstinitial_prog2

(i.e. John Smith would name his project smith_j_prog2)

Once your Save World As... dialog box is setup similarly to the one below...

click on save

... click on the Save button to save your world.

With our world (program) safely saved lets try playing (running) the world again by clicking on the Play button as shown below:

click the play button to
                      run your world.

You will notice that the addition of a new object to our world still does not add any action to the world.  The new object (the car) just stands still.  Click the Stop button at the top of the World Running... window to stop the world from running and close the window.

To make the world a little more exciting we will need to learn more about the objects in the world.  Click once on the Car object in the Object Tree to select it as shown below:

click on the car
                      object in the object tree

With the car object selected the details panel below the Object Tree panel shows the car's details as shown below:

the details of the
                      penguin are displayed on the details panel

At the top of the details panel is three tabs called properties, methods, and functions. These three tabs list the three elements that comprise any object.  The methods tab is currently selected. 

A method is a coordinated sequence of instructions that will be carried out when requested. You have already used methods in your animations created in earlier labs. Every object in an Alice world has a repertoire of instructions it knows how to do— move, turn, turn to face, etc. These instructions are actually called primitive methods because they are built into the object and are present when the object is copied from the library.

Every object has a list of primitive methods that determine the objects potential behavior.  This means we use methods to tell an object to do something (how to behave).  We will now use one of the cars methods to tell the car how to behave.  The first method listed in the cars details is car move.   When we use the car move method we will have to set parameters.  In this case the two parameters of the car move method is what direction to move the car and how many meters. 

(IMPORTANT NOTE: WHEN WORKING WITH AN OBJECTS METHODS DO NOT CLICK ON ANY DO NOT
                    CLICK THE EDIT BUTTONS BUTTON UNLESS TOLD):

To tell Alice we would like to use this (or call) method when we play our world we need to complete a two step process.  First we will drag the method to the method editor, and then second when we let go of the method, we need to select the parameter from the drop down menu as shown below

drag the car
                      move method to the editor area


After you have dragged the car move method to the method editor, and set its parameters, it should look like this:

the coar move method
                      in the method editor

Click the Play button to play your world (program).  The car should now move forward 5 meters (if it does not ask your instructor for help).  Click the Stop button at the top of the World Running... window to stop the world (program) from running and close the window.

Notice that the whole program only starts after you click on the Play button.  This action is called an event. An event is something that happens. In response to an event, an action ( or a sequence of many actions) is carried out. We say the event triggers an expression. 

In our program when the event of clicking the Play button is executed it triggers the expression of starting the program.  We can see this by looking at the Events panel near the top right of the Alice window as shown below:

the events panel

Once the world.my first method is called it in turn calls the car move method (and the car move forward 5 meters). This chain of action is shown below:
the event starts the
                      methods

Right now our world is not very exciting.  The car moves and the user just watches it move like they were watching a movie.  We need to provide some interaction with the user or this will be a real boring game.  One way to introduce interaction into your program is through the use of events.

Many computer programs today are user- centric. In other words, it is the computer user (rather than the programmer) who determines the order of actions. The user clicks the mouse or presses a key on the keyboard to send a signal to the computer about what to do next.

At the top of the Events panel click on the create new event button and select the event of Let the arrow keys move <subject> as shown below:

click on
                      create new event and select then the mouse clicks                      on something

A new event will show up in the Events panel as shown below:

the new mouse event is
                      listed

Click on the drop down menu that says camera and select car as shown below:

delete the fires
                      event

The second event should now look like this:

change anything to
                      entire penguin


Your Events panel should now look like this:

final event

Click the Play button to play your world (program) and notice that the car still moves forward 5 meters.  However, now you can use the arrow keys to drive the car.  The event of pressing the arrow keys is expressed by moving the car object.  Go ahead and drive the car using the arrow keys (you can click the Restart button in the window if you lose the car off the screen). 

You most likely noticed two problems with our program.  1) We do not need the car to move 5 meters forward anymore since the user now has control of the car. 2) It is very easy to lose the car off the screen when driving.

To correct our first problem we will delete the car move method by dragging it to the trash can at the top of the screen as shown below (when dragging an item to the trash make sure to place the mouse pointer on the trash can and do not let go until the trash can has a green box around it and the lid opens):

drag the car move
                      method to the trash

We will correct our second problem by adjusting the camera's view.  To do this we need to review object properties. The properties of an object are the characteristics the object presents.  For instance, the car object is yellow.   In the Object Tree click on the camera object and then select its properties tab as shown below:

select camera and the
                      properties tab

Notice that the vehicle for the camera is the world.  This is why we can drive our car out of sight.  The camera is told to follow the world and not the car.  Click on the drop down menu that currently says world and select car as shown below:

select car from menu

Now play your world, and trigger the second event by pressing the arrow keys, and see how changing the properties of the camera has changed the program.

Now, like many of today's games, the point of view is from the item the user is controlling.  Just by adding an event and changing a property we have added much interaction to the world.

Save the world.

Our game's goal is to drive the car to an object.  Now we can drive the car we need to bring in an object for it to find.  Click the green ADD OBJECTS button as shown below:

click add objects
                      button

We will now add a cube object from the Local Gallery Shapes library.  When the cube is added to the world it will appear on top of the car and you will not be able to see the car object.  This is OK as two Alice objects can occupy the same space as shown below:

cube on top of car

Once you have added the cube use the Move Object Freely tool shown below...

use the correct
                      butoon


... to drag the cube in front of the car as shown below:

drag cube in front
                      of car

... and then click the green Done button.

Click Play and try driving to the cube.

As the program stands right now driving to the cube is easy and not much of a game.  To make the game more fun we need to provide several things.
  1. We need to provide instructions on how to play the game to the user.
  2. We need to tell the user once they find the cube that they have won.
  3. We need to ask the user after they have found the cube if they want to play again.
  4. If the user wants to play again we need to move the cube to a new location.
  5. If the user does not want to play again we need to end the program.
You can think of the above steps as the Problem Statement for the rest of the program.  These are the things that the program needs to do to be a successful game. 

Programming is usually a 6 step process shown below:
  1. Define the problem.
  2. Create an algorithm.
  3. Create pseudo code.
  4. Code program.
  5. Test program.
  6. Debug program
At this point, having created a problem statement, normally you would create an algorithm (a solution) to the problem.  You would then translate the algorithm to pseudo programming code.  Pseudo code is when you start turning your algorithm from human language into a computer programming language.  After you have created your pseudo code you then translate that into program code in a computer language.  After you code the program you then test and debug (finding and removing errors) the program.

Alice effectively removes steps three and four form the programming process.  You do not need to translate your algorithm into code since Alice allows you to create programs without typing any code.  This allows the users of Alice to concentrate on the steps 1 (Define the Problem), 2 (Create an Algorithm), 5 (Test), and 6 (Debug).  This is very important because the best programmers are the ones that accurately define the problem and come up with a effective simple algorithm to solve the problem.

For your program today we have just defined the problem. 
  1. We need to provide instructions on how to play the game to the user.
  2. We need to tell the user once they find the cube that they have won.
  3. We need to ask the user after they have found the cube if they want to play again.
  4. If the user wants to play again we need to move the cube to a new location.
  5. If the user does not want to play again we need to end the program.
We will now step you through the algorithm we have created to solve the problem.

As we construct this program we could place all the code in the world.my first method.  If we did the code will grow and grow until we end up with a large number of instructions all together. If we continue to write our program this way, our program code is likely to grow to lots of lines of code all in one big block. The problem with this is that it becomes difficult to read and even more difficult to find and remove bugs (errors). We need a way to better organize the instructions to make it easier to read and debug a program.

One way to do this is to organize the instructions into smaller methods. Once the method is defined, we can tell Alice to run it (call it) from other methods.  To accomplish these goal we need to learn a bit about methods.  A method is a coordinated sequence of instructions that will be carried out when requested. You already used one method ('car move forward 5 meters' which we have since deleted) in your program. Every object in an Alice world has a repertoire of instructions it knows how to do— move, turn, turn to face, etc. These instructions are called primitive methods and are built in to the Alice software. The primitive methods can be used to create methods of your own. By making methods of your own you can divide a program into small, manageable pieces that work together to create a meaningful whole. Another advantages to this way of programming is once a method is written it allows us to think about an overall task instead of all the small actions that were needed to complete the task. This is called abstraction.

To solve our first problem:
  1. We need to provide instructions on how to play the game to the user.

We will create a new method.  With the world selected on the Object Tree click on the Methods tab as shown below...

click on world

... and then click on the create new method button. The Name dialog box appears type in start game as shown below...

type in start game

... and click OK.

Notice that a new tab has opened in the Editor area as shown below and highlighted in red:

new tab open in
                      editor

Since we now have to methods open to edit (world.my first method and world.start game) it will be important that we always make sure we are editing the correct method by checking which tab is active (or yellow) in the Editor area.

At the start of the game we need to tell the user the name of the game and how to play.  Click on the car object in the Object Tree and with the methods tab selected drag the car say method to the new start game method and select the parameter of other... as shown below:

add the stuff

When the Enter a string: dialog box appear type in Welcome to Crazy Cube as shown below:

enter welcome
                      to crazy cube

Add another car say method to the world.start game method and place it under the other car say method and select the parameter of other... as shown below...

drag and drop

... and enter Use the arrow keys to move the car to the cube! as shown below ...

type Use the
                      arrow keys to move the car to the cube.

... and then click OK

Click on the world.my first world method tab in the Editor area to select that method to edit.  Then select the world in the Object Tree and make sure its methods tab is selected.  Now drag the new start game method into the world.my first method as shown below:

drag the start game method to
                    the world.my first world method

Now the next time we click the Play button the first event will call the world.my first world method which then calls the start game method as the arrows show below:

the event calls the methods

Click Play to check your program.

We have a little bit of a logic error in the program.  A logic error is when the computer runs the program but the program does not solve the problem correctly.  In this case the car says the correct instructions but the instructions are not on the screen long enough for the user to read comfortably.  We can correct this by adjusting some parameters.  Click on world.start game tab.  Now in the first car say method click on the arrow after the more... and select duration and then 2 seconds as shown below:

select 2
                    seconds

Repeat the process for the second car say method and then play the world.

Save the world by selecting File menu > Save World.

By changing the parameters of the car say methods we have now solved our logic problem by having the directions shown on the screen lone enough for the user to read.

Our next problem is: We need to tell the user once they find the cube that they have won.

To keep our program well organized we will create a new method.  With the world.my first method tab selected click on the create new method button and when the name: dialog box appears type in found cube winner as shown below:

name the method found
                    cube winner

Alice should now look like this (notice that the new method world.found cube winner is the active method in the Editor area since its tab is yellow):

your screen
                    should look like this

Select the car in the Object Tree and then drag the car say to the new method and select other... as shown below:

use the car say
                    method

In the Enter a string: dialog box type Congratulations! You found the cube! as shown below:

type the message

Obviously, we will need to call our new method when the user drives the car to the block.  Since this will not happen until the user finds the block we will need to use an event to call our new method.

In the Events editor click on the create new event button and select While something is true as shown below:

select while
                    something is true

Scroll down in the Events area to see the full new event as shown below:

the new event

The user wins by driving their car to the cube, so we need event that will recognize if this condition happens (the car and the cube come together).  The new event will allow us to test for the condition. 

To test if the car is within the cube we will need to learn about the third characteristic of an object which is their functions.

Let's look at the functions for the car object by selecting the car object in the Object Tree and then clicking on its functions tab as shown below:

select the worlds
                    functions tab

We can use a function to ask questions and get back an answer. In this case we need a function that will ask when the car object is within a certain distance of the cube object.

It turns out the car has such a function and it is called: car distance function

To use this function drag it from the detail's panel to the first box in the new event with the red word None in it as shown below (do not let go until the box turns green)...

drag the
                    function to the event

 ... and select the parameters of 1 meter and cube as shown below:

select 1 meter
                    and cube

Your event will now look like this (you will need to either scroll or enlarge the Alice window to see the whole event):

the event

We now have an event that will monitor if the condition of car within 1 meter of cube becomes true.  When the car comes within one meter of the cube it will trigger the event.  Which means we need to tell the event how to express the trigger.  In this case we need the event to call the world.found cube winner method we just created. 

Select the world in the Object Tree and then click on the on in the methods tab.  Your screen should now look like this:

your screen
                    should look like this

Drag the world.found cube winner method to the to the first box of the event that says a red Nothing and do not let go until the box turns green as shown below:

drag to event

You screen should now look like this:

current screen

The new event should now look like this (you will need to scroll the events window to see the whole event):

the completed new event

The trigger for the new event is the car object coming with in 1 meter of the cube object.  The event will be expressed by calling the world.found cube winner which will tell the user they have won.

Play your world and see what happens when you drive the car to the cube.

When you drove the car to the cube the following should have happened (if not ask your instructor for help):



Once again we have a little logic error.  The program works but the player is most likely not expecting the car to disappear into the cube.  To solve this we will use on the cube's properties.

Select the cube in the Object Tree and then click on the properties tab.  Now drag the isShowing property so that it is executed first in the world.found cube winner method and set its parameter to false to hide the cube as shown below:



Your world.found cube winner method should now look like this:

new value

Play your world to see the results.

Save the world.

This brings us to our third problem: We need to ask the user after they have found the cube if they want to play again.

To accomplish this we will need to learn about If/Else control structures.  An If/Else control structure involves making a decision based on a current condition in the world. In this case if the player wants to play again we will need to do something different then if the player wants to quit the game.

At the bottom of the method editor are several advanced programming concepts that can be used in an Alice world.  Drag the If/Else tile to the bottom of the world.found cube winner method and set the parameter to true as shown below:

drage the if else to the
                    method

The method should now look like this:

the if/else in place

The If/Else works as shown below:

if else statement

To create the above scenario we will first need to setup the condition of asking the user 'yes' or 'no' question about playing the game again.  This is a job for a function.  Click on the world in the Object Tree and then click on its function tab as shown below:

select the
                    worlds functions

Scroll down the world's functions until you see the ask user for yes or no as shown below:

find the yes no function

Drag the ask user for yes or no function to the true box of the If/Else statement until the box turns green and then let go as shown below...

drag the function to the true
                    box

... and then select other... as shown below:

select other

In the Enter a string: dialog box that opens type Do you want to play again? and then click OK as shown below:

type do you
                    want to play again

Your If/Else statement should now look like this:

completed if/else

Try playing your game to see if it tests the condition (asks if you want to play again).

You may have noticed that if you answer either yes or no to the question nothing happens.  This is because both paths of the If/Else statement currently say Do Nothing. Either way you answer nothing is going to happen.

Let's handle the false condition first.  What happens when the user answers no.  In this case we can thank the user for playing and end the program. 

Select the car in the Object Tree and then click on its methods tab as shown below:

select car and methods

Drag the car say method to the Do Nothing after the Else and select other... as shown below:

drag car say

In the Enter a string: dialog box type Thank You For Playing and click OK as shown below:

enter thank you
                    for playing

Your If/Else statement should now look like this:

false conditon set

Play your world and after you find the cube answer No.

What happens if the user answers yes to the play again question.  In the current state of the program the cube is invisible and still in the same place.  This will not make for a very fun second game.  We will need to move the cube to a new location and make it visible.

To keep the program well organized we will accomplish these tasks in a new method.  Select the world in the Object Tree and then click on the methods tab as shown below:

 world methods

Click the create new method and when the New Method dialog box opens type in play again and then click on OK as shown below:

type play
                    again

First we will have to tell the user to wait while we move the cube to a new location.  Select the car in the Object Tree and then select the methods tab as shown below:

select the car methods

Drag the car say method to the new method and select other... as shown below...

drag the car
                    say method

... in the Enter a string: dialog box that opens type Wait until I move the cube! as shown below:

type wait until
                    I move the cube

We now need to move the now invisible cube to a new location.  Select the cube in the Object Tree and the methods should already be selected as shown below:

select the cube methods tab

We will now move the cube left, right, backwards, and forwards to a new location.  Drag the cube move method under the car say method and select left and 10 meters as the parameters as shown below:

select left and
                    10 meters

Add the cube move method three more time setting the parameters of the three methods to:
  1. right 5 meters
  2. forward 10 meters
  3. backward 5 meters
The world.play again method should now look like this:

add the four move methods

We now need the cube to become visible so the player can find the cube.  Click on the properties tab for the cube and drag the isShowing property under the last method and set the parameter to true as shown below:

drag the is showing and set to
                    true

Your world.play game method should now look as shown below:

current method

Lastly, we need to tell the user to find the cube.

Select the car in the Object Tree and then select the methods tab as shown below:

select the car methods

Drag the car say method to the new method and select other... as shown below...

drag the car
                    say method

... and when the Enter a string: dialog box appear type Find the cube! and click OK as shown below:

type Find the
                    cube!

Your world.play again method should now look like this:

how method should look

Our world.play again method is now ready for use but it is not being called by any event or method.  To change this click on the world in the Object Tree and then make sure the methods tab is selected as shown below:

select the worlds methods


Now in the method editor work area select the world.found cube winner method by clicking on its tab.  You Alice screen should now look like this:

your screen
                    should look like this

Now drag the play again method to the area of the If/Else statement that contains the instructions for if the player answers 'yes' to wanting to play again as shown below:

add play again to method

Play your world and use the Restart button to play the game a few times to test the program.

You most likely very quickly noticed we have another logic error.  When we move the cube it always comes up in the same place relative to the car.  Not much of a challenge for the user.  To correct this we will use another function.

In the methods editor click on the world.play again method.  This is the method where we move the cube.  Your screen should now look like this:

your sreen
                    should look like his

The problem is the method always moves the cube 10 meters left, 5 meters right, 10 meters forward, and 5 meters backward.  So it always ends up in the same relative spot from were it was last found.  To change this we need to move the cube left, right, forward, and backward a random amount of meters so the cube always shows up in a different place relative to the last place it was found.  To accomplish this task select the world in the Object Tree and then select the functions tab and scroll up to the top of the functions as shown below:

select the world functions

One of the functions the world has is a random number generator.  Every time the random number generator is called it it asks the computer the question: Create a random number from a range of numbers? The answer to the function is a random number the computer generates.  We will use this to very the amount of meters the cube moves.

Drag the random number function on top of the 10 meters in the first move cube method until the box turn green as shown below...

drag the random
                    number function on to 10 meters

... and after you dragged the function to the correct location your screen should look like this:

1st random number in
                    place

Click on the first down arrow on the random number function you just installed and set the parameter to maximum and 50 as shown below:

select maximum
                    and 50

Your world.play again method should now look like this:

current method

Repeat the process with the other three cube move methods and when you are done you world.play again method should look like this:

correct method

Play the world and repeat the game the few times to see if the random number functions move the cube to varied locations.

The cube now moves randomly which should increase users game enjoyment.

Select File menu > Save World to save your program.

After a program (world) is created you need to test and debug. You test to make sure it works correctly and correct any errors (bugs). Test your program to make sure it correctly solves all of the problems in our problem statement. 
  1. We need to provide instructions on how to play the game to the user.
  2. We need to tell the user once they find the cube that they have won.
  3. We need to ask the user after they have found the cube if they want to play again.
  4. If the user wants to play again we need to move the cube to a new location.
  5. If the user does not want to play again we need to end the program.

If their are any problems in your program make sure to correct them.

You may have noticed while testing your program there are some aspects of the program that could be better. You may have noticed that the cube takes a long time (about 6 seconds) to move if the user plays the game more then once.

For five points towards your grade find and correct the section of the program were the cube moves to its new location so that the cube moves at least 4 seconds faster.

For up to 20 extra credit points:

After the player finds the cube the first time and chooses to play the game again use an If/Else control structure, and a function, to check if after cube is moved the first time it is within 5 meters of the car.  If the cube is within 5 meters of the car it should then be moved again until it is not within 5 meters of the car.  After cube is moved more then 5 meters away from the car it should then reappear.  The player should then be instructed to find the cube.

Your instructor will be grading your code. To make it easier to grade we need a printout of your code.  Alice exports your code as an HTML file on the desktop that we can later open in Firefox and printout.  To achieve this first select File menu > Export Code for Printing... as shown below:

select file menu
                    export code for printing

When the Export Code dialog box opens find the Author's name: box near the bottom and type in your name (see the example of John Smith below ) and lab section number as shown below and highlighted by the red box...

Type your name in the
                    author field and then click on export code button

...and then click the Export Code button as shown below to export your code to the desktop.

Exit Alice by selecting File menu > Exit as shown below:

select file
                    menu exit


If Alice asks you to Save World? with a dialog box click on Yes as shown below:

click yes

You should now see the HTML file containing your code on the desktop as shown below:

fine the html
                    file on the desktop



When you double click on your html file in just a moment it will open in its own tab in Firefox as shown below:

drag to Firefox icon

After making sure that the Firefox tab that contains your code is the active tab select File menu > Print Preview.. as shown below:

code open in safru
                    tab

In the print preview box that opens make sure to select 60% from the Scale menu as shown below:

set scaling to 65%


Next verify that your printout is 1 0f 1 pages as shown below:

1 of 1 pages

Click on the Print... button as shown below...

click the print button

Select a printer (ByDoor or ByCabinet) and click the Print button to printout one copy of your code as shown below:

click on print

Click the red window close button in the upper left corner of the screen to close the Print Preview window.

 After making the directions the active tab in Firefox your screen should now look like this:

drag
                      direction to the right

On the Desktop right click underneath your HTML icon and select New Folder as shown below:

select new
                    folder

When the new folder appears on the Desktop type the following new name:

lastname_firstinitial_prog2
(i.e John Smith would call the folder smith_j_prog2)


Drag the three icons on the desktop into your folder as shown below:

icon 1  drag your html file into your folder    drag second file

Extra Knowledge: Alice is a free download.  If you are interested in learning more about Alice you can go download it at Alice.org where there are Windows, Mac, and Linux versions.  There are also many free tutorials for Alice online and there are many books that teach Alice programming.  Students who first learn Alice usually do much better in beginning programming classes than students who do not.

Part 3: Check all tasks are complete, email assignment to instructor and self, shut down computer, and staple together and turn in grade sheet and code printouts.
Open your folder on the desktop by double clicking.   When your folder opens make sure it contains the following 3 items shown below:

check the
                    contents of your folder

If you are missing any items ask your instructor for help.  Close the window containing your folder items.

Now look over your grade sheet to make sure you have completed all items.  If you are unsure of any of the steps ask your instructor for help.

Your screen should look similar to this:

termnial windows closed


Next we compress a copy of your folder so that we can email it to both yourself as a backup and to your instructor for grading. Right click on our folder and select Compress... as shown below:

compress your folder

Make sure that the dialog box that appears is setup similar to the one shown below...

click create

... and then click on Create. A confirmation box will open as shown below...

click ok

... click Close.

A compress version of your folder and files will show up on the desktop as shown below:

compressed file

Follow the steps below to send the new compressed folder to yourself and your instructor:

Step 1) Login to your online SSU email account (or other online email account).

Step 2) Create a new email.

Step 3) Fill in the subject for the email as:

lastname_firstinitial_prog2
(example: smith_j_prog2)

Step 4) Attach the compressed folder to the new email.

Step 5) Address the email to your instructor's email address (highlight and copy the email address for your instructor from the list below):

Mr. Carter's lab section's use this email address = cs101carter@cs.sonoma.edu

Step 6) CC the email to yourself.

Step 7) Send the email.

Once you have emailed in your assignment make sure you have your two printouts. You will turn these into your instructor with the grade sheet stapled to the top.

Lastly, to exit out of Ubuntu running in VMware Fusion and shut down the computer place your mouse at the top of the screen and wait until the VMware Fusion menus appear and then select Apple menu > Shut Down... as shown below...

Select shut down.

... and when the following dialog box appears select Shut Down as shown below:

Select Shut Down

End of Lab.