Skip to content

Animal Selection Display

Shaivika Anand edited this page Sep 11, 2024 · 2 revisions

AnimalSelectionDisplay

Overview

The AnimalSelectionDisplay class is responsible for setting up and managing the user interface for the animal selection screen in the game. This class creates the layout for displaying animal images and buttons, and it also provides access to these UI elements for interaction by other components.

Purpose

The AnimalSelectionDisplay class is responsible for:

  • Creating and organizing the UI elements (images, buttons) used in the animal selection screen.
  • Managing the layout and appearance of these elements using a Stage and Table.
  • Providing access to the UI elements so that actions can be attached to them by other classes.

Structure

Constructor

The constructor initializes the AnimalSelectionDisplay class by setting up the stage and skin, and then calling the initializeDisplay() method to create and arrange the UI elements.

public AnimalSelectionDisplay(Stage stage, Skin skin) {
    this.stage = stage;
    this.skin = skin;
    this.animalImages = new Image[3];
    this.animalButtons = new TextButton[3];
    this.selectButton = new TextButton("Ready?", skin);
    this.backButton = new TextButton("Go Back", skin);
    initializeDisplay();
}

Methods

initializeDisplay(): Sets up the UI layout by creating tables and adding the animal images, buttons, and control buttons (selectButton and backButton) to the stage.

private void initializeDisplay() {
    // Used to setup layout and to add UI elements to the stage
}

getAnimalImages(): Returns an array of Image objects representing the animal images displayed on the screen.

public Image[] getAnimalImages() {
    return animalImages;
}

getAnimalButtons(): Returns an array of TextButton objects representing the buttons associated with each animal.

public TextButton[] getAnimalButtons() {
    return animalButtons;
}

getSelectButton(): Returns the TextButton used to confirm the player's selection.

public TextButton getSelectButton() {
    return selectButton;
}

getBackButton(): Returns the TextButton used to return to the previous screen.

public TextButton getBackButton() {
    return backButton;
}

getSkin(): Returns the Skin used for styling the UI elements.

public Skin getSkin() {
    return skin;
}

getStage(): Returns the Stage on which the UI elements are displayed.

public Stage getStage() {
    return stage;
}

Dependencies

This class relies on the following components:

  • Stage: A 2D scene graph for managing UI elements.
  • Skin: Defines the appearance of UI elements.
  • Table: A layout widget for organizing UI elements in rows and columns.
  • Image: Represents an image displayed in the UI.
  • TextButton: A button with text that can be clicked.

Usage

To use AnimalSelectionDisplay, instantiate it by passing a Stage and Skin, and then use its methods to access and interact with the UI elements:

Stage stage = new Stage();
Skin skin = new Skin(Gdx.files.internal("flat-earth/skin/flat-earth-ui.json"));
AnimalSelectionDisplay display = new AnimalSelectionDisplay(stage, skin);

Access UI elements

Image[] animalImages = display.getAnimalImages();
TextButton selectButton = display.getSelectButton();

Notes

The layout of the UI elements is managed using a Table, which provides flexibility in arranging components on the screen. The initializeDisplay() method sets up the UI, so any changes to the layout should be made there. Ensure that the textures for the animal images are correctly loaded to avoid runtime errors.

Additions

For Sprint 2, new additions Animal Screen Kingdom have been made corresponding to the specific Land and Display :

AnimalSelectionDisplay-for-Land,-Water,-and-Air

Clone this wiki locally