package pathgame.gameplay;

import pathgame.tilemap.TileMap;
import pathgame.tilemap.TileMapGenerator;

public final class Level
{
    private final Player player = new Player();
    private int level = 1;
    private TileMap map = null;
    private boolean showScoreMenu = false;
    private boolean showAfterScore = false;

    public Level()
    {
        reset();
    }

    public void tick(Gamestate gamestate)
    {
        map.tick();
        if(gamestate.is(Gamestates.GAMEPLAY) && !showScoreMenu)
        {
            player.tick(map);
        }
        if(gamestate.is(Gamestates.GAMEPLAY) && !showScoreMenu && (player.hasLost() || player.hasWon()))
        {
            showScoreMenu = true;
        }
        else if(showScoreMenu && Keys.CONFIRM_KEY.getTime() == 1)
        {
            showScoreMenu = false;
            showAfterScore = true;
        }
    }

    public void nextLevel()
    {
        level++;
        reset();
    }

    public void reset()
    {
        player.reset();
        map = TileMapGenerator.getMap(5 + 5 * level, 5 + 5 * level, level, 2 + level);
        player.setEnergySupply(100); // ToDo: insert value of algorithm
        player.setObjectivesAmount(map.getNumberOfTowns());
    }

    public TileMap getMap()
    {
        return map;
    }

    public Player getPlayer()
    {
        return player;
    }

    public int getLevel()
    {
        return level;
    }
    
    public boolean getShowAfterScore()
    {
        return showAfterScore;
    }
    
    public void setShowAfterScore(boolean show)
    {
        showAfterScore = show;
    }
    public boolean getShowScoreMenu()
    {
        return showScoreMenu; 
    }
}
