Skip to content

traditional snake game in Python using turtle library

License

Notifications You must be signed in to change notification settings

VojtaMi/Snake_game

Repository files navigation

Snake Game in Python

Table of Contents
  1. Description
  2. How to Download the Game
  3. Game Description
  4. Internal Implementation Comments
  5. License

1. Description

This project is an implementation of the traditional snake game, written in Python 3.12 and utilizing the turtle graphical library.

Snake Game

2. How to Download the Game

Prerequisites

  1. Getting Python:
    • Check if Python is installed by running the following commands in your terminal (for macOS/Linux) or command prompt/PowerShell (for Windows):
      python --version
    • If Python is not installed or the version is older than 3.12, you can install it from here.

Getting Git:

  • Git is required to clone this repository. If you don't have Git installed, download it here.

Game Installation

  1. Clone the Repository:

    • Choose the folder on your computer where you want to save the project.
    • Open the terminal window/command prompt in that location.
    • Clone the project using the following command:
      git clone https://github.com/VojtaMi/Snake_game
  2. Run the Game using Python:

    • In the same terminal window, run the following command:
      python Snake_game/main.py

3. Game Description

Menu

Upon opening the project, a simple menu is displayed.

Navigation Keys:

  • w: Select upper option
  • s: Select lower option
  • Enter: Confirm the selected option

Menu Options:

  • Play Game: Start a new snake game
  • Leaderboard: Display the table of the highest saved scores
  • Exit: Terminate the program
Snake Game Menu

Game Mechanics

The goal is to eat as many green dots as possible. After eating a dot, the snake's body grows, and the player's score increases. The score table is shown at the bottom-right corner.

Move the Snake using Keys:

  • w: Move up
  • a: Move left
  • s: Move down
  • d: Move right

The game ends when the snake hits the border, collides with its body, or covers the entire play field.

If the score qualifies for the leaderboard, a prompt for the player's name is displayed. (The player's name is limited to 10 characters for the leaderboard table. When no name is entered, "___" is used.)

Snake Game Score Prompt

Leaderboard

The leaderboard stores the highest scores, with a maximum of 5 entries.

A score qualifies for the leaderboard if the table has less than 5 members or if the score is higher than the last member's score.

The leaderboard display menu has only one option: Exit, which returns the user to the main menu when Enter is pressed.

Leaderboard Menu

4. Internal Implementation Comments

This project follows object-oriented principles, making some functionalities easily reusable in other programs. Notably, the Menu class from the menu.py module and the InputHandler class from utils.py can be useful in other projects.

The program generates a file named high_scores.csv in the project's folder to permanently save the leaderboard, ensuring persistence even after the program terminates.

For detailed documentation, please refer to the docstrings and code comments throughout the project.

5. License

Distributed under the MIT License. See LICENSE.txt for more information.

About

traditional snake game in Python using turtle library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages