CompSci 4 - Classwork - Oct 24, 2006
10 pts
Today's classwork goes along with Chapter 7, Section 1, and also
covers more on variables, showing you how to do timers and counters.
The following work needs to be checked off when you have completed it.
Download the ClickACow world from the web page.
Your computer may save it as a zip file, be sure to rename it as
a .a2w file.
- First run the world to see what it does. Look at the existing methods
and functions.
- Add a counter to keep track of the number of times the cow is clicked on.
- Add a 3D text to display the counter value. This object will need to
keep track of three items via class variables: the number of times the cow
has been clicked, the target value (number of times the cow must be clicked
to win), and the increment value (we will use 1). See the lecture notes.
- Write a method to initialize the three class variables (passing in
their initial values as parameters).
- In world.myFirstMethod, call the previous method to initialize
the class variables and to setup the game. Then setup a loop to
call world.moveCow 20 times. Try this out to see if your
counter is working correctly.
- Add a timer with class variables and a method to initialize its class
variables. The timer should start at 20 and count down by 1 each time
until it reaches 0. You should have an initialize method, similar to what you
had for the counter. The cow should appear one time for each value in the
timer.
- When the timer stops, the cow should stop and say a message. If the user
reached or passed the target value, the user won; otherwise, the user lost.
If you finish early, feel free to embelish your animation.