# 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.

### Take Home Exam 2 - due Wednesday, 10/21 before class

Note: This is a take home exam. That means that (differently from the homework assignments) you have to work on this on your own. Do not talk to class members or any one else about the questions or your solutions. Do not use any resources other than a) the text book (Gaddis, Starting out with Python), b) the online text book Think Python, c) the python documentation, and d) the pygame documentation.

For all programming problems submit both an algorithm description and the implementation.

#### 1) Snowflake

To understand this program, run it several times and try out different cases: for example, try to understand what happens when you call draw_snowflake in the main function with parameter 0, with parameter 1, with parameter 2. Also, things may become clearer, if you only draw one side of the snowflake. (Comment out the calls for the other two sides.)

#### 2) Palindromes

A palindrome is a word that is the same when read from left to right or from right to left.

Write a function is_palindrome which takes a string as a parameter and checks whether this string is a palindrome. The function should return 'True' if the string is a palindrom and 'False' otherwise. (Remember that strings are very similar to lists. In particular, indexing and for-loops work on strings.)

For example, the function you write should behave like this:

```	is_palindrome("anna")
```
should return True
```	is_palindrome("banana")
```
should return False.

#### 3) Data representation

The Python library `sys` defines a variable `maxint` which refers to the largest integer value available to Python. For example:

```>>> import sys
>>> print sys.maxint
2147483647
```

So the largest plain integer value available in Python is 2147483647. What does that tell us about the number of bits that Python uses internally for representing plain integers? Explain.

#### 4) Pop lots of balls

Download pop_all_balls_v0.py. This is essentially a solution to the problem from the homework assignment in which you were asked to create a list of bouncing balls.

##### Make them pop

Add code that plays a popping sound whenever you click on one of the balls. (But no sound, if you miss.) Things that may help you: pop.wav, pop_the_ball.py (the program where you popped a single ball).

##### Speed them up

Now, every time the player clicks a ball, all balls in the list should get faster.

Hint: set up a boolean variable called `clicked_ball` and initialize it to False. When you detect a click on a ball, change that variable to True. So, when you are updating your game objects, this variable tells you whether or not there was a click that hit a ball or not. Don't forget to reset the boolean variable for the next round of the game loop.

#### For extra credit

##### Make them disappear

Now add code so that if the player clicks on a ball it disappears. (The goal of the game will be to make all balls disappear.)

##### Congratulations

If the player manages to click away all balls, a congratulation image should appear on the screen.

#### Submit

Submit on Blackboard. If it does not let you upload your files, send them to me by email and use the following subject line "CSC 105 take home exam 2".