15-112 Spring 2014 Homework 8

Due Monday, 24-Mar, at 10pm

Read these instructions first!

  1. Collaborative
    The problems in this section only are collaborative.  You may work in groups of up to 2 students (yourself included), so do not work with more than one other student.  Each student should submit their own work individually.  Include the name and andrew id of your groupmate, if any, at the top of your hw8.py file.  And as always with collaborative work, you must be actively involved in every part of your solution, and you may never simply copy any code from anyone.
     
    1. Snake [20 pts]
      This problem is COLLABORATIVE. You may work in groups of up to 2 students (yourself included).  Carefully follow all the steps in this step-by-step Snake Tutorial (except that you should name your functions snakeRun, snakeMousePressed, etc, as noted above).  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!
       
    2. Tetris [40 pts]
      This problem is COLLABORATIVE. You may work in groups of up to 2 students (yourself included). Write Tetris exactly according to the design given in this step-by-step tutorial (except that you should name your functions tetrisRun, tetrisMousePressed, etc, as noted above). You may not use a different design (except as noted here), even if you think there's a better way to do it (there probably is, but you still have to do it this way).  Note: The Tetris tutorial uses a dictionary in canvas.data, like this: canvas.data["foo"]. You have to change this to use a Struct(), like this: canvas.data.foo. Also, it uses a global canvas, which of course you should not do.
       
  2. Solo
    The problems in this section are solo.
     
    1. Shape Invasion [40 pts]
      SOLO.  Here you will write a simplified version of this already fairly simple game.  You don’t need the cute graphics, or the sounds, and so on.  But you do need to reproduce the basic gameplay.  In particular, you should have 5 distinctive shapes, each in a different distinctive color, along the bottom.  The same 5 shapes, but in some random order, start falling slowly from above.  The player selects shapes at the bottom by clicking in them (actually, if it is easier, you can instead check if they clicked in the so-called “bounding box”, which is the smallest rectangle that encloses the shape).   The player can swap shapes at the bottom by selecting one shape (which must highlight to show it is selected) and then selecting another shape, at which point they swap.  If the shapes at the bottom are in the right order, one more star in the top left turns yellow.  On the other hand, if the falling shapes reach the bottom row, then one of the yellow stars turns non-yellow.  When the player gets 5 yellow stars, the game stops and displays YOU WIN!  But if the player loses a star but has no yellow stars to lose, then the game stops and displays YOU LOSE!  Also — and this is different from the given game — do something to make the game get noticeably harder each time you earn another yellow star (and easier again if you lose that star).  That said, it should still be possible for an average player to win sometimes.

      Important note:  unlike Snake and Tetris, this game does not use a grid or board of cells.  The falling shapes move some small number of pixels on each timerFired, and so are not stored in a grid.
       
  3. Bonus/Optional [up to 10 pts]
    The problems in this section are solo.  Note that you may only do up to 2 of these 3 bonus problems (your choice of which two), for a max of up to +10 points of bonus:
     
    1. Sokoban [up to 5 pts]
      SOLO.  First, read the Wikipedia page on Sokoban.  Then, write the function playSokoban() that plays the game.   Do not use any images.  All drawing must be with graphics primitives (lines, rectangles, ovals, etc).   Also, do not use any sound.  Besides that, design as you will.   The nicer the game, the more points awarded.   Have fun!
       
    2. Dots and Boxes [up to 5 pts]
      SOLO.  First, read the Wikipedia page on Dots and Boxes.  Then, write the function runDotsAndBoxes(rows, cols, maxSecondsPerTurn) which will play a human-human Dots and Boxes game on a rows x cols board, but also not allowing more than maxSecondsPerTurn time to elapse on any give turn.  If the time elapses, the screen should visibly flash and the player should lose that turn (though not the game).  Your user interface can be simple, even quite plain, but it must be functional so two people can use it to play.  It must display the board, make clear whose turn it is and where legal moves are, make it easy for players to enter moves, actually make those moves if legal (or reject them if illegal), display who has captured which boxes, alternate turns, display the score, detect game over, and print a suitable game over message.  Don't forget about the maximum time per turn, too!


carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem   -   carpe diem