Beispiel #1
0
        private void ToImgWithoutInset(Graphics g, CartesianCell cell, DrawMode mode, int cellSize, int x, int y)
        {
            CELLSIZE = cellSize;
            var    x1 = x;
            var    y1 = y;
            var    x2 = x1 + cellSize;
            var    y2 = y1 + cellSize;
            Random v  = new Random(555 * cellSize);
            int    vN = v.Next();

            if (cell.Neighbors.Count == 0)
            {
                return;
            }
            if (mode == DrawMode.Background)
            {
                var color = BackgroundColorFor(cell);
                if (color != null)
                {
                    if (hasPlayer(x1, y1) == true)
                    {
                        var brush = new SolidBrush(Color.Green);
                        g.FillRectangle(brush, x1, y1, cellSize, cellSize);
                    }
                    else
                    {
                        if (cell.containsBonus(y1 * vN * x) == true && hasPlayer(x1, y1) == false)
                        {
                            var brush = new SolidBrush(Color.Red);
                            g.FillRectangle(brush, x1, y1, cellSize, cellSize);
                        }
                        else
                        {
                            g.FillRectangle(new SolidBrush(color.GetValueOrDefault()), x1, y1, cellSize, cellSize);
                        }
                    }
                }
            }
            else if (mode == DrawMode.Walls)
            {
                if (cell.North == null)
                {
                    g.DrawLine(Pens.Black, x1, y1, x2, y1);
                }
                if (cell.West == null)
                {
                    g.DrawLine(Pens.Black, x1, y1, x1, y2);
                }

                if (!cell.IsLinked(cell.East))
                {
                    g.DrawLine(Pens.Black, x2, y1, x2, y2);
                }
                if (!cell.IsLinked(cell.South))
                {
                    g.DrawLine(Pens.Black, x1, y2, x2, y2);
                }

                if (cell == ActiveCell)
                {
                    g.FillRectangle(Brushes.GreenYellow, x1 + 2, y1 + 2, cellSize - 4, cellSize - 4);
                }
            }
            else if (mode == DrawMode.Path)
            {
                DrawPath(cell, g, cellSize);
            }
        }
Beispiel #2
0
        protected virtual void ToImgWithInset(Graphics g, CartesianCell cell, DrawMode mode, int cellSize, int x, int y, int inset)
        {
            var(x1, x2, x3, x4, y1, y2, y3, y4) = CellCoordinatesWithInset(x, y, cellSize, inset);

            if (mode == DrawMode.Background)
            {
                var color = BackgroundColorFor(cell);

                if (color != null)
                {
                    // fill center
                    var brush = new SolidBrush(Color.AliceBlue);
                    g.FillRectangle(brush, x2, y2, cellSize - inset * 2, cellSize - inset * 2);
                    Console.WriteLine("REached");
                    if (cell.IsLinked(cell.North))
                    {
                        brush = new SolidBrush(Color.Red);
                        g.FillRectangle(brush, x2, y2, cellSize - inset * 2, cellSize - inset * 2);
                    }
                    if (cell.IsLinked(cell.South))
                    {
                        g.FillRectangle(brush, x2, y3, cellSize - 2 * inset, inset);
                        if (cell.containsBonus(y3) == true)
                        {
                            brush = new SolidBrush(Color.Red);
                            g.FillRectangle(brush, x2, y3, cellSize - 2 * inset, inset);
                        }
                    }
                    if (cell.IsLinked(cell.West))
                    {
                        g.FillRectangle(brush, x1, y2, inset, cellSize - 2 * inset);
                        if (cell.containsBonus(x1) == true)
                        {
                            Icon  bonus = Icon.ExtractAssociatedIcon("../../bonus.ico");
                            Point p     = new Point(x1, y2);
                            g.DrawIcon(icon: bonus, x1, y2);
                        }
                    }
                    if (cell.IsLinked(cell.East))
                    {
                        g.FillRectangle(brush, x3, y2, inset, cellSize - 2 * inset);
                        if (cell.containsBonus(x3) == true)
                        {
                            Icon  bonus = Icon.ExtractAssociatedIcon("../../bonus.ico");
                            Point p     = new Point(x3, y2);
                            g.DrawIcon(icon: bonus, x3, y2);
                        }
                    }
                }
            }
            else if (mode == DrawMode.Walls)
            {
                if (cell.IsLinked(cell.North))
                {
                    g.DrawLine(Pens.Black, x2, y1, x2, y2);
                    g.DrawLine(Pens.Black, x3, y1, x3, y2);
                }
                else
                {
                    g.DrawLine(Pens.Black, x2, y2, x3, y2);
                }
                if (cell.IsLinked(cell.South))
                {
                    g.DrawLine(Pens.Black, x2, y3, x2, y4);
                    g.DrawLine(Pens.Black, x3, y3, x3, y4);
                }
                else
                {
                    g.DrawLine(Pens.Black, x2, y3, x3, y3);
                }

                if (cell.IsLinked(cell.West))
                {
                    g.DrawLine(Pens.Black, x1, y2, x2, y2);
                    g.DrawLine(Pens.Black, x1, y3, x2, y3);
                }
                else
                {
                    g.DrawLine(Pens.Black, x2, y2, x2, y3);
                }
                if (cell.IsLinked(cell.East))
                {
                    g.DrawLine(Pens.Black, x3, y2, x4, y2);
                    g.DrawLine(Pens.Black, x3, y3, x4, y3);
                }
                else
                {
                    g.DrawLine(Pens.Black, x3, y2, x3, y3);
                }

                if (cell == ActiveCell)
                {
                    g.FillRectangle(Brushes.GreenYellow, x2 + 1, y2 + 1, cellSize - inset * 2 - 2, cellSize - inset * 2 - 2);
                }
            }
            else if (mode == DrawMode.Path)
            {
                DrawPath(cell, g, cellSize);
            }
        }