On this page:
Bubbles!
Before you go...
Signature Detective
Bubble Extensions!
6.6

Lab 6 Working with Lists

lab!

Purpose: LISTS. Let’s use lists! But not the function list which we don’t know yet.

Textbook references: Chapter 9: Designing with Self-Referential Data Definitions

Bubbles!

Goals: Use lists to create a fun bubble game!

Dr. Natalie Hartzell needs your help to create an educational bubble program for children. This program will take as input the number of bubbles to show on the screen. These bubbles will be of random color and size and will have a random velocity in both the x and y directions. They will be placed at a random position on the screen. The bubbles will float around the screen at their given velocity and bounce off the walls so that they never leave. When you move your mouse over the bubbles they will pop and disappear forever. You don’t need to click to make this happen. It just happens when your mouse meets the bubble.

To prevent the screen from emptying of bubbles we will add a new random bubble every tick of the clock. Just like the initial bubbles this will have a random color, size, position, and velocity.

Exercise 1 Design the data definition for your world program. What’s changing? What aspects of the game are randomly generated? These are things you will need to keep track of.

Exercise 2 Design the world program itself. Remember to follow the steps for designing a world program. If you have forgotten these steps, check out this Piazza post which we so lovingly put together for you.

Before you go...

If you had trouble finishing any of the exercises in the lab or homework, or just feel like you’re struggling with any of the class material, please feel free to come to office hours and talk to a TA or tutor for additional assistance.

Signature Detective

Goals: Practice understanding what the data type restrictions on code must be when reading it.

Exercise 3 *** Determine the signature for the following functions.

(define (this is a function)
  (cond [(empty? is) a]
        [else (+ function (this (rest is)))]))
 
(define (so is this)
  (cond [(zero? this) (string-length is)]
        [else (string-append is (so (substring is 1) (sub1 this)))]))

Bubble Extensions!

Goals: Extend your bubble game to be cooler and more interesting than ever

Exercise 4 Update your game so that instead of adding a bubble on every tick, it adds a bubble when you press the spacebar.

Exercise 5 Update your game so that you can drag bubbles around. Since the lack of popping will mean an abundance of bubbles you can allow your bubbles to drift off-screen instead of being constrained by the walls of your scene.