Skip to main content

08 | Assignment 08

Snake Game

The purpose of this assignment is for all students to get a global feel for what is involved to create a Python game using the Pygame library and Object Orienting programming. This is actually a fairly advanced game. It is not necessary for you to know all of the code requirements in great detail. The goal is not for you to submit one final game file. If that was a goal, then there would be nothing to prevent a student from simply turning in the finished code example that is freely available. However, there will be some questions about the game on the final exam.

You will start out editing the snake.py file and then you will save it as step_1a_definitions.py. When you finish step_1a_definitions.py you will save it as step_1b_game_loop.py and continue coding. You can only create these files as you go along. At the completion of each file, you should run your program and make sure it runs as expected.

As you continue the process you will finish up with the following files:

step_1a_definitions.py            
step_1b_game_loop.py
step_2a_add_green.py
step_3a_grid_cells.py
step_3b_food_fixed_rect.py
step_3c_food_fixed_image.py
step_3d_food_random.py
step_4a_create_rect_snake.py
step_4b_make_segments_rounded.py
step_5a_move_snake_yes_reverse.py
step_5b_move_snake_no_reverse.py
step_5c_game_class.py
step_6a_eating_food.py
step_6b_gen-rand-pos.py
step_6c_gen-check-snake.py
step_7_make_snake_grow.py
step_8_collision_print_game_over.py
step_8b_game_over_reset.py
step_8c_game_over_restart.py
step_8d_game_over_hit_tail.py

This is not the complete game. This is all that I am requiring for the project. If you want to create additional steps for extra practice or extra credit, then you may do so.

All of these steps are in the Panopto videos.

  1. Video 1: In class video (29:04)
  2. Video 2: In class video (8:50)
  3. Video 3: After class video (24:44)
  4. Video 4: After class video (5:59)

You will need to follow Videos 1 and 2 if you missed the class. There were only a few students that were still in class for Video 2. So if you left early, then you will need to watch Video 2.

All students will need to watch Video 3 and 4.

If you have not yet started the project, you will need to download the zipped starter file at the top of this page: https://opal.ils.unc.edu/~lblakej/snake-game/01-pygame/

Pygame installation

We had a previous online session for all students to confirm that they had Pygame installed.

If you are having issues with Pygame running, then contact me. You will not be able to test your code if Pygame is not installed and working. Here is the page to make sure you have pygame installed. https://opal.ils.unc.edu/~lblakej/snake-game/01-pygame/

Resources

There is a website that has step by step instructions: https://opal.ils.unc.edu/~lblakej/snake-game/

These are mostly formatted, but I still need to polish up a few pages.

If you would like to have primarly instructional video you can access it here. https://opal.ils.unc.edu/~lblakej/560/

Login and Password is in the Canvas Assignment page

It is my hope that you will take this opportunity to document this process for future reference. Therefore it would be good to add comments as you go that will help you remember what you learned as you do the project. These comments should be your own comments. Each project should be done individually. This is not a group project. Any files that are exactly the same with the exact same comments will constitute a potential integrity issue. Any submissions with no additional comments will not earn full points.

When you have completed all of the steps, you can zip up the folder and submit here.

There will be a resubmit opportunity provided you submit it early enough.