# Game Development:Intro to Computer Science

## CSC 105Union CollegeFall 2009

Exercises about dictionaries and to practice for the final are on Codelab.

Helpdesk in Olin 102, Sun-Thu 7-9pm.

### Homework 3 - due Wednesday, 10/7 before class

For all problems, hand in an algorithm description as well as your Python code. Document test cases.

#### Some list exercises

These problems ask you to define functions. We are going to talk about that in Friday's class.

##### Has 'a'?

Write a function that takes a list as a parameter and returns true if that list contains the string "a".

##### Reverse a list

Write a Python function that takes a list as a parameter and returns a new list that has the same elements, but in reverse order.

#### Lots of bouncing balls

Download, run, and examine the following program: lots_of_bouncing_balls_v0.py. It creates one ball at a random position on the screen and with a random speed and lets it bounce around.

Study the code. Note that I am using a "new" representation for the ball in the code. I am using a list of four elements (x-coordinate, y-coordinate, x-speed, y-speed) to represent the position and the speed of the ball in one datastructure.

The goal for this exercise is to create a list of lots of balls and have them all bounce around.

That means changes in three places: 1) Instead of creating a single 4-tuple representing one ball, you need to create a whole list of 4-tupels, each one of which is representing a ball. 2) Instead of moving and bouncing just a single ball, you need to move and bounce all balls in your list. 3) Instead of drawing just a single ball, you need to draw all balls in your list.

##### Creating a list of balls.

Here is one strategy for creating a list of balls: create an empty list. Then, in a loop that repeats 10 times, add 10 elements to this list. Each element should be a 4-tuple representing a ball. Each ball should be placed at a random location and should have random speeds.

##### Drawing all balls in the list.

Instead of having a draw statement for just one ball, create a loop that goes through your list of balls and draws each one of them.

##### Move and bounce all balls.

Instead of updating the position and speed for just one ball, create a loop that goes through your list of balls and updates the position and speed for each one of them.

#### Submit

Submit on Blackboard.