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

/**
 * liest Map aus
 * 
 * @author Felix Pfeffer 
 * @version 1.0
 */
public class Map extends Actor
{
    public int map[][] = new int[(int)TeD_World.NY][(int)TeD_World.NX];
    
   
    ///////////////////////////////////////////
    // 00 = normaler Rasen                   //
    // 01 = normaler Weg (sekrecht)          //
    // 02 = normaler Weg (waagrecht)         //
    // 03 = rechts Kurve/Richtung unten      //
    // 04 = rechts Kurve/Richtung oben       //
    // 05 = links  Kurve/Richtung unten      //
    // 06 = links  Kurve/Richtung oben       //
    // 07 = Monster Start                    //
    // 08 = Monster Ziel                     //
    // 09 = Seeeck oben links                //
    // 10 = Seekante mitte oben              //
    // 11 = Seeeck oben rechts               //
    // 12 = Seekante mitte links             //
    // 13 = Seemitte                         //
    // 14 = Seekante mitte rechts            //
    // 15 = Seeeck unten links               //
    // 16 = Seekante mitte unten             //
    // 17 = Seeeck unten rechts              //
    // 18 = Turm Mittelalter                 //
    // 19 =                                  //
    // 20 =                                  //
    
    
    
    
    public Map(int n)
    {
           readMap(n);
    }
    
    public GreenfootImage printMap()
    {
        
        GreenfootImage back = new GreenfootImage( (int)(TeD_World.NX*TeD_World.PIX) , (int)(TeD_World.NY*TeD_World.PIX) );
        
        int hilf = 0;
        
        for(int i = 0; i < TeD_World.NY ; ++i)
        {
            for(int j = 0; j < TeD_World.NX ; ++j)
            {
                hilf = map[i][j];
                
                if( hilf == 0)
                {
                    back.drawImage( TeD_World.B_RASEN ,  TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 1 )
                {
                    back.drawImage( TeD_World.B_WEG_S  , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 2 )
                {
                    back.drawImage( TeD_World.B_WEG_W  , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 3 )
                {
                    back.drawImage( TeD_World.B_KU_R_U , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 4 )
                {
                    back.drawImage( TeD_World.B_KU_R_O , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 5 )
                {
                    back.drawImage( TeD_World.B_KU_L_U , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 6 )
                {
                    back.drawImage( TeD_World.B_KU_L_O , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 7 )
                {
                    back.drawImage( TeD_World.B_START ,    TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 8 )
                {
                    back.drawImage( TeD_World.B_ZIEL  ,    TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 )); 
                }
                else if( hilf == 9 )
                {
                    back.drawImage( TeD_World.B_WASSER_LO , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 10 )
                {
                    back.drawImage( TeD_World.B_WASSER_MO , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 11 )
                {
                    back.drawImage( TeD_World.B_WASSER_RO , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 12 )
                {
                    back.drawImage( TeD_World.B_WASSER_LM , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 13 )
                {
                    back.drawImage( TeD_World.B_WASSER_MM , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 14 )
                {
                    back.drawImage( TeD_World.B_WASSER_RM , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 15 )
                {
                    back.drawImage( TeD_World.B_WASSER_LU , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 16 )
                {
                    back.drawImage( TeD_World.B_WASSER_MU , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 17 )
                {
                    back.drawImage( TeD_World.B_WASSER_RU , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 18 )
                {
                    back.drawImage( TeD_World.B_TOWERBODEN_Z1 , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i ));
                }
                else if( hilf == 19 )
                {
                    back.drawImage( TeD_World.B_TOWERBODEN_Z1 , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i ));
                }
                else if( hilf == 20 )
                {
                    back.drawImage( TeD_World.B_TOWERBODEN_Z1 , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i ));
                }
                else if( hilf == 40 )
                {
                    back.drawImage( TeD_World.B_TOWERBODEN_Z2 , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i ));
                }
                else if( hilf == 41 )
                {
                    back.drawImage( TeD_World.B_TOWERBODEN_Z2 , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i ));
                }
                else if( hilf == 42 )
                {
                    back.drawImage( TeD_World.B_TOWERBODEN_Z2 , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i ));
                }
                else if( hilf == 50 )
                {
                    back.drawImage( TeD_World.B_TOWERBODEN_Z2 , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i ));
                }
                else if( hilf == 51 )
                {
                    back.drawImage( TeD_World.B_TOWERBODEN_Z2 , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i ));
                }
                else if( hilf == 52 )
                {
                    back.drawImage( TeD_World.B_TOWERBODEN_Z2 , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i ));
                }
                else if( hilf == 91 )
                {
                    back.drawImage( TeD_World.B_WEG_S , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 92 )
                {
                    back.drawImage( TeD_World.B_WEG_W , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 93 )
                {
                    back.drawImage( TeD_World.B_WEG_S , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 94 )
                {
                    back.drawImage( TeD_World.B_WEG_W , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 95 )
                {
                    back.drawImage( TeD_World.B_WEG_S , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                else if( hilf == 96 )
                {
                    back.drawImage( TeD_World.B_WEG_W , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
               
                else
                {
                    back.drawImage( TeD_World.NOIMAGE , TeD_World.cellToPixD( j+1 ) , TeD_World.cellToPixD( i+1 ));
                }
                
            }
            
        }
        
        return back;
    }
     /**
     * liest Map aus
     */
    private void readMap( int n )
    {
        
        String mapName = new String("maps/map"+n+".txt");
        Reader r = new Reader(mapName);
         
        for(int i = 0; i < TeD_World.NY ; ++i)
        {
            for(int j = 0; j < TeD_World.NX ; ++j)
            {
               map[i][j] = r.readInt();
            }
        }
        
        /*for(int i = 0; i < TeD_World.NY ; ++i)
        {
            for(int j = 0; j < TeD_World.NX ; ++j)
            {
               System.out.print(map[i][j]+" ");
            }
             System.out.println(" ");
        }*/
        
        
        r.close();
    }
    
     /**
     * gibt Map aus
     */
    public int getMap( int X , int Y )
    {
        return map[Y][X];
    }
}
