CMU 15-112 Fall 2018: Fundamentals of Programming and Computer Science
Homework 6 (Due Sunday 7-Oct, at 5pm)



  1. COLLABORATIVE: Tetris [50 pts] [manually graded]
    Write Tetris according to the design given in this step-by-step tutorial. You may not use a different design, even if you think there's a better way to do it (there probably is, but you still have to do it this way). This may seem limiting, but sometimes you have to write code according to a specific algorithm, rather than writing code to solve a specific problem.

    To get full credit, you'll need to complete the basic implementation according to the design spec. Please write this basic version (WITHOUT extra features) in hw6-tetris.py. If you'd like to add extra features to your game for extra credit (up to 3 points, at graders' discretion), create a second version of your Tetris file called hw6-tetris-bonus.py and add your bonus features in this file. Have fun!

  2. SOLO: Clicker Game [50 pts] [manually graded]
    Using tkinter and the animation framework we've learned about in class, implement the Clicker Game. The goal of this game is to click on as many icons as possible before time runs out.

    For a video walkthrough of the game's requirements, see the video below.


    You do not have to implement the game as shown in the video pixel-perfect. In fact, you can theme the game according to your own interests by changing the icon that you use! However, we will expect that your game contains the following features:

    • Three main states: the start screen (which shows introduction text and a bouncing icon), the game screen (where you actually play the game), and the game over screen (which displays the final score and ends the game)

    • In the start state:
      • The screen should display text showing the game's name and instructions for how to start
      • The player should not be able to interact with the game at all, except by pressing 'p' to play (which brings the player to the game state)
      • There should be one infinitely bouncing icon, which should not go offscreen at all.

    • In the game state:
      • Gameplay takes place in a rectangle that is 2*data.width x 2*data.height in dimensions. When you start the game, the view is centered in the middle of that rectangle. The rectangle is surrounded by a black border with thick walls.
      • To move around within the rectangle, press the arrow keys. Pressing an arrow key moves the screen in the correct direction by a tenth of the screen's width/height. The user is allowed to move outside of the bounding rectangle if they want to.
      • A new icon should appear in a random location within the rectangle every 0.5 seconds. Icons should always appear fully within the rectangle (not outside of the black border), and are allowed to overlap each other.
      • Whenever the player clicks on an icon, that icon disappears and the user gets 1 point. If the player clicks on a spot where two icons are overlapping, only the outermost (most recently added) icon disappears. The user can click anywhere in the icon's bounding box for it to disappear (so clicking on the icon's background is okay).
      • The player's score should be displayed in the lower left corner of the screen
      • The player starts the game with 20 seconds remaining to play. However, every five icons that the player clicks on adds 1 second back to the clock.
      • The time remaining is shown in the upper left corner of the screen, and can be rounded down to the nearest integer. This means that the clock will show 0 seconds when there's actually still time left; that's okay for now.
      • The game ends when the time remaining reaches 0 seconds. At that point, the game should switch to the game over state.

    • In the game over state:
      • The background should be red, with white text
      • The screen should display text stating that the game is over, showing the player's final score, and showing instructions for how to play again.
      • The player should not be able to interact with the game at all, except by pressing 's' to start again (which brings them back to the start screen)

    To personalize the game, you're encouraged to make your own icon! Just make sure it's small enough to fit on the screen, and that it's stored in a .gif format either in the week6 folder or at a URL.

    To use the default icon or a GIF from a URL: download image_util.py and image_util_example.py. In your hw6-clicker.py file, add the import:

    from image_util import *

    Then, to create the default image, use the code:

    PhotoImageFromLink("https://www.cs.cmu.edu/~112/notes/hw6-112-icon.gif")

    If you want to use a different GIF image, change the URL to be your URL of choice. The example file provides more information on how to do this.

    To use a local GIF image: move your gif image into your week6 folder, then name it hw6-image.gif. Note that your file must be named this way to work during grading! The image can then be created with the code:

    PhotoImage(file="hw6-image.gif")

    If you have a non-gif image that you want to turn into a gif, use a service like this, and if you have an image that's too big, use a service like this.

    Have fun!

  3. Bonus/Optional: runDotsAndBoxes [3 pts] [manually graded]
    First, read the Wikipedia page on Dots and Boxes. Then, in the file hw6-bonus-dab.py, 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!