Пример #1
0
        private void pnlBackground_Paint(object sender, PaintEventArgs e)
        {
            var   p     = sender as Panel;
            var   g     = e.Graphics;
            Pen   pen   = new Pen(Color.Red, 3);
            Brush brush = new SolidBrush(Color.Black);



            foreach (Tile tile in theMap.Tiles)
            {
                Point topLeft, topRight, bottomLeft, bottomRight;
                topLeft     = new Point(tile.Coordinate.X * 50, tile.Coordinate.Y * 50);
                topRight    = new Point((tile.Coordinate.X + 1) * 50, tile.Coordinate.Y * 50);
                bottomLeft  = new Point(tile.Coordinate.X * 50, (tile.Coordinate.Y + 1) * 50);
                bottomRight = new Point((tile.Coordinate.X + 1) * 50, (tile.Coordinate.Y + 1) * 50);

                // add 4 points

                g.FillEllipse(brush, topLeft.X, topLeft.Y, 3, 3);
                g.FillEllipse(brush, topRight.X, topRight.Y, 3, 3);
                g.FillEllipse(brush, bottomLeft.X, bottomLeft.Y, 3, 3);
                g.FillEllipse(brush, bottomRight.X, bottomRight.Y, 3, 3);

                // walls
                if (tile.MyWalls.HasFlag(TheWalls.North))
                {
                    g.DrawLine(pen, topLeft, topRight);
                }
                if (tile.MyWalls.HasFlag(TheWalls.South))
                {
                    g.DrawLine(pen, bottomLeft, bottomRight);
                }
                if (tile.MyWalls.HasFlag(TheWalls.East))
                {
                    g.DrawLine(pen, topRight, bottomRight);
                }
                if (tile.MyWalls.HasFlag(TheWalls.West))
                {
                    g.DrawLine(pen, topLeft, bottomLeft);
                }

                // exit
                if (tile.MyWalls.HasFlag(TheWalls.End))
                {
                    if (pbExit == null)
                    {
                        pbExit      = new PictureBox();
                        pbExit.Name = "pbExit";
                        Point exitPoint = Painter.SetLocation(tile.Coordinate, 50);
                        exitPoint.X = exitPoint.X + 5;
                        exitPoint.Y = exitPoint.Y + 5;


                        pbExit.Location = exitPoint;
                        pbExit.Image    = Image.FromFile(mediaPath + @"\images\exit.gif");
                        pbExit.Size     = new Size(30, 30);
                        pbExit.SizeMode = PictureBoxSizeMode.Zoom;

                        pnlBackground.Controls.Add(pbExit);
                        pbExit.BringToFront();
                    }
                    else
                    {
                        Point exitPoint = Painter.SetLocation(tile.Coordinate, 50);
                        exitPoint.X     = exitPoint.X + 5;
                        exitPoint.Y     = exitPoint.Y + 5;
                        pbExit.Location = exitPoint;
                    }
                }
            }

            g.Dispose();
        }
Пример #2
0
        protected void RenderCharacters()
        {
            pbTheseus       = new PictureBox();
            pbTheseus.Name  = "pbTheseus";
            pbTheseus.Image = Image.FromFile(mediaPath + @"\images\theseus.png");
            pbTheseus.Size  = pbTheseus.Image.Size;
            pnlBackground.Controls.Add(pbTheseus);


            if (builder.GetTheseus() != null)
            {
                pbTheseus.Location = Painter.SetLocation(builder.GetTheseus().Coordinate, 50);
            }
            else
            {
                pbTheseus.Location = new Point(-50, 0);
            }

            pbMinotaur      = new PictureBox();
            pbMinotaur.Name = "pbMinotaur";

            pbMinotaur.Image = Image.FromFile(mediaPath + @"\images\minotaur.png");
            pbMinotaur.Size  = pbMinotaur.Image.Size;
            pnlBackground.Controls.Add(pbMinotaur);


            if (builder.GetMinotaur() != null)
            {
                pbMinotaur.Location = Painter.SetLocation(builder.GetMinotaur().Coordinate, 50);
            }
            else
            {
                pbMinotaur.Location = new Point(-50, 25);
            }

            pbExit          = new PictureBox();
            pbExit.Name     = "pbExit";
            pbExit.Image    = Image.FromFile(mediaPath + @"\images\exit.gif");
            pbExit.Size     = new Size(30, 30);
            pbExit.SizeMode = PictureBoxSizeMode.Zoom;
            pnlBackground.Controls.Add(pbExit);


            if (builder.GetExit() != null)
            {
                Point exitPoint = Painter.SetLocation(builder.GetExit().Coordinate, 50);
                exitPoint.X     = exitPoint.X + 3;
                exitPoint.Y     = exitPoint.Y + 3;
                pbExit.Location = exitPoint;
            }
            else
            {
                pbExit.Location = new Point(-50, 50);
            }

            pbSelectedTile           = new PictureBox();
            pbSelectedTile.Name      = "pbSelectedTile";
            pbSelectedTile.Location  = new Point(-50, 75);
            pbSelectedTile.Size      = new Size(45, 45);
            pbSelectedTile.BackColor = Color.Honeydew;
            pnlBackground.Controls.Add(pbSelectedTile);
            pbSelectedTile.BringToFront();

            pbTheseus.BringToFront();
            pbExit.BringToFront();
            pbMinotaur.BringToFront();
        }