package wge3.game.engine.gamestates;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import wge3.game.engine.GameState;
import wge3.game.engine.GameStateManager;
import wge3.game.engine.constants.Statistic;
import wge3.game.engine.utilities.Statistics;

// Remember to implement statistics

public final class EndGameState extends GameState {

    private BitmapFont font;
    private boolean result;
    private Statistics statistics;
    
    public EndGameState(GameStateManager gsm, boolean result) {
        super(gsm);
        font = new BitmapFont();
        this.result = result;
        init();
    }

    @Override
    public void init() {
    }

    @Override
    public void update(float delta) {
        handleInput();
    }

    @Override
    public void draw(Batch batch) {
        batch.begin();
        int maxX = Gdx.graphics.getWidth(); 
        int maxY = Gdx.graphics.getHeight();
        if (result) {
            font.draw(batch, "You won!", maxX / 2, maxY / 2);
        }
        else {
            font.draw(batch, "You lost!", maxX / 2, maxY / 2);
            String player = statistics.getPlayers().get(0);
            font.draw(batch, "You took " + statistics.getStatFromPlayer(player, Statistic.DAMAGETAKEN) + " damage", maxX / 2, maxY / 4);
            
            font.draw(batch, "You dealt " + statistics.getStatFromPlayer(player, Statistic.DAMAGEDEALT) + " damage", maxX / 2, maxY / 3);
            
            font.draw(batch, "You regained " + statistics.getStatFromPlayer(player, Statistic.HEALTHREGAINED) + " health", maxX / 2, maxY / 5);
            
            font.draw(batch, "You fired " + statistics.getStatFromPlayer(player, Statistic.GUNSHOTSFIRED) + " shots", maxX / 2, maxY / 6);
            
            font.draw(batch, "You used " + statistics.getStatFromPlayer(player, Statistic.TELEPORTERSUSED) + " teleporters", maxX / 2, maxY / 7);
        }
        batch.end();
    }

    @Override
    public void handleInput() {
        if (Gdx.input.isTouched()) {
            gsm.setState(0);
        }
    }

    @Override
    public void dispose() {
        font.dispose();
    }
    
    public void setStatistics(Statistics statistics) {
        this.statistics = statistics;
    }
}

@@ -1774,18 +1774,99 @@
 + %22 shot
+%22 + (statistics.getStatFromPlayer(player, Statistic.GUNSHOTSFIRED) == 1 ? %22%22 : %22
 s%22
+)
 , maxX /
@@ -2014,18 +2014,101 @@
 leporter
+%22 + (statistics.getStatFromPlayer(player, Statistic.TELEPORTERSUSED) == 1 ? %22%22 : %22
 s%22
+)
 , maxX /

Fix for "You fired 1 shots"