PIbd-21_Valitov_D.F_Sailboa.../Sailboat/DrawingObjectBoat.cs

93 lines
2.5 KiB
C#
Raw Normal View History

2023-03-18 02:49:20 +04:00
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()
{
2023-04-13 16:43:46 +04:00
return _boat?.GetCurrentPosition() ?? default;
2023-03-18 02:49:20 +04:00
}
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);
}
2023-04-21 23:04:27 +04:00
public string GetInfo() => _boat?.GetDataForSave();
2023-04-22 01:09:06 +04:00
public DrawingBoat GetBoat => _boat;
2023-04-21 23:04:27 +04:00
public static IDrawingObject Create(string data) => new DrawingObjectBoat(data.CreateDrawningBoat());
2023-04-22 01:09:06 +04:00
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;
}
2023-03-18 02:49:20 +04:00
}
}