Skip to content

CodeWithAnubhav-ICT/SnakeGame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐍 OOP Snake Game (Nokia 3310 Remake)

Python Game Engine Architecture

A reconstruction of the classic Arcade Game using Python, focusing on Class Inheritance and File I/O.


🔄 The Logic Story (Day 20-21)

Most tutorials teach turtle for drawing simple shapes. In Day 20 & 21, I pushed the library to build a dynamic game engine.

The challenge wasn't just "moving a square"; it was Memory Management and State Persistence.

  • The Movement Problem: A snake isn't one object; it's a list of objects. Moving them requires "Reverse Slicing" logic (shifting the tail to the head's position).
  • The Inheritance Solution: Instead of writing new rendering code for the Food and Scoreboard, I made them inherit from the Turtle class, giving them instant access to graphical methods while maintaining unique behaviors.
  • Persistence: Added a File I/O system to read/write high scores to data.txt, so the record survives even after the program closes.

🏗️ System Architecture

The game loop relies on three custom classes interacting in real-time:

Class Type Responsibility
Snake Object Manager Manages the list of body segments, controls direction, and handles the "Reverse Slicing" movement logic.
Food Child Class Inherits from Turtle. Spawns at random Cartesian coordinates to be "eaten."
Scoreboard Child Class Inherits from Turtle. Manages the UI, updates live score, and handles File I/O for the High Score.

🛠️ How to Run

  1. Clone the repository:
    git clone [https://github.com/CodeWithAnubhav-ICT/SnakeGame.git](https://github.com/CodeWithAnubhav-ICT/SnakeGame.git)
  2. Run the application:
    python main.pyw

🎮 Controls

  • ⬆️ Up Arrow: Move North
  • ⬇️ Down Arrow: Move South
  • ⬅️ Left Arrow: Move West
  • ➡️ Right Arrow: Move East

Part of my 100 Days of Code Journey.

About

A reconstruction of the Nokia Snake Game using Python. Features Class Inheritance for food/scoreboard and file I/O for high-score persistence.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages