Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/SnakeInPython.iml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

File renamed without changes.
19 changes: 1 addition & 18 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
certifi==2024.2.2
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
cvlib==0.2.7
gTTS==2.5.1
idna==3.7
imageio==2.34.1
imutils==0.5.4
numpy==1.26.4
opencv-contrib-python==4.9.0.80
opencv-python-headless==4.9.0.80
pillow==10.3.0
progressbar==2.5
PyAudio==0.2.14
pygame==2.5.2
requests==2.31.0
urllib3==2.2.1
pygame==2.5.2
42 changes: 42 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Main package

This package provides a simple implementation of the classic Snake game using the Pygame library.
It consists of three modules:

1. `__init__.py`: Defines the main function `snake_game()` to run the game.
2. `config_apple.py`: Contains the Apple class, which represents an apple object in the game.
3. `config_snake.py`: Contains the Snake class, which represents the snake entity in the Snake game.
"""

# Author
__author__ = "Eduardo Benatti"

# Version
__version__ = "1.1.0"

# Import
import pygame

""" Game configuration """

# Initialize Pygame
pygame.init()

# Screen dimensions
SW, SH = 650, 650

# Block size for snake and other game elements
BLOCK_SIZE = 50

# Font used for the game
FONT = pygame.font.Font(None, BLOCK_SIZE * 2)

# Create the game screen
screen = pygame.display.set_mode((SW, SH))

# Create a clock object to control frame rate
clock = pygame.time.Clock()

# Set the window caption
pygame.display.set_caption("Snake!")
16 changes: 16 additions & 0 deletions src/apple_config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Configuration module for the Apple class.

This module provides the Apple class, which represents an
apple object in the game. The apple is an item that the
player can collect for points.
"""

# Internal import
from .config_apple import Apple

# Author
__author__ = "Eduardo Benatti <https://github.com/eduardo2580/SnakeInPython>"

# Version
__version__ = "1.1.0"
50 changes: 50 additions & 0 deletions src/apple_config/config_apple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
This module provides the Apple class, which represents an
apple object in the game. The apple is an item that the
player can collect for points.

Author: Eduardo Benatti
"""

import random
from src import (BLOCK_SIZE, SH, SW, pygame)

class Apple:
"""
A class to represent an apple in the game.

Attributes:
- rect (pygame.Rect): A rectangle representing the apple's position and size on the screen.

Methods:
- __init__(): Initializes the apple attributes and randomly places it on the screen.
- randomize(): Randomly places the apple on the screen.
- draw(screen): Draws the apple on the given screen.
"""

def __init__(self):
"""
Initialize an Apple object.

Sets the initial position of the apple to (0, 0) and then randomizes its position.
"""
self.rect = pygame.Rect(0, 0, BLOCK_SIZE, BLOCK_SIZE)
self.randomize()

def randomize(self) -> None:
"""
Randomize the position of the apple.

Randomly sets the x and y coordinates of the apple within the boundaries of the screen.
"""
self.rect.x = random.randint(0, SW - BLOCK_SIZE) // BLOCK_SIZE * BLOCK_SIZE
self.rect.y = random.randint(0, SH - BLOCK_SIZE) // BLOCK_SIZE * BLOCK_SIZE

def draw(self, screen) -> None:
"""
Draw the apple on the screen.

Args:
- screen: The surface on which the apple will be drawn.
"""
pygame.draw.rect(screen, "red", self.rect)
125 changes: 0 additions & 125 deletions src/snake.py

This file was deleted.

16 changes: 16 additions & 0 deletions src/snake_config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Configuration module for the Snake class.

This module provides the Snake class, which represents the snake
entity in the Snake game. The Snake class handles the snake's
movement, collision detection, and drawing on the screen.
"""

# Internal import
from .snake_config import Snake

# Author
__author__ = "Eduardo Benatti <https://github.com/eduardo2580/SnakeInPython>"

# Version
__version__ = "1.1.0"
Loading