package jaredws35.state;

import jaredws35.OctoShooter;
import jaredws35.res.Button;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class EndGame extends BasicGameState {
	private static final String loseText = "YOU'RE A LOSER!";
	private static final String winText = "YOU'RE A WINNER!";
	private static final int ID = 3;
	
	private Button playAgain,exit,shop,mainMenu;

	@Override
	public void init(GameContainer gc, StateBasedGame sbg)
			throws SlickException {
		playAgain = new Button(125, "Play Again");
		shop = new Button(200, "Shop");
		mainMenu = new Button(275, "Main Menu");
		exit = new Button(350, "Exit");
	}

	@Override
	public void update(GameContainer gc, StateBasedGame sbg, int delta)
			throws SlickException {
		Input input = new Input(OctoShooter.getHeight());
		
		if (input.isMouseButtonDown(0)){
			if (playAgain.getBoundingBox().contains(input.getMouseX(), input.getMouseY())){
				OctoShooter.setLose(false);
				OctoShooter.setWin(false);
				sbg.enterState(2);
			}
			else if (shop.getBoundingBox().contains(input.getMouseX(), input.getMouseY())){
			}
			else if (mainMenu.getBoundingBox().contains(input.getMouseX(), input.getMouseY())){
				OctoShooter.setLose(false);
				OctoShooter.setWin(false);
				sbg.enterState(1);
			}
			else if (exit.getBoundingBox().contains(input.getMouseX(), input.getMouseY())){
				gc.exit();
			}
		}
	}

	@Override
	public void render(GameContainer gc, StateBasedGame sbg, Graphics g)
			throws SlickException {
		g.drawImage(OctoShooter.getScreencap(), 0, 0);
		if (OctoShooter.getWin()){
			g.drawString(winText, OctoShooter.getWidth()/2-(winText.length()*5), 100);
		}
		else if (OctoShooter.getLose()){
			g.drawString(loseText, OctoShooter.getWidth()/2-(loseText.length()*5), 100);
		}
		g.drawImage(playAgain.getImg(), playAgain.getX(), playAgain.getY());
		g.drawString(playAgain.getText(), playAgain.getTextX(), playAgain.getTextY());
		g.drawImage(shop.getImg(), shop.getX(), shop.getY());
		g.drawString(shop.getText(), shop.getTextX(), shop.getTextY());
		g.drawImage(mainMenu.getImg(), mainMenu.getX(), mainMenu.getY());
		g.drawString(mainMenu.getText(), mainMenu.getTextX(), mainMenu.getTextY());
		g.drawImage(exit.getImg(), exit.getX(), exit.getY());
		g.drawString(exit.getText(), exit.getTextX(), exit.getTextY());
	}

	@Override
	public int getID() {
		return ID;
	}
	
}
