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

MID-TERM NEXT WEEK!

Here's last year's lab mid-term. If you can produce this in 2 hours and meet spec, you should be able to ace the mid-term. If you're having trouble with it, make sure to come by during my office hours or make an appointment with me via email: dogwynn@cis.uab.edu.

Understand: this is last year's mid-term. This year's will be similar in scope, but not in content.

Chapter 4: Decision Structures

Boolean Values, If/Else decision structure, Relational comparisons

Part 1 Basic If/Else with a Boolean variable
Part 2 Relational Comparison
Part 3 String Comparison
Part 4 Nested If/Else Structure
Part 5 Logical Operators
Part 6 More Logic

Part 1 - Basic If/Else with a Boolean variable

Part 2 - Relational Comparison - Kick the closest thing

  1. Using the monkey kicks the ball program. Place a soccer ball in the scene and have the monkey kick the closest ball.
  2. Open the file from Lab 3 (part 3) in which the monkey kicks the ball using methods
  3. Save this file under the new name Lab6-2.
  4. From the web gallery > sports add a soccer ball to the scene.
  5. Place the soccer ball 2 meters to the left of the monkey (some distance that is father away from the monkey than the toy ball.)
  6. Place an If/Else statement above the first line of code. Use a default value of true.
  7. In lab 4, you learned to use world functions. Use the world function a < b as the If statement’s condition. That is, drag the a < b over the true value. Select a default value of .25 < .25.
  8. Use the monkey functions monkey distance to to return the distance to the toy ball and the distance to the soccer ball. Drag monkey distance to toyBall to the first 0.25 in the If condition space. Drag monkey distance to soccerBall to the second 0.25 in the If condition space. You should now have If monkey distance to toyBall < monkey distance to soccerBall as the first line of the program.
  9. Move the method calls into the If block (the first Do Nothing space).
  10. Press play.

Part 3 - String comparison, Which ball to kick

Part 4 - Nested If/Else

Part 5 - Logical Operators, Lazy monkey

The and operator allows you to check two conditions at once and verify that both are true. The monkey will only kick the closest ball. Ask the monkey to kick a ball. If it is the closest ball, kick the ball. If it is not the closest have the monkey say, it's too far away.

  1. In Part 2 the monkey kicked the closest ball. In part 4 the monkey asked which ball to kick. We will combine these two operations.
  2. As the first line of code, have the monkey say tell me which ball to kick.
  3. Drag the world function both a and b to the first If condition block (kick toy ball); over the kickball == tBall statement.
  4. You should have both kickball == tBall and true as the If condition. Replace the true value with the result of a comparison of which ball is closest from part 2. Replace true with a < b. Replace a with monkey distance to toyBall and b with monkey distance to soccerBall.
  5. In the Else block have the monkey say "it's to far away".
  6. Play the scene twice answering toy ball and soccer ball (the toy ball should be the closest.)
  7. Change the scene such that the soccer ball is the closest. Replay the scene answering toy ball and soccer ball.

Part 6 - Fix the last program

Assignment

In the last program, what happens if the user specifies a tennis ball?

Fix the code so that the program checks for a valid ball name and then executes the existing code. If the ball entered is neither the toy ball nor soccer ball, have the monkey say I don't see that ball.

Hint: Add an outside If/Else that uses Boolean logic.




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