package com.uoc.educationalVG.memorycon;

import java.util.*;

import com.uoc.educationalVG.framework.Game;
import com.uoc.educationalVG.framework.Graphics;
import com.uoc.educationalVG.framework.Input.TouchEvent;
import com.uoc.educationalVG.utils.Assets;
import com.uoc.educationalVG.utils.Settings;
import com.uoc.educationalVG.utils.World;

/**
 * @author "Beginning Android 4 Games Development"
 * @author (adapted by Sergi Colina)
 * 
 */
public class FinalScoreScreen extends GameScreen {

	enum GameState {
		Ready, Running, Paused, GameOver
	}

	GameState state = GameState.Ready;
	private String score;

	public FinalScoreScreen(Game game) {
		super(game);
		this.score = World.score;
}

	@Override
	public void update(float deltaTime) {
		List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
		game.getInput().getKeyEvents();
		if (state == GameState.Running)
			updateRunning(touchEvents, deltaTime);
		if (state == GameState.Ready)
			updateMusic();
	}

	public void updateMusic() {
		if (Settings.isSoundEnabled())
			if (!(Assets.getExitmusic().isPlaying()))
				Assets.getExitmusic().play();
		Assets.getExitmusic().setLooping(true);
		state = GameState.Running;
	}
	
	
	public void updateRunning(List<TouchEvent> touchEvents, float deltaTime) {
		int len = touchEvents.size();
		for (int i = 0; i < len; i++) {
			TouchEvent event = touchEvents.get(i);
			if (event.type == TouchEvent.TOUCH_UP) {
				if (inBounds(event, 120, 410, 85, 22)) {
					if (Settings.isSoundEnabled())
						Assets.getClick().play(1);
					game.setScreen(new HighscoreScreen(game));
					return;
				}
			}			
		}
	}

	@Override
	public void present(float deltaTime) {
		Graphics g = game.getGraphics();
        g.drawPixmap(Assets.getBackground(), 0, 0);
        g.drawPixmap(Assets.getFinalScoreScreen(), 0, 0);
		drawText(g, score, Assets.getNumbers(), 190, 345);
	}

	
	@Override
	public void pause() {
	
	}

	@Override
	public void resume() {

	}

	@Override
	public void dispose() {

	}

}