CMU 15-112 Spring 2018: Fundamentals of Programming and Computer Science
Homework 6 (Due Saturday 24-Feb, at 8pm)
This assignment is SOLO. This means you may not look at other student's code or let other students look at your code for these problems. See the syllabus for details.
To start:
Go to your folder named 'week6'
Create a file named hw6.py in that folder
Edit hw6.py using Pyzo
When you're done, compress hw6.py, hw6-bonus.py (if needed), and any images you used into a zip file. If you don't know how to create a zip file, learn how here.
Submit hw6.zip to Autolab. For this hw, you may submit as many times as you want.
Do not use dictionaries or recursion this week.
Do not hardcode the test cases in your solutions.
Lab Problems [10pts]
Attend your scheduled lab on Friday. While there, complete the basic problem and make a real attempt at the advanced problem. One of the TAs will record your participation by hand.
Clicker Game [90 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. You can download the default 112 icon here.
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 in either a .gif or .ppm format. 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!
Bonus/Optional: runDotsAndBoxes [3 pts] [manually graded]
First, read
the Wikipedia page on Dots and Boxes.
. Then, in the file hw6-bonus.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!