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; }
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; }
/// <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); } } }
/// <summary> /// Убрать объект /// </summary> /// <param name="obj">Объект, который надо убрать</param> public void Remove(IAquariumObject obj) { lock (_syncObj) { _objectsToRemove.Add(obj); } }