PIbd-21. Alekseev I.S. Lab work 08. Base #8
60
ProjectBomber/ProjectBomber/DrawiningPlaneEqutables.cs
Normal file
60
ProjectBomber/ProjectBomber/DrawiningPlaneEqutables.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectBomber.DrawningObjects;
|
||||
using ProjectBomber.Entities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace ProjectBomber.Generics
|
||||
{
|
||||
internal class DrawiningPlaneEqutables : IEqualityComparer<DrawningBomber>
|
||||
{
|
||||
public bool Equals(DrawningBomber x, DrawningBomber y)
|
||||
{
|
||||
if (x == null || x.EntityBomber == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityBomber == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityBomber.Speed != y.EntityBomber.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityBomber.Weight != y.EntityBomber.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityBomber.BodyColor != y.EntityBomber.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawningBomberAdvanced && y is DrawningBomberAdvanced)
|
||||
{
|
||||
EntityBomberAdvanced EntityX = (EntityBomberAdvanced)x.EntityBomber;
|
||||
EntityBomberAdvanced EntityY = (EntityBomberAdvanced)y.EntityBomber;
|
||||
if (EntityX.Bombs != EntityY.Bombs)
|
||||
return false;
|
||||
if (EntityX.FuelTanks != EntityY.FuelTanks)
|
||||
return false;
|
||||
if (EntityX.Line != EntityY.Line)
|
||||
return false;
|
||||
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode([DisallowNull] DrawningBomber obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
15
ProjectBomber/ProjectBomber/PlaneCompareByColor.cs
Normal file
15
ProjectBomber/ProjectBomber/PlaneCompareByColor.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectBomber.Entities;
|
||||
using ProjectBomber.DrawningObjects;
|
||||
|
||||
namespace ProjectBomber
|
||||
{
|
||||
internal class PlaneCompareByColor : IComparer<DrawningCar?>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
35
ProjectBomber/ProjectBomber/PlaneCompareByType.cs
Normal file
35
ProjectBomber/ProjectBomber/PlaneCompareByType.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectBomber.Entities;
|
||||
using ProjectBomber.DrawningObjects;
|
||||
|
||||
namespace ProjectBomber.Generics
|
||||
{
|
||||
internal class PlaneCompareByType : IComparer<DrawningBomber>
|
||||
{
|
||||
public int Compare(DrawningBomber x, DrawningBomber y)
|
||||
{
|
||||
if (x == null || x.EntityBomber == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityBomber == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
var speedCompare = x.EntityBomber.Speed.CompareTo(y.EntityBomber.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityBomber.Weight.CompareTo(y.EntityBomber.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -162,6 +162,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="AbstractStrategy.cs" />
|
||||
<Compile Include="Direction.cs" />
|
||||
<Compile Include="DrawiningPlaneEqutables.cs" />
|
||||
<Compile Include="DrawningBomber.cs" />
|
||||
<Compile Include="DrawningBomberAdvanced.cs" />
|
||||
<Compile Include="DrawningObjectBomber.cs" />
|
||||
@ -190,6 +191,8 @@
|
||||
<Compile Include="MoveToBottomRight.cs" />
|
||||
<Compile Include="MoveToCenter.cs" />
|
||||
<Compile Include="ObjectParameters.cs" />
|
||||
<Compile Include="PlaneCompareByColor.cs" />
|
||||
<Compile Include="PlaneCompareByType.cs" />
|
||||
<Compile Include="PlaneNotFoundException.cs" />
|
||||
<Compile Include="PlanesGenericCollection.cs" />
|
||||
<Compile Include="PlanesGenericStorage.cs" />
|
||||
|
@ -39,30 +39,13 @@ namespace ProjectBomber.Generics
|
||||
/// </summary>
|
||||
/// <param name="plane">Добавляемый самолет</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T plane)
|
||||
public bool Insert(T plane, IEqualityComparer<T> equal = null)
|
||||
{
|
||||
if (_places.Count == 0)
|
||||
{
|
||||
_places.Add(plane);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_places.Count < _maxCount)
|
||||
{
|
||||
_places.Add(plane);
|
||||
for (int i = 0; i < _places.Count; i++)
|
||||
{
|
||||
T temp = _places[i];
|
||||
_places[i] = _places[_places.Count - 1];
|
||||
_places[_places.Count - 1] = temp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
throw new StorageOverflowException(_places.Count);
|
||||
}
|
||||
}
|
||||
if (_places.Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
Insert(plane, 0);
|
||||
Insert(plane, 0, equal);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
@ -70,33 +53,19 @@ namespace ProjectBomber.Generics
|
||||
/// <param name="plane">Добавляемый самолет</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T plane, int position)
|
||||
public bool Insert(T plane, int position, IEqualityComparer<T> equal = null)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
if (_places.Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
if (!(position >= 0 && position <= Count))
|
||||
return false;
|
||||
}
|
||||
if (_places[position] == null)
|
||||
if (equal != null)
|
||||
{
|
||||
_places[position] = plane;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_places.Count < _maxCount)
|
||||
{
|
||||
_places.Add(plane);
|
||||
for (int i = position; i < _places.Count; i++)
|
||||
{
|
||||
T temp = _places[i];
|
||||
_places[i] = _places[_places.Count - 1];
|
||||
_places[_places.Count - 1] = temp;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new StorageOverflowException();
|
||||
if (_places.Contains(plane, equal))
|
||||
throw new ArgumentException(nameof(plane));
|
||||
}
|
||||
_places.Insert(position, plane);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
|
Loading…
Reference in New Issue
Block a user