Ejemplo n.º 1
0
 private void DrawMap(Graphics g, Map map)
 {
     int i, j;
     for (i = 0; i < map.Size.Width; i++)
     {
         for (j = 0; j < map.Size.Height; j++)
         {
             m_tileRend.RenderTile(g, map, i, j);
         }
     }
 }
Ejemplo n.º 2
0
        // Methods
        public void RenderTile(Graphics g, Map m, int i, int j)
        {
            int x, y;
            int wall = 16;

            x = i * m_blockSize;
            y = m_headerSize + j * m_blockSize;
            switch (m[i, j])
            {
                case TileType.Pill:
                    DrawPill(g, x, y);
                    break;
                case TileType.PowerPill:
                    DrawPowerPill(g, x, y);
                    break;
                case TileType.Wall:
                    if (LikeWall(m[i - 1, j - 1]))
                        wall |= 1;
                    if (LikeWall(m[i, j - 1]))
                        wall |= 2;
                    if (LikeWall(m[i + 1, j - 1]))
                        wall |= 4;
                    if (LikeWall(m[i - 1, j]))
                        wall |= 8;
                    if (LikeWall(m[i + 1, j]))
                        wall |= 32;
                    if (LikeWall(m[i - 1, j+1]))
                        wall |= 64;
                    if (LikeWall(m[i, j+1]))
                        wall |= 128;
                    if (LikeWall(m[i + 1, j+1]))
                        wall |= 256;
                    DrawWall(g, wall, x, y);
                    break;
                case TileType.BadguyDoor:
                    if (LikeWall(m[i - 1, j]))
                        DrawHorizontalDoor(g, x, y);
                    else
                        DrawVerticalDoor(g, x, y);
                    break;
            }
        }
Ejemplo n.º 3
0
        public static Map Load(String filename)
        {
            StreamReader sr;
            Map rv;
            int width, height, i, j;
            String line;
            char[] chars;
            List<String> lines = new List<String>();

            // Load the file into a lines vector
            sr = File.OpenText(filename);
            while (!sr.EndOfStream)
            {
                line = sr.ReadLine();
                if (line.Length > 0)
                {
                    lines.Add(line);
                }
            }

            // Initialize the map given the size we know
            Debug.Assert(lines.Count > 0, "Map file with length 0 found");
            width = lines[0].Length;
            height = lines.Count;
            rv = new Map(new Size(width, height));

            // Use the line vector to build the map
            for (i = 0; i < height; i++)
            {
                chars = lines[i].ToCharArray();
                for (j = 0; j < width; j++)
                {
                    rv[j, i] = TileFromChar(chars[j]);
                }
            }
            return rv;
        }