/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package wge3.engine;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;

// 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, Statistics statistics) {
        super(gsm);
        font = new BitmapFont();
        this.result = result;
        this.statistics = statistics;
        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) + " shot" + (statistics.getStatFromPlayer(player, Statistic.GUNSHOTSFIRED) == 1 ? "" : "s"), maxX / 2, maxY / 6);
            
            font.draw(batch, "You used " + statistics.getStatFromPlayer(player, Statistic.TELEPORTERSUSED) + " teleporter" + (statistics.getStatFromPlayer(player, Statistic.TELEPORTERSUSED) == 1 ? "" : "s"), maxX / 2, maxY / 7);
        }
        batch.end();
    }
    
    @Override
    public void handleInput() {
        if (Gdx.input.isTouched()) {
            gsm.setState(new MenuState(gsm));
        }
    }
    
    @Override
    public void dispose() {
        font.dispose();
    }
}

@@ -1240,24 +1240,39 @@
 Y / 2);%0A    
+    %7D%0A        %0A
         Stri
@@ -1315,20 +1315,16 @@
 get(0);%0A
-    
         
@@ -1456,32 +1456,25 @@
         
-    %0A   
+%0A
         
  font.dr
@@ -1457,33 +1457,32 @@
        %0A        
- 
 font.draw(batch,
@@ -1595,39 +1595,33 @@
 3);%0A        
-    %0A  
+%0A
         
   font.draw(
@@ -1600,34 +1600,32 @@
        %0A        
-  
 font.draw(batch,
@@ -1740,36 +1740,32 @@
 Y / 5);%0A        
-    
 %0A            fon
@@ -1749,36 +1749,32 @@
        %0A        
-    
 font.draw(batch,
@@ -1969,33 +1969,25 @@
 6);%0A        
-    %0A    
+%0A
         font
@@ -2199,33 +2199,32 @@
 Y / 7);%0A        
-%7D
 %0A        batch.e

Print end game stats also when player wins