Improve package structure and add proper setup.py

This commit is contained in:
Rbanh 2025-02-23 12:38:45 -05:00
parent 75a9cc5ba8
commit 0571392afe
5 changed files with 124 additions and 10 deletions

View File

@ -1,8 +1,24 @@
#!/usr/bin/env python3
"""
AI Snake Game Runner
This script provides the entry point for running the AI Snake Game.
It handles command-line arguments for different game modes and configurations.
"""
import argparse
from src.game import Game
from src import Game, GameMode
def main():
"""
Main entry point for the AI Snake Game.
Parses command line arguments and initializes the game with the specified settings.
Available modes:
- Normal mode: Standard game settings
- Test mode: Smaller window and faster speed
- Debug mode: Shows grid and additional debug information
"""
parser = argparse.ArgumentParser(description='Run AI Snake Game')
parser.add_argument('--test', action='store_true',
help='Run game in test mode (smaller window, faster speed)')
@ -25,10 +41,18 @@ def main():
# Apply debug mode settings
if args.debug:
game.debug = True # Will need to add debug support to Game class
game.debug = True
# Run the game
try:
game.run()
except KeyboardInterrupt:
print("\nGame terminated by user")
except Exception as e:
print(f"Error: {e}")
finally:
# Clean up will be handled by Game class destructor
pass
if __name__ == "__main__":
main()

39
setup.py Normal file
View File

@ -0,0 +1,39 @@
from setuptools import setup, find_packages
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setup(
name="ai-snake-game",
version="0.1.0",
author="Rbanh",
description="A classic snake game with AI capabilities",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://git.spacetrainclubhouse.com/Rbanh/AI-Snake-Game",
packages=find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Development Status :: 3 - Alpha",
"Topic :: Games/Entertainment :: Arcade",
],
python_requires=">=3.8",
install_requires=[
"pygame>=2.5.2",
"numpy>=1.24.3",
],
extras_require={
"dev": [
"pytest>=7.4.3",
"pytest-xdist>=3.5.0",
"black>=23.12.1",
],
},
entry_points={
"console_scripts": [
"snake-game=run_game:main",
],
},
)

View File

@ -1,2 +1,30 @@
# This file is intentionally empty.
# It marks the src directory as a Python package.
"""
AI Snake Game - A classic snake game with AI capabilities.
This package contains all the core game components including:
- Game engine and state management
- Snake movement and collision detection
- Food spawning system
- Menu interface
- AI controllers (coming soon)
"""
from src.game import Game, GameState
from src.snake import Snake, Direction
from src.food import Food
from src.menu import Menu, GameMode, MenuItem
__version__ = '0.1.0'
__author__ = 'Rbanh'
# Define what's available when using "from src import *"
__all__ = [
'Game',
'GameState',
'Snake',
'Direction',
'Food',
'Menu',
'GameMode',
'MenuItem'
]

View File

@ -1,9 +1,9 @@
import pygame
import sys
from enum import Enum, auto
from snake import Snake, Direction
from food import Food
from menu import Menu, GameMode
from src.snake import Snake, Direction
from src.food import Food
from src.menu import Menu, GameMode
class GameState(Enum):
MENU = auto()
@ -13,6 +13,12 @@ class GameState(Enum):
class Game:
def __init__(self):
# Initialize pygame and font system
if not pygame.get_init():
pygame.init()
if not pygame.font.get_init():
pygame.font.init()
# Initialize display
self.width = 800
self.height = 600

View File

@ -1,2 +1,19 @@
# This file is intentionally empty.
# It marks the tests directory as a Python package for test discovery.
"""
Test suite for the AI Snake Game.
This package contains all test modules including:
- Unit tests for game components
- Integration tests for game mechanics
- Performance tests for AI algorithms
"""
# Import test utilities and fixtures
from tests.conftest import game_config, mock_screen
__version__ = '0.1.0'
# Define test utilities available for import
__all__ = [
'game_config',
'mock_screen'
]