лаб-8
This commit is contained in:
parent
7a2b6d4d45
commit
67a94b5b5c
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AircraftCarrier
|
namespace AircraftCarrier
|
||||||
{
|
{
|
||||||
internal abstract class AbstractMap
|
internal abstract class AbstractMap : IEquatable<AbstractMap>
|
||||||
{
|
{
|
||||||
private IDrawningObject _drawningObject = null;
|
private IDrawningObject _drawningObject = null;
|
||||||
protected int[,] _map = null;
|
protected int[,] _map = null;
|
||||||
@ -17,6 +17,43 @@ namespace AircraftCarrier
|
|||||||
protected readonly Random _random = new();
|
protected readonly Random _random = new();
|
||||||
protected readonly int _freeRoad = 0;
|
protected readonly int _freeRoad = 0;
|
||||||
protected readonly int _barrier = 1;
|
protected readonly int _barrier = 1;
|
||||||
|
public bool Equals(AbstractMap? other)
|
||||||
|
{
|
||||||
|
if (other == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var otherMap = other as AbstractMap;
|
||||||
|
if (otherMap == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_width != otherMap._width)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_height != otherMap._height)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_size_x != otherMap._size_x)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_size_y != otherMap._size_y)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < _map.GetLength(0); i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
|
{
|
||||||
|
if (_map[i, j] != otherMap._map[i, j])
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
public Bitmap CreateMap(int width, int height, IDrawningObject
|
public Bitmap CreateMap(int width, int height, IDrawningObject
|
||||||
drawningObject)
|
drawningObject)
|
||||||
{
|
{
|
||||||
@ -70,7 +107,6 @@ namespace AircraftCarrier
|
|||||||
yNumOfCells = (int)Math.Ceiling(_drawningObject.Step / _size_y);
|
yNumOfCells = (int)Math.Ceiling(_drawningObject.Step / _size_y);
|
||||||
xObjOffset = (int)(Left / _size_x);
|
xObjOffset = (int)(Left / _size_x);
|
||||||
yObjOffset = (int)Math.Ceiling(Bottom / _size_y);
|
yObjOffset = (int)Math.Ceiling(Bottom / _size_y);
|
||||||
|
|
||||||
for (int i = 0; i < yNumOfCells; i++)
|
for (int i = 0; i < yNumOfCells; i++)
|
||||||
{
|
{
|
||||||
if (!roadIsClear)
|
if (!roadIsClear)
|
||||||
@ -91,13 +127,11 @@ namespace AircraftCarrier
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Direction.Left:
|
case Direction.Left:
|
||||||
xNumOfCells = (int)Math.Ceiling(_drawningObject.Step / _size_x);
|
xNumOfCells = (int)Math.Ceiling(_drawningObject.Step / _size_x);
|
||||||
yNumOfCells = (int)Math.Ceiling((Bottom - Top) / _size_y);
|
yNumOfCells = (int)Math.Ceiling((Bottom - Top) / _size_y);
|
||||||
xObjOffset = (int)Math.Floor(Left / _size_x);
|
xObjOffset = (int)Math.Floor(Left / _size_x);
|
||||||
yObjOffset = (int)(Top / _size_y);
|
yObjOffset = (int)(Top / _size_y);
|
||||||
|
|
||||||
for (int i = 0; i < yNumOfCells; i++)
|
for (int i = 0; i < yNumOfCells; i++)
|
||||||
{
|
{
|
||||||
if (!roadIsClear)
|
if (!roadIsClear)
|
||||||
@ -118,13 +152,11 @@ namespace AircraftCarrier
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Direction.Right:
|
case Direction.Right:
|
||||||
xNumOfCells = (int)Math.Ceiling(_drawningObject.Step / _size_x);
|
xNumOfCells = (int)Math.Ceiling(_drawningObject.Step / _size_x);
|
||||||
yNumOfCells = (int)Math.Ceiling((Bottom - Top) / _size_y);
|
yNumOfCells = (int)Math.Ceiling((Bottom - Top) / _size_y);
|
||||||
xObjOffset = (int)(Right / _size_x);
|
xObjOffset = (int)(Right / _size_x);
|
||||||
yObjOffset = (int)Math.Ceiling(Top / _size_y);
|
yObjOffset = (int)Math.Ceiling(Top / _size_y);
|
||||||
|
|
||||||
for (int i = 0; i < yNumOfCells; i++)
|
for (int i = 0; i < yNumOfCells; i++)
|
||||||
{
|
{
|
||||||
if (!roadIsClear)
|
if (!roadIsClear)
|
||||||
@ -165,7 +197,6 @@ namespace AircraftCarrier
|
|||||||
int yNumOfCells = (int)Math.Ceiling(Bottom / _size_y) - (int)Math.Floor(Top / _size_y);
|
int yNumOfCells = (int)Math.Ceiling(Bottom / _size_y) - (int)Math.Floor(Top / _size_y);
|
||||||
int xObjOffset = (int)(x / _size_x);
|
int xObjOffset = (int)(x / _size_x);
|
||||||
int yObjOffset = (int)(y / _size_y);
|
int yObjOffset = (int)(y / _size_y);
|
||||||
|
|
||||||
while (y < _height - (Bottom - Top))
|
while (y < _height - (Bottom - Top))
|
||||||
{
|
{
|
||||||
while (x < _width - (Right - Left))
|
while (x < _width - (Right - Left))
|
||||||
|
@ -18,12 +18,14 @@
|
|||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||||
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.0" />
|
||||||
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
|
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
|
||||||
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
|
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AircraftCarrier
|
||||||
|
{
|
||||||
|
internal class AircraftCarrierCompareByColor : IComparer<IDrawningObject>
|
||||||
|
{
|
||||||
|
public int Compare(IDrawningObject? x, IDrawningObject? y)
|
||||||
|
{
|
||||||
|
if (x == null && y == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (x == null && y != null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (x != null && y == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
var xAircraftCarrier = x as DrawningObjectAircraftCarrier;
|
||||||
|
var yAircraftCarrier = y as DrawningObjectAircraftCarrier;
|
||||||
|
if (xAircraftCarrier == null && yAircraftCarrier == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (xAircraftCarrier == null && yAircraftCarrier != null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (xAircraftCarrier != null && yAircraftCarrier == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
string xAircraftCarrierColor = xAircraftCarrier.GetAircraftCarrier.AircraftCarrier.BodyColor.Name;
|
||||||
|
string yAircraftCarrierColor = yAircraftCarrier.GetAircraftCarrier.AircraftCarrier.BodyColor.Name;
|
||||||
|
if (xAircraftCarrierColor != yAircraftCarrierColor)
|
||||||
|
{
|
||||||
|
return xAircraftCarrierColor.CompareTo(yAircraftCarrierColor);
|
||||||
|
}
|
||||||
|
if (xAircraftCarrier.GetAircraftCarrier.GetType().Name != yAircraftCarrier.GetAircraftCarrier.GetType().Name)
|
||||||
|
{
|
||||||
|
if (xAircraftCarrier.GetAircraftCarrier.GetType().Name == "DrawningAircraftCarrier")
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (xAircraftCarrier.GetAircraftCarrier.AircraftCarrier is EntityModernAircraftCarrier xModernAircraftCarrier &&
|
||||||
|
yAircraftCarrier.GetAircraftCarrier.AircraftCarrier is EntityModernAircraftCarrier yModernAircraftCarrier)
|
||||||
|
{
|
||||||
|
string xAircraftCarrierDopColor = xModernAircraftCarrier.DopColor.Name;
|
||||||
|
string yAircraftCarrierDopColor = yModernAircraftCarrier.DopColor.Name;
|
||||||
|
var dopColorCompare = xAircraftCarrierDopColor.CompareTo(yAircraftCarrierDopColor);
|
||||||
|
if (dopColorCompare != 0)
|
||||||
|
{
|
||||||
|
return dopColorCompare;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var speedCompare = xAircraftCarrier.GetAircraftCarrier.AircraftCarrier.Speed.CompareTo(yAircraftCarrier.GetAircraftCarrier.AircraftCarrier.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return xAircraftCarrier.GetAircraftCarrier.AircraftCarrier.Weight.CompareTo(yAircraftCarrier.GetAircraftCarrier.AircraftCarrier.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AircraftCarrier
|
||||||
|
{
|
||||||
|
internal class AircraftCarrierCompareByType : IComparer<IDrawningObject>
|
||||||
|
{
|
||||||
|
public int Compare(IDrawningObject? x, IDrawningObject? y)
|
||||||
|
{
|
||||||
|
if (x == null && y == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (x == null && y != null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (x != null && y == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
var xAircraftCarrier = x as DrawningObjectAircraftCarrier;
|
||||||
|
var yAircraftCarrier = y as DrawningObjectAircraftCarrier;
|
||||||
|
if (xAircraftCarrier == null && yAircraftCarrier == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (xAircraftCarrier == null && yAircraftCarrier != null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (xAircraftCarrier != null && yAircraftCarrier == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (xAircraftCarrier.GetAircraftCarrier.GetType().Name != yAircraftCarrier.GetAircraftCarrier.GetType().Name)
|
||||||
|
{
|
||||||
|
if (xAircraftCarrier.GetAircraftCarrier.GetType().Name == "DrawningAircraftCarrier")
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
var speedCompare =
|
||||||
|
xAircraftCarrier.GetAircraftCarrier.AircraftCarrier.Speed.CompareTo(yAircraftCarrier.GetAircraftCarrier.AircraftCarrier.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return xAircraftCarrier.GetAircraftCarrier.AircraftCarrier.Weight.CompareTo(yAircraftCarrier.GetAircraftCarrier.AircraftCarrier.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user