package com.uoc.educationalVG.memorycon;

import java.util.List;
import java.util.Random;

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

/**
 * @author "Beginning Android 4 Games Development"
 * @author (adapted by Sergi Colina)
 * 
 */
public class Exercise04IntroScreen extends Screen {
	
    public Exercise04IntroScreen(Game game) {
        super(game);
    }   

    @Override
    public void update(float deltaTime) {
        List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
        game.getInput().getKeyEvents();
        int len = touchEvents.size();
        for(int i = 0; i < len; i++) {
            TouchEvent event = touchEvents.get(i);
            if(event.type == TouchEvent.TOUCH_UP) {	//touch on screen
            	int number = randInt(1, 3);
            	switch (number) {
            	case 1: 
            		game.setScreen(new Exercise04aGameScreen(game));
            		break;
            	case 2: 
            		game.setScreen(new Exercise04bGameScreen(game));
            		break;
            	case 3: 
            		game.setScreen(new Exercise04cGameScreen(game));
            		break;
            	}
            		if(Settings.isSoundEnabled())
            		Assets.getClick().play(1);
            	return;
            	}
        }
    }
    
    @Override
    public void present(float deltaTime) {
        Graphics g = game.getGraphics();
        g.drawPixmap(Assets.getBackground(), 0, 0);
        g.drawPixmap(Assets.getExercise04intro(), 0, 0);
    }
        
    /**
     * Returns a pseudo-random number between min and max, inclusive.
     * The difference between min and max can be at most
     * <code>Integer.MAX_VALUE - 1</code>.
     *
     * @param min Minimum value
     * @param max Maximum value.  Must be greater than min.
     * @return Integer between min and max, inclusive.
     * @see java.util.Random#nextInt(int)
     */
    public static int randInt(int min, int max) {

        // NOTE: Usually this should be a field rather than a method
        // variable so that it is not re-seeded every call.
        Random rand = new Random();

        // nextInt is normally exclusive of the top value,
        // so add 1 to make it inclusive
        int randomNum = rand.nextInt((max - min) + 1) + min;

        return randomNum;
    }
    
    @Override
    public void pause() {        
        Settings.save(game.getFileIO());
    }

    @Override
    public void resume() {

    }

    @Override
    public void dispose() {

    }
}
