Доделал 8 лабу дома
This commit is contained in:
parent
04124e04f7
commit
69e2561f87
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AirBomber
|
||||
{
|
||||
internal abstract class AbstractMap
|
||||
internal abstract class AbstractMap : IEquatable<AbstractMap>
|
||||
{
|
||||
private IDrawningObject _drawningObject = null;
|
||||
|
||||
@ -122,5 +122,27 @@ namespace AirBomber
|
||||
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 AirBomber
|
||||
{
|
||||
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 xAirBomber = x as DrawningObjectBomber;
|
||||
var yAirBomber = y as DrawningObjectBomber;
|
||||
if (xAirBomber == null && yAirBomber == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xAirBomber == null && yAirBomber != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xAirBomber != null && yAirBomber == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
string xAirBomberColor = xAirBomber.GetBomber.AirBomber.BodyColor.Name;
|
||||
string yAirBomberColor = yAirBomber.GetBomber.AirBomber.BodyColor.Name;
|
||||
if (xAirBomberColor != yAirBomberColor)
|
||||
{
|
||||
return xAirBomberColor.CompareTo(yAirBomberColor);
|
||||
}
|
||||
if (xAirBomber.GetBomber.AirBomber is EntityWarplane xWarplane && yAirBomber.GetBomber.AirBomber is EntityWarplane yWarplane)
|
||||
{
|
||||
string xWarplaneDopColor = xWarplane.DopColor.Name;
|
||||
string yWarplaneDopColor = yWarplane.DopColor.Name;
|
||||
var dopColorCompare = xWarplaneDopColor.CompareTo(yWarplaneDopColor);
|
||||
if (dopColorCompare != 0)
|
||||
{
|
||||
return dopColorCompare;
|
||||
}
|
||||
}
|
||||
var speedCompare = xAirBomber.GetBomber.AirBomber.Speed.CompareTo(yAirBomber.GetBomber.AirBomber.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xAirBomber.GetBomber.AirBomber.Weight.CompareTo(yAirBomber.GetBomber.AirBomber.Weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,8 +69,27 @@ namespace AirBomber
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO
|
||||
if ((airBomber is EntityWarplane) && !(otherBomberBomber is EntityWarplane)
|
||||
|| !(airBomber is EntityWarplane) && (otherBomberBomber is EntityWarplane))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (airBomber is EntityWarplane warplane && otherBomberBomber is EntityWarplane otherWarplane)
|
||||
{
|
||||
if (warplane.DopColor != otherWarplane.DopColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (warplane.Weapons != otherWarplane.Weapons)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (warplane.Engines != otherWarplane.Engines)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,6 @@ namespace AirBomber
|
||||
{
|
||||
public partial class FormMapWithSetAirBomber : Form
|
||||
{
|
||||
private MapWithSetAirBomberGeneric<DrawningObjectBomber, AbstractMap> _mapAirBomberCollectionGeneric;
|
||||
|
||||
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||
{
|
||||
{ "Простая карта", new SimpleMap() },
|
||||
@ -274,7 +272,12 @@ namespace AirBomber
|
||||
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
// TODO прописать логику
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new AirBomberCompareByColor());
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,10 @@ namespace AirBomber
|
||||
|
||||
public int Insert(T airBomber, int position)
|
||||
{
|
||||
//TODO проверка на уникальность
|
||||
if (_places.Contains(airBomber))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (_places.Count >= _maxCount)
|
||||
{
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
|
Loading…
Reference in New Issue
Block a user