15-112 Fall 2012 Homework 9
Due Monday, 5-Nov, at
10pmRead 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, and
when you do collaborate, be certain to list the names and andrew id's of
each collaborator. You may collaborate with different students on
different questions.
- To start, download these files and place them all in the same directory:
- What to turn in:
- Turn in a single file, hw9.py, that contains all your solutions.
Be sure to start with the hw9.py that we provide!
- As you would expect, do not include any global variables in hw9.py.
- OO-based Animation
Case Study Review [20 pts]
- Adding Text to
AnimationWithRetainedGraphics [40 pts]
- 2d Board Game
[40 pts]
- Bonus: Othello
[5 pts]
- OO-based Animation Case Study Review
[20 pts]
This problem is COLLABORATIVE.
You may work in groups of up to 4 students (yourself included). Your
task here is to meet in a group and to carefully work through the course
notes from this week, and then to write Animation.py
from scratch, and then to write AnimationWithRetainedGraphics.py
also from scratch. You may peek at the notes and even the solutions as
needed, but it is expected that you will be able to completely write these
easily from scratch under quiz conditions. This is not a minor
task, and we expect you to allocate about 4 hours for this.
What to submit: In your hw9.py file, there is a comment at the header
that presently reads "I did NOT do #1." Assuming you did in fact meet
with your group, and that you invested hours of hard work into this, and
that you can basically write Animation.py and
AnimationWithRetainedGraphics.py from scratch under quiz conditions, then
you should change this comment to read "I *DID* do #1, along with <andrewId's
of your groupmates>". That's it!
- Adding Text to
AnimationWithRetainedGraphics (SOLO)
[40 pts]
This problem is SOLO.
In the designated part of the file hw9.py, write the classes Font, Text, and
AnimationWithRetainedGraphicsWithText so that the Hw9_textExample code in
hw9-driver.py runs without errors and produces this output:
Hint: if you forget to include the anchors, the text will not be
properly positioned, and it may instead appear that the fonts are wrong.
- 2d Board Game [40 pts]
This problem is COLLABORATIVE.
You may work in groups of up to 4 students (yourself included). In the
designated part of the file hw9.py, following the guidelines provided below,
write the classes Piece and BoardGame to implement a basic 2d board game
that extends AnimationWithRetainedGraphics so that the Hw9_boardGameDemo
code in hw9-driver.py runs without errors, and produces this output:
This "game" (just a simple demo, really) changes players when you click on a
cell. Player 0 is blue, player 1 is red. Clicking changes player
0 to player 1 and player 1 to no player (actually, player == None).
Thus, here is the "game" after clicking in each of the cells one-at-a-time
across the first row:
Guidelines:
- Create a Piece class that extends Circle (which extends Shape).
- The game should include a board (self.board), which should be a 2d
list of Piece instances. Initially, piece.player == None for all
of these.
- Do not include the checkerboard background squares as actual Shape
instances. Instead, draw these first (basically in the background)
and then call super class redrawAll to get all the Shape instances (just
the circular pieces) to draw.
- Include the method getCellBounds that takes a row and col (in
addition to self) and returns a tuple (left, top, right, bottom) that
defines the pixel boundaries of that cell. You should use this
method to help compute the values you provide in the calls to the Piece
constructor.
- Include the method cellPressed(self, row, col), and then include the
code in mousePressed that determines in which cell the press occurred
and calls cellPressed accordingly. Provide a default cellPressed
method that just passes.
- Bonus: Othello (SOLO)
[up to 5 pts]
This problem is SOLO.
In the designated part of the file hw9.py, write the class Othello that
extends the BoardGame class to implement a playable game of
Othello
(also known as Reversi). It should be human-human playable (no
computer player / AI needed!). Hint: you will probably want to
adapt the wordSearch code from earlier this semester. If you do that,
this is not an overly complicated task.
Have fun!
carpe diem - carpe
diem - carpe diem - carpe diem - carpe diem
- carpe diem -
carpe diem - carpe diem - carpe diem