PIbd-21_Valitov_D.F_Sailboa.../Sailboat/DrawingObjectBoat.cs
2023-04-22 01:09:06 +04:00

93 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat
{
class DrawingObjectBoat : IDrawingObject
{
private DrawingBoat _boat;
public DrawingObjectBoat(DrawingBoat boat)
{
_boat = boat;
}
public float Step => _boat?.Boat?.Step ?? 0;
public void DrawingObject(Graphics g)
{
_boat.DrawTransport(g);
}
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return _boat?.GetCurrentPosition() ?? default;
}
void IDrawingObject.MoveObject(Direction direction)
{
_boat?.MoveTransport(direction);
}
public void SetObject(int x, int y, int width, int height)
{
_boat.SetPosition(x, y, width, height);
}
public string GetInfo() => _boat?.GetDataForSave();
public DrawingBoat GetBoat => _boat;
public static IDrawingObject Create(string data) => new DrawingObjectBoat(data.CreateDrawningBoat());
public bool Equals(IDrawingObject? other)
{
if (other == null)
{
return false;
}
var otherBoat = other as DrawingObjectBoat;
if (otherBoat == null)
{
return false;
}
var boat = _boat.Boat;
var otherBoatBoat = otherBoat._boat.Boat;
if (boat.GetType().Name != otherBoatBoat.GetType().Name)
{
return false;
}
if (boat.Speed != otherBoatBoat.Speed)
{
return false;
}
if (boat.Weight != otherBoatBoat.Weight)
{
return false;
}
if (boat.BodyColor != otherBoatBoat.BodyColor)
{
return false;
}
if (boat is Sailboat sailboat && otherBoatBoat is Sailboat otherSailboat)
{
if (sailboat.EdgeColor != otherSailboat.EdgeColor)
{
return false;
}
if (sailboat.Sail != otherSailboat.Sail)
{
return false;
}
if (sailboat.ExtendedBody != otherSailboat.ExtendedBody)
{
return false;
}
}
return true;
}
}
}