How adrianovaladar/snake works
Main Components
• Game Engine/Core Loop: Represented by the Game class (Game.cpp/Game.h) and the entry point main.cpp.
• Input Handling: The Input module (Input.cpp/Input.h) that captures user inputs.
• Rendering/Graphics: The Graphics module (Graphics.cpp/Graphics.h) for drawing the game state to the terminal.
• Game Entities:
• Snake: Encapsulated in Snake.cpp/Snake.h.
• Regular Food: Represented by Food.cpp/Food.h.
• SuperFood: Represented by SuperFood.cpp/SuperFood.h.
• Player and Best Scores: Managed by Player.cpp/Player.h and BestScores.cpp/BestScores.h to maintain score tracking and high score listings.
• Utility Functions: Provided by Utils.cpp/Utils.h for any helper or common functions.
• Testing Components: Under the tests directory, individual test files (e.g., GameTests, SnakeTests, FoodTests) ensure each component works correctly.
Relationships and Interactions
• The Main entry point (main.cpp) initializes the Game engine.
• The Game component coordinates the overall game loop, managing updates, rendering, and input reading.
• During the game loop, the Input module collects user commands which are processed by the Game module to update the Snake's state.
• The Graphics component renders the current game state (snake position, food items, borders, etc.) to the terminal.
• The various entity classes (Snake, Food, SuperFood) interact with game dynamics such as collision detection, score updating, and level adjustments.
• BestScores and Player modules handle the persistence of game scores and ranking based on the configured map size and border settings.
• The Utils module likely provides helper functions used across various parts of the game (e.g., random number generation, formatting output, etc.).
Architectural Patterns and Design Principles
• Separation of Concerns: Each module (input, graphics, game logic, entities) is isolated in its own file(s), fostering maintainability.
• Modular Design: Because of well-defined components, changes in one part (like graphics) have minimal impact on others (e.g., game logic).
• Test-Driven Approach: The tests directory indicates unit tests for core functionalities, which helps with robustness and reliability.
• Use of CMake: Emphasizes portability and build automation for the C++ project.