Example #1
0
        public void Render(IAquariumObject obj, IDrawingControl control, Graphics graphics)
        {
            int x = obj.X - obj.SizeX / 2;
            int y = control.InvertY(obj.Y + obj.SizeY / 2);
            int sizeX = obj.SizeX;
            int sizeY = obj.SizeY;

            Image image = GetImage(obj);
            Rectangle rectangle = new Rectangle(x, y, sizeX, sizeY);
            graphics.DrawImage(image, rectangle);
        }
        /// <summary>
        /// Обернуть объект в декораторы
        /// </summary>
        public IAquariumObject Wrap(IAquariumObject obj)
        {
            IAquariumObject result = obj;

            IAquariumMovableObjectEditable movableObjEditable = obj as IAquariumMovableObjectEditable;
            if (movableObjEditable != null)
            {
                result = new AquariumHealthDecorator(movableObjEditable, _healthRenderer, _aquariumPopulationController);
            }

            return result;
        }
Example #3
0
        private Image GetImage(IAquariumObject obj)
        {
            Image image = _image;

            // Переделать. Работает медленно
            IAquariumMovableObject movableObj = obj as IAquariumMovableObject;
            if (movableObj != null)
            {
                if (movableObj.MovementDirection == Direction.Left)
                {
                    image = MirroredImage;
                }
            }

            return image;
        }
Example #4
0
        /// <summary>
        /// Нарисовать здоровье рыбки
        /// </summary>
        public void Render(IAquariumObject obj, IDrawingControl control, Graphics graphics)
        {
            AquariumHealthDecorator healthObj = obj as AquariumHealthDecorator;
            if (healthObj != null)
            {
                int x = obj.X - obj.SizeX / 2;
                int y = control.InvertY(obj.Y + obj.SizeY / 2);

                string health = healthObj.Health.ToString();
                Font font = SystemFonts.MenuFont;

                SizeF sizeHealth = graphics.MeasureString(health, font);
                float sizeX = sizeHealth.Width;
                float sizeY = sizeHealth.Height;

                RectangleF rectangle = new RectangleF(x, y, sizeX, sizeY);

                using (SolidBrush brush = new SolidBrush(Color.Green))
                {
                    graphics.DrawString(health, SystemFonts.MenuFont, brush, rectangle);
                }
            }
        }
Example #5
0
 /// <summary>
 /// Убрать объект
 /// </summary>
 /// <param name="obj">Объект, который надо убрать</param>
 public void Remove(IAquariumObject obj)
 {
     lock (_syncObj)
     {
         _objectsToRemove.Add(obj);
     }
 }