Skip to content

A classic Snake game implemented in Java using the Processing library. Features human-controlled mode and AI players using pathfinding (Dijkstra) and genetic algorithms. Built with MVP architecture and design patterns.

License

Notifications You must be signed in to change notification settings

SebAs-man/ViperVision

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License: MIT Language: Java 24 Uses: Processing Build: Maven

ViperVision Logo

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.


✨ Features

  • 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.

🏗️ Architecture & Design

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.

Architectural Layers

  • 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.

Design Patterns in Use

  • 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.

Key Diagrams

Here are some diagrams illustrating the project's structure and flow.

Package Structure

Package Structure

State Machine

State Diagram

Class Diagram

You can access all class diagrams in the file docs/diagrams/diagrams.mdj.


🛠️ Technologies Used

  • Language: Java 24
  • Graphics & Interaction: Processing (v4.4.1)
  • Build Tool: Apache Maven
  • Diagramming: StarUML / Mermaid

🚀 Getting Started

Follow these instructions to get a copy of the project up and running on your local machine.

Prerequisites

  • JDK 24 (or the version specified in pom.xml). Make sure JAVA_HOME is set correctly.
  • Apache Maven installed and configured in your system's PATH.

Installation & Running

  1. Clone the repository:
    git clone https://github.com/SebAs-man/ViperVision.git
    cd ViperVision
  2. Build and run the project using Maven:
    mvn clean package exec:java

🎨 A Note on Design

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!


📜 License

This project is distributed under the MIT License. See the LICENSE file for more information.

🙏 Acknowledgements

  • The Processing Foundation for their amazing creative coding environment.
  • You, for exploring this project!

About

A classic Snake game implemented in Java using the Processing library. Features human-controlled mode and AI players using pathfinding (Dijkstra) and genetic algorithms. Built with MVP architecture and design patterns.

Topics

Resources

License

Stars

Watchers

Forks

Languages