ISEbd-21 Nikolay Gapon LabWork08 #13
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Airbus
|
||||
{
|
||||
internal abstract class AbstractMap
|
||||
internal abstract class AbstractMap : IEquatable<AbstractMap>
|
||||
{
|
||||
private IDrawningObject _drawningObject = null;
|
||||
|
||||
@ -118,5 +118,32 @@ namespace Airbus
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
|
||||
public bool Equals(AbstractMap? other)
|
||||
{
|
||||
if (other == null ||
|
||||
_map != other._map ||
|
||||
_width != other._width ||
|
||||
_size_x != other._size_x ||
|
||||
_size_y != other._size_y ||
|
||||
_height != other._height ||
|
||||
GetType() != other.GetType() ||
|
||||
_map.GetLength(0) != other._map.GetLength(0) ||
|
||||
_map.GetLength(1) != other._map.GetLength(1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < _map.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); j++)
|
||||
{
|
||||
if (_map[i, j] != other._map[i, j])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,54 @@ namespace Airbus
|
||||
{
|
||||
public int Compare(IDrawningObject? x, IDrawningObject? y)
|
||||
{
|
||||
// TODO реализовать логику сравнения
|
||||
throw new NotImplementedException();
|
||||
if (x == null && y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (x == null && y != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (x != null && y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var xAirplane = x as DrawningObjectAirplane;
|
||||
var yAirplane = y as DrawningObjectAirplane;
|
||||
if (xAirplane == null && yAirplane == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xAirplane == null && yAirplane != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xAirplane != null && yAirplane == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
string xAirplaneColor = xAirplane.GetAirplane.airplane.BodyColor.Name;
|
||||
string yAirplaneColor = yAirplane.GetAirplane.airplane.BodyColor.Name;
|
||||
if (xAirplaneColor != yAirplaneColor)
|
||||
{
|
||||
return xAirplaneColor.CompareTo(yAirplaneColor);
|
||||
}
|
||||
if (xAirplane.GetAirplane.airplane is EntityAirbus xContainerShip && yAirplane.GetAirplane.airplane is EntityAirbus yContainerShip)
|
||||
{
|
||||
string xShipDopColor = xContainerShip.DopColor.Name;
|
||||
string yShipDopColor = yContainerShip.DopColor.Name;
|
||||
var dopColorCompare = xShipDopColor.CompareTo(yShipDopColor);
|
||||
if (dopColorCompare != 0)
|
||||
{
|
||||
return dopColorCompare;
|
||||
}
|
||||
}
|
||||
var speedCompare = xAirplane.GetAirplane.airplane.Speed.CompareTo(yAirplane.GetAirplane.airplane.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xAirplane.GetAirplane.airplane.Weight.CompareTo(yAirplane.GetAirplane.airplane.Weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -38,7 +38,7 @@ namespace Airbus
|
||||
}
|
||||
if (xAirplane.GetAirplane.GetType().Name != yAirplane.GetAirplane.GetType().Name)
|
||||
{
|
||||
if (xAirplane.GetAirplane.GetType().Name == "DrawingAirplane")
|
||||
if (xAirplane.GetAirplane.GetType().Name == "DrawningAirplane")
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
@ -61,7 +61,22 @@ namespace Airbus
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// TODO доделать проверки в случае продвинутого объекта
|
||||
|
||||
if (airplane is EntityAirbus airbus && otherAirplaneAirplane is EntityAirbus otherAirbus)
|
||||
{
|
||||
if (airbus.DopColor != otherAirbus.DopColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (airbus.Engine != otherAirbus.Engine)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (airbus.Compartment != otherAirbus.Compartment)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -311,7 +311,12 @@ namespace Airbus
|
||||
|
||||
private void buttonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new AirplaneCompareByColor());
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,10 @@ namespace Airbus
|
||||
|
||||
public int Insert(T airplane, int position)
|
||||
{
|
||||
if (_places.Contains(airplane))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
if (position < 0 || position > _places.Count) return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user