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

/**
 * Verwaltet alle Prozesse des Programms
 * 
 * @author Felix Pfeffer, Marek Parucha, Yacin Boualili
 * @version 2.0
 */
public class Spieleverwaltung extends Actor
{
    
    
    /**bei jedem Frame wird dieser integer um 1 erhöht*/
    public static int frameCounter =0; 
    /**gibt die anzahl der Frames pro sekunde a*/
    public static int framesPerSecond = 0; 
    /** zählt die millisekunden bis 1 sekunde erreicht ist*/
    public static long lastAdded = System.currentTimeMillis(); 
    /** anfangs Spielgeschwindigkeit --> liefert 29 FPS*/
    public static int gameSpeed = 44; 
    /** die jetzige Spielgeschwindigkeit --> reguliert auf ca. 29 FPS*/
    public static int currentGameSpeed = gameSpeed; 
    /**Visueller stand des FPS*/
    public static int startFPS = 29;
    /**aktueller Frame*/
    public static int currentFPS = startFPS;
    
    //Drawing fpsViewer = new Strings(framesPerSecond +" FPS",30,0);
    /**ausgeführte Map*/
    static public Map map0      = new Map(0);
    /**Map1*/
    private Map map1      = new Map(1);
    /**Map2*/
    private Map map2      = new Map(2);
    /**Map3*/
    private Map map3      = new Map(3);
    /**Map4*/
    private Map map4      = new Map(4);
    /**Map5*/
    private Map map5      = new Map(5);
    /**Map6*/
    private Map map6      = new Map(6);
    /**Map7*/
    private Map map7      = new Map(7);
    /**Map8*/
    private Map map8      = new Map(8);
    /**true falls Tower gerade gekauft wird*/
    public boolean buyProzess[][] = new boolean[(int)TeD_World.NY][(int)TeD_World.NX];
    
    /**ausgeführte Map*/
    private Map currentMap;
    /**geld des Sielers*/
    private static int money;
    /**leben des Sielers*/
    private static int life;
    /**score des Sielers*/
    private static int score = 0;
    /**true falls tower gedrückt wurde*/
    private static boolean firstTouch = true;
    /**gespeicherter Tower*/
    public static Actor towerActor;
    /**schuss power des towers*/
    private static int towerShotPower;
    /**schuss geschwindigkeit des Towers*/
    private static int towerShotSpeed;
    /**schuss intervall des Towers*/
    private static int towerShotIntervall;
    /**radius des Towers*/
    private static int towerDistance;
    /**kosten des Towers*/
    private static int towerMoney;
    /**level des Towers*/
    private static int towerLevel;
    /**upgrade kosten des Towers*/
    private static int towerUpgradeKosten;
    /**einzelne Strings der Tower Infos*/
    Strings shotPowerString;
    Strings shotSpeedString; 
    Strings shotIntervallString; 
    Strings distanceString; 
    Strings towerMoneyString; 
    Strings levelString; 
    Strings towerString;
    Strings upgradeKostenString;

    
    /**Strings der Spieler Infos*/
    Strings scoreString;
    Strings lifeString;
    Strings moneyString;
    
    private  boolean rasterOn = false;  //Zeigt ob das Raster an oder aus ist ( ture = an )
    
    private boolean rasterStatus = false;
    
    private boolean ersterDurchlauf = true;
    /**Kaufprozesse*/
    private boolean buyTowerOne = false;
    private boolean buyTowerTwo = false;
    private boolean buyTowerThree = false;
    private boolean buyWegelagerer1 = false;
    private boolean buyWegelagerer2 = false;
    private boolean buyWegelagerer3 = false;
    /**neues Objekt der Klasse Writer*/
    Writer w = new Writer();
    /**Hauptmenü*/
    Menue hauptmenue;
    boolean hauptmenueOnline = false;
    /**Baumenü*/
    Menue baumenue;
    boolean baumenueOnline = false;
    /**Mapmenü*/
    Menue mapmenue;
    boolean mapmenueOnline = false;
    /**Upgrademenü*/
    Menue upgrademenue;
    boolean upgrademenueOnline = false;
    /**gamevermenü*/
    Menue gameovermenue;
    boolean gameovermenueOnline = false;
    
    boolean gameHasStarted;
    boolean inGameIsRunning = false;
    
    private long lastTime = System.currentTimeMillis();
    int mapNumber;
    /**neues Objekt der Klasse Clock (Zählt Wellen Intervalle)*/
    Clock intervallCountdown= new Clock(false,false,0,"");
    /**neues Objekt der Klasse Clock (Zählt Pausenzeit)*/
    Clock pauseCounter = new Clock(true,true,10,"next Wave in:");
    int waveNumber = 0;
    boolean pauseCounterTimeOver = false;
    
    Picture pic = new Picture();
    boolean picOn = false;
   
    private int n = 0;
    private LevelReader lR;

    List monster;
    
    /**
     * Act - do whatever the Spieleverwaltung wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        setFrameRate();
        monster = getWorld().getObjects( Monsters.class );
        
        
        
        if(ersterDurchlauf)
        {
            for(int i=0; i < TeD_World.NY ; ++i )
            {
                for(int j=0; j < TeD_World.NY ; ++j )
                {
                    buyProzess[i][j] = false;
                }
            }
            
            
            lR = new LevelReader("waves/level1.txt");
            money = lR.getMoney();
            life = lR.getLife();
            
            startHauptmenue();
            
            
            hauptmenue.lockButton(1);
            hauptmenue.lockButton(3);
            gameHasStarted  = false;
            ersterDurchlauf = false;
            
     
        }
        
        if(hauptmenueOnline)
        {
            if( hauptmenue.getButtonStatus(1) == true )
            {
                stopHauptmenue();
                TeD_World.M_MENUE.stop();
                startBaumenue();
                zeichneSpiel( map0 );
                
                gameHasStarted  = true;
            }
            else if( hauptmenue.getButtonStatus(2) == true )
            {
                 stopHauptmenue();
                 startMapmenue();
                 mapmenue.lockButton(2);
                 mapmenue.lockButton(3);
                 mapmenue.lockButton(4);
                 mapmenue.lockButton(5);
                 mapmenue.lockButton(6);
                 mapmenue.lockButton(7);
                 mapmenue.lockButton(8);
                 gameHasStarted  = true;
            }
            else if( hauptmenue.getButtonStatus(3) == true )
            {
                stopHauptmenue();
                TeD_World.M_MENUE.stop();
                startBaumenue();
                zeichneSpiel( map0 );
            }
        }
        
        if(gameovermenueOnline)
        {
            if( gameovermenue.getButtonStatus(1) == true )
            {
                stopGameovermenue();
                
                startHauptmenue();

            }
           
        }
        
        if(mapmenueOnline)
        {
            if( mapmenue.getButtonStatus(1) == true )
            {
                stopMapmenue();
                lR = new LevelReader("waves/level1.txt");
                money = lR.getMoney();
                life = lR.getLife();
                for(int i = 0 ; i < TeD_World.NY ; ++i )
                {
                    for(int j = 0 ; j < TeD_World.NX ; ++j )
                    {
                        map0.map[i][j] = map1.getMap( j , i );
                    }
                }
                w.getMap( map0.map );
                w.printMap(0);
                currentMap = map1;
                startHauptmenue();
                
                hauptmenue.unlockButton(1);
                hauptmenue.lockButton(3);
            }
            else if( mapmenue.getButtonStatus(2) == true )
            {
                stopMapmenue();
                lR = new LevelReader("waves/level2.txt");
                money = lR.getMoney();
                life = lR.getLife();
                for(int i = 0 ; i < TeD_World.NY ; ++i )
                {
                    for(int j = 0 ; j < TeD_World.NX ; ++j )
                    {
                        map0.map[i][j] = map2.getMap( j , i );
                    }
                }
                
                w.getMap( map0.map );
                w.printMap(0);
                currentMap = map2;
                startHauptmenue();
                hauptmenue.lockButton(3);
                
            }
            else if( mapmenue.getButtonStatus(3) == true )
            {
                stopMapmenue();
                lR = new LevelReader("waves/level3.txt");
                money = lR.getMoney();
                life = lR.getLife();
                for(int i = 0 ; i < TeD_World.NY ; ++i )
                {
                    for(int j = 0 ; j < TeD_World.NX ; ++j )
                    {
                        map0.map[i][j] = map3.getMap( j , i );
                    }
                }
                
                w.getMap( map0.map );
                w.printMap(0);
                currentMap = map3;
                startHauptmenue();
                hauptmenue.lockButton(3);
                
            }
            else if( mapmenue.getButtonStatus(3) == true )
            {
                stopMapmenue();
                lR = new LevelReader("waves/level4.txt");
                money = lR.getMoney();
                life = lR.getLife();
                for(int i = 0 ; i < TeD_World.NY ; ++i )
                {
                    for(int j = 0 ; j < TeD_World.NX ; ++j )
                    {
                        map0.map[i][j] = map4.getMap( j , i );
                    }
                }
                
                w.getMap( map0.map );
                w.printMap(0);
                currentMap = map4;
                startHauptmenue();
                hauptmenue.lockButton(3);
                
            }
            else if( mapmenue.getButtonStatus(5) == true )
            {
                stopMapmenue();
                lR = new LevelReader("waves/level5.txt");
                money = lR.getMoney();
                life = lR.getLife();
                for(int i = 0 ; i < TeD_World.NY ; ++i )
                {
                    for(int j = 0 ; j < TeD_World.NX ; ++j )
                    {
                        map0.map[i][j] = map5.getMap( j , i );
                    }
                }
                
                w.getMap( map0.map );
                w.printMap(0);
                currentMap = map5;
                startHauptmenue();
                hauptmenue.lockButton(3);
                
            }
            else if( mapmenue.getButtonStatus(6) == true )
            {
                stopMapmenue();
                lR = new LevelReader("waves/level6.txt");
                money = lR.getMoney();
                life = lR.getLife();
                for(int i = 0 ; i < TeD_World.NY ; ++i )
                {
                    for(int j = 0 ; j < TeD_World.NX ; ++j )
                    {
                        map0.map[i][j] = map6.getMap( j , i );
                    }
                }
                
                w.getMap( map0.map );
                w.printMap(0);
                currentMap = map6;
                startHauptmenue();
                hauptmenue.lockButton(3);
                
            }
            else if( mapmenue.getButtonStatus(7) == true )
            {
                stopMapmenue();
                lR = new LevelReader("waves/level7.txt");
                money = lR.getMoney();
                life = lR.getLife();
                for(int i = 0 ; i < TeD_World.NY ; ++i )
                {
                    for(int j = 0 ; j < TeD_World.NX ; ++j )
                    {
                        map0.map[i][j] = map7.getMap( j , i );
                    }
                }
                
                w.getMap( map0.map );
                w.printMap(0);
                currentMap = map7;
                startHauptmenue();
                hauptmenue.lockButton(3);
                
            }
            else if( mapmenue.getButtonStatus(8) == true )
            {
                stopMapmenue();
                lR = new LevelReader("waves/level8.txt");
                money = lR.getMoney();
                life = lR.getLife();
                for(int i = 0 ; i < TeD_World.NY ; ++i )
                {
                    for(int j = 0 ; j < TeD_World.NX ; ++j )
                    {
                        map0.map[i][j] = map8.getMap( j , i );
                    }
                }
                
                w.getMap( map0.map );
                w.printMap(0);
                currentMap = map8;
                startHauptmenue();
                hauptmenue.lockButton(3);
                
            }
            
        }
        
        if(inGameIsRunning)
        {
            waveConstructor(waveNumber);
        }
        
        if(baumenueOnline)
        {
            if( monster.isEmpty() )
            {
                baumenue.unlockButton(2);
            }
            else
            {
                baumenue.lockButton(2);
            }
            if( baumenue.getButtonStatus(1) == true )
            {
                stopBaumenue();
                TeD_World.M_HINTERGRUND.stop();
                startHauptmenue();
                hauptmenue.lockButton(1);
            }
            else if( baumenue.getButtonStatus(2) == true )
            {
                setRasterOn(false);
                
                pic.setPicture( "TowerOne" ) ;
                getWorld().addObject( pic , TeD_World.cellToPixM((int)(TeD_World.NX/2)),TeD_World.cellToPixM((int)(TeD_World.NY/2)));
                
                picOn = true;
                buyTowerOne = true;
            }
            else if( baumenue.getButtonStatus(3) == true )
            {
                setRasterOn(false);
                
                pic.setPicture( "TowerTwo" ) ;
                getWorld().addObject( pic , TeD_World.cellToPixM((int)(TeD_World.NX/2)),TeD_World.cellToPixM((int)(TeD_World.NY/2)));
                
                picOn = true;
                buyTowerTwo = true;
            }
            else if( baumenue.getButtonStatus(4) == true )
            {
                setRasterOn(false);
                
                pic.setPicture( "TowerThree" ) ;
                getWorld().addObject( pic , TeD_World.cellToPixM((int)(TeD_World.NX/2)),TeD_World.cellToPixM((int)(TeD_World.NY/2)));
                
                picOn = true;
                buyTowerThree = true;
            } 
            else if( baumenue.getButtonStatus(5) == true )
            {
                setRasterOn(true);
                
                pic.setPicture( "Wegelagerer1" ) ;
                getWorld().addObject( pic , TeD_World.cellToPixM((int)(TeD_World.NX/2)),TeD_World.cellToPixM((int)(TeD_World.NY/2)));
                
                picOn = true;
                buyWegelagerer1 = true;
            } 
            else if( baumenue.getButtonStatus(6) == true )
            {
                setRasterOn(true);
                
                pic.setPicture( "Wegelagerer2" ) ;
                getWorld().addObject( pic , TeD_World.cellToPixM((int)(TeD_World.NX/2)),TeD_World.cellToPixM((int)(TeD_World.NY/2)));
                
                picOn = true;
                buyWegelagerer2 = true;
            } 
            else if( baumenue.getButtonStatus(7) == true )
            {
                setRasterOn(true);
                
                pic.setPicture( "Wegelagerer3" ) ;
                getWorld().addObject( pic , TeD_World.cellToPixM((int)(TeD_World.NX/2)),TeD_World.cellToPixM((int)(TeD_World.NY/2)));
                
                picOn = true;
                buyWegelagerer3 = true;
            } 
            lockTowerButton(1,150,2);
            lockTowerButton(1,200,3);
            lockTowerButton(1,250,4);
            lockTowerButton(1,300,5);
            lockTowerButton(2,400,6);
            lockTowerButton(3,500,7);
            
            
           
            
            if(getLife() <= 0)
            {
                stopBaumenue();
                startGameovermenue();
            }
            
            
            if(!firstTouch && !upgrademenueOnline)
            {
                stopBaumenue();
                startUpgrademenue(towerActor,towerShotPower,towerShotSpeed,towerShotIntervall,towerDistance, towerMoney, towerLevel, towerUpgradeKosten);
                zeichneSpiel( map0 );
            }
            
        }
        
        if(upgrademenueOnline)
        {
            if( upgrademenue.getButtonStatus(1) == true ) //upgrade Button
            {
                removeMoney(towerUpgradeKosten);
                stopUpgrademenue();
                startBaumenue();
                zeichneSpiel(map0 );
                ((Towers)towerActor).upgrade();
                firstTouch = true;
                
            }
            else if( upgrademenue.getButtonStatus(2) == true )//entfernen Button
            {
                map0.map[TeD_World.pixToCell(towerActor.getY()-1)][TeD_World.pixToCell(towerActor.getX()-1)-1] = 00;
                Towers.towerClicked = false;
                getWorld().removeObject(towerActor);
                towerActor = null;
                addMoney(towerMoney/2);
                stopUpgrademenue();
                startBaumenue();
                zeichneSpiel(map0 );
                firstTouch = true;
            }
           else if(firstTouch)
            {
                stopUpgrademenue();
                startBaumenue();
                zeichneSpiel( map0 );
            }

                lockUpgradeButton(towerLevel,towerUpgradeKosten);

            if(getLife() <= 0)
            {
                stopUpgrademenue();
                startGameovermenue();
            }
        }
        
        if(picOn)
        {
            MouseInfo mouse = Greenfoot.getMouseInfo();
            
            if(mouse != null)
            {
                if(mouse.getX() < TeD_World.PIX*TeD_World.NX)
                {
                    pic.setLocation(mouse.getX(),mouse.getY());
                }
            }
        }
        
        if( rasterOn  && Greenfoot.mouseClicked(null) && rasterStatus)
        {
            MouseInfo mouse = Greenfoot.getMouseInfo();
            
            if(buyTowerOne)
            {
                buyTowerOne = false;
                if(mouse.getX() < TeD_World.PIX*TeD_World.NX)
                {
                    map0.map[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = 18;
                    buyProzess[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = true;
                }
            }
            else if(buyTowerTwo)
            {
                buyTowerTwo = false;
                if(mouse.getX() < TeD_World.PIX*TeD_World.NX)
                {
                    map0.map[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = 19;
                    buyProzess[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = true;
                }
            }
            else if(buyTowerThree)
            {
                buyTowerThree = false;
                if(mouse.getX() < TeD_World.PIX*TeD_World.NX)
                {
                    map0.map[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = 20;
                    buyProzess[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = true;
                }
            }
            else if(buyWegelagerer1)
            {
                buyWegelagerer1 = false;
                if(mouse.getX() < TeD_World.PIX*TeD_World.NX)
                {
                    if( map0.map[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] == 1 )
                    {
                        map0.map[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = 91;
                        buyProzess[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = true;
                    }
                    else
                    {
                         map0.map[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = 92;
                         buyProzess[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = true;
                    }
                }
            }
            else if(buyWegelagerer2)
            {
                buyWegelagerer2 = false;
                if(mouse.getX() < TeD_World.PIX*TeD_World.NX)
                {
                    if( map0.map[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] == 1 )
                    {
                        map0.map[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = 93;
                        buyProzess[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = true;
                    }
                    else
                    {
                         map0.map[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = 94;
                         buyProzess[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = true;
                    }
                }
            }
            else if(buyWegelagerer3)
            {
                buyWegelagerer3 = false;
                if(mouse.getX() < TeD_World.PIX*TeD_World.NX)
                {
                    if( map0.map[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] == 1 )
                    {
                        map0.map[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = 95;
                        buyProzess[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = true;
                    }
                    else
                    {
                         map0.map[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = 96;
                         buyProzess[TeD_World.pixToCell(mouse.getY())-1][TeD_World.pixToCell(mouse.getX())-1] = true;
                    }
                }
            }
            else
            {
                return;
            }
            
            getWorld().removeObject(pic);
            picOn = false;
            
            w.getMap( map0.map );
            w.printMap(0);
            zeichneSpiel( map0 );
            
            setRasterOff();
        }
        
        
        
        
        if( waitEn(lastTime,100) )
        {
            if(Greenfoot.isKeyDown("escape"))
            {
                if( monster.isEmpty() )
                {
                    if(hauptmenueOnline && gameHasStarted)
                    {
                        stopHauptmenue();
                        TeD_World.M_MENUE.stop();
                        startBaumenue();
                        zeichneSpiel( map0 );
                
                        gameHasStarted  = true;
                    }
                    else if(!hauptmenueOnline && gameHasStarted)
                    {   
                        stopBaumenue();
                        TeD_World.M_HINTERGRUND.stop();
                        startHauptmenue();
                        hauptmenue.lockButton(1);
                    }
                }
            }
            lastTime = System.currentTimeMillis();
        } 
        
        
    } 
    /**Zeichnet Karte*/
    private void zeichneSpiel(Map m )
    {
        //startBaumenue();
        builtTowers();
        druckeKarte( m );
    }
    /**Druckt Karte*/
    public void druckeKarte( Map m )
    {
        GreenfootImage hilf = new GreenfootImage( getWorld().getBackground() );
        hilf.drawImage(m.printMap(), 0 , 0);
        getWorld().setBackground(hilf);
    }
    /**Baut Tower auf die Karte*/
    private void builtTowers()
    {
        
        
        for(int i = 0 ; i < TeD_World.NY ; ++i )
        {
            for(int j = 0 ; j < TeD_World.NX ; ++j )
            {
                int hilf = map0.map[i][j];
                List l1 = getWorld().getObjectsAt(TeD_World.cellToPixM(j+1),(TeD_World.cellToPixM(i+1)-53),Towers.class);
                //List l2 = getWorld().getObjectsAt(TeD_World.cellToPixM(j+1),(TeD_World.cellToPixM(i+1)-53),TowerTwo.class);
                //List l3 = getWorld().getObjectsAt(TeD_World.cellToPixM(j+1),(TeD_World.cellToPixM(i+1)-53),TowerThree.class);
                List l4 = getWorld().getObjectsAt(TeD_World.cellToPixM(j+1),(TeD_World.cellToPixM(i+1)),Wegelagerer.class);
                
                
                
                if( hilf  == 18 && (l1.isEmpty()&&l4.isEmpty()))
                {
                    getWorld().addObject( new TowerOne() , TeD_World.cellToPixM(j+1) ,TeD_World.cellToPixM(i+1)-53 );
                }
                else if( hilf  == 19 && (l1.isEmpty()&&l4.isEmpty()) ) 
                {
                    getWorld().addObject( new TowerTwo() , TeD_World.cellToPixM(j+1) ,TeD_World.cellToPixM(i+1)-53 );
                }
                else if( hilf  == 20 && (l1.isEmpty()&&l4.isEmpty())) 
                {
                    getWorld().addObject( new TowerThree() , TeD_World.cellToPixM(j+1) ,TeD_World.cellToPixM(i+1)-53 );
                }
                else if( (hilf  == 91||hilf  == 92)  && (l1.isEmpty()&&l4.isEmpty())) 
                {
                    getWorld().addObject( new WegelagererOne() , TeD_World.cellToPixM(j+1) ,TeD_World.cellToPixM(i+1) );
                }
                else if( (hilf  == 93||hilf  == 94)  && (l1.isEmpty()&&l4.isEmpty())) 
                {
                    getWorld().addObject( new WegelagererTwo() , TeD_World.cellToPixM(j+1) ,TeD_World.cellToPixM(i+1) );
                }
                else if( (hilf  == 95||hilf  == 96)  && (l1.isEmpty()&&l4.isEmpty())) 
                {
                    getWorld().addObject( new WegelagererThree() , TeD_World.cellToPixM(j+1) ,TeD_World.cellToPixM(i+1) );
                }
            }
        }
        
    }
    /**startet Hauptmenü*/
    private void startHauptmenue()
    {
        if(!hauptmenueOnline)
        {
            int[][] positionen = new int[3][2];
            GreenfootImage[][] images = new GreenfootImage[3][3];
        
        
            positionen[0][0] = 519;
            positionen[0][1] = 300;
            positionen[1][0] = 519;
            positionen[1][1] = 380;
            positionen[2][0] = 519;
            positionen[2][1] = 500;
        
        
            images[0][0] = TeD_World.B_BUT_SG;
            images[0][1] = TeD_World.B_BUT_SG_PRESSED;
            images[0][2] = TeD_World.B_BUT_SG_LOCKED;
            images[1][0] = TeD_World.B_BUT_SM;
            images[1][1] = TeD_World.B_BUT_SM_PRESSED;
            images[1][2] = TeD_World.B_BUT_SM_LOCKED;
            images[2][0] = TeD_World.B_BUT_CO;
            images[2][1] = TeD_World.B_BUT_CO_PRESSED;
            images[2][2] = TeD_World.B_BUT_CO_LOCKED;
        
            deleteGameplay();
            hauptmenue = new Menue( 3 , positionen , images);
            getWorld().addObject( hauptmenue ,1,1);
            
            TeD_World.M_MENUE.playLoop();
            getWorld().setBackground(TeD_World.B_MAINMENUE);
            inGameIsRunning = false;
            hauptmenueOnline = true;
        }
    }
    /**stoppt Hauptmenü*/
    private void stopHauptmenue()
    {
        if(hauptmenueOnline)
        {
            hauptmenue.close();
            
            getWorld().removeObject( hauptmenue );
            hauptmenueOnline = false;
        }
    }
    /**startet Gameovermenü*/
    private void startGameovermenue()
    {
        if(!gameovermenueOnline)
        {
            int[][] positionen = new int[1][2];
            GreenfootImage[][] images = new GreenfootImage[1][3];
        
        
            positionen[0][0] = 519;
            positionen[0][1] = 700;
            
        
        
            images[0][0] = TeD_World.B_BUT_MM;
            images[0][1] = TeD_World.B_BUT_MM_PRESSED;
            images[0][2] = TeD_World.B_BUT_SG_PRESSED;
            
        
            deleteGameplay();
            gameovermenue = new Menue( 1 , positionen , images);
            getWorld().addObject( gameovermenue ,1,1);
            mapmenue.lockButton(2);
            mapmenue.lockButton(3);
            mapmenue.lockButton(4);
            mapmenue.lockButton(5);
            mapmenue.lockButton(6);
            mapmenue.lockButton(7);
            mapmenue.lockButton(8);
            TeD_World.M_MENUE.playLoop();
            getWorld().setBackground(TeD_World.B_GAMEOVERMENUE);
            scoreString = new Strings(getScore()+"",40,6);
            getWorld().addObject(scoreString,519,500);
            inGameIsRunning = false;
            gameovermenueOnline = true;
        }
    }
    /**stoppt Gameovermenü*/
    private void stopGameovermenue()
    {
        if(gameovermenueOnline)
        {
            score=0;
            gameovermenue.close();
            getWorld().removeObject( scoreString );
            getWorld().removeObject( gameovermenue );
            gameovermenueOnline = false;
        }
    }
    /**startet Baumenü*/
    private void startBaumenue()
    {
        if(!baumenueOnline)
        {
            
            int[][] positionen = new int[7][2];
            GreenfootImage[][] images = new GreenfootImage[7][3];
            int butZ = 7;
        
        
            
            positionen[0][0] = 1000;
            positionen[0][1] = 60;
            positionen[1][0] = 864;
            positionen[1][1] = 383;
            positionen[2][0] = 964;
            positionen[2][1] = 383;
            positionen[3][0] = 864;
            positionen[3][1] = 509;
            positionen[4][0] = 964;
            positionen[4][1] = 509;
            positionen[5][0] = 864;
            positionen[5][1] = 635;
            positionen[6][0] = 964;
            positionen[6][1] = 635;
            
            
        
        
            
            images[0][0] = TeD_World.B_BUT_PG;
            images[0][1] = TeD_World.B_BUT_PG_PRESSED;
            images[0][2] = TeD_World.B_BUT_PG_LOCKED;
            images[1][0] = TeD_World.B_BUT_T1;
            images[1][1] = TeD_World.B_BUT_T1_PRESSED;
            images[1][2] = TeD_World.B_BUT_T1_LOCKED;
            images[2][0] = TeD_World.B_BUT_T2;
            images[2][1] = TeD_World.B_BUT_T2_PRESSED;
            images[2][2] = TeD_World.B_BUT_T2_LOCKED;
            images[3][0] = TeD_World.B_BUT_T3;
            images[3][1] = TeD_World.B_BUT_T3_PRESSED;
            images[3][2] = TeD_World.B_BUT_T3_LOCKED;
            images[4][0] = TeD_World.B_BUT_W3;
            images[4][1] = TeD_World.B_BUT_W3_PRESSED;
            images[4][2] = TeD_World.B_BUT_W3_LOCKED;
            images[5][0] = TeD_World.B_BUT_W2;
            images[5][1] = TeD_World.B_BUT_W2_PRESSED;
            images[5][2] = TeD_World.B_BUT_W2_LOCKED;
            images[6][0] = TeD_World.B_BUT_W1;
            images[6][1] = TeD_World.B_BUT_W1_PRESSED;
            images[6][2] = TeD_World.B_BUT_W1_LOCKED;
            
            
        
        
            baumenue = new Menue( butZ , positionen , images);
            getWorld().addObject( baumenue ,1,1);
            scoreString = new Strings(getScore()+"",20,2);
            lifeString = new Strings(getLife()+"",20,4);
            moneyString = new Strings(getMoney()+"€",20,3);
            getWorld().setBackground(TeD_World.B_BUILDMENUE);
            getWorld().addObject(pauseCounter,(int)(((TeD_World)getWorld()).X)+125 ,(int)(((TeD_World)getWorld()).Y)-50 ); 
            //getWorld().addObject(fpsViewer,(int)(((TeD_World)getWorld()).X)/2,50);
            getWorld().addObject(lifeString,900,231);
            getWorld().addObject(moneyString,900,281);
            getWorld().addObject(scoreString,900,186);
            inGameIsRunning = true;
            baumenueOnline = true;
            
            TeD_World.M_HINTERGRUND.playLoop();
            
        }
    }
    /**stoppt Baumenü*/
    private void stopBaumenue()
    {
        if(baumenueOnline)
        {
            baumenue.close();
            getWorld().removeObject( scoreString );
            getWorld().removeObject( lifeString );
            getWorld().removeObject( moneyString );
            getWorld().removeObject( baumenue );
            getWorld().removeObject( pauseCounter );
            //getWorld().removeObject( fpsViewer );
            
            baumenueOnline = false;
        }
    }
    /**startet Upgrademenü*/
    private void startUpgrademenue(Actor tower, int shotPower, int shotSpeed, int shotIntervall, int distance,int money, int level, int upgradekosten)
    {
        if(!upgrademenueOnline)
        {
            int[][] positionen = new int[2][2];
            GreenfootImage[][] images = new GreenfootImage[2][3];
            int butZ = 2;
            towerString = new Strings("aaaaaaaaaaaaaa",20,5);;
            if(tower.getClass().getSimpleName() == "TowerOne")
            {
                towerString = new Strings("Typ: "+"Bogenschütze",20,5);
            }
            else if(tower.getClass().getSimpleName() == "TowerTwo")
            {
                towerString = new Strings("Typ: "+"Katapult",20,5);
            }
            else if(tower.getClass().getSimpleName() == "TowerThree")
            {
                towerString = new Strings("Typ: "+"Scharfschütze",20,5);
            }
            shotPowerString = new Strings("Power: "+shotPower,20,5);
            shotSpeedString = new Strings("Geschwindigkeit: "+shotSpeed,20,5);
            shotIntervallString = new Strings("Intervall: "+shotIntervall,20,5);
            distanceString = new Strings("Radius: "+distance,20,5);
            towerMoneyString = new Strings("Geld Zurück: "+(money/5)+"€",20,5);
            levelString = new Strings("Level: "+towerLevel,20,5);
            upgradeKostenString = new Strings("Upgrade Kosten: "+towerUpgradeKosten,20,5);
        
        
            positionen[0][0] = 915;
            positionen[0][1] = 610;
            positionen[1][0] = 915;
            positionen[1][1] = 660;
            
        
        
            images[0][0] = TeD_World.B_BUT_UP;
            images[0][1] = TeD_World.B_BUT_UP_PRESSED;
            images[0][2] = TeD_World.B_BUT_UP_LOCKED;
            images[1][0] = TeD_World.B_BUT_EF;
            images[1][1] = TeD_World.B_BUT_EF_PRESSED;
            images[1][2] = TeD_World.B_BUT_EF_LOCKED;
            
            
            
        
        
            upgrademenue = new Menue( butZ , positionen , images);
            getWorld().addObject( upgrademenue ,1,1);
            scoreString = new Strings(getScore()+"",20,2);
            lifeString = new Strings(getLife()+"",20,4);
            moneyString = new Strings(getMoney()+"€",20,3);
            getWorld().setBackground(TeD_World.B_UPGRADEDMENUE);
            getWorld().addObject(pauseCounter,(int)(((TeD_World)getWorld()).X)+125 ,(int)(((TeD_World)getWorld()).Y)-50 ); 
            //getWorld().addObject(fpsViewer,(int)(((TeD_World)getWorld()).X)/2,50);
            getWorld().addObject(lifeString,900,231);
            getWorld().addObject(moneyString,900,281);
            getWorld().addObject(scoreString,900,186);
            getWorld().addObject(towerString,910,340);
            getWorld().addObject(shotPowerString,910,370);
            getWorld().addObject(shotSpeedString,910,400);
            getWorld().addObject(shotIntervallString,910,430);
            getWorld().addObject(distanceString,910,460);
            getWorld().addObject(towerMoneyString,910,490);
            getWorld().addObject(levelString,910,520);
            getWorld().addObject(upgradeKostenString,910,550);
            inGameIsRunning = true;
            upgrademenueOnline = true;
            
        }
    }
    /**stoppt Upgrademenü*/
    private void stopUpgrademenue()
    {
         if(upgrademenueOnline)
        {
            upgrademenue.close();
            getWorld().removeObject( scoreString );
            getWorld().removeObject( lifeString );
            getWorld().removeObject( moneyString );
            getWorld().removeObject( upgrademenue );
            getWorld().removeObject( pauseCounter );
            //getWorld().removeObject( fpsViewer );
            getWorld().removeObject( shotPowerString );
            getWorld().removeObject( shotSpeedString );
            getWorld().removeObject( shotPowerString );
            getWorld().removeObject( shotIntervallString );
            getWorld().removeObject( distanceString );
            getWorld().removeObject( towerMoneyString );
            getWorld().removeObject( levelString );
            getWorld().removeObject( towerString );
            getWorld().removeObject( upgradeKostenString );
           
            upgrademenueOnline = false;
        }
    }
    /**startet Mapmenü*/
    private void startMapmenue()
    {
        if(!mapmenueOnline)
        {
            int[][] positionen = new int[8][2];
            GreenfootImage[][] images = new GreenfootImage[8][3];
            int butZ = 8;
        
        
            positionen[0][0] = 150;
            positionen[0][1] = 250;
            positionen[1][0] = 400;
            positionen[1][1] = 250;
            positionen[2][0] = 650;
            positionen[2][1] = 250;
            positionen[3][0] = 900;
            positionen[3][1] = 250;
            positionen[4][0] = 150;
            positionen[4][1] = 600;
            positionen[5][0] = 400;
            positionen[5][1] = 600;
            positionen[6][0] = 650;
            positionen[6][1] = 600;
            positionen[7][0] = 900;
            positionen[7][1] = 600;
           
            
            
        
        
            images[0][0] = TeD_World.B_BUT_M1;
            images[0][1] = TeD_World.B_BUT_M1_PRESSED;
            images[0][2] = TeD_World.B_BUT_M1_LOCKED;
            images[1][0] = TeD_World.B_BUT_M2;
            images[1][1] = TeD_World.B_BUT_M2_PRESSED;
            images[1][2] = TeD_World.B_BUT_M2_LOCKED;
            images[2][0] = TeD_World.B_BUT_M3;
            images[2][1] = TeD_World.B_BUT_M3_PRESSED;
            images[2][2] = TeD_World.B_BUT_M3_LOCKED;
            images[3][0] = TeD_World.B_BUT_M4;
            images[3][1] = TeD_World.B_BUT_M4_PRESSED;
            images[3][2] = TeD_World.B_BUT_M4_LOCKED;
            images[4][0] = TeD_World.B_BUT_M5;
            images[4][1] = TeD_World.B_BUT_M5_PRESSED;
            images[4][2] = TeD_World.B_BUT_M5_LOCKED;
            images[5][0] = TeD_World.B_BUT_M6;
            images[5][1] = TeD_World.B_BUT_M6_PRESSED;
            images[5][2] = TeD_World.B_BUT_M6_LOCKED;
            images[6][0] = TeD_World.B_BUT_M7;
            images[6][1] = TeD_World.B_BUT_M7_PRESSED;
            images[6][2] = TeD_World.B_BUT_M7_LOCKED;
            images[7][0] = TeD_World.B_BUT_M8;
            images[7][1] = TeD_World.B_BUT_M8_PRESSED;
            images[7][2] = TeD_World.B_BUT_M8_LOCKED;
            
            
            deleteGameplay();
            mapmenue = new Menue( butZ , positionen , images);
            getWorld().addObject( mapmenue ,1,1);
            lockLevel();
            TeD_World.M_MENUE.playLoop();
            getWorld().setBackground(TeD_World.B_MAINMENUE);
            inGameIsRunning = false;
            mapmenueOnline = true;
            
            
            
        }
    }
    /**stoppt Mapmenü*/
    private void stopMapmenue()
    {
        if(mapmenueOnline)
        {
            mapmenue.close();
            getWorld().removeObject( mapmenue );
            mapmenueOnline = false;
        }
    }
    /**Startet das Raster*/
    public  void setRasterOn(boolean b)              
    {
        rasterOn = true;
        printRaster(b);
    }
    /**Beendet das Raster*/
    public  void setRasterOff()             
    {
        rasterOn = false;
        delRaster();
    }
    /**gibt Status des Rasters aus*/
    public boolean getRasterStatus()
    {
        return rasterStatus;
    }
    /**setzt Status des Raster fest*/
    public void setRasterStatus(boolean b)
    {
        rasterStatus = b ;
    }
    /**true falls --> Raster an*/
    public boolean rasterOn()
    {
        return rasterOn;
    }
    
    /**Druckt Raster*/
    private void printRaster(boolean b)          //Erzeugt das Raster aus dem Actor Raster
    {
        for(int i = 0; i < TeD_World.NY ; ++i)
        {
            for(int j = 0; j < TeD_World.NX ; ++j)
            {
                getWorld().addObject( new Raster(b) , TeD_World.cellToPixM( j+1 ) , TeD_World.cellToPixM( i+1 ) );
            }
        }
    }
   /**Löscht Raster*/
    private void delRaster()            //Löscht das Raster
    {
        List l;
        l = getWorld().getObjects( Raster.class );
        for(int i = 0; i < TeD_World.NY ; ++i)
        {
            for(int j = 0; j < TeD_World.NX ; ++j)
            {
                getWorld().removeObjects(l);
            }
        }
    }
    
    private boolean waitEn(long last , int intervall)
    {
        boolean b = false;
        
        if( System.currentTimeMillis() >= (last + intervall) )
        {
            b = true;
        }
        
        return b;
    }
    /**Erzeugt Die Monster Wellen*/
    public void waveMaker(int anzahlMonster, int intervallMonster, String monster)//intervall in millisekunden!!! 1000 millisekunden sind 1 sekunde
    {
        Actor monsterNumber = null;
        int intervallInFrames = (intervallMonster*29)/1000;
        
        if (monster.equals("MonsterOne"))
        {
            monsterNumber = new MonsterOne();
        }
        else if(monster.equals("MonsterTwo"))
        {
            monsterNumber = new MonsterTwo();
        }
        else if(monster.equals("MonsterThree"))
        {
            monsterNumber = new MonsterThree();
        }
        else if(monster.equals("MonsterFour"))
        {
            monsterNumber = new MonsterFour();
        }
        else if(monster.equals("MonsterFive"))
        {
            monsterNumber = new MonsterFive();
        }
        /*else if(monster.equals("MonsterSix"))
        {
            monsterNumber = new MonsterSix();
        }*/
            if (intervallCountdown.getFrames()== intervallInFrames && anzahlMonster > n)
            {
                
                getWorld().addObject(monsterNumber, startX() , startY());
                intervallCountdown.setClock();
                n++;
            }
            else if (getWorld().getObjects(Monsters.class).size() == 0 && anzahlMonster == n)
            {
                n = 0;
                waveNumber++;
                deleteWegelagerer();
                getWorld().addObject(pauseCounter,(int)(((TeD_World)getWorld()).X)+125 ,(int)(((TeD_World)getWorld()).Y)-50);
                pauseCounterTimeOver = false;
                pauseCounter.resetClock();
            }
        
        
    }
    /**Verwaltet die Monster Wellen*/
    public void waveConstructor(int number)
     {
         if(pauseCounter.timeUp()&& !pauseCounterTimeOver)
                {
                    
                    getWorld().removeObject(pauseCounter);
                    getWorld().addObject(intervallCountdown,0,0);
                    intervallCountdown.setClock();
                    pauseCounterTimeOver = true;
                    
                }
         
            
                
                
           
            
            
            
         if (waveNumber < lR.waves())
         {
             
                if(pauseCounter.getSeconds() > 0)
                {
                    return;
                }
                
             
                waveMaker(lR.getAnzahlMonster(waveNumber),lR.getIntervallMonster(waveNumber),lR.getStringMonster(waveNumber));
            }
         
            
            else
            {
                waveNumber = 0;
                getWorld().removeObject(pauseCounter);
                if(baumenueOnline)
                {
                   stopBaumenue(); 
                }
                else
                {
                    stopUpgrademenue();
                }
                startMapmenue();
                
            
            }
     }
     
     public  int startX()
    {
        
        int hilf = 0;
        for(int i = 0; i < TeD_World.NY ; ++i)
        {
            for(int j = 0; j < TeD_World.NX ; ++j)
            {
               hilf = map0.getMap(j,i);
               
               if (hilf == 7)
               {
                   return TeD_World.cellToPixM( j+1 );
               }
               
            }
            
        }
        return 0;
    }
    
    public  int startY()
    {
         
        int hilf = 0;
        for(int i = 0; i < TeD_World.NY ; ++i)
        {
            for(int j = 0; j < TeD_World.NX ; ++j)
            {
               hilf = map0.getMap(j,i);
               
               if (hilf == 7)
               {
                   return TeD_World.cellToPixM( i+1 );
               }
               
            }
            
        }
        return 0;
    }
    /**Setzt FPS fest*/
    public void setFrameRate() 
    {
        frameCounter++;
        long curTime  = System.currentTimeMillis(); //gibt die jetzige Zeit in millisekunden an
        if ( curTime >= lastAdded + 1000)  //if 1 sekunde vergangen ist
            {
               if (frameCounter < currentFPS && frameCounter < currentFPS-1)
            {
                currentGameSpeed +=1;
                Greenfoot.setSpeed(currentGameSpeed);
                
            }
            else if (frameCounter >currentFPS&& frameCounter > currentFPS+1)
            {
                currentGameSpeed -=1;
                Greenfoot.setSpeed(currentGameSpeed );
                
                
            }
            framesPerSecond = frameCounter;
            
            frameCounter = 0;
            lastAdded = curTime;
            }
        
    }
    /**fügt Geld hinzu*/
    public static void addMoney(int monsterMoney)
    {
         money = money + monsterMoney;
    }
        /**entfernt Geld*/
    public static void removeMoney(int towerKosten)
    {
         money = money - towerKosten;
    }
        /**gibt Geld aus*/
    public static int getMoney()
    {
        return money;
    }
    /**Zieht ein Leben ab*/
    public static void removeLife()
    {
         life -= 1;
    }
        /**gibt leben aus*/
    public static int getLife()
    {
        return life;
    }
    /**gibt Score aus*/
    public static int getScore()
    {
        return score;
    }
    /**fügt Score hinzu*/
    public static void addScore(int addscore)
    {
        score += addscore;
    }
    /**überprüft was für ein Level jeder Tower hat --> gibt die höchste Level zahl aus*/
    private int checkLevel()
    {
        int firstLevel = 0;
        boolean levelFirstCheck = true;
        boolean first = false;
        List <Towers>towerAll = getWorld().getObjects(Towers.class);
        
            if(!towerAll.isEmpty()){
                    for(int i=0;i<(towerAll.size());i++)
                        {
                            if (first)
                            {
                                if (firstLevel == towerAll.get(i).getTowerLevel() && levelFirstCheck)
                                {
                                    levelFirstCheck =true;
                                }
                                else 
                                {
                                    levelFirstCheck =false;
                                }
                            
                            }
                            else
                            {
                                first = true;
                            }
                            if(firstLevel < towerAll.get(i).getTowerLevel())
                            {
                                firstLevel =towerAll.get(i).getTowerLevel();
                            }

                        }
                        if(!levelFirstCheck)
                        {
                           return firstLevel; 
                        }
                        else
                        {
                           if (firstLevel<3) return firstLevel+1;
                           if (firstLevel<3) return firstLevel;
                        }
                        
                    }
                    return 1;
                }
                /**zerstört Das laufende Spiel*/
    private void deleteGameplay()
    {
        waveNumber = 0;
        buyTowerOne = false;
        buyTowerTwo = false;
        buyTowerThree = false;
        buyWegelagerer1 = false;
        buyWegelagerer2 = false;
        buyWegelagerer3 = false;
        picOn = false;
        getWorld().removeObjects(getWorld().getObjects(Picture.class));
        getWorld().removeObjects(getWorld().getObjects(Bar.class));
        getWorld().removeObjects(getWorld().getObjects(Wegelagerer.class));
        getWorld().removeObjects(getWorld().getObjects(Munition.class));
        getWorld().removeObjects(getWorld().getObjects(Monsters.class));
        getWorld().removeObjects(getWorld().getObjects(Drawing.class));
        getWorld().removeObjects(getWorld().getObjects(Point.class));
        getWorld().removeObjects(getWorld().getObjects(Raster.class));
        getWorld().removeObjects(getWorld().getObjects(Towers.class));
        TeD_World.M_HINTERGRUND.stop();
        
    }
    /**SPeichert Info des Towers*/
    public static void getTowerInfo(Actor tower, int shotPower, int shotSpeed, int shotIntervall, int distance,int money, int level, int upgradekosten, boolean first)
    {
        firstTouch = first;
        towerActor = tower;
        towerShotPower = shotPower;
        towerShotSpeed = shotSpeed;
        towerShotIntervall = shotIntervall;
        towerDistance = distance;
        towerMoney = money;
        towerLevel = level;
        towerUpgradeKosten = upgradekosten;
        
    }
    /**schliesst oder öffnet Button im Baumenü*/
    public void lockTowerButton(int level,int towermoney,int buttonnummer)
    {
         if(towermoney > money)
            {
                if(!baumenue.getLockedButtonStatus(buttonnummer))
                {
                    baumenue.lockButton(buttonnummer);
                }
                
            }
            else if(level>checkLevel())
            {
                if(!baumenue.getLockedButtonStatus(buttonnummer))
                {
                    baumenue.lockButton(buttonnummer);
                }
            }
            else
            {
                if(baumenue.getLockedButtonStatus(buttonnummer))
                {
                    baumenue.unlockButton(buttonnummer);
                }

            }
    }
    /**schliesst oder öffnet Button im Upgrademenü*/
    public void lockUpgradeButton(int level,int towermoney)
    {
         if(towermoney > money)
            {
                if(!upgrademenue.getLockedButtonStatus(1))
                {
                    upgrademenue.lockButton(1);
                }
                
            }
            else if(level>2)
            {
                if(!upgrademenue.getLockedButtonStatus(1))
                {
                    upgrademenue.lockButton(1);
                }
            }
            else
            {
                if(upgrademenue.getLockedButtonStatus(1))
                {
                    upgrademenue.unlockButton(1);
                }

            }
    }
    /**schliesst oder öffnet Button im Mapmenü*/
    private void lockLevel()
    {
        mapmenue.lockButton(2);
            mapmenue.lockButton(3);
            mapmenue.lockButton(4);
            mapmenue.lockButton(5);
            mapmenue.lockButton(6);
            mapmenue.lockButton(7);
            mapmenue.lockButton(8);
            
            
            if(currentMap == map1)
            {
                mapmenue.unlockButton(2);
            }
            else if(currentMap == map2)
            {
                mapmenue.unlockButton(2);
                mapmenue.unlockButton(3);
            }
            else if(currentMap == map3)
            {
                mapmenue.unlockButton(2);
                mapmenue.unlockButton(3);
                mapmenue.unlockButton(4);
            }
            else if(currentMap == map4)
            {
                mapmenue.unlockButton(2);
                mapmenue.unlockButton(3);
                mapmenue.unlockButton(4);
                mapmenue.unlockButton(5);
            }
            else if(currentMap == map5)
            {
                mapmenue.unlockButton(2);
                mapmenue.unlockButton(3);
                mapmenue.unlockButton(4);
                mapmenue.unlockButton(5);
                mapmenue.unlockButton(6);
            }
            else if(currentMap == map6)
            {
                mapmenue.unlockButton(2);
                mapmenue.unlockButton(3);
                mapmenue.unlockButton(4);
                mapmenue.unlockButton(5);
                mapmenue.unlockButton(6);
                mapmenue.unlockButton(7);
            }
            else if(currentMap == map7 || currentMap == map8)
            {
                mapmenue.unlockButton(2);
                mapmenue.unlockButton(3);
                mapmenue.unlockButton(4);
                mapmenue.unlockButton(5);
                mapmenue.unlockButton(6);
                mapmenue.unlockButton(7);
                mapmenue.unlockButton(8);
            }
    }
    /**entfernt Wegelagerer nach einer Runde*/
    private void deleteWegelagerer()
    {
        
            List <WegelagererOne>WegelagererOne = getWorld().getObjects(WegelagererOne.class);
        
            if(!WegelagererOne.isEmpty()){
                    for(int i=0;i<(WegelagererOne.size());i++)
                        {
                            if( map0.map[TeD_World.pixToCell((WegelagererOne.get(i)).getY())-1][TeD_World.pixToCell((WegelagererOne.get(i)).getX())-1] == 91 )
                                {
                                        map0.map[TeD_World.pixToCell((WegelagererOne.get(i)).getY())-1][TeD_World.pixToCell((WegelagererOne.get(i)).getX())-1] = 1;
                                    }
                            else
                                {
                                        map0.map[TeD_World.pixToCell((WegelagererOne.get(i)).getY())-1][TeD_World.pixToCell((WegelagererOne.get(i)).getX())-1] = 2;
                                    }
                            
                        }
                    }
    
                    List <WegelagererTwo>WegelagererTwo = getWorld().getObjects(WegelagererTwo.class);
        
            if(!WegelagererTwo.isEmpty()){
                    for(int i=0;i<(WegelagererTwo.size());i++)
                        {
                            if( map0.map[TeD_World.pixToCell((WegelagererTwo.get(i)).getY())-1][TeD_World.pixToCell((WegelagererTwo.get(i)).getX())-1] == 93 )
                                {
                                        map0.map[TeD_World.pixToCell((WegelagererTwo.get(i)).getY())-1][TeD_World.pixToCell((WegelagererTwo.get(i)).getX())-1] = 1;
                                    }
                            else
                                {
                                        map0.map[TeD_World.pixToCell((WegelagererTwo.get(i)).getY())-1][TeD_World.pixToCell((WegelagererTwo.get(i)).getX())-1] = 2;
                                    }
                            
                        }
                    }
    
                    List <WegelagererThree>WegelagererThree = getWorld().getObjects(WegelagererThree.class);
        
            if(!WegelagererThree.isEmpty()){
                    for(int i=0;i<(WegelagererThree.size());i++)
                        {
                            if( map0.map[TeD_World.pixToCell((WegelagererThree.get(i)).getY())-1][TeD_World.pixToCell((WegelagererThree.get(i)).getX())-1] == 95 )
                                {
                                        map0.map[TeD_World.pixToCell((WegelagererThree.get(i)).getY())-1][TeD_World.pixToCell((WegelagererThree.get(i)).getX())-1] = 1;
                                    }
                            else
                                {
                                        map0.map[TeD_World.pixToCell((WegelagererThree.get(i)).getY())-1][TeD_World.pixToCell((WegelagererThree.get(i)).getX())-1] = 2;
                                    }
                            
                        }
                    }
    
                    getWorld().removeObjects(getWorld().getObjects(Wegelagerer.class));
         }
    
}
