CSC 111: Intro to Computer Science through Programming

Final Project

Due: Wednesday, May 3 at 11:59pm on Moodle

The final project for this course is to create an interactive graphics game. We will again be practicing classes and integrating several concepts from the past few weeks.

Final Project Assistance

Since the final exam is on pencil and paper, the final project is a chance for you to demonstrate your programming abilities in a setting where you test and debug your code. I want to be able to see what you can program without detailed assistance from anyone else. So for the final project, you may get help from the TAs and myself on conceptual questions and code design, but not debugging or specific coding issues (also, this will only be until Thursday April 27 - after that we will only be answering final exam related questions).

In addition, you may discuss concepts and code design with other students, but no other students should look at your code and you should not look at theirs. All code you submit should be your own original work - produced and understood by you.

Credit for this assignment: Dominique Thiebaut

Froggy Game

In Homework 9 we saw how to create an animation using classes, but it wasn't interactive. And in Homework 7 we created a game, but it didn't use classes. In this assignment you will put these two pieces together to create an interactive game using classes.

The high-level idea is to have a character (for example: a frog) who is trying to cross a road of moving traffic. If the mouse is clicked above the road, the frog moves up a little bit. And if the mouse is clicked below the road (not shown in the video), the frog moves down a little bit. If the frog successfully crosses the road, the text at the top of the window increments the number of crossings. If the frog is hit by a car, their number of lives reduces by 1. After 3 lives are used up, the game is over.

See the video below for an example of what your game should do:

Credit for this game: Farida Sabry

The required functionality is described below in a suggested order of implementation, but feel free to break down the project however you like. Make sure to take it step by step though - don't try to implement everything at once!

Requirements

  • Road

    To set up your window, first create two Rectangles to represent the boundaries of the road (I would recommend using a function for this part and calling it from main). When the mouse is clicked above these boundaries, the frog will move up, and when the mouse is clicked below these boundaries, the frog will move down.

  • Car class

    Building on the Car class we wrote in class, create a Car class. You should have a draw method and a move method. The move method should just move the car a little bit each time, but it should also wrap the car, similar to the swimming fish from Homework 9. The car does not have to look exactly like the video, but it should have at least four components, which need to be kept track of in a list.

    In your main method, create one car traveling left and one traveling right. You should not have separate Car classes for left and right or separate move methods - you can keep track of the direction using a negative or positive speed.

  • Two lists of Cars

    Once you can get two cars to wrap (one in each direction), then create two lists of cars: one of cars moving left and one of cars moving right. There should be at least three cars in each list, roughly equally spaced and traveling at the same speed. The cars should be different colors. Test this part thoroughly and make sure the cars working before moving on to the frog and game play. You are also welcome to set up the car lists in a helper function.

  • Frog functionality

    The main character in your game should be represented as an Image instance (see Homework 8 for an example of how to create an Image). Here are png (left) and gif (right) versions of the frog shown above, but you are welcome to use another image file for your character instead.

    frog frog

    You do not need to put your frog in a separate class (since it is only one graphics object), but you are welcome to if that makes more sense for your code. The frog should start towards the bottom of the window. When the mouse is clicked above the road, the frog should move up a little bit. When the mouse is clicked below the road, the frog should move down a little bit. When the frog reaches roughly the top of the window, it has crossed the road and then should be moved back to the other side.

    To start this out, have the frog's movement be independent of the cars. Make sure you can have the frog cross the road and jump back indefinitely (using the same loop you are using to move the cars). Note: see the .getAnchor() method for a way to obtain the position of the frog.

  • Did a car hit the frog?

    We also need a way to determine if a car hit the frog. To do this we need to know the position of the car, so I would recommend having .getX() and .getY() methods in your Car class. Then in your animation loop, also loop over the two lists of cars to determine if the frog is roughly close to each car. If so, the frog should return the bottom and lose one life. Try to make your game play challenging but possible - the frog shouldn't be able to cross every time, but it also shouldn't get hit right away.

  • Banner

    Now that the game play is working, we need a way to show the results to the user. Create a Banner class to keep track of this changing text. Think about what you need to keep track of. Ultimately your class will be holding a graphics object, the Text. But you also might need methods to update the text based on the number of lives and the number of crossings.

  • Ending the game

    When the number of lives reaches 0, the game should end and the animation loop should be over.

Extensions

There are many ways you could extend your game. You could have a different character besides a frog, you could have different moving objects besides cars, you could make the road crossing more elaborate with more roads or different types of moving objects. You could change the background or modify the environment. You could make the game winnable after a certain number of successful crossings. Feel free to experiment and/or email me a video (QuickTime for Mac is built-in, and here are some Windows options).

Submit

You do not have to submit a transcript for the final project. Instead, take a representative screenshot of your animation and submit that with your code. Make sure that you've thought about variable names and code structure, and that your code is well-commented. It is okay to have some hard-coded numbers for this assignment. Try to keep your main function as short as possible though - for setting up the game you can use helper functions. For each method and helper function, create a docstring describing the functionality and input/output. I would also recommend having headers for each section (globals, classes, helper functions, and main), but it is not required. (See Lab 9 for an example.)

TO SUBMIT ON MOODLE:

  • final_project.py

  • game.png