private AllBorders DrawTileIcon(Tile tile, Graphics g, Rectangle r)
        {
            Contract.Requires(tile != null);
            Contract.Requires(g != null);
            Contract.Requires(r != null);

            AllBorders borderInfo = new AllBorders();
            borderInfo.noAdjacent = CompareTileBorders(tile);
            borderInfo.top = borderInfo.noAdjacent;
            borderInfo.left = borderInfo.noAdjacent;
            borderInfo.right = borderInfo.noAdjacent;
            borderInfo.bottom = borderInfo.noAdjacent;
            borderInfo.r = r;

            int tx = tile.X;
            int ty = tile.Y;
            foreach (Tile t in tile.AdjacentTiles)
            {
                if (t == null) { continue; }
                BorderDesc border = CompareTileBorders(tile, t);
                if (tx == t.X)
                {
                    if (t.Y == ty - 1)
                    { borderInfo.top = border; }
                    else if (t.Y == ty + 1)
                    { borderInfo.bottom = border; }
                }
                else if (ty == t.Y)
                {
                    if (t.X == tx - 1)
                    { borderInfo.left = border; }
                    else if (t.X == tx + 1)
                    { borderInfo.right = border; }
                }
            }
            if (!WallEditMode)
            {
                if (tile.HasSecret)
                {
                    if (tile.IsRevealed && _secretRevealedIcon != null)
                    {
                        g.DrawImage(_secretRevealedIcon, r);
                    }
                    else if (!tile.IsRevealed && _secretHiddenIcon != null)
                    {
                        g.DrawImage(_secretHiddenIcon, r);
                    }
                }
                if (tile.IsPlayerPresent)
                {
                    int first = Math.Max(1, MapInfo.PlayersAtPosition(tile).FirstOrDefault());
                    first = Math.Min(LineOfSightIcons.Count, first);
                    first -= 1;
                    g.DrawImage(LineOfSightIcons[first], r);
                }
                if (tile.LightSource > 0)
                {
                    int lastLevel = _lightLevels.FirstOrDefault();
                    foreach (int level in _lightLevels)
                    {
                        if (level <= tile.LightSource)
                        {
                            lastLevel = level;
                        }
                    }
                    Image icon;
                    if (_lightIcons.TryGetValue(lastLevel, out icon))
                    {
                        g.DrawImage(icon, r);
                    }
                }

                int alpha = (int)((double)(10 - tile.LightLevel) / 10 * 255 * .5);
                alpha = Math.Min(255, Math.Max(0, alpha));
                using (Brush lightBrush = new SolidBrush(Color.FromArgb(alpha, Color.Black)))
                {
                    g.FillRectangle(lightBrush, r);
                }
            }
            return borderInfo;
        }
 private void DrawBorders(AllBorders borderInfo, Graphics g)
 {
     Rectangle r = borderInfo.r;
     if (borderInfo.top != null)
     { DrawBorder(borderInfo.top, g, r.Left, r.Top, r.Right, r.Top, 0, -1); }
     if (borderInfo.bottom != null)
     { DrawBorder(borderInfo.bottom, g, r.Left, r.Bottom, r.Right, r.Bottom, 0, +1); }
     if (borderInfo.left != null)
     { DrawBorder(borderInfo.left, g, r.Left, r.Top, r.Left, r.Bottom, 1, 0); }
     if (borderInfo.right != null)
     { DrawBorder(borderInfo.right, g, r.Right, r.Top, r.Right, r.Bottom, -1, 0); }
 }