Этап 2

This commit is contained in:
ityurner02@mail.ru 2022-12-04 14:28:50 +04:00
parent 89b3388307
commit ae6b62589a
5 changed files with 81 additions and 15 deletions

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AntiAircraftGun namespace AntiAircraftGun
{ {
internal abstract class AbstractMap internal abstract class AbstractMap : IEquatable<AbstractMap>
{ {
private IDrawingObject _drawingObject = null; private IDrawingObject _drawingObject = null;
protected int[,] _map = null; protected int[,] _map = null;
@ -153,5 +153,10 @@ namespace AntiAircraftGun
protected abstract void GenerateMap(); protected abstract void GenerateMap();
protected abstract void DrawRoadPart(Graphics g, int i, int j); protected abstract void DrawRoadPart(Graphics g, int i, int j);
protected abstract void DrawBarrierPart(Graphics g, int i, int j); protected abstract void DrawBarrierPart(Graphics g, int i, int j);
public bool Equals(AbstractMap? other)
{
return this == other && this._width == other._width && this._height == other._height && this._map == other._map && this._drawingObject == other._drawingObject;
}
} }
} }

View File

@ -10,8 +10,45 @@ namespace AntiAircraftGun
{ {
public int Compare(IDrawingObject? x, IDrawingObject? y) public int Compare(IDrawingObject? x, IDrawingObject? y)
{ {
// TODO реализовать логику сравнения if (x == null && y == null)
throw new NotImplementedException(); {
return 0;
}
if (x == null && y != null)
{
return 1;
}
if (x != null && y == null)
{
return -1;
}
var xAntiAircraftGun = x as DrawingObjectAntiAircraftGun;
var yAntiAircraftGun = y as DrawingObjectAntiAircraftGun;
if (xAntiAircraftGun == null && yAntiAircraftGun == null)
{
return 0;
}
if (xAntiAircraftGun == null && yAntiAircraftGun != null)
{
return 1;
}
if (xAntiAircraftGun != null && yAntiAircraftGun == null)
{
return -1;
}
if (xAntiAircraftGun.GetAntiAircraftGun.AntiAircraftGun.BodyColor == yAntiAircraftGun.GetAntiAircraftGun.AntiAircraftGun.BodyColor)
{
return 0;
}
if (xAntiAircraftGun.GetAntiAircraftGun.AntiAircraftGun.BodyColor.R.CompareTo(yAntiAircraftGun.GetAntiAircraftGun.AntiAircraftGun.BodyColor.R) == 0)
{
if (xAntiAircraftGun.GetAntiAircraftGun.AntiAircraftGun.BodyColor.G.CompareTo(yAntiAircraftGun.GetAntiAircraftGun.AntiAircraftGun.BodyColor.G) == 0)
{
return xAntiAircraftGun.GetAntiAircraftGun.AntiAircraftGun.BodyColor.B.CompareTo(yAntiAircraftGun.GetAntiAircraftGun.AntiAircraftGun.BodyColor.B);
}
else return xAntiAircraftGun.GetAntiAircraftGun.AntiAircraftGun.BodyColor.G.CompareTo(yAntiAircraftGun.GetAntiAircraftGun.AntiAircraftGun.BodyColor.G);
}
else return xAntiAircraftGun.GetAntiAircraftGun.AntiAircraftGun.BodyColor.R.CompareTo(yAntiAircraftGun.GetAntiAircraftGun.AntiAircraftGun.BodyColor.R);
} }
} }
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection.PortableExecutable;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -48,21 +49,36 @@ namespace AntiAircraftGun
{ {
return false; return false;
} }
var car = _antiAircraftGun.AntiAircraftGun; var antiAircraftGun = _antiAircraftGun.AntiAircraftGun;
var otherCarCar = otherAntiAircraftGun._antiAircraftGun.AntiAircraftGun; var otherAntiAircraftGunAntiAircraftGun = otherAntiAircraftGun._antiAircraftGun.AntiAircraftGun;
if (car.Speed != otherCarCar.Speed) if (antiAircraftGun.Speed != otherAntiAircraftGunAntiAircraftGun.Speed)
{ {
return false; return false;
} }
if (car.Weight != otherCarCar.Weight) if (antiAircraftGun.Weight != otherAntiAircraftGunAntiAircraftGun.Weight)
{ {
return false; return false;
} }
if (car.BodyColor != otherCarCar.BodyColor) if (antiAircraftGun.BodyColor != otherAntiAircraftGunAntiAircraftGun.BodyColor)
{ {
return false; return false;
} }
// TODO доделать проверки в случае продвинутого объекта
if (antiAircraftGun is EntityUpdateAntiAircraftGun && otherAntiAircraftGunAntiAircraftGun is EntityUpdateAntiAircraftGun)
{
var updateAntiAircraftGun = antiAircraftGun as EntityUpdateAntiAircraftGun;
var otherUpdateAntiAircraftGun = otherAntiAircraftGunAntiAircraftGun as EntityUpdateAntiAircraftGun;
if (updateAntiAircraftGun.DopColor != otherUpdateAntiAircraftGun.DopColor || updateAntiAircraftGun.Gun != otherUpdateAntiAircraftGun.Gun ||
updateAntiAircraftGun.Radar != otherUpdateAntiAircraftGun.Radar)
{
return false;
}
}
else if (antiAircraftGun is EntityUpdateAntiAircraftGun || otherAntiAircraftGunAntiAircraftGun is EntityUpdateAntiAircraftGun)
{
return false;
}
return true; return true;
} }
} }

View File

@ -145,8 +145,8 @@ namespace AntiAircraftGun
DrawingObjectAntiAircraftGun antiAircraftGun = new DrawingObjectAntiAircraftGun(drawingAntiAircraftGuns); DrawingObjectAntiAircraftGun antiAircraftGun = new DrawingObjectAntiAircraftGun(drawingAntiAircraftGuns);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + antiAircraftGun != -1) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + antiAircraftGun != -1)
{ {
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
MessageBox.Show("Объект добавлен");
_logger.LogInformation($"Добавлен объект {drawingAntiAircraftGuns} на карту "); _logger.LogInformation($"Добавлен объект {drawingAntiAircraftGuns} на карту ");
} }
else else
@ -329,7 +329,12 @@ namespace AntiAircraftGun
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonSortByColor_Click(object sender, EventArgs e) private void ButtonSortByColor_Click(object sender, EventArgs e)
{ {
// TODO прописать логику if (listBoxMaps.SelectedIndex == -1)
{
return;
}
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new AntiAircraftGunCompareByColor());
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
} }
} }

View File

@ -40,7 +40,6 @@ namespace AntiAircraftGun
/// <returns></returns> /// <returns></returns>
public int Insert(T antiAircraftGun) public int Insert(T antiAircraftGun)
{ {
//TODO проверка на уникальность
if (_places.Count < _maxCount) return Insert(antiAircraftGun, 0); if (_places.Count < _maxCount) return Insert(antiAircraftGun, 0);
else throw new StorageOverflowException(_maxCount); else throw new StorageOverflowException(_maxCount);
} }
@ -51,11 +50,15 @@ namespace AntiAircraftGun
/// <param name="position">Позиция</param> /// <param name="position">Позиция</param>
/// <returns></returns> /// <returns></returns>
public int Insert(T antiAircraftGun, int position) public int Insert(T antiAircraftGun, int position)
{
if (_places.All(p => p.Equals(antiAircraftGun) == false))
{ {
if (position >= _maxCount) throw new StorageOverflowException(_maxCount); if (position >= _maxCount) throw new StorageOverflowException(_maxCount);
_places.Insert(position, antiAircraftGun); _places.Insert(position, antiAircraftGun);
return position; return position;
} }
return - 1;
}
/// <summary> /// <summary>
/// Удаление объекта из набора с конкретной позиции /// Удаление объекта из набора с конкретной позиции
/// </summary> /// </summary>