import java.awt.Graphics;
import java.awt.Image;

public class Map
{

    int cy1;
    int cy2;
    int cx1;
    int cx2;
    int currentmap[][];
    int changedmap[][];
    Image tiles[];
    Graphics where;
    WW_Infinite game;

    public void loadmap(String s)
    {
        int i1 = 0;
        int ai[][] = new int[45][20];
        int k = 0;
        do
        {
            int i = 0;
            do
            {
                ai[k][i] = 14;
            } while(++i < 20);
        } while(++k < 45);
        for(int l = 0; l < s.length() / 20; l++)
        {
            int j = 0;
            do
            {
                byte byte0 = 14;
                switch(s.charAt(i1))
                {
                case 97: // 'a'
                    byte0 = 0;
                    break;

                case 98: // 'b'
                    byte0 = 1;
                    break;

                case 99: // 'c'
                    byte0 = 2;
                    break;

                case 100: // 'd'
                    byte0 = 3;
                    break;

                case 101: // 'e'
                    byte0 = 4;
                    break;

                case 102: // 'f'
                    byte0 = 5;
                    break;

                case 103: // 'g'
                    byte0 = 6;
                    break;

                case 104: // 'h'
                    byte0 = 7;
                    break;

                case 105: // 'i'
                    byte0 = 8;
                    break;

                case 106: // 'j'
                    byte0 = 9;
                    break;

                case 107: // 'k'
                    byte0 = 10;
                    break;

                case 108: // 'l'
                    byte0 = 11;
                    break;

                case 109: // 'm'
                    byte0 = 12;
                    break;

                case 110: // 'n'
                    byte0 = 13;
                    break;

                case 111: // 'o'
                    byte0 = 14;
                    break;

                case 112: // 'p'
                    byte0 = 15;
                    break;

                case 113: // 'q'
                    byte0 = 16;
                    break;

                case 114: // 'r'
                    byte0 = 17;
                    break;

                case 115: // 's'
                    byte0 = 18;
                    break;

                case 116: // 't'
                    byte0 = 19;
                    break;

                case 117: // 'u'
                    byte0 = 20;
                    break;

                case 118: // 'v'
                    byte0 = 21;
                    break;

                case 65: // 'A'
                    byte0 = 40;
                    break;

                case 66: // 'B'
                    byte0 = 41;
                    break;

                case 67: // 'C'
                    byte0 = 42;
                    break;

                case 68: // 'D'
                    byte0 = 43;
                    break;

                case 69: // 'E'
                    byte0 = 44;
                    break;

                case 70: // 'F'
                    byte0 = 45;
                    break;

                case 71: // 'G'
                    byte0 = 46;
                    break;

                case 72: // 'H'
                    byte0 = 47;
                    break;

                case 73: // 'I'
                    byte0 = 48;
                    break;

                case 74: // 'J'
                    byte0 = 49;
                    break;

                case 75: // 'K'
                    byte0 = 50;
                    break;

                case 76: // 'L'
                    byte0 = 51;
                    break;

                case 77: // 'M'
                    byte0 = 52;
                    break;

                case 78: // 'N'
                    byte0 = 53;
                    break;

                case 79: // 'O'
                    byte0 = 54;
                    break;

                case 80: // 'P'
                    byte0 = 55;
                    break;

                case 81: // 'Q'
                    byte0 = 56;
                    break;

                case 82: // 'R'
                    byte0 = 57;
                    break;

                case 83: // 'S'
                    byte0 = 58;
                    break;

                case 84: // 'T'
                    byte0 = 59;
                    break;

                case 85: // 'U'
                    byte0 = 30;
                    break;

                case 86: // 'V'
                    byte0 = 31;
                    break;

                case 87: // 'W'
                    byte0 = 32;
                    break;

                case 88: // 'X'
                    byte0 = 33;
                    break;

                case 89: // 'Y'
                    byte0 = 34;
                    break;

                case 48: // '0'
                    byte0 = 39;
                    break;

                case 49: // '1'
                    byte0 = 32;
                    break;

                case 50: // '2'
                    byte0 = 38;
                    break;

                case 51: // '3'
                    byte0 = 33;
                    break;
                }
                ai[l][j] = byte0;
                i1++;
            } while(++j < 20);
        }

        currentmap = ai;
        displayMap();
    }

    public void displayMap()
    {
        int i = 0;
        do
        {
            int j = 0;
            do
            {
                changedmap[i][j] = 0;
                where.drawImage(tiles[currentmap[i][j]], j * 24, i * 24, game);
            } while(++j < 20);
        } while(++i < 45);
    }

    public Map(WW_Infinite wickywoo, Image aimage[], Graphics g)
    {
        currentmap = null;
        changedmap = new int[45][20];
        tiles = null;
        game = wickywoo;
        tiles = aimage;
        where = g;
    }

    public int checkCollision(int i, int j, int k, int l)
    {
        cy1 = j / 24;
        cy2 = ((j + l) - 1) / 24;
        cx1 = i / 24;
        cx2 = ((i + k) - 1) / 24;
        if(currentmap[cy1][cx1] < 30)
        {
            return 100;
        }
        if(currentmap[cy2][cx2] < 30)
        {
            return 100;
        }
        if(currentmap[cy1][cx2] < 30)
        {
            return 100;
        }
        if(currentmap[cy2][cx1] < 30)
        {
            return 100;
        }
        if(currentmap[cy1][cx1] == 30)
        {
            return 300;
        }
        if(currentmap[cy2][cx2] == 30)
        {
            return 300;
        }
        if(currentmap[cy1][cx2] == 30)
        {
            return 300;
        }
        if(currentmap[cy2][cx1] == 30)
        {
            return 300;
        }
        if(currentmap[cy1][cx1] == 33)
        {
            return 310;
        }
        if(currentmap[cy2][cx2] == 33)
        {
            return 310;
        }
        if(currentmap[cy1][cx2] == 33)
        {
            return 310;
        }
        if(currentmap[cy2][cx1] == 33)
        {
            return 310;
        }
        if(currentmap[cy1][cx1] == 31 || currentmap[cy1][cx1] == 32)
        {
            return 400;
        }
        if(currentmap[cy2][cx2] == 31 || currentmap[cy2][cx2] == 32)
        {
            return 400;
        }
        if(currentmap[cy1][cx2] == 31 || currentmap[cy1][cx2] == 32)
        {
            return 400;
        }
        return currentmap[cy2][cx1] != 31 && currentmap[cy2][cx1] != 32 ? 0 : 400;
    }

    public void setMap(int ai[][])
    {
        currentmap = ai;
    }

    public void placetile(int i, int j, int k)
    {
        where.drawImage(tiles[i], j * 24, k * 24, game);
        currentmap[k][j] = i;
    }
}
