Updated architechure and Readme.md
This commit is contained in:
parent
c9514edb9e
commit
f5ff198dd3
58
.gitignore
vendored
58
.gitignore
vendored
@ -1,26 +1,52 @@
|
|||||||
# Build directories
|
# Build directories
|
||||||
build/
|
build/
|
||||||
cmake-build-*/
|
cmake-build-*/
|
||||||
|
|
||||||
# CMake files
|
|
||||||
CMakeCache.txt
|
|
||||||
CMakeFiles/
|
CMakeFiles/
|
||||||
Makefile
|
CMakeCache.txt
|
||||||
cmake_install.cmake
|
cmake_install.cmake
|
||||||
build.ninja
|
Makefile
|
||||||
rules.ninja
|
*.cmake
|
||||||
|
|
||||||
# Executables
|
|
||||||
Snake
|
|
||||||
*.exe
|
|
||||||
|
|
||||||
# IDE files
|
# IDE files
|
||||||
.idea/
|
|
||||||
.vscode/
|
.vscode/
|
||||||
*.user
|
.idea/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*~
|
||||||
|
|
||||||
# Testing
|
# Compiled binaries
|
||||||
Testing/
|
Snake
|
||||||
|
*.exe
|
||||||
|
*.out
|
||||||
|
*.app
|
||||||
|
|
||||||
# OS files
|
# Object files
|
||||||
.DS_Store
|
*.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
|
||||||
|
|||||||
@ -1,22 +1,49 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
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(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 SFML
|
||||||
find_package(SFML 2.5 COMPONENTS graphics window system REQUIRED)
|
find_package(SFML 2.5 COMPONENTS graphics window system REQUIRED)
|
||||||
|
|
||||||
# Add executable
|
# Source files
|
||||||
add_executable(Snake
|
file(GLOB_RECURSE SOURCES
|
||||||
main.cpp
|
"src/*.cpp"
|
||||||
Game.cpp
|
"src/*.c"
|
||||||
Snake.cpp
|
|
||||||
Food.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Include headers
|
# Create executable
|
||||||
target_include_directories(Snake PRIVATE .)
|
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||||
|
|
||||||
# Link SFML libraries
|
# Include directories
|
||||||
target_link_libraries(Snake sfml-graphics sfml-window sfml-system)
|
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()
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
73
README.md
73
README.md
@ -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
|
## ✨ Features
|
||||||
- `main.cpp` — Entry point
|
- Modern graphics with SFML
|
||||||
- `Game.*` — Game logic and rendering
|
- WASD/Arrow key controls
|
||||||
- `Snake.*` — Snake class implementation
|
- Score tracking with best score persistence
|
||||||
- `Food.*` — Food generation system
|
- Menu and pause functionality
|
||||||
- `Point.h` — Coordinate structure
|
- Smooth collision detection
|
||||||
- `Direction.h` — Direction enumeration
|
|
||||||
- `best_score.txt` — High score storage
|
|
||||||
- `CMakeLists.txt` — Build configuration
|
|
||||||
|
|
||||||
## 🛠️ Requirements
|
## 📋 Requirements
|
||||||
- C++11 or higher
|
- C++17+
|
||||||
- CMake 3.10+
|
- CMake 3.10+
|
||||||
- Linux/Unix terminal
|
- SFML 2.5+
|
||||||
|
|
||||||
## 🎮 Features
|
## 🚀 Quick Start
|
||||||
- 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
|
|
||||||
```bash
|
```bash
|
||||||
|
# Install dependencies (Ubuntu/Debian)
|
||||||
|
sudo apt install cmake build-essential libsfml-dev
|
||||||
|
|
||||||
|
# Build and run
|
||||||
mkdir build && cd build
|
mkdir build && cd build
|
||||||
cmake ..
|
cmake .. && make
|
||||||
make
|
|
||||||
./Snake
|
./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.
|
||||||
|
|||||||
@ -53,7 +53,7 @@ public:
|
|||||||
MenuButton* startBtn = nullptr,
|
MenuButton* startBtn = nullptr,
|
||||||
MenuButton* exitBtn = nullptr,
|
MenuButton* exitBtn = nullptr,
|
||||||
MenuButton* restartBtn = nullptr,
|
MenuButton* restartBtn = nullptr,
|
||||||
MenuButton* menuBtn = nullptr);
|
MenuButton* menuBtn = nullptr) const;
|
||||||
|
|
||||||
bool isGameOver() const { return gameOver; }
|
bool isGameOver() const { return gameOver; }
|
||||||
int getScore() const { return score; }
|
int getScore() const { return score; }
|
||||||
@ -21,7 +21,7 @@ void Game::run()
|
|||||||
{
|
{
|
||||||
sf::RenderWindow window(sf::VideoMode(BOARD_WIDTH * CELL_SIZE, BOARD_HEIGHT * CELL_SIZE + 60), "Snake Game");
|
sf::RenderWindow window(sf::VideoMode(BOARD_WIDTH * CELL_SIZE, BOARD_HEIGHT * CELL_SIZE + 60), "Snake Game");
|
||||||
sf::Clock clock;
|
sf::Clock clock;
|
||||||
float timer = 0.0f, delay = 0.15f;
|
float timer = 0.0f;
|
||||||
|
|
||||||
// Menu buttons initialization
|
// Menu buttons initialization
|
||||||
MenuButton startBtn, exitBtn, restartBtn, menuBtn;
|
MenuButton startBtn, exitBtn, restartBtn, menuBtn;
|
||||||
@ -57,7 +57,8 @@ void Game::run()
|
|||||||
|
|
||||||
if (!paused && !gameOver && !inMenu)
|
if (!paused && !gameOver && !inMenu)
|
||||||
{
|
{
|
||||||
timer += clock.restart().asSeconds();
|
float delay = 0.15f;
|
||||||
|
timer += clock.restart().asSeconds();
|
||||||
if (timer > delay)
|
if (timer > delay)
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
@ -213,8 +214,7 @@ void Game::processEvent(const sf::Event& event, sf::RenderWindow* window,
|
|||||||
// Rendering with interactive menu buttons and centered text
|
// Rendering with interactive menu buttons and centered text
|
||||||
void Game::render(sf::RenderWindow& window,
|
void Game::render(sf::RenderWindow& window,
|
||||||
MenuButton* startBtn, MenuButton* exitBtn,
|
MenuButton* startBtn, MenuButton* exitBtn,
|
||||||
MenuButton* restartBtn, MenuButton* menuBtn)
|
MenuButton* restartBtn, MenuButton* menuBtn) const {
|
||||||
{
|
|
||||||
// Draw gradient background
|
// Draw gradient background
|
||||||
sf::VertexArray background(sf::Quads, 4);
|
sf::VertexArray background(sf::Quads, 4);
|
||||||
background[0].position = sf::Vector2f(0, 0);
|
background[0].position = sf::Vector2f(0, 0);
|
||||||
@ -477,11 +477,10 @@ void Game::loadBestScore()
|
|||||||
bestScore = 0;
|
bestScore = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::saveBestScore()
|
void Game::saveBestScore() {
|
||||||
{
|
std::ofstream out(BEST_SCORE_FILE);
|
||||||
std::ofstream out(BEST_SCORE_FILE);
|
if (out)
|
||||||
if (out)
|
out << bestScore;
|
||||||
out << bestScore;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::reset()
|
void Game::reset()
|
||||||
Loading…
Reference in New Issue
Block a user