15-112 Spring 2013 Homework
7
Due Wednesday, 27-Mar, at 9pm
Read these instructions first!
- Parts of this homework are SOLO and other parts are COLLABORATIVE (see hw1 and the syllabus for details). Be sure to know which is which! For COLLABORATIVE problems, you may work in groups of up to 4 students (including yourself). You may not split up the work -- everyone must work on every problem. And you may not simply copy any code but rather truly work together. For SOLO problems, you may not work with anyone else in any way, which means you may not discuss these problems with anyone else, even if you do not show them your code nor view theirs. Except, of course, you may always discuss the problems with the course staff, who are happy to help!
- Otherwise, the same rules as hw6 apply.
- You will be submitting multiple files for this assignment (snake.py, moreSnake.py, tetris.py, and
friends.py, and optionally also lineRunner.py). In order to do this, you will need to put all of your files into a single folder
named hw7, then 'zip' that folder into the file hw7.zip. You can find instructions about how to create a zip file here.
Be sure to only submit a single zip file. Any other archive types (such as .rar and .tgz) will not be accepted.
There is no autograder for this assignment.
- You may not use globals in this assignment. You will need to change some of the starter animation code in order to do this- make sure you are using the file
events-example1-no-globals.py from the animation notes in order to do this.
- [20pts] friendsOfFriends
Write this function in a file named friends.py
Background: we can create a dictionary mapping people to sets of their friends.
For example, we might say:
d["fred"] = set(["wilma", "betty", "barney", "bam-bam"])
d["wilma"] = set(["fred", "betty", "dino"])
With this in mind, write the function friendsOfFriends(d) that takes such a
dictionary mapping people to sets of friends and returns a new dictionary
mapping all the same people to sets of their friends of friends. For
example, since wilma is a friend of fred, and dino is a friend of wilma, dino is
a friend-of-friend of fred. This set should exclude any direct friends, so
even though betty is also a friend of wilma, betty does not count as a
friend-of-friend of fred (since she is simply a friend of fred). Thus, in
this example, if fof = friendsOfFriends(d), then fof["fred"] is a set containing
just "dino" and fof["wilma"] is a set containing both "barney" and "bam-bam".
Also, do not include anyone either in their own set of friends or their own set
of friends-of-friends.
Note: you may assume that everyone listed in any of the friend sets also is
included as a key in the dictionary. Also, do not worry about
friends-of-friends-of-friends.
- [40 pts] Tetris Tutorial
This problem is COLLABORATIVE.
You may work in groups of up to 4 students (yourself included). In a file named tetris.py, write
Tetris exactly according to the design given in
this step-by-step tutorial. You may not use a different design (except
for eliminating globals), even if you think there's a better way to do it
(there probably is, but you still have to do it this way).
- [10 pts] Snake Tutorial
This problem is COLLABORATIVE.
You may work in groups of up to 4 students (yourself included).
In a file named snake.py, carefully follow all the steps in this
step-by-step Snake Tutorial. Of course, you are ultimately given
the answer in the tutorial. Even so, while you may consult that
solution, you may not simply copy and submit that version, but instead you
must work through each step carefully and then submit the version that you
typed in (and hopefully completely understood, from first principles)
yourself, even if it is basically the same as the solution (as one would
expect). Make sure that you change the solution so that it does not use globals!
- [30 pts] More Snake (SOLO)
This problem is SOLO.
In a file named moreSnake.py, starting from the code in the
snake8.py file at the end of the Snake Tutorial, add the following
features:
- A pause feature, where the game pauses when the player
presses 'p'
for 'pause', and where the game resumes (exactly where it left off) when
the user presses 'p' again. While paused, the board should be
visible, but the colors should be a bit dimmer than when unpaused.
- A score, which should be displayed at the top-center, above
the board (which will have to be moved down by enough pixels to make
room for the score). The score should start at 0 for each game,
and increase by 1 each time the snake eats food.
- A high score list, which should be displayed as part of the
"Game Over" screen at the end of each game. This is just a list of
the 3 highest scores (during this execution; so if you exit and restart
the program, the list is cleared), in sorted order from largest (on top)
to smallest (on the bottom). If there are fewer than 3 scores
available, do not list the missing scores as 0's, but just do not list
them at all (thus, you will list one score after the first game).
- Two levels. Level 1 works just as described in the
Snake tutorial. But when the snake eats the 3rd piece of food, the
game switches to Level 2, with the following changes:
- Speed-up: make the game move noticeably faster, but
not unplayably faster.
- Poison: in addition to randomly-placed food, a
separate randomly-placed piece of red poison is placed on the board
(and of course not on the snake nor on the food). If the snake
eats the poison, it dies. Note that you must be sure the
poison is not placed one square away from the snake's head unless
that is the only location remaining. (Note that this is slightly ambiguous-
when necessary, you should make design decisions, and document them!)
- Walls. When the game is paused, the user can click with
the mouse in empty cells to create walls (which are brown), or click on
walls to remove them. If the snake runs into a wall, it does not
die, but rather it destroys the wall at a cost of 1 point. If that
would result in a negative score, then the snake dies. At the end
of a level, if any walls existed for at least 20 snake moves on that level,
the score increases by 1 extra bonus point. Do not remove the
walls when placing new food or poison.
- [up to 5 pts] Bonus: Line Runner (SOLO)
This problem is SOLO.
Line Runner is a simple, fun game available for Android and iPhones.
Find it, learn how it works, and then implement a game (in a file named lineRunner.py) that is fairly close
to it (not exact, since it uses touch events, and maybe you should use
keyboard events seeing as your code will be running on a desktop and not a
phone). Don't go too crazy with this. Keep it simple (for
example, you can still get some points if the line runner is just, say, a
rectangle (though it'd be much more interesting if you attempt the running
animation)).. And
have fun!
carpe diem - carpe
diem - carpe diem - carpe diem - carpe diem - carpe diem -
carpe diem - carpe diem - carpe diem