Skip to content

SnakeScreen

rp3002 edited this page Aug 28, 2024 · 2 revisions

Overview

The SnakeScreen class in the Snake mini-game manages the transitions between various game states, such as restarting the game or exiting to the menu. The SnakeScreen ensures that the Snake mini-game is presented to the player, providing them a smooth and engaging gameplay experience.

Class: SnakeScreen

Package

package com.csse3200.game.screens;

Imports

import com.csse3200.game.components.minigame.snake.controller.Events;
import com.csse3200.game.components.minigame.snake.rendering.SnakeGameRenderer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.csse3200.game.GdxGame;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.EntityService;
import com.csse3200.game.entities.factories.RenderFactory;
import com.csse3200.game.input.InputComponent;
import com.csse3200.game.input.InputDecorator;
import com.csse3200.game.input.InputService;
import com.csse3200.game.rendering.RenderService;
import com.csse3200.game.rendering.Renderer;
import com.csse3200.game.services.GameTime;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.ui.terminal.Terminal;
import com.csse3200.game.ui.terminal.TerminalDisplay;
import com.csse3200.game.components.gamearea.PerformanceDisplay;
import com.csse3200.game.components.maingame.MainGameActions;
import com.csse3200.game.components.maingame.MainGameExitDisplay;
import com.csse3200.game.components.minigame.snake.SnakeGame;
import com.badlogic.gdx.graphics.g2d.BitmapFont;

Constructor SnakeScreen(GdxGame game)

  • Parameters:
    • GdxGame game: The main game instance that controls the screen.
  • Description:
    • Initialises the SnakeScreen with the provided game instance.

Methods

  • void setDirection(Direction direction)

    • Parameters: Direction direction: The new direction for the snake to move.
    • Description: Sets the direction the snake is moving
  • SnakeScreen(GdxGame game):

    • Initialises the SnakeScreen with the provided game instance.
  • render(float delta):

    • Renders the Snake game screen, including the grid and the apple. This method is made for future use, so it will have a lot to change probably
  • handleInput():

    • Handles player input for restarting or exiting the game.
  • clearBackground():

    • Clears the screen with a specific background colour.
  • updateGame(float delta):

    • Updates the game state, including moving the snake and checking for game-over
  • resize(int width, int height):

    • Adjusts the rendering setup to accommodate changes in the screen size
  • dispose():

    • Disposes of the resources used by the SnakeScreen, includes the ShapeRenderer used for rendering the grid and apple.
Clone this wiki locally