Code Monkey home page Code Monkey logo

py-snake's Introduction

Project Preview Image

py-snake (GUI)

๐Ÿ“™ About the project

An implementation of the 'Snake' game.

Snake is a sub-genre of action video game where the player maneuvers the end of a growing line, often themed as a snake. The player must keep the snake from colliding with both other obstacles and itself, which gets harder as the snake lengthens. Read more.

โš™๏ธ Game settings

  • Snake is represented by three black links.
  • Apple is represented by one, static green link.
  • Wall is represented by three blue vertical or horizontal links, moves in a certain direction at half the speed of the snake.

In the beginning of the game, the snake's head is located in the center of the screen facing upward. Until the required amount is reached, an apple (in green color) and a wall (in blue color) are added.

โ–ถ๏ธ Interactions

The following diagram illustrates the interactions between the game's objects and their effects

Alt text

Snake eats an apple

  • In the round in which the snake ate the apple, the player receives a score equal to the square root of the snake's length.
    • As an example, a snake whose length at the beginning of the current round is 8 will receive the score of โŒŠโˆš8โŒ‹ = 2.
  • Starting from the round after eating the apple, the snake's length will gradually increase by 3 links.
  • A new apple is added in its place the next round.

A wall goes beyond the boundaries of the board

  • A new wall is added in its place the next round.

A wall colliding with an apple

  • A new apple is added in its place the next round.

A wall colliding with the snake's body

  • The snake's tail will be cut off at the point of collision.

Snake's head is outside the board's boundaries, colliding with a wall or itself

  • Game over.

๐Ÿšฉ Getting started

run:

> python game_display.py --help

usage: game_display.py [-h] [-x WIDTH] [-y HEIGHT] [-s SEED] [-a APPLES] [-d]
                       [-w WALLS] [-r ROUNDS] [-t DELAY] [-v]

Runs the "Snake" game. Closes the program automatically when disqualified.

optional arguments:
  -h, --help            show this help message and exit
  -x WIDTH, --width WIDTH
                        args.width: Game board width
  -y HEIGHT, --height HEIGHT
                        args.height: Game board height
  -s SEED, --seed SEED  Seed for random number generator (not passed to game loop)
  -a APPLES, --apples APPLES
                        args.apples: Number of apples
  -d, --debug           args.debug: Debug mode with no snake
  -w WALLS, --walls WALLS
                        args.walls: Number of walls
  -r ROUNDS, --rounds ROUNDS
                        args.rounds: Number of rounds
  -t DELAY, --delay DELAY
                        Delay between rounds in milliseconds (not passed to game loop)
  -v, --verbose         Print helpful debugging information (not passed to game loop, can be used multiple times)

๐Ÿ”Ž Examples

>  python game_display.py
# A board with a width of 30, a height of 40, 4 apples, and 1 wall
> python game_display.py --width 30 --height 40 --apples 4 --walls 1
# A board with a width of 50, a height of 60, 5 apples, 2 walls, and 500 rounds
> python game_display.py -x 50 -y 60 -a 5 -w 2 -r 500

The program uses tkinter, Python's standard GUI package. If you do not already have tkinter, you can install it with:

> pip install -r requirements.txt

๐Ÿ’ป Built with

The game was built in Python 3.9, using the tkinter package ("Tk interface") GUI toolkit.

Designed and tested on Windows 11.

py-snake's People

Contributors

erelado avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.