Beispiel #1
0
        private void DrawTankHealth(object o, PaintEventArgs e)
        {
            Tank tank = o as Tank;

            using (SolidBrush greenBrush = new SolidBrush(Color.SpringGreen))
                using (SolidBrush yellowBrush = new SolidBrush(Color.Yellow))
                    using (SolidBrush redBrush = new SolidBrush(Color.Red)) {
                        SolidBrush drawBrush    = null;
                        Rectangle  healthBounds = new Rectangle(0, 0, 0, 0);
                        if (tank.IsHighHealth())
                        {
                            drawBrush    = greenBrush;
                            healthBounds = new Rectangle(-25, 60, 60, 10);
                        }
                        else if (tank.IsMediumHealth())
                        {
                            drawBrush    = yellowBrush;
                            healthBounds = new Rectangle(-25, 60, 40, 10);
                        }
                        else if (tank.IsLowHealth())
                        {
                            drawBrush    = redBrush;
                            healthBounds = new Rectangle(-25, 60, 20, 10);
                        }
                        if (drawBrush != null)
                        {
                            e.Graphics.FillRectangle(drawBrush, healthBounds);
                        }
                    }
        }