import java.util.*;
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * 
 * 
 * @author Jonathan, Florian
 * @version (a version number or a date)
 */
public class Welt extends World
{
    public static int width = 640;
    public static int height = width * 3 / 4; //Verhältniss 3 zu 4, d.h: 640x480
    public int heartsbuf = 9;

    public static int paddingX = 11;
    public static int paddingY = 20;
    public static int step = 10;
    public static boolean pause = false;
    public static boolean firstAsprinFound = false;

    public static boolean jdown = false;
    public static boolean adown = false;
    public static boolean ndown = false;
    public String easteregg = "";
    
    static Linch linch;
    Heart[] hearts = new Heart[5];
    Bottle bottle;
    Bomb bomb;
    throw_bottle throwbottle;
    Title title;
    Itemsshow items;

    Bombimage bombimage;
    Bottleimage bottleimage;
    Throwimage throwimage;

    Button menubutton = new Button("pause",1,25,25);
    Button changebutton = new Button("change",3,25,25);

    public Welt()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(width, height, 1, false);
        //System.out.print('\f'); 
        pause = false;
        Background.setCurrent(10);  
        Background.w = this;

        Bottle.available = false;
        Bomb.available = false;
        throw_bottle.available = false;
        Linch.dir = "";
        Bottlecheck.bottleavailable = false;
        Bombcheck.bombavailable = false;
        throw_bottlecheck.throw_bottleavailable= false;
        prepareWorld();

        GreenfootSound backgroundMusic = new GreenfootSound("background.mp3");
        backgroundMusic.playLoop();
        
        MenuHandler.giveWelt(this);
    }

    public void act(){
        Background.check(linch, this);
        setBildorder();    
        String tmp = Greenfoot.getKey();
        
        if (tmp != null)
        {easteregg = easteregg + tmp;}
        
        if (easteregg.endsWith("jann"))
        {
            String[] BombenGefunden = {"Jannnnnnn!"};
            developer.person = 1;
            Background.msg(BombenGefunden);
            easteregg = "";
            
        }
        //System.out.println(easteregg);
        
    }

    public void cheat(int num){
        Background.setCurrent(num);
    }

    /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    private void prepareWorld()
    {
        linch = new Linch();
        bottle = new Bottle();
        bomb = new Bomb();
        title = new Title();
        throwbottle = new throw_bottle();
        items = new Itemsshow();
        bombimage = new Bombimage();
        bottleimage = new Bottleimage();
        throwimage = new Throwimage();
        addObject(bombimage,-100,-100);
        addObject(bottleimage,-100,-100);
        addObject(throwimage,-100,-100);
        addObject(linch, 300, 300);
        addObject(bottle, -100,-100);
        addObject(bomb, -100,-100);
        addObject(throwbottle, -100, -100);
        addObject(menubutton, 620,20);
        addObject(changebutton, 580, 20);
        addObject(title, 320,20);
        addObject(items, -100,-100);
        setBackground(Background.img);
        List<OH> newObj = Background.obj;
        for(OH a: newObj){
            addObject(a.obj, a.x, a.y);
        }

        for (int i = 0; i < hearts.length; i++)
        {
            //System.out.println(hearts.length);
            hearts[i]= new Heart();
            addObject(hearts[i], 20+heartsbuf*i+20*i,15);
        }

        linch.giveHearts(hearts);
        bottle.giveLinch(linch);
        bomb.giveLinch(linch);
        throwbottle.giveLinch(linch);
    }

    /**
     * 
     * 
     * @author Jonathan
     */
    public void setBildorder()
    {
        if(linch.down == true)
        {
            setPaintOrder(Bottle.class,Linch.class);
        }
        else if(linch.up == true)
        {
            setPaintOrder(Linch.class,Bottle.class);
        }
        else if(linch.right == true)
        {
            setPaintOrder(Linch.class,Bottle.class);
        }
        else if(linch.left == true)
        {
            setPaintOrder(Linch.class,Bottle.class);
        }
        setPaintOrder(developer.class,throw_bottlecheck.class, Bottlecheck.class, Bombcheck.class,Button.class, Message.class, Heart.class, Throwimage.class, Bottleimage.class, Bombimage.class, Title.class, Linch.class);
        
    }

}
