コード例 #1
0
        private void TerrainPaint(object sender, PaintEventArgs e)
        {
            var pen        = new Pen(Color.Wheat);
            var waterColor = new SolidBrush(Color.Aqua);
            var rockColor  = new SolidBrush(Color.Chocolate);
            var cellWidth  = terrain.Width / _n;
            var cellHeight = terrain.Height / _m;

            for (var i = 0; i < _n; i++)
            {
                e.Graphics.DrawLine(pen, new Point(i * cellWidth, 0), new Point(i * cellWidth, i * cellWidth + terrain.Height));
            }

            for (var i = 0; i < _m; i++)
            {
                e.Graphics.DrawLine(pen, new Point(0, i * cellHeight), new Point(i * cellHeight + terrain.Width, i * cellHeight));
            }

            if (_marsRover.ExistsPlan())
            {
                foreach (var cell in _marsRover.CurrentPlan.Path)
                {
                    e.Graphics.FillRectangle(new SolidBrush(Color.Yellow), cell.Item2 * cellWidth, cell.Item1 * cellHeight,
                                             cellWidth, cellHeight);
                }
            }

            for (var i = 0; i < _n; i++)
            {
                for (var j = 0; j < _m; j++)
                {
                    if (_mars.TerrainAt(i, j) > _marsRover.RunningOverThreshold)
                    {
                        e.Graphics.DrawImage(new Bitmap("obstacle-transparency.png"), j * cellWidth, i * cellHeight,
                                             cellWidth, cellHeight);
                    }
                    if (_mars.WaterAt(i, j))
                    {
                        e.Graphics.DrawImage(new Bitmap("water-transparency.png"), j * cellWidth, i * cellHeight, cellWidth, cellHeight);
                    }

                    // Draw every belief in white
                    foreach (var belief in _marsRover.Beliefs)
                    {
                        var pred = belief.Predicate as List <Tuple <int, int> >;
                        if (pred != null && !pred.Contains(new Tuple <int, int>(i, j)))
                        {
                            continue;
                        }

                        if (belief.Name == TypesBelief.ObstaclesOnTerrain)
                        {
                            e.Graphics.DrawImage(new Bitmap("obstacle-transparency.png"), j * cellWidth, i * cellHeight,
                                                 cellWidth, cellHeight);
                            e.Graphics.DrawRectangle(new Pen(Color.Gold, 6), j * cellWidth, i * cellHeight,
                                                     cellWidth, cellHeight);
                        }
                        if (belief.Name == TypesBelief.PotentialWaterSpots)
                        {
                            e.Graphics.DrawImage(new Bitmap("water-transparency.png"), j * cellWidth, i * cellHeight,
                                                 cellWidth, cellHeight);
                            e.Graphics.DrawRectangle(new Pen(Color.Gold, 6), j * cellWidth, i * cellHeight,
                                                     cellWidth, cellHeight);
                        }
                    }
                }
            }

            e.Graphics.DrawImage(new Bitmap("rover-transparency.png"), _marsRover.Y * cellWidth, _marsRover.X * cellHeight, cellWidth, cellHeight);

            var sightColor = Color.FromArgb(80, Color.Lavender);

            _marsRover.GetCurrentTerrain();

            foreach (var cell in _marsRover.CurrentTerrain)
            {
                e.Graphics.FillRectangle(new SolidBrush(sightColor), cell.Item2 * cellWidth, cell.Item1 * cellHeight, cellWidth, cellHeight);
            }
        }