Updated architechure and Readme.md

This commit is contained in:
Sigismund Dijkstra 2025-07-28 20:28:58 -05:00
parent c9514edb9e
commit f5ff198dd3
13 changed files with 131 additions and 72 deletions

56
.gitignore vendored
View File

@ -1,26 +1,52 @@
# Build directories
build/
cmake-build-*/
# CMake files
CMakeCache.txt
CMakeFiles/
Makefile
CMakeCache.txt
cmake_install.cmake
build.ninja
rules.ninja
# Executables
Snake
*.exe
Makefile
*.cmake
# IDE files
.idea/
.vscode/
*.user
.idea/
*.swp
*.swo
*~
# Testing
Testing/
# Compiled binaries
Snake
*.exe
*.out
*.app
# OS files
# Object files
*.o
*.obj
# Libraries
*.lib
*.a
*.la
*.lo
*.dll
*.so
*.so.*
*.dylib
# Temporary files
*.tmp
*.temp
*~
# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# Game data
best_score.txt

View File

@ -1,22 +1,49 @@
cmake_minimum_required(VERSION 3.10)
project(Snake)
project(Snake VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Set build type if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
# Compiler flags
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
# Find SFML
find_package(SFML 2.5 COMPONENTS graphics window system REQUIRED)
# Add executable
add_executable(Snake
main.cpp
Game.cpp
Snake.cpp
Food.cpp
# Source files
file(GLOB_RECURSE SOURCES
"src/*.cpp"
"src/*.c"
)
# Include headers
target_include_directories(Snake PRIVATE .)
# Create executable
add_executable(${PROJECT_NAME} ${SOURCES})
# Link SFML libraries
target_link_libraries(Snake sfml-graphics sfml-window sfml-system)
# Include directories
target_include_directories(${PROJECT_NAME} PRIVATE include)
# Link libraries
target_link_libraries(${PROJECT_NAME}
sfml-graphics
sfml-window
sfml-system
)
# Copy assets to build directory
if(EXISTS ${CMAKE_SOURCE_DIR}/assets)
file(COPY assets DESTINATION ${CMAKE_BINARY_DIR})
endif()
# Install rules
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
if(EXISTS ${CMAKE_SOURCE_DIR}/assets)
install(DIRECTORY assets DESTINATION share/${PROJECT_NAME})
endif()

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2025 Snake Game Project
Copyright (c) 2025 DarkSnake Project
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,42 +1,49 @@
# 🐍 Snake Game
<div align="center">
<img src="DarkSnake.png" alt="Dark Snake Logo" width="200"/>
Classic Snake game implemented in C++ with a console interface.
**A modern Snake game built with C++ and SFML**
</div>
## 📁 Project Structure
- `main.cpp` — Entry point
- `Game.*` — Game logic and rendering
- `Snake.*` — Snake class implementation
- `Food.*` — Food generation system
- `Point.h` — Coordinate structure
- `Direction.h` — Direction enumeration
- `best_score.txt` — High score storage
- `CMakeLists.txt` — Build configuration
## ✨ Features
- Modern graphics with SFML
- WASD/Arrow key controls
- Score tracking with best score persistence
- Menu and pause functionality
- Smooth collision detection
## 🛠️ Requirements
- C++11 or higher
## 📋 Requirements
- C++17+
- CMake 3.10+
- Linux/Unix terminal
- SFML 2.5+
## 🎮 Features
- Console-based graphics
- WASD controls
- Food generation
- Collision detection
- Growing snake mechanics
- Score tracking
- Best score persistence
## 🎯 Controls
- W — Move up
- S — Move down
- A — Move left
- D — Move right
- Q — Quit game
## 📦 Build and Run
## 🚀 Quick Start
```bash
# Install dependencies (Ubuntu/Debian)
sudo apt install cmake build-essential libsfml-dev
# Build and run
mkdir build && cd build
cmake ..
make
cmake .. && make
./Snake
```
## 🎮 Controls
- **WASD/Arrows** — Move
- **Space** — Pause
- **Enter** — Menu select
- **Escape** — Menu/Quit
## 📁 Structure
```
Snake/
├── src/ # Source files
├── include/ # Headers
├── assets/ # Game assets
└── CMakeLists.txt # Build config
```
## 🤝 Contributing
Feel free to submit issues and pull requests!
## 📄 License
MIT License - see [LICENSE](LICENSE) file.

View File

@ -53,7 +53,7 @@ public:
MenuButton* startBtn = nullptr,
MenuButton* exitBtn = nullptr,
MenuButton* restartBtn = nullptr,
MenuButton* menuBtn = nullptr);
MenuButton* menuBtn = nullptr) const;
bool isGameOver() const { return gameOver; }
int getScore() const { return score; }

View File

@ -21,7 +21,7 @@ void Game::run()
{
sf::RenderWindow window(sf::VideoMode(BOARD_WIDTH * CELL_SIZE, BOARD_HEIGHT * CELL_SIZE + 60), "Snake Game");
sf::Clock clock;
float timer = 0.0f, delay = 0.15f;
float timer = 0.0f;
// Menu buttons initialization
MenuButton startBtn, exitBtn, restartBtn, menuBtn;
@ -57,7 +57,8 @@ void Game::run()
if (!paused && !gameOver && !inMenu)
{
timer += clock.restart().asSeconds();
float delay = 0.15f;
timer += clock.restart().asSeconds();
if (timer > delay)
{
update();
@ -213,8 +214,7 @@ void Game::processEvent(const sf::Event& event, sf::RenderWindow* window,
// Rendering with interactive menu buttons and centered text
void Game::render(sf::RenderWindow& window,
MenuButton* startBtn, MenuButton* exitBtn,
MenuButton* restartBtn, MenuButton* menuBtn)
{
MenuButton* restartBtn, MenuButton* menuBtn) const {
// Draw gradient background
sf::VertexArray background(sf::Quads, 4);
background[0].position = sf::Vector2f(0, 0);
@ -477,11 +477,10 @@ void Game::loadBestScore()
bestScore = 0;
}
void Game::saveBestScore()
{
std::ofstream out(BEST_SCORE_FILE);
if (out)
out << bestScore;
void Game::saveBestScore() {
std::ofstream out(BEST_SCORE_FILE);
if (out)
out << bestScore;
}
void Game::reset()