WinScreen.java

package io.github.some_example_name;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class WinScreen implements Screen {

    private final MyGame game;

    private OrthographicCamera camera;
    private SpriteBatch batch;
    private BitmapFont font;
    private GlyphLayout layout;

    private WinScreenLogic winScreenLogic;

    private int finalScore;
    private int timeRemaining;
    private int timesCaught;

    public WinScreen(MyGame game, int finalScore, int timeRemaining, int timesCaught) {
        this.game = game;
        this.finalScore = finalScore;
        this.timeRemaining = timeRemaining;
        this.timesCaught = timesCaught;

        camera = new OrthographicCamera();
        camera.setToOrtho(false, 640, 480);

        batch = new SpriteBatch();
        font = new BitmapFont();
        font.getData().setScale(2.5f);

        layout = new GlyphLayout();

        // Initialise logic handler for WinScreen
        winScreenLogic = new WinScreenLogic();

        Gdx.input.setInputProcessor(new InputAdapter() {
            @Override
            public boolean keyTyped(char character) {
                // Pass character input to logic
                winScreenLogic.processKeyTyped(character);
                return true;
            }
        });
    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0.1f, 0.3f, 0.1f, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        camera.update();
        batch.setProjectionMatrix(camera.combined);

        // Update the cursor and logic
        winScreenLogic.update(delta);

        batch.begin();

        // Title
        drawCenteredText("You Win!", 400);

        // Scores
        drawCenteredText("Final Score: " + finalScore, 340);
        drawCenteredText("Dean Penalty: " + (timesCaught * 5), 300);

        // Name entry
        drawCenteredText("Enter your name:", 240);

        String displayText = winScreenLogic.getName();

        // If the name is not confirmed, show the cursor
        if (!winScreenLogic.isNameConfirmed() && winScreenLogic.isCursorVisible()) {
            displayText += "|";  // Add cursor if visible
        }
        drawCenteredText(displayText, 200);

        // Instructions
        if (winScreenLogic.isNameConfirmed()) {
            drawCenteredText("Press L to view Leaderboard", 140);
            drawCenteredText("Press SPACE to return to menu", 100);
        } else {
            drawCenteredText("Press ENTER to confirm name", 140);
        }

        batch.end();

        if (winScreenLogic.isNameConfirmed()) {
            if (Gdx.input.isKeyJustPressed(Input.Keys.L)) {
                Gdx.input.setInputProcessor(null);
                game.setScreen(new LeaderBoard(game, winScreenLogic.getName(), finalScore));
            }

            if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) {
                Gdx.input.setInputProcessor(null);
                game.setScreen(new MenuScreen(game));
            }
        }
    }

    private void drawCenteredText(String text, float y) {
        layout.setText(font, text);
        float x = (camera.viewportWidth - layout.width) / 2f;
        font.draw(batch, layout, x, y);
    }

    @Override
    public void dispose() {
        batch.dispose();
        font.dispose();
    }

    @Override public void show() {}
    @Override public void resize(int width, int height) {}
    @Override public void pause() {}
    @Override public void resume() {}
    @Override public void hide() {}
}