package se.urmo.game.main;

import lombok.Getter;
import se.urmo.game.state.GameOverState;
import se.urmo.game.state.GameState;
import se.urmo.game.state.PlayingState;
import se.urmo.game.util.GameStateType;

import java.awt.Graphics2D;
import java.util.HashMap;
import java.util.Map;

public class GameStateManager {
    private final Map<GameStateType, GameState> states = new HashMap<>();
    @Getter
    private GameState currentState;

    public GameStateManager() {
        GameOverState gameOverState = new GameOverState(this, new HighScoreManager());
        states.put(GameStateType.PLAYING, new PlayingState(this, gameOverState));
        states.put(GameStateType.GAME_OVER, gameOverState);
        setState(GameStateType.PLAYING);
    }

    public void setState(GameStateType type) {
        currentState = states.get(type);
    }

    public void update() {
        currentState.update();
    }

    public void render(Graphics2D g) {
        currentState.render(g);
    }
}
