This commit is contained in:
Daniya_Youdakova 2022-12-25 17:49:14 +04:00
parent 0c62307525
commit 1c9d167958
3 changed files with 34 additions and 21 deletions

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace AircraftCarrier
{
internal class MapWithSetAircraftCarriersGeneric<T, U>
where T : class, IDrawningObject
where T : class, IDrawningObject, IEquatable<T>
where U : AbstractMap
{
/// Ширина окна отрисовки
@ -131,6 +131,10 @@ namespace AircraftCarrier
_setAircraftCarriers.Insert(DrawningObjectAircraftCarrier.Create(rec) as T);
}
}
public void Sort(IComparer<T> comparer)
{
_setAircraftCarriers.SortSet(comparer);
}
/// <summary>
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
/// </summary>
@ -184,10 +188,8 @@ namespace AircraftCarrier
{
int yNumOfPlaces = _pictureHeight / _placeSizeHeight;
int xNumOfPlaces = _pictureWidth / _placeSizeWidth;
int rowNum = yNumOfPlaces - 1;
int columnNum = 0;
for (int i = 0; i < _setAircraftCarriers.Count; i++)
{
if (_setAircraftCarriers[i] != null)

View File

@ -1,3 +1,4 @@
using NLog.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -19,7 +20,6 @@ namespace AircraftCarrier
ApplicationConfiguration.Initialize();
var services = new ServiceCollection();
ConfigureServices(services);
//Application.Run(new FormMapWithSetAircraftCarriers());
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetAircraftCarriers>());
@ -31,16 +31,16 @@ namespace AircraftCarrier
.AddLogging(option =>
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
.Build();
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
.Build();
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
option.SetMinimumLevel(LogLevel.Information);
option.AddSerilog(logger);
option.SetMinimumLevel(LogLevel.Information);
option.AddSerilog(logger);
});
}
}

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace AircraftCarrier
{
internal class SetAircraftCarriersGeneric<T>
where T : class
where T : class, IEquatable<T>
{
private readonly List<T> _places;
/// <summary>
@ -32,7 +32,6 @@ namespace AircraftCarrier
/// <returns></returns>
public int Insert(T AircraftCarrier)
{
// TODO вставка в начало набора
return Insert(AircraftCarrier, 0);
}
private bool CorrectPos(int pos)
@ -47,13 +46,18 @@ namespace AircraftCarrier
/// <returns></returns>
public int Insert(T AircraftCarrier, int position)
{
// TODO проверка позиции
if (_places.Contains(AircraftCarrier))
{
return -1;
}
if (Count == _maxCount)
{
throw new StorageOverflowException(_maxCount);
throw new StorageOverflowException(Count);
}
if (position < 0 || position > Count)
{
return -1;
}
if (position < 0 || position > _maxCount) return -1;
// TODO вставка по позиции
_places.Insert(position, AircraftCarrier);
return position;
}
@ -64,14 +68,13 @@ namespace AircraftCarrier
/// <returns></returns>
public T Remove(int position)
{
// TODO проверка позиции
if (position >= Count || position < 0)
{
throw new AircraftCarrierNotFoundException(position);
}
T aircraftcarrier = _places[position];
T plane = _places[position];
_places.RemoveAt(position);
return aircraftcarrier;
return plane;
}
/// <summary>
/// Получение объекта из набора по позиции
@ -104,5 +107,13 @@ namespace AircraftCarrier
}
}
}
public void SortSet(IComparer<T> comparer)
{
if (comparer == null)
{
return;
}
_places.Sort(comparer);
}
}
}