Snake Mini‐Game - UQcsse3200/2024-studio-2 GitHub Wiki
Overview
The Snake Mini-Game is one of the mini-games featured within the main game. In this mini-game, players will control a snake character to collect apples (snake's food) and grow longer while avoiding collisions (self/ boundary). The goal is to achieve the highest score possible.
Game Mechanics
Controls
The Direction enum is an essential component for the Snake mini-game which defines the possible directions in which the snake can move within the game grid. The Direction
enum defines four directions (right, left, up, and down) in which the snake can move in, and a ZERO
state, which represents a stationary or an initial state.
- Arrow Keys: Navigate the snake in four directions (Up, Down, Left, Right)
- W, A, S, D: Alternative keys for directional movement
Snake Screen
The SnakeScreen ensures that the Snake mini-game is presented to the player, providing them a smooth and engaging gameplay experience.
Snake Pop-Up Screen
Before the Snake Game begins, a pop-up screen will appear, providing detailed instructions on how to play. It will explain the game controls, including how to move the snake, how to interact with various game elements. The pop-up will also introduce the characters, describing their roles and significance in the game. Additionally, it will outline the winning conditions, explaining how to earn points, achieve goals, and win the game. The screen will include additional information such as how to pause/ restart or exit the game.
Scoring
- Each apple consumed adds one point to the score.
- The current score is displayed on the game screen.
In this example, the snake character consumed 8 apples, resulting in a score of 8
The High Score is now saved and carried over for the next gameplay session.
Game Elements
Snake Character
The Snake class in the snake mini-game is the central component which defines the structure and the behaviour of the snake.
This Snake
class handles the movement, growth, and directional control of the snake on the grid while interacting with the other game components, such as the apple.
- The snake is composed of segments, with the head being the leading part and the body following.
- As the snake consumes apples, it grows by adding new segments.
The Snake UI has been enhanced to give it a more polished and appealing look. Refer to the Images below:
Snake before consuming any apples
Snake after consuming some apples
Refer to the Score and Medals Wiki for a more detailed explanation of how it works. Here's the link: Medals and Scoring Wiki
Apple Component
The snake mini-game has an Apple class which represents the food item that the snake consumes to increase it's size and grow longer.
This Apple
class plays a crucial role in handling the spawning of the apple on the game grid, ensuring it appears in a random, unoccupied cell each time. The player's goal in this mini-game is to guide the snake character to this apple to score points and increase the snake's length.
The Apple
class is responsible for:
- Generating the apple at a random location on the game grid
- Making sure it does overlap with the snake's current position
- Checking if the snake's head is in the same position as the apple (this will trigger the snake to consume the apple)
Grid
The Grid class in the Snake mini-game represents the game board where the snake moves and the apples spawn. The grid is composed of individual cells, each of which can either be occupied or unoccupied. This class provides the functionality to manage and interact with the grid, such as checking occupancy and setting cell states.
The Grid
class is responsible for creating and managing a two-dimensional grid. It tracks the occupancy status of each cell, ensuring that the game's logic (snake movement and apple spawning).
Grid Cell
The GridCell class is an important component of the Snake mini-game, representing a single cell within the game's grid. Each GridCell
has a fixed position on the grid and can be either occupied or unoccupied, which is essential for managing the game's logic, such as detecting collisions and determining valid spawn locations for the snake or apples.
Snake Grid
The SnakeGrid class is a designed specifically for the Snake mini-game. This extends the general Grid
class and provides additional functionality such as checking for collisions and having grid positions for rendering.
The Snake Game uses the MiniGame Renderer. Refer to the Renderers Wiki for a more detailed explanation of how each of the apple, snake, grid and SnakeGame renderers works. Here's the link: Snake Renderers Wiki
Current Game Screenshot
End Screen
The EndSnakeScreen
class in the game handles the end-of-game state for the Snake mini-game. It displays the player's final score, awards a medal based on the score, and provides options to restart the game or return to the mini-game menu.
- Fail: If the score is less than 15, the player has failed the snake mini-game.
- Bronze: For scores of 15 or greater but less than 35, the bronze medal will be achieved.
- Silver: For scores of 35 or greater but less than 45, the silver medal will be achieved.
- Gold: For scores of 45 or greater, the gold medal will be achieved.
Game Flow
- Initialisation: The game starts with a snake and a single apple randomly placed on the grid.
- Gameplay: The snake moves in the direction specified by the player’s controls.
- Apple Collision: When the snake’s head collides with an apple, the apple disappears, and a new apple appears randomly.
- Boundary and Self-Collision: If the snake collides with the screen boundaries or itself, the game ends.
Sequence Diagram
Wireframes
UML Diagram
Testing Plans
For a comprehensive overview of the testing approach, including details on the classes that have been tested as well as those that remain to be tested, please refer to the Snake Testing Plan Wiki