/SNAKE_GAME_CLIENT

C#

.NET

JSON

Javascript

Blazor

/PROJECT OVERVIEW

Purpose

To demonstrate skill in client networking through the creation of a client for a snake game, capable of real-time world rendering and state management given a server that sends object information over JSON.

My Role

Collaborated as a developer to implement the networking and rendering logic, while ensuring smooth gameplay.

  • Implement the Model-View-Controller (MVC) pattern to separate game state from UI
  • Develop the NetworkController to handle socket connections and the multi-stage handshake protocol
  • Deserialize JSON updates into custom objects for snakes, powerups, walls, and the world, to be drawn and displayed
  • Design a visually appealing UI with a customized game theme, in addition to a homepage describing the project
  • Use MySQL to construct databases that will track and display data

/TECHNICAL IMPLEMENTATION

Architecture (MVC)

Our application adheres strictly to the MVC pattern. The Models folder contains the core data structures (Snake, Powerups, Walls, World). The Controller layer is centered around a custom NetworkController that manages the TCP socket and asynchronous message processing. The View layer, built with Blazor Pages, listens for model updates and renders the world on the HTML5 Canvas.

Networking & Handshake

The client initiates a connection via a specific address and port, executing a formal handshake: sending the player name, receiving a unique ID, obtaining the world dimensions, and finally streaming live game objects. This process ensures the client and server are perfectly synchronized before the first frame is drawn.

State Management

A key architectural decision was making the client "reactive." The client does not decide when a snake grows or dies; instead, it consumes state updates from the server and accurately re-draws the model. This prevents desync issues and ensures that the server remains the single source of truth for game logic.

Features

Local Multiplayer

Support for multiple snake players on the same machine, with distinguishing snake body colors, scores, and ids.

Real-time World Updates

World and player states are batch-drawn, allowing for smooth rendering during chaotic multiplayer sessions. Game views are translated to follow players and stay within the world walls.

"Exploding" Animations

As an extra visual feature, snake powerups (cupcakes) were given a custom "exploding" animation that triggers when a powerup is consumed.

Snake State Tracking

Uses a database to keep track of player names, join/leave times, scores, max scores, and ids which are queried when necessary.

This project successfully demonstrated our ability to handle high-frequency networking in a C# environment.

  • Mastered TCP Socket programming and asynchronous networking in .NET
  • Gained experience in object-oriented design using the MVC pattern to represent and use World, Snake, Wall, and Powerup objects
  • Practiced efficient database querying skills through batch queries instead of querying on each re-render

If we continue development on this client, some features we could add are:

  • Full multiplayer support for players in any location
  • Customizable snake skins and trail effects
  • Game stats and badges to reward players with