package hello;

import javax.microedition.lcdui.game.Sprite;
import javax.microedition.lcdui.Graphics;

public class Instructions
{
    private mySprite TitleBar;
    private mySprite Navigate;
    private mySprite You;
    private mySprite MoveAround;
    private mySprite Fire;
    private mySprite Spawn;
    private mySprite LookLike;
    private mySprite Survive;
    private mySprite Proceed;

    private Building cityBlock;

    private GoodGuy InstructSoldier;
    private BadGuy InstructHipster;

    private int screenNo = 0;
    private boolean finished = false;
    private int counter = 0;

    public Instructions(Canvas canv)
    {
        TitleBar = new mySprite("InstructionTitleBar.png", 69, 10);
        Navigate = new mySprite("Navigate.png", 182, 36);
        You = new mySprite("ThisisYou.png", 99, 91);
        MoveAround = new mySprite("MoveAround.png", 165, 23);
        Fire = new mySprite("FireYourWeapon.png", 174, 23);
        Spawn = new mySprite("EnemySpawn.png", 296, 200);
        LookLike = new mySprite("LookLike.png", 230, 70);
        Survive = new mySprite("Survive.png", 175, 10);
        Proceed = new mySprite("Proceed.png", 164, 23);

        InstructSoldier = new GoodGuy();
        InstructHipster = new BadGuy(1);

    }

    public void nextScreen(Graphics g, Canvas canv)
    {
        if(cityBlock == null)
        {
            cityBlock = new Building(canv, g);
        }

        TitleBar.setActive();
        TitleBar.setLocation(60, 1);
        TitleBar.draw(g);

        cityBlock.draw(g, null);

        Navigate.setInactive();
        You.setInactive();
        MoveAround.setInactive();
        Fire.setInactive();
        Spawn.setInactive();
        LookLike.setInactive();
        Survive.setInactive();
        Proceed.setInactive();
        InstructSoldier.getSprite().setInactive();
        InstructHipster.getSprite(0).setInactive();

        switch(screenNo)
        {
            case 0:
                Navigate.setActive();
                You.setInactive();
                MoveAround.setInactive();
                Fire.setInactive();
                Spawn.setInactive();
                LookLike.setInactive();
                Survive.setInactive();
                Proceed.setInactive();
                InstructHipster.getSprite(0).setInactive();
                InstructSoldier.getSprite().setInactive();
                Navigate.setLocation(1, 100);
                //System.out.println("0");
                Navigate.draw(g);
                break;
            case 1:
                Navigate.setInactive();
                MoveAround.setInactive();
                Fire.setInactive();
                Spawn.setInactive();
                LookLike.setInactive();
                Survive.setInactive();
                Proceed.setInactive();
                InstructHipster.getSprite(0).setInactive();
                You.setActive();
                You.setLocation(1, 100);
                InstructSoldier.getSprite().setActive();
                InstructSoldier.getSprite().setLocation(80, 100);
                //System.out.println("1");
                You.draw(g);
                InstructSoldier.draw(g);
                break;
            case 2:
                Navigate.setInactive();
                You.setInactive();
                Spawn.setInactive();
                LookLike.setInactive();
                Survive.setInactive();
                Proceed.setInactive();
                InstructHipster.getSprite(0).setInactive();
                MoveAround.setLocation(1, 100);
                Fire.setLocation(1, 200);
                MoveAround.setActive();
                Fire.setActive();
                //System.out.println("2");
                MoveAround.draw(g);
                Fire.draw(g);
                break;
            case 3:
                Navigate.setInactive();
                You.setInactive();
                MoveAround.setInactive();
                Fire.setInactive();
                LookLike.setInactive();
                Survive.setInactive();
                Proceed.setInactive();
                InstructHipster.getSprite(0).setInactive();
                Spawn.setActive();
                Spawn.setLocation(1, 100);
                //System.out.println("3");
                Spawn.draw(g);
                break;
            case 4:
                Navigate.setInactive();
                You.setInactive();
                MoveAround.setInactive();
                Fire.setInactive();
                Spawn.setInactive();
                Survive.setInactive();
                Proceed.setInactive();
                LookLike.setActive();
                LookLike.setLocation(1, 100);
                InstructHipster.getSprite(0).setActive();
                InstructHipster.getSprite(0).setLocation(80, 100);
                //System.out.println("4");
                LookLike.draw(g);
                InstructHipster.draw(g, 0);
                break;
            case 5:
                Navigate.setInactive();
                You.setInactive();
                MoveAround.setInactive();
                Fire.setInactive();
                Spawn.setInactive();
                LookLike.setInactive();
                Proceed.setInactive();
                Survive.setActive();
                Survive.setLocation(1, 100);
                //System.out.println("5");
                Survive.draw(g);
                break;
            case 6:
                Navigate.setInactive();
                You.setInactive();
                MoveAround.setInactive();
                Fire.setInactive();
                Spawn.setInactive();
                LookLike.setInactive();
                Survive.setInactive();
                Proceed.setActive();
                Proceed.setLocation(1, 100);
                //System.out.println("6");
                Proceed.draw(g);
                break;
            default:
                Navigate.setInactive();
                You.setInactive();
                MoveAround.setInactive();
                Fire.setInactive();
                Spawn.setInactive();
                LookLike.setInactive();
                Survive.setInactive();
                Proceed.setInactive();
                InstructSoldier.getSprite().setInactive();
                InstructHipster.getSprite(0).setInactive();
                break;
        }
    }

    public void navigate(Canvas canv)
      {
        int keyState = canv.getKeyStates();

        if ((keyState & canv.RIGHT_PRESSED) != 0)
        {
            if(counter == 0)
            {
                if(screenNo <= 6)
                {
                   screenNo++;
                   counter = 30;
                }
                else
                    finished = true;
            }
            else
            {
                while(counter > 0)
                {
                    counter--;
                }
            }
        }
        else if ((keyState & canv.LEFT_PRESSED) != 0)
        {
            if(counter == 0)
            {
                if(screenNo > 0)
                {
                    screenNo--;
                    counter = 30;
                }
            }
            else
            {
                while(counter > 0)
                {
                    counter--;
                }
            }
        }
    }

    public boolean isFinished()
    {
        return finished;
    }
}
