EndSnakeScreen - UQcsse3200/2024-studio-2 GitHub Wiki

Overview

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.

Class: EndSnakeScreen

Package

package com.csse3200.game.screens;

Imports

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.csse3200.game.GdxGame;
import com.csse3200.game.components.minigame.MiniGameConstants;
import com.csse3200.game.components.minigame.MiniGameMedals;

Methods

setupExitButton()

  • Sets up the "Exit" button that returns the player to the Main Menu screen.

render(float delta)

  • Renders the screen, handles key presses, and updates the UI elements.

handleKeyPress()

  • Handles key presses for restarting the game or returning to the mini-game menu.

renderEndMessage()

  • Displays the end-of-game message, the score, the awarded medal, and provides buttons to retry or return to the mini-game menu.

getMessage()

  • Generates a personalized message based on the player's score.

getMedal(int score)

  • Determines the medal awarded based on the player's score.

setBackgroundColor()

  • Sets the background color based on the player's score and awarded medal.

Dispose

  • Releases resources used by the screen.