Skip to content

lorenkr/Snake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Snake Game - Python Edition

Welcome to my Snake Game! This is a classic implementation of the beloved arcade game, built using Python and the tkinter library.


Overview

This project was created to demonstrate fundamental programming concepts such as:

  • GUI Development: Using Python's built-in tkinter library.
  • Game Logic: Handling movement, collisions (walls & self), and food generation.
  • Event Handling: Managing user keyboard inputs in real-time.
  • Recursion & Timing: Using the .after() method to create a continuous game loop.

Features

  • Smooth Controls: Use the arrow keys (Up, Down, Left, Right) to navigate.
  • Dynamic Food: Food spawns randomly on the grid every time the snake eats.
  • Collision Detection: The game ends if the snake hits the wall or its own tail.

Tech Stack

  • Language: Python 3.x
  • Library: tkinter (Standard Python Interface to Tcl/Tk)

How to Run

  1. Clone the repository:
    git clone [https://github.com/YOUR_USERNAME/snake-game-python.git](https://github.com/YOUR_USERNAME/snake-game-python.git)
  2. Navigate to the folder:
    cd snake-game-python
  3. Run the script:
    python snake_game.py
    (Note: tkinter is usually included with Python by default!)

Logic Breakdown

  • Movement: The snake is represented as a list of coordinates. Every 300ms, a new "head" is added based on the current direction, and the "tail" is removed—unless food is eaten!
  • Coordinate System: The game operates on a grid of $20 \times 20$ pixel squares ($SNAKE_SIZE = 20$).
  • Game Loop: The move_snake() function calls itself repeatedly using root.after(DELAY, move_snake), creating the animation effect.

Preview

Snake Game

About

A classic, retro-style Snake game built with Python and the Tkinter library.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages