Functional Snake

Scala  //  Functional Programming  //  Object-Oriented Programming

01. Overview

Developed a Scala-based implementation of the classic Snake game, built from the ground up using strictly functional programming paradigms. The project challenges traditional game state management by replacing mutable arrays and loops with immutable data structures and recursive logic.

The game features unique mechanics such as screen-wrapping boundaries, variable growth rates, and a custom head-direction indicator, all while adhering to a architecture designed for complete state reproducibility.

02. Engineering & Immutability

The core philosophy of this project was to maintain a purely functional game state. To achieve this, I avoided 2-dimensional arrays and mutable variables in favor of persistent collections.

03. Reverse Mode (Time Rewind)

A standout feature of this implementation is the Reverse Mode, which allows players to rewind the game to an earlier state in real-time.

By maintaining a history of immutable GameState objects, the system can "rewind" time by simply replacing the current state with previous ones from a stack. When the player releases the reverse key, the game resumes normal progression from that specific point in history. This project demonstrates how functional programming simplifies the implementation of complex features like "undo" and "time travel" through state persistence.

View Source on GitHub