A modern take on the classic Snake game, engineered with a focus on clean, decoupled architecture, classic design patterns, and multiple AI-driven gameplay modes.
ViperVision is a comprehensive implementation of the Snake game built from the ground up using Java and the Processing library for rendering. More than just a game, it serves as a practical case study for applying robust software design principles to build a flexible, maintainable, and extensible application.
- Classic Gameplay: Smooth, interpolated movement, food consumption, and score tracking.
- Multiple Game Modes:
- Human Player: Take control with the arrow keys in a responsive input-buffered system.
- Pathfinding AI (WIP): Watch the snake autonomously navigate using algorithms like A* to find the optimal and safest path to the food.
- Genetic Algorithm AI (Planned): Observe an AI that evolves and learns to play through generations of simulated evolution.
- Polished UI/UX: Interactive menus with custom fonts, graphics, and a fluid game loop.
- Clean, Decoupled Architecture: Built to be easily understood, modified, and extended.
ViperVision is engineered with a modern, decoupled architecture based on the Model-View-Presenter (MVP) pattern. This clean separation of concerns ensures the codebase is scalable, maintainable, and highly testable. The core of the architecture is a central contracts package that uses interfaces to prevent cyclical dependencies, adhering to the Dependency Inversion Principle.
- contracts (The Core API): This package contains only interfaces and data transfer objects (like events). It is the central pillar that all other layers depend on, but it depends on nothing. This guarantees a unidirectional dependency flow.
- model (The Data and Business Logic): This layer contains the pure game state and rules. It is completely independent of the UI.
- view (The Presentation Layer): This layer is responsible for everything the user sees and hears. It is "dumb" and only acts on the commands of the Presenter.
- presenter (The Application Logic): This layer acts as the middleman. It responds to user input from the View, manipulates the Model, and tells the View what to display.
- Model-View-Presenter (MVP): The core architectural pattern separating data, presentation, and logic.
- State: Manages the game's high-level flow (e.g., MenuState, PlayingState).
- Strategy: Decouples the snake's control algorithm (HumanControlStrategy, FollowFoodStrategy) from the game logic.
- Observer (Event Bus): A global EventManager allows decoupled communication between different parts of the system (e.g., game logic notifying the sound system).
- Factory: ComponentFactory centralizes the creation of UI components from configuration data. ApplicationFactory encapsulates the initial setup of the game.
- Singleton: Used for stateless, global services like renderers and the EventManager.
- Composite: The UI is built as a composite structure of Layouts and IUiComponents, managed by a UiManager.
- Command: UI button actions are encapsulated as Command objects, decoupling the button from the action it performs.
Here are some diagrams illustrating the project's structure and flow.
You can access all class diagrams in the file docs/diagrams/diagrams.mdj
.
- Language: Java 24
- Graphics & Interaction: Processing (v4.4.1)
- Build Tool: Apache Maven
- Diagramming: StarUML / Mermaid
Follow these instructions to get a copy of the project up and running on your local machine.
- JDK 24 (or the version specified in
pom.xml
). Make sureJAVA_HOME
is set correctly. - Apache Maven installed and configured in your system's PATH.
- Clone the repository:
git clone https://github.com/SebAs-man/ViperVision.git cd ViperVision
- Build and run the project using Maven:
mvn clean package exec:java
This project's primary focus is on software architecture and clean, maintainable code. While efforts were made to create a pleasant user interface, the visual design choices reflect an engineer's perspective. Contributions, ideas, and pull requests from design-savvy individuals are most welcome!
This project is distributed under the MIT License. See the LICENSE
file for more information.
- The Processing Foundation for their amazing creative coding environment.
- You, for exploring this project!