Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
28981e02a6 | ||
|
4335e642a9 | ||
|
e84985aaf5 | ||
|
4ab74bde46 | ||
|
a8456abc36 | ||
|
94b298145b | ||
|
742275b7e4 | ||
|
740b975dc7 | ||
|
1c5ea38fdf | ||
|
20291ba6a8 | ||
|
6c787200aa | ||
|
bf9dbaa9dc | ||
|
6344340950 | ||
|
55300032aa | ||
|
83b9163072 | ||
|
4a9cdb1255 | ||
|
fecbbfd469 | ||
|
9e7872158e |
147
ContainerShip/ContainerShip/AbstractMap.cs
Normal file
147
ContainerShip/ContainerShip/AbstractMap.cs
Normal file
@ -0,0 +1,147 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal abstract class AbstractMap : IEquatable<AbstractMap>
|
||||
{
|
||||
private IDrawingObject _drawingObject = null;
|
||||
protected int[,] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
protected float _size_x;
|
||||
protected float _size_y;
|
||||
protected readonly Random _random = new();
|
||||
protected readonly int _freeRoad = 0;
|
||||
protected readonly int _barrier = 1;
|
||||
public Bitmap CreateMap(int width, int height, IDrawingObject drawingObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawingObject = drawingObject;
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
if (_drawingObject == null) return DrawMapWithObject();
|
||||
bool canMove = true;
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.Left:
|
||||
if (!CheckForBarriers(0, -1 * _drawingObject.Step, -1 * _drawingObject.Step, 0)) canMove = false;
|
||||
break;
|
||||
case Direction.Right:
|
||||
if (!CheckForBarriers(0, _drawingObject.Step, _drawingObject.Step, 0)) canMove = false;
|
||||
break;
|
||||
case Direction.Up:
|
||||
if (!CheckForBarriers(-1 * _drawingObject.Step, 0, 0, -1 * _drawingObject.Step)) canMove = false;
|
||||
break;
|
||||
case Direction.Down:
|
||||
if (!CheckForBarriers(_drawingObject.Step, 0, 0, _drawingObject.Step)) canMove = false;
|
||||
break;
|
||||
}
|
||||
if (canMove)
|
||||
{
|
||||
_drawingObject.MoveObject(direction);
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
//Вспомогательная функция проверки
|
||||
private bool CheckForBarriers(float topBorder, float rightBorder, float leftBorder, float bottomBorder)
|
||||
{
|
||||
int top = Convert.ToInt32((_drawingObject.GetCurrentPosition().Top + topBorder)/_size_y);
|
||||
int bottom = Convert.ToInt32((_drawingObject.GetCurrentPosition().Bottom + bottomBorder)/_size_y);
|
||||
int right = Convert.ToInt32((_drawingObject.GetCurrentPosition().Right + rightBorder)/_size_x);
|
||||
int left = Convert.ToInt32((_drawingObject.GetCurrentPosition().Left + leftBorder)/_size_x);
|
||||
|
||||
if (left < 0 || top < 0 || right >= _map.GetLength(0) || bottom >= _map.GetLength(1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = top; i <= bottom; i++)
|
||||
{
|
||||
for (int j = left; j <= right; j++)
|
||||
{
|
||||
if (_map[j, i] == 1) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private bool SetObjectOnMap()
|
||||
{
|
||||
if (_drawingObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.Next(0, 10);
|
||||
int y = _random.Next(0, 10);
|
||||
_drawingObject.SetObject(x, y, _width, _height);
|
||||
if (!CheckForBarriers(0, 0, 0, 0)) return false;
|
||||
return true;
|
||||
}
|
||||
private Bitmap DrawMapWithObject()
|
||||
{
|
||||
Bitmap bmp = new(_width, _height);
|
||||
if (_drawingObject == null || _map == null)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
if (_map[i, j] == _freeRoad)
|
||||
{
|
||||
DrawRoadPart(gr, i, j);
|
||||
}
|
||||
else if (_map[i, j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
_drawingObject.DrawingObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
public bool Equals(AbstractMap? other)
|
||||
{
|
||||
if (_width != other._width)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_height != other._height)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_size_x != other._size_x)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_size_y != other._size_y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < _map.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); j++)
|
||||
{
|
||||
if (other._map[i, j] != _map[j, i]) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
}
|
||||
}
|
65
ContainerShip/ContainerShip/CompareByColor.cs
Normal file
65
ContainerShip/ContainerShip/CompareByColor.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal class CompareByColor : IComparer<IDrawingObject>
|
||||
{
|
||||
public int Compare(IDrawingObject? x, IDrawingObject? y)
|
||||
{
|
||||
if (x == null && y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (x == null && y != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (x != null && y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var xShip = x as DrawingObjectShip;
|
||||
var yShip = y as DrawingObjectShip;
|
||||
var rgbCompareR = xShip.GetShip.Ship.BodyColor.R.CompareTo(yShip.GetShip.Ship.BodyColor.R);
|
||||
if (rgbCompareR != 0)
|
||||
{
|
||||
return rgbCompareR;
|
||||
}
|
||||
var rgbCompareG = xShip.GetShip.Ship.BodyColor.G.CompareTo(yShip.GetShip.Ship.BodyColor.G);
|
||||
if (rgbCompareG != 0)
|
||||
{
|
||||
return rgbCompareG;
|
||||
}
|
||||
var rgbCompareB = xShip.GetShip.Ship.BodyColor.B.CompareTo(yShip.GetShip.Ship.BodyColor.B);
|
||||
if (rgbCompareB != 0)
|
||||
{
|
||||
return rgbCompareB;
|
||||
}
|
||||
if (xShip.GetShip.Ship is EntityContainerShip xContainerShip && yShip.GetShip.Ship is EntityContainerShip yContainerShip)
|
||||
{
|
||||
var rgbDopCompareR = xContainerShip.DopColor.R.CompareTo(yContainerShip.DopColor.R);
|
||||
if (rgbDopCompareR != 0)
|
||||
{
|
||||
return rgbDopCompareR;
|
||||
}
|
||||
var rgbDopCompareB = xContainerShip.DopColor.G.CompareTo(yContainerShip.DopColor.G);
|
||||
if (rgbDopCompareB != 0)
|
||||
{
|
||||
return rgbDopCompareB;
|
||||
}
|
||||
var rgbDopCompareG = xContainerShip.DopColor.B.CompareTo(yContainerShip.DopColor.B);
|
||||
if (rgbDopCompareG != 0)
|
||||
{
|
||||
return rgbDopCompareG;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
55
ContainerShip/ContainerShip/CompareByType.cs
Normal file
55
ContainerShip/ContainerShip/CompareByType.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal class CompareByType: IComparer<IDrawingObject>
|
||||
{
|
||||
public int Compare(IDrawingObject? x, IDrawingObject? y)
|
||||
{
|
||||
if (x == null && y == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (x == null && y != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (x != null && y == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var xShip = x as DrawingObjectShip;
|
||||
var yShip = y as DrawingObjectShip;
|
||||
if (xShip == null && yShip == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (xShip == null && yShip != null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (xShip != null && yShip == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (xShip.GetShip.GetType().Name != yShip.GetShip.GetType().Name)
|
||||
{
|
||||
if (xShip.GetShip.GetType().Name == "DrawingShip")
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
var speedCompare = xShip.GetShip.Ship.Speed.CompareTo(yShip.GetShip.Ship.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xShip.GetShip.Ship.Weight.CompareTo(yShip.GetShip.Ship.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,30 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="appsettings.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" 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.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
|
||||
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
|
||||
<PackageReference Include="Serilog.Settings.AppSettings" Version="2.2.2" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
|
@ -6,8 +6,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal enum Direction
|
||||
public enum Direction
|
||||
{
|
||||
None = 0,
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
|
100
ContainerShip/ContainerShip/DrawingContainerShip.cs
Normal file
100
ContainerShip/ContainerShip/DrawingContainerShip.cs
Normal file
@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal class DrawingContainerShip : DrawingShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public DrawingContainerShip(int speed, float weight, Color bodyColor, Color dopColor, bool crane, bool containers) :
|
||||
base(speed, weight, bodyColor, 135, 70)
|
||||
{
|
||||
Ship = new EntityContainerShip(speed, weight, bodyColor, dopColor, crane, containers);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Ship is not EntityContainerShip containerShip)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(containerShip.DopColor);
|
||||
Pen dopPen = new (containerShip.DopColor);
|
||||
|
||||
_startPosY += 30;
|
||||
base.DrawTransport(g);
|
||||
_startPosY -= 30;
|
||||
int _startPosYInt = (int)_startPosY;
|
||||
int _startPosXInt = (int)_startPosX;
|
||||
if (containerShip.Containers)
|
||||
{
|
||||
Point[] container1 =
|
||||
{
|
||||
new Point(_startPosXInt + 5, _startPosYInt + 45),
|
||||
new Point(_startPosXInt + 5, _startPosYInt + 35),
|
||||
new Point(_startPosXInt + 25, _startPosYInt + 35),
|
||||
new Point(_startPosXInt + 25, _startPosYInt + 45)
|
||||
};
|
||||
|
||||
|
||||
Point[] container2 =
|
||||
{
|
||||
new Point(_startPosXInt + 40, _startPosYInt + 45),
|
||||
new Point(_startPosXInt + 40, _startPosYInt + 35),
|
||||
new Point(_startPosXInt + 75, _startPosYInt + 35),
|
||||
new Point(_startPosXInt + 75, _startPosYInt + 45),
|
||||
|
||||
};
|
||||
|
||||
Point[] container3 =
|
||||
{
|
||||
new Point(_startPosXInt + 80, _startPosYInt + 45),
|
||||
new Point(_startPosXInt + 80, _startPosYInt + 35),
|
||||
new Point(_startPosXInt + 110, _startPosYInt + 35),
|
||||
new Point(_startPosXInt + 110, _startPosYInt + 45)
|
||||
};
|
||||
|
||||
Point[] container4 =
|
||||
{
|
||||
new Point(_startPosXInt + 110, _startPosYInt + 30),
|
||||
new Point(_startPosXInt + 110, _startPosYInt + 45),
|
||||
new Point(_startPosXInt + 130, _startPosYInt + 45),
|
||||
new Point(_startPosXInt + 130, _startPosYInt + 30)
|
||||
};
|
||||
|
||||
g.FillPolygon(dopBrush, container1);
|
||||
g.DrawPolygon(pen, container1);
|
||||
g.FillPolygon(dopBrush, container2);
|
||||
g.DrawPolygon(pen, container2);
|
||||
g.FillPolygon(dopBrush, container3);
|
||||
g.DrawPolygon(pen, container3);
|
||||
g.FillPolygon(dopBrush, container4);
|
||||
g.DrawPolygon(pen, container4);
|
||||
|
||||
|
||||
}
|
||||
if (containerShip.Crane)
|
||||
{
|
||||
g.DrawLine(dopPen, _startPosX + 40, _startPosY + 15, _startPosX + 40, _startPosY);
|
||||
g.DrawLine(dopPen, _startPosX + 40, _startPosY, _startPosX + 80, _startPosY);
|
||||
g.DrawLine(dopPen, _startPosX + 40, _startPosY, _startPosX + 80, _startPosY + 5);
|
||||
g.DrawLine(dopPen, _startPosX + 80, _startPosY, _startPosX + 80, _startPosY + 30);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
92
ContainerShip/ContainerShip/DrawingObjectShip.cs
Normal file
92
ContainerShip/ContainerShip/DrawingObjectShip.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal class DrawingObjectShip : IDrawingObject
|
||||
{
|
||||
private DrawingShip _ship = null;
|
||||
public DrawingObjectShip(DrawingShip ship)
|
||||
{
|
||||
_ship = ship;
|
||||
}
|
||||
public DrawingShip GetShip => _ship;
|
||||
public float Step => _ship?.Ship?.Step ?? 0;
|
||||
|
||||
public (float Left, float Top, float Right, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return _ship?.GetCurrentPosition() ?? default;
|
||||
}
|
||||
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_ship?.MoveTransport(direction);
|
||||
}
|
||||
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_ship.SetPosition(x, y, width, height);
|
||||
}
|
||||
void IDrawingObject.DrawingObject(Graphics g)
|
||||
{
|
||||
if (_ship == null) return;
|
||||
if (_ship is DrawingContainerShip ship)
|
||||
{
|
||||
ship.DrawTransport(g);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ship.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
public string GetInfo() => _ship?.GetDataForSave();
|
||||
public static IDrawingObject Create(string data) => new DrawingObjectShip(data.CreateDrawingShip());
|
||||
|
||||
public bool Equals(IDrawingObject? other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var otherShip = other as DrawingObjectShip;
|
||||
if (otherShip == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var ship = _ship.Ship;
|
||||
var otherShipShip = otherShip._ship.Ship;
|
||||
if (ship.Speed != otherShipShip.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ship.Weight != otherShipShip.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ship.BodyColor != otherShipShip.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ship is EntityContainerShip containerShip && otherShipShip is EntityContainerShip otherContainerShip)
|
||||
{
|
||||
if (containerShip.DopColor != otherContainerShip.DopColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (containerShip.Containers != otherContainerShip.Containers)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (containerShip.Crane != otherContainerShip.Crane)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (ship is EntityContainerShip || otherShipShip is EntityContainerShip) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -7,11 +7,11 @@ using static ContainerShip.EntityShip;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal class DrawingShip
|
||||
public class DrawingShip
|
||||
{
|
||||
public EntityShip Ship { private set; get; }
|
||||
private float _startPosX;
|
||||
private float _startPosY;
|
||||
public EntityShip Ship { protected set; get; }
|
||||
protected float _startPosX;
|
||||
protected float _startPosY;
|
||||
private int? _pictureWidth = null;
|
||||
private int _startPosXInt;
|
||||
private int _startPosYInt;
|
||||
@ -22,7 +22,7 @@ namespace ContainerShip
|
||||
/// <summary>
|
||||
/// Ширина отрисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _shipWidth = 120;
|
||||
private readonly int _shipWidth = 135;
|
||||
/// <summary>
|
||||
/// Высота отрисовки автомобиля
|
||||
/// </summary>
|
||||
@ -33,12 +33,18 @@ namespace ContainerShip
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public DrawingShip(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Ship = new EntityShip();
|
||||
Ship.Init(speed, weight, bodyColor);
|
||||
Ship = new EntityShip(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
protected DrawingShip(int speed, float weight, Color bodyColor, int
|
||||
shipWidth, int shipHeight) :
|
||||
this(speed, weight, bodyColor)
|
||||
{
|
||||
_shipWidth = shipWidth;
|
||||
_shipHeight = shipHeight;
|
||||
}
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
@ -100,7 +106,7 @@ namespace ContainerShip
|
||||
/// Отрисовка
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0
|
||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
@ -130,7 +136,6 @@ namespace ContainerShip
|
||||
g.DrawLine(pen, _startPosXInt + 30, _startPosYInt + 20, _startPosXInt + 30, _startPosYInt + 30);
|
||||
g.DrawLine(pen, _startPosXInt + 25, _startPosYInt + 25, _startPosXInt + 35, _startPosYInt + 25);
|
||||
g.DrawLine(pen, _startPosXInt + 25, _startPosYInt + 30, _startPosXInt + 35, _startPosYInt + 30);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Смена границ формы отрисовки
|
||||
@ -156,5 +161,14 @@ namespace ContainerShip
|
||||
_startPosY = _pictureHeight.Value - _shipHeight;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение текущей позиции объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public (float Left, float Top, float Right, float Bottom) GetCurrentPosition()
|
||||
{
|
||||
return (_startPosX, _startPosY, _startPosX + _shipWidth, _startPosY + _shipHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
37
ContainerShip/ContainerShip/EntityContainerShip.cs
Normal file
37
ContainerShip/ContainerShip/EntityContainerShip.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal class EntityContainerShip : EntityShip
|
||||
{
|
||||
public Color DopColor { get; private set; }
|
||||
public bool Containers { get; private set; }
|
||||
public bool Crane { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public EntityContainerShip(int speed, float weight, Color bodyColor, Color dopColor, bool crane, bool containers) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
Crane = crane;
|
||||
Containers = containers;
|
||||
}
|
||||
|
||||
public void setDopColor(Color newDopColor)
|
||||
{
|
||||
DopColor = newDopColor;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal class EntityShip
|
||||
public class EntityShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
@ -31,12 +31,16 @@ namespace ContainerShip
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <returns></returns>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public EntityShip(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new();
|
||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
public void setColor (Color newColor)
|
||||
{
|
||||
BodyColor = newColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
54
ContainerShip/ContainerShip/ExtentionShip.cs
Normal file
54
ContainerShip/ContainerShip/ExtentionShip.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal static class ExtentionShip
|
||||
{
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по объекту в файл
|
||||
/// </summary>
|
||||
private static readonly char _separatorForObject = ':';
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
/// <returns></returns>
|
||||
public static DrawingShip CreateDrawingShip(this string info)
|
||||
{
|
||||
string[] strs = info.Split(_separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawingShip(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
||||
}
|
||||
if (strs.Length == 6)
|
||||
{
|
||||
return new DrawingContainerShip(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
|
||||
Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
|
||||
Convert.ToBoolean(strs[5]));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение данных для сохранения в файл
|
||||
/// </summary>
|
||||
/// <param name="drawningCar"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetDataForSave(this DrawingShip drawingShip)
|
||||
{
|
||||
var ship = drawingShip.Ship;
|
||||
var str = $"{ship.Speed}{_separatorForObject}{ship.Weight}{_separatorForObject}{ship.BodyColor.Name}";
|
||||
if (ship is not EntityContainerShip containerShip)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return $"{str}{_separatorForObject}{containerShip.DopColor.Name}{_separatorForObject}{containerShip.Containers}{_separatorForObject}{containerShip.Crane}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
365
ContainerShip/ContainerShip/FormMapWithSetShips.Designer.cs
generated
Normal file
365
ContainerShip/ContainerShip/FormMapWithSetShips.Designer.cs
generated
Normal file
@ -0,0 +1,365 @@
|
||||
namespace ContainerShip
|
||||
{
|
||||
partial class FormMapWithSetShips
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
|
||||
this.ButtonDeleteMap = new System.Windows.Forms.Button();
|
||||
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
||||
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
||||
this.ButtonAddMap = new System.Windows.Forms.Button();
|
||||
this.ComboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.ButtonAddShip = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.button3 = new System.Windows.Forms.Button();
|
||||
this.ButtonShowStorage = new System.Windows.Forms.Button();
|
||||
this.ButtonRemoveShip = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||
this.файлToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
this.ButtonSortByColor = new System.Windows.Forms.Button();
|
||||
this.ButtonSortByType = new System.Windows.Forms.Button();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBoxMaps.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.menuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.ButtonSortByType);
|
||||
this.groupBox1.Controls.Add(this.ButtonSortByColor);
|
||||
this.groupBox1.Controls.Add(this.groupBoxMaps);
|
||||
this.groupBox1.Controls.Add(this.ButtonAddShip);
|
||||
this.groupBox1.Controls.Add(this.buttonUp);
|
||||
this.groupBox1.Controls.Add(this.buttonRight);
|
||||
this.groupBox1.Controls.Add(this.buttonDown);
|
||||
this.groupBox1.Controls.Add(this.buttonLeft);
|
||||
this.groupBox1.Controls.Add(this.button3);
|
||||
this.groupBox1.Controls.Add(this.ButtonShowStorage);
|
||||
this.groupBox1.Controls.Add(this.ButtonRemoveShip);
|
||||
this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBox1.Location = new System.Drawing.Point(559, 33);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(300, 799);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// groupBoxMaps
|
||||
//
|
||||
this.groupBoxMaps.Controls.Add(this.ButtonDeleteMap);
|
||||
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
|
||||
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
|
||||
this.groupBoxMaps.Controls.Add(this.ButtonAddMap);
|
||||
this.groupBoxMaps.Controls.Add(this.ComboBoxSelectorMap);
|
||||
this.groupBoxMaps.Location = new System.Drawing.Point(10, 32);
|
||||
this.groupBoxMaps.Name = "groupBoxMaps";
|
||||
this.groupBoxMaps.Size = new System.Drawing.Size(284, 327);
|
||||
this.groupBoxMaps.TabIndex = 12;
|
||||
this.groupBoxMaps.TabStop = false;
|
||||
this.groupBoxMaps.Text = "Карты";
|
||||
//
|
||||
// ButtonDeleteMap
|
||||
//
|
||||
this.ButtonDeleteMap.Location = new System.Drawing.Point(6, 277);
|
||||
this.ButtonDeleteMap.Name = "ButtonDeleteMap";
|
||||
this.ButtonDeleteMap.Size = new System.Drawing.Size(272, 44);
|
||||
this.ButtonDeleteMap.TabIndex = 15;
|
||||
this.ButtonDeleteMap.Text = "Удалить карту";
|
||||
this.ButtonDeleteMap.UseVisualStyleBackColor = true;
|
||||
this.ButtonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
|
||||
//
|
||||
// listBoxMaps
|
||||
//
|
||||
this.listBoxMaps.FormattingEnabled = true;
|
||||
this.listBoxMaps.ItemHeight = 25;
|
||||
this.listBoxMaps.Location = new System.Drawing.Point(6, 167);
|
||||
this.listBoxMaps.Name = "listBoxMaps";
|
||||
this.listBoxMaps.Size = new System.Drawing.Size(272, 104);
|
||||
this.listBoxMaps.TabIndex = 14;
|
||||
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
|
||||
//
|
||||
// textBoxNewMapName
|
||||
//
|
||||
this.textBoxNewMapName.Location = new System.Drawing.Point(6, 39);
|
||||
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||
this.textBoxNewMapName.Size = new System.Drawing.Size(272, 31);
|
||||
this.textBoxNewMapName.TabIndex = 13;
|
||||
//
|
||||
// ButtonAddMap
|
||||
//
|
||||
this.ButtonAddMap.Location = new System.Drawing.Point(6, 115);
|
||||
this.ButtonAddMap.Name = "ButtonAddMap";
|
||||
this.ButtonAddMap.Size = new System.Drawing.Size(272, 44);
|
||||
this.ButtonAddMap.TabIndex = 12;
|
||||
this.ButtonAddMap.Text = "Добавить карту";
|
||||
this.ButtonAddMap.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
|
||||
//
|
||||
// ComboBoxSelectorMap
|
||||
//
|
||||
this.ComboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.ComboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Модифицированная карта"});
|
||||
this.ComboBoxSelectorMap.Location = new System.Drawing.Point(6, 76);
|
||||
this.ComboBoxSelectorMap.Name = "ComboBoxSelectorMap";
|
||||
this.ComboBoxSelectorMap.Size = new System.Drawing.Size(272, 33);
|
||||
this.ComboBoxSelectorMap.TabIndex = 10;
|
||||
//
|
||||
// ButtonAddShip
|
||||
//
|
||||
this.ButtonAddShip.Location = new System.Drawing.Point(6, 365);
|
||||
this.ButtonAddShip.Name = "ButtonAddShip";
|
||||
this.ButtonAddShip.Size = new System.Drawing.Size(288, 34);
|
||||
this.ButtonAddShip.TabIndex = 11;
|
||||
this.ButtonAddShip.Text = "Добавить корабль";
|
||||
this.ButtonAddShip.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddShip.Click += new System.EventHandler(this.ButtonAddShip_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::ContainerShip.Properties.Resources.upArrow;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(131, 673);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(50, 50);
|
||||
this.buttonUp.TabIndex = 9;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::ContainerShip.Properties.Resources.LeftArrow;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(187, 729);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(50, 50);
|
||||
this.buttonRight.TabIndex = 8;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::ContainerShip.Properties.Resources.DownArrow;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(131, 729);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(50, 50);
|
||||
this.buttonDown.TabIndex = 7;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::ContainerShip.Properties.Resources.RightArrow;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(75, 729);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(50, 50);
|
||||
this.buttonLeft.TabIndex = 6;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// button3
|
||||
//
|
||||
this.button3.Location = new System.Drawing.Point(6, 529);
|
||||
this.button3.Name = "button3";
|
||||
this.button3.Size = new System.Drawing.Size(288, 34);
|
||||
this.button3.TabIndex = 3;
|
||||
this.button3.Text = "Посмотреть карту";
|
||||
this.button3.UseVisualStyleBackColor = true;
|
||||
this.button3.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
||||
//
|
||||
// ButtonShowStorage
|
||||
//
|
||||
this.ButtonShowStorage.Location = new System.Drawing.Point(6, 489);
|
||||
this.ButtonShowStorage.Name = "ButtonShowStorage";
|
||||
this.ButtonShowStorage.Size = new System.Drawing.Size(288, 34);
|
||||
this.ButtonShowStorage.TabIndex = 2;
|
||||
this.ButtonShowStorage.Text = "Просмотреть хранилище";
|
||||
this.ButtonShowStorage.UseVisualStyleBackColor = true;
|
||||
this.ButtonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
||||
//
|
||||
// ButtonRemoveShip
|
||||
//
|
||||
this.ButtonRemoveShip.Location = new System.Drawing.Point(6, 442);
|
||||
this.ButtonRemoveShip.Name = "ButtonRemoveShip";
|
||||
this.ButtonRemoveShip.Size = new System.Drawing.Size(288, 41);
|
||||
this.ButtonRemoveShip.TabIndex = 1;
|
||||
this.ButtonRemoveShip.Text = "Удалить корабль";
|
||||
this.ButtonRemoveShip.UseVisualStyleBackColor = true;
|
||||
this.ButtonRemoveShip.Click += new System.EventHandler(this.ButtonRemoveShip_Click);
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 405);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(288, 31);
|
||||
this.maskedTextBoxPosition.TabIndex = 0;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 33);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(559, 799);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
|
||||
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.файлToolStripMenuItem});
|
||||
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip.Name = "menuStrip";
|
||||
this.menuStrip.Size = new System.Drawing.Size(859, 33);
|
||||
this.menuStrip.TabIndex = 2;
|
||||
this.menuStrip.Text = "menuStrip1";
|
||||
//
|
||||
// файлToolStripMenuItem
|
||||
//
|
||||
this.файлToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.SaveToolStripMenuItem,
|
||||
this.LoadToolStripMenuItem});
|
||||
this.файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||
this.файлToolStripMenuItem.Size = new System.Drawing.Size(69, 29);
|
||||
this.файлToolStripMenuItem.Text = "Файл";
|
||||
//
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(212, 34);
|
||||
this.SaveToolStripMenuItem.Text = "Сохранение";
|
||||
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(212, 34);
|
||||
this.LoadToolStripMenuItem.Text = "Загрузка";
|
||||
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
this.openFileDialog.FileName = "openFileDialog1";
|
||||
this.openFileDialog.Filter = "txt file|*.txt";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
this.saveFileDialog.Filter = "txt file|*.txt";
|
||||
//
|
||||
// ButtonSortByColor
|
||||
//
|
||||
this.ButtonSortByColor.Location = new System.Drawing.Point(6, 594);
|
||||
this.ButtonSortByColor.Name = "ButtonSortByColor";
|
||||
this.ButtonSortByColor.Size = new System.Drawing.Size(288, 34);
|
||||
this.ButtonSortByColor.TabIndex = 13;
|
||||
this.ButtonSortByColor.Text = "Сорт. по цвету";
|
||||
this.ButtonSortByColor.UseVisualStyleBackColor = true;
|
||||
this.ButtonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
|
||||
//
|
||||
// ButtonSortByType
|
||||
//
|
||||
this.ButtonSortByType.Location = new System.Drawing.Point(6, 634);
|
||||
this.ButtonSortByType.Name = "ButtonSortByType";
|
||||
this.ButtonSortByType.Size = new System.Drawing.Size(288, 34);
|
||||
this.ButtonSortByType.TabIndex = 14;
|
||||
this.ButtonSortByType.Text = "Сорт. по типу";
|
||||
this.ButtonSortByType.UseVisualStyleBackColor = true;
|
||||
this.ButtonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||
//
|
||||
// FormMapWithSetShips
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(859, 832);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
this.MainMenuStrip = this.menuStrip;
|
||||
this.Name = "FormMapWithSetShips";
|
||||
this.Text = "Карта с набором объектов";
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.groupBoxMaps.ResumeLayout(false);
|
||||
this.groupBoxMaps.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.menuStrip.ResumeLayout(false);
|
||||
this.menuStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBox1;
|
||||
private Button button3;
|
||||
private Button ButtonShowStorage;
|
||||
private Button ButtonRemoveShip;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private Button ButtonAddShip;
|
||||
private ComboBox ComboBoxSelectorMap;
|
||||
private ListBox listBoxMaps;
|
||||
private TextBox textBoxNewMapName;
|
||||
private Button ButtonAddMap;
|
||||
private GroupBox groupBoxMaps;
|
||||
private Button ButtonDeleteMap;
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem файлToolStripMenuItem;
|
||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button ButtonSortByType;
|
||||
private Button ButtonSortByColor;
|
||||
}
|
||||
}
|
322
ContainerShip/ContainerShip/FormMapWithSetShips.cs
Normal file
322
ContainerShip/ContainerShip/FormMapWithSetShips.cs
Normal file
@ -0,0 +1,322 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using static System.Windows.Forms.DataFormats;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
public partial class FormMapWithSetShips : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь для выпадающего списка
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||
{
|
||||
{ "Простая карта", new SimpleMap() },
|
||||
{ "Модифицированная карта", new ModifyMap()}
|
||||
};
|
||||
/// <summary>
|
||||
/// Объект от класса карты с набором объектов
|
||||
/// </summary>
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// /// <summary>
|
||||
/// Логер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
private Action<DrawingShip> addShipAction;
|
||||
public FormMapWithSetShips(ILogger<FormMapWithSetShips> logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||
ComboBoxSelectorMap.Items.Clear();
|
||||
addShipAction = addShip;
|
||||
foreach (var elem in _mapsDict)
|
||||
{
|
||||
ComboBoxSelectorMap.Items.Add(elem.Key);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Заполнение listBoxMaps
|
||||
/// </summary>
|
||||
private void ReloadMaps()
|
||||
{
|
||||
int index = listBoxMaps.SelectedIndex;
|
||||
|
||||
listBoxMaps.Items.Clear();
|
||||
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
|
||||
{
|
||||
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
|
||||
}
|
||||
|
||||
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
|
||||
{
|
||||
listBoxMaps.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
|
||||
{
|
||||
listBoxMaps.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
private void addShip(DrawingShip ship)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].add(new DrawingObjectShip(ship));
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
_logger.LogInformation($"Добавлен объект {ship}");
|
||||
}
|
||||
catch(ArgumentNullException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"Ошибка: {ex.Message}");
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
MessageBox.Show($"Идентичный корабль уже есть на форме: {ex.Message}");
|
||||
}
|
||||
catch (StorageOverflowException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"Ошибка: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Неизвестная ошибка: {ex.Message}", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning($"Ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddShip_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var formShipConfig = new FormShipConfig();
|
||||
formShipConfig.AddEvent(addShipAction);
|
||||
formShipConfig.Show();
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveShip_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
try
|
||||
{
|
||||
IDrawingObject drawingObject = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos;
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
_logger.LogInformation($"Удален объект {drawingObject}");
|
||||
}
|
||||
catch (ShipNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show($"Ошибка удаления: {ex.Message}");
|
||||
_logger.LogWarning($"Ошибка: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
|
||||
_logger.LogWarning($"Ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//получаем имя кнопки
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
Direction dir = Direction.None;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
dir = Direction.Up;
|
||||
break;
|
||||
case "buttonDown":
|
||||
dir = Direction.Down;
|
||||
break;
|
||||
case "buttonLeft":
|
||||
dir = Direction.Left;
|
||||
break;
|
||||
case "buttonRight":
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||
}
|
||||
|
||||
private void ButtonAddMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ComboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (!_mapsDict.ContainsKey(ComboBoxSelectorMap.Text))
|
||||
{
|
||||
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[ComboBoxSelectorMap.Text]);
|
||||
ReloadMaps();
|
||||
_logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}");
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
_logger.LogInformation($"Выбрана карта {listBoxMaps.SelectedItem?.ToString() ?? string.Empty}");
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonDeleteMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string deletedMapName = listBoxMaps.SelectedItem?.ToString();
|
||||
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||
ReloadMaps();
|
||||
_logger.LogInformation($"Удалена карта {deletedMapName}");
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation($"Данные сохранены в файле {saveFileDialog.FileName}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mapsCollection.LoadData(openFileDialog.FileName);
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
ReloadMaps();
|
||||
_logger.LogInformation($"Данные загружены из файла {openFileDialog.FileName}");
|
||||
}
|
||||
catch (FileFormatException ex)
|
||||
{
|
||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning($"Ошибка: {ex.Message}");
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning($"Ошибка: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning($"Ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new CompareByColor());
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new CompareByType());
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
}
|
||||
}
|
72
ContainerShip/ContainerShip/FormMapWithSetShips.resx
Normal file
72
ContainerShip/ContainerShip/FormMapWithSetShips.resx
Normal file
@ -0,0 +1,72 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>163, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>357, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>25</value>
|
||||
</metadata>
|
||||
</root>
|
120
ContainerShip/ContainerShip/FormShip.Designer.cs
generated
120
ContainerShip/ContainerShip/FormShip.Designer.cs
generated
@ -32,12 +32,14 @@
|
||||
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.pictureBoxShip = new System.Windows.Forms.PictureBox();
|
||||
this.ButtonCreate = new System.Windows.Forms.Button();
|
||||
this.ButtonCreateModif = new System.Windows.Forms.Button();
|
||||
this.ButtonSelectShip = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -60,31 +62,92 @@
|
||||
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
|
||||
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(93, 25);
|
||||
this.toolStripStatusLabelSpeed.Text = "Скорость:";
|
||||
this.toolStripStatusLabelSpeed.Click += new System.EventHandler(this.toolStripStatusLabelSpeed_Click);
|
||||
//
|
||||
// toolStripStatusLabelWeight
|
||||
//
|
||||
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
|
||||
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(43, 25);
|
||||
this.toolStripStatusLabelWeight.Text = "Вес:";
|
||||
this.toolStripStatusLabelWeight.Click += new System.EventHandler(this.toolStripStatusLabelWeight_Click);
|
||||
//
|
||||
// toolStripStatusLabelBodyColor
|
||||
//
|
||||
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(55, 25);
|
||||
this.toolStripStatusLabelBodyColor.Text = "Цвет:";
|
||||
this.toolStripStatusLabelBodyColor.Click += new System.EventHandler(this.toolStripStatusLabelBodyColor_Click);
|
||||
//
|
||||
// pictureBoxShip
|
||||
//
|
||||
this.pictureBoxShip.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxShip.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxShip.Name = "pictureBoxShip";
|
||||
this.pictureBoxShip.Size = new System.Drawing.Size(800, 418);
|
||||
this.pictureBoxShip.TabIndex = 7;
|
||||
this.pictureBoxShip.TabStop = false;
|
||||
this.pictureBoxShip.Click += new System.EventHandler(this.pictureBoxShip_Click);
|
||||
//
|
||||
// ButtonCreate
|
||||
//
|
||||
this.ButtonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.ButtonCreate.BackColor = System.Drawing.SystemColors.Window;
|
||||
this.ButtonCreate.Location = new System.Drawing.Point(12, 381);
|
||||
this.ButtonCreate.Name = "ButtonCreate";
|
||||
this.ButtonCreate.Size = new System.Drawing.Size(112, 34);
|
||||
this.ButtonCreate.TabIndex = 8;
|
||||
this.ButtonCreate.Text = "Создать";
|
||||
this.ButtonCreate.UseVisualStyleBackColor = false;
|
||||
this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||
//
|
||||
// ButtonCreateModif
|
||||
//
|
||||
this.ButtonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.ButtonCreateModif.BackColor = System.Drawing.SystemColors.Window;
|
||||
this.ButtonCreateModif.Location = new System.Drawing.Point(130, 381);
|
||||
this.ButtonCreateModif.Name = "ButtonCreateModif";
|
||||
this.ButtonCreateModif.Size = new System.Drawing.Size(143, 34);
|
||||
this.ButtonCreateModif.TabIndex = 9;
|
||||
this.ButtonCreateModif.Text = "Модификация";
|
||||
this.ButtonCreateModif.UseVisualStyleBackColor = false;
|
||||
this.ButtonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||
//
|
||||
// ButtonSelectShip
|
||||
//
|
||||
this.ButtonSelectShip.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.ButtonSelectShip.BackColor = System.Drawing.SystemColors.Window;
|
||||
this.ButtonSelectShip.Location = new System.Drawing.Point(479, 381);
|
||||
this.ButtonSelectShip.Name = "ButtonSelectShip";
|
||||
this.ButtonSelectShip.Size = new System.Drawing.Size(112, 34);
|
||||
this.ButtonSelectShip.TabIndex = 10;
|
||||
this.ButtonSelectShip.Text = "Выбрать";
|
||||
this.ButtonSelectShip.UseVisualStyleBackColor = false;
|
||||
this.ButtonSelectShip.Click += new System.EventHandler(this.ButtonSelectShip_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::ContainerShip.Properties.Resources.LeftArrow;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(738, 353);
|
||||
this.buttonRight.Location = new System.Drawing.Point(738, 362);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(50, 50);
|
||||
this.buttonRight.TabIndex = 2;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::ContainerShip.Properties.Resources.RightArrow;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(626, 362);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(50, 50);
|
||||
this.buttonLeft.TabIndex = 5;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
@ -102,51 +165,20 @@
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::ContainerShip.Properties.Resources.DownArrow;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(682, 352);
|
||||
this.buttonDown.Location = new System.Drawing.Point(682, 362);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(50, 50);
|
||||
this.buttonDown.TabIndex = 4;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::ContainerShip.Properties.Resources.RightArrow;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(626, 353);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(50, 50);
|
||||
this.buttonLeft.TabIndex = 5;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// pictureBoxShip
|
||||
//
|
||||
this.pictureBoxShip.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxShip.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxShip.Name = "pictureBoxShip";
|
||||
this.pictureBoxShip.Size = new System.Drawing.Size(800, 418);
|
||||
this.pictureBoxShip.TabIndex = 7;
|
||||
this.pictureBoxShip.TabStop = false;
|
||||
//
|
||||
// ButtonCreate
|
||||
//
|
||||
this.ButtonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.ButtonCreate.BackColor = System.Drawing.SystemColors.Window;
|
||||
this.ButtonCreate.Location = new System.Drawing.Point(12, 381);
|
||||
this.ButtonCreate.Name = "ButtonCreate";
|
||||
this.ButtonCreate.Size = new System.Drawing.Size(112, 34);
|
||||
this.ButtonCreate.TabIndex = 8;
|
||||
this.ButtonCreate.Text = "Создать";
|
||||
this.ButtonCreate.UseVisualStyleBackColor = false;
|
||||
this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||
//
|
||||
// FormShip
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.ButtonSelectShip);
|
||||
this.Controls.Add(this.ButtonCreateModif);
|
||||
this.Controls.Add(this.ButtonCreate);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
@ -168,14 +200,16 @@
|
||||
#endregion
|
||||
|
||||
private StatusStrip statusStrip1;
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private ToolStripStatusLabel toolStripStatusLabelSpeed;
|
||||
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||
private PictureBox pictureBoxShip;
|
||||
private Button ButtonCreate;
|
||||
private Button ButtonCreateModif;
|
||||
private Button ButtonSelectShip;
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
}
|
||||
}
|
@ -1,8 +1,14 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
public partial class FormShip : Form
|
||||
{
|
||||
private DrawingShip _ship;
|
||||
/// <summary>
|
||||
/// âûáðàííûé îáõåêò
|
||||
/// </summary>
|
||||
public DrawingShip SelectedShip { get; private set; }
|
||||
public FormShip()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -61,16 +67,73 @@ namespace ContainerShip
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
_ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_ship.Ship.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_ship.Ship.BodyColor.Name}";
|
||||
}
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_ship = new DrawingShip();
|
||||
_ship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_ship.Ship.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_ship.Ship.BodyColor.Name}";
|
||||
Draw();
|
||||
Random rnd = new();
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialogDop = new();
|
||||
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialogDop.Color;
|
||||
}
|
||||
_ship = new DrawingContainerShip(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonSelectShip_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedShip = _ship;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
private void pictureBoxShip_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void toolStripStatusLabelBodyColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void toolStripStatusLabelWeight_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void toolStripStatusLabelSpeed_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
407
ContainerShip/ContainerShip/FormShipConfig.Designer.cs
generated
Normal file
407
ContainerShip/ContainerShip/FormShipConfig.Designer.cs
generated
Normal file
@ -0,0 +1,407 @@
|
||||
namespace ContainerShip
|
||||
{
|
||||
partial class FormShipConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonOk = new System.Windows.Forms.Button();
|
||||
this.panelObject = new System.Windows.Forms.Panel();
|
||||
this.labelDopColor = new System.Windows.Forms.Label();
|
||||
this.labelBaseColor = new System.Windows.Forms.Label();
|
||||
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
||||
this.groupBoxConfig = new System.Windows.Forms.GroupBox();
|
||||
this.labelModifiedObject = new System.Windows.Forms.Label();
|
||||
this.labelSimpleObject = new System.Windows.Forms.Label();
|
||||
this.groupBoxColors = new System.Windows.Forms.GroupBox();
|
||||
this.panelPurple = new System.Windows.Forms.Panel();
|
||||
this.panelYellow = new System.Windows.Forms.Panel();
|
||||
this.panelBlack = new System.Windows.Forms.Panel();
|
||||
this.panelBlue = new System.Windows.Forms.Panel();
|
||||
this.panelGray = new System.Windows.Forms.Panel();
|
||||
this.panelGreen = new System.Windows.Forms.Panel();
|
||||
this.panelWhite = new System.Windows.Forms.Panel();
|
||||
this.panelRed = new System.Windows.Forms.Panel();
|
||||
this.checkBoxContainers = new System.Windows.Forms.CheckBox();
|
||||
this.checkBoxCrane = new System.Windows.Forms.CheckBox();
|
||||
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
||||
this.labelWeight = new System.Windows.Forms.Label();
|
||||
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
||||
this.labelSpeed = new System.Windows.Forms.Label();
|
||||
this.panelObject.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
|
||||
this.groupBoxConfig.SuspendLayout();
|
||||
this.groupBoxColors.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(966, 321);
|
||||
this.buttonCancel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(149, 50);
|
||||
this.buttonCancel.TabIndex = 9;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonOk
|
||||
//
|
||||
this.buttonOk.Location = new System.Drawing.Point(793, 321);
|
||||
this.buttonOk.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.buttonOk.Name = "buttonOk";
|
||||
this.buttonOk.Size = new System.Drawing.Size(149, 50);
|
||||
this.buttonOk.TabIndex = 8;
|
||||
this.buttonOk.Text = "Добавить";
|
||||
this.buttonOk.UseVisualStyleBackColor = true;
|
||||
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
|
||||
//
|
||||
// panelObject
|
||||
//
|
||||
this.panelObject.AllowDrop = true;
|
||||
this.panelObject.Controls.Add(this.labelDopColor);
|
||||
this.panelObject.Controls.Add(this.labelBaseColor);
|
||||
this.panelObject.Controls.Add(this.pictureBoxObject);
|
||||
this.panelObject.Location = new System.Drawing.Point(765, 4);
|
||||
this.panelObject.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.panelObject.Name = "panelObject";
|
||||
this.panelObject.Size = new System.Drawing.Size(374, 307);
|
||||
this.panelObject.TabIndex = 7;
|
||||
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
|
||||
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
|
||||
//
|
||||
// labelDopColor
|
||||
//
|
||||
this.labelDopColor.AllowDrop = true;
|
||||
this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelDopColor.Location = new System.Drawing.Point(201, 15);
|
||||
this.labelDopColor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.labelDopColor.Name = "labelDopColor";
|
||||
this.labelDopColor.Size = new System.Drawing.Size(148, 52);
|
||||
this.labelDopColor.TabIndex = 2;
|
||||
this.labelDopColor.Text = "Доп. цвет";
|
||||
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
|
||||
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||
//
|
||||
// labelBaseColor
|
||||
//
|
||||
this.labelBaseColor.AllowDrop = true;
|
||||
this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelBaseColor.Location = new System.Drawing.Point(29, 15);
|
||||
this.labelBaseColor.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.labelBaseColor.Name = "labelBaseColor";
|
||||
this.labelBaseColor.Size = new System.Drawing.Size(148, 52);
|
||||
this.labelBaseColor.TabIndex = 1;
|
||||
this.labelBaseColor.Text = "Цвет";
|
||||
this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
|
||||
this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
this.pictureBoxObject.Location = new System.Drawing.Point(29, 73);
|
||||
this.pictureBoxObject.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.pictureBoxObject.Name = "pictureBoxObject";
|
||||
this.pictureBoxObject.Size = new System.Drawing.Size(321, 208);
|
||||
this.pictureBoxObject.TabIndex = 0;
|
||||
this.pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// groupBoxConfig
|
||||
//
|
||||
this.groupBoxConfig.Controls.Add(this.labelModifiedObject);
|
||||
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
|
||||
this.groupBoxConfig.Controls.Add(this.groupBoxColors);
|
||||
this.groupBoxConfig.Controls.Add(this.checkBoxContainers);
|
||||
this.groupBoxConfig.Controls.Add(this.checkBoxCrane);
|
||||
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
|
||||
this.groupBoxConfig.Controls.Add(this.labelWeight);
|
||||
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
|
||||
this.groupBoxConfig.Controls.Add(this.labelSpeed);
|
||||
this.groupBoxConfig.Location = new System.Drawing.Point(13, 4);
|
||||
this.groupBoxConfig.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.groupBoxConfig.Name = "groupBoxConfig";
|
||||
this.groupBoxConfig.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.groupBoxConfig.Size = new System.Drawing.Size(743, 367);
|
||||
this.groupBoxConfig.TabIndex = 6;
|
||||
this.groupBoxConfig.TabStop = false;
|
||||
this.groupBoxConfig.Text = "Параметры";
|
||||
//
|
||||
// labelModifiedObject
|
||||
//
|
||||
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelModifiedObject.Location = new System.Drawing.Point(563, 270);
|
||||
this.labelModifiedObject.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.labelModifiedObject.Name = "labelModifiedObject";
|
||||
this.labelModifiedObject.Size = new System.Drawing.Size(138, 62);
|
||||
this.labelModifiedObject.TabIndex = 16;
|
||||
this.labelModifiedObject.Text = "Продвинутый";
|
||||
this.labelModifiedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelModifiedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||
//
|
||||
// labelSimpleObject
|
||||
//
|
||||
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.labelSimpleObject.Location = new System.Drawing.Point(403, 270);
|
||||
this.labelSimpleObject.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.labelSimpleObject.Name = "labelSimpleObject";
|
||||
this.labelSimpleObject.Size = new System.Drawing.Size(138, 62);
|
||||
this.labelSimpleObject.TabIndex = 15;
|
||||
this.labelSimpleObject.Text = "Простой";
|
||||
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
|
||||
//
|
||||
// groupBoxColors
|
||||
//
|
||||
this.groupBoxColors.Controls.Add(this.panelPurple);
|
||||
this.groupBoxColors.Controls.Add(this.panelYellow);
|
||||
this.groupBoxColors.Controls.Add(this.panelBlack);
|
||||
this.groupBoxColors.Controls.Add(this.panelBlue);
|
||||
this.groupBoxColors.Controls.Add(this.panelGray);
|
||||
this.groupBoxColors.Controls.Add(this.panelGreen);
|
||||
this.groupBoxColors.Controls.Add(this.panelWhite);
|
||||
this.groupBoxColors.Controls.Add(this.panelRed);
|
||||
this.groupBoxColors.Location = new System.Drawing.Point(381, 37);
|
||||
this.groupBoxColors.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.groupBoxColors.Name = "groupBoxColors";
|
||||
this.groupBoxColors.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.groupBoxColors.Size = new System.Drawing.Size(344, 212);
|
||||
this.groupBoxColors.TabIndex = 14;
|
||||
this.groupBoxColors.TabStop = false;
|
||||
this.groupBoxColors.Text = "Цвета";
|
||||
//
|
||||
// panelPurple
|
||||
//
|
||||
this.panelPurple.BackColor = System.Drawing.Color.Purple;
|
||||
this.panelPurple.Location = new System.Drawing.Point(263, 122);
|
||||
this.panelPurple.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.panelPurple.Name = "panelPurple";
|
||||
this.panelPurple.Size = new System.Drawing.Size(57, 67);
|
||||
this.panelPurple.TabIndex = 3;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
|
||||
this.panelYellow.Location = new System.Drawing.Point(263, 37);
|
||||
this.panelYellow.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.panelYellow.Name = "panelYellow";
|
||||
this.panelYellow.Size = new System.Drawing.Size(57, 67);
|
||||
this.panelYellow.TabIndex = 1;
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
this.panelBlack.BackColor = System.Drawing.Color.Black;
|
||||
this.panelBlack.Location = new System.Drawing.Point(181, 122);
|
||||
this.panelBlack.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.panelBlack.Name = "panelBlack";
|
||||
this.panelBlack.Size = new System.Drawing.Size(57, 67);
|
||||
this.panelBlack.TabIndex = 4;
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
this.panelBlue.BackColor = System.Drawing.Color.Blue;
|
||||
this.panelBlue.Location = new System.Drawing.Point(181, 37);
|
||||
this.panelBlue.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.panelBlue.Name = "panelBlue";
|
||||
this.panelBlue.Size = new System.Drawing.Size(57, 67);
|
||||
this.panelBlue.TabIndex = 1;
|
||||
//
|
||||
// panelGray
|
||||
//
|
||||
this.panelGray.BackColor = System.Drawing.Color.Gray;
|
||||
this.panelGray.Location = new System.Drawing.Point(103, 122);
|
||||
this.panelGray.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.panelGray.Name = "panelGray";
|
||||
this.panelGray.Size = new System.Drawing.Size(57, 67);
|
||||
this.panelGray.TabIndex = 5;
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
this.panelGreen.BackColor = System.Drawing.Color.Green;
|
||||
this.panelGreen.Location = new System.Drawing.Point(103, 37);
|
||||
this.panelGreen.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.panelGreen.Name = "panelGreen";
|
||||
this.panelGreen.Size = new System.Drawing.Size(57, 67);
|
||||
this.panelGreen.TabIndex = 1;
|
||||
//
|
||||
// panelWhite
|
||||
//
|
||||
this.panelWhite.BackColor = System.Drawing.Color.White;
|
||||
this.panelWhite.Location = new System.Drawing.Point(21, 122);
|
||||
this.panelWhite.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.panelWhite.Name = "panelWhite";
|
||||
this.panelWhite.Size = new System.Drawing.Size(57, 67);
|
||||
this.panelWhite.TabIndex = 2;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
this.panelRed.BackColor = System.Drawing.Color.Red;
|
||||
this.panelRed.Location = new System.Drawing.Point(21, 37);
|
||||
this.panelRed.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.panelRed.Name = "panelRed";
|
||||
this.panelRed.Size = new System.Drawing.Size(57, 67);
|
||||
this.panelRed.TabIndex = 0;
|
||||
//
|
||||
// checkBoxContainers
|
||||
//
|
||||
this.checkBoxContainers.AutoSize = true;
|
||||
this.checkBoxContainers.Location = new System.Drawing.Point(32, 233);
|
||||
this.checkBoxContainers.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.checkBoxContainers.Name = "checkBoxContainers";
|
||||
this.checkBoxContainers.Size = new System.Drawing.Size(280, 29);
|
||||
this.checkBoxContainers.TabIndex = 12;
|
||||
this.checkBoxContainers.Text = "Признак наличия контейнера";
|
||||
this.checkBoxContainers.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxCrane
|
||||
//
|
||||
this.checkBoxCrane.AutoSize = true;
|
||||
this.checkBoxCrane.Location = new System.Drawing.Point(32, 194);
|
||||
this.checkBoxCrane.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.checkBoxCrane.Name = "checkBoxCrane";
|
||||
this.checkBoxCrane.Size = new System.Drawing.Size(233, 29);
|
||||
this.checkBoxCrane.TabIndex = 11;
|
||||
this.checkBoxCrane.Text = "Признак наличия крана";
|
||||
this.checkBoxCrane.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
this.numericUpDownWeight.Location = new System.Drawing.Point(129, 120);
|
||||
this.numericUpDownWeight.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.numericUpDownWeight.Maximum = new decimal(new int[] {
|
||||
1000,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownWeight.Minimum = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
this.numericUpDownWeight.Size = new System.Drawing.Size(113, 31);
|
||||
this.numericUpDownWeight.TabIndex = 10;
|
||||
this.numericUpDownWeight.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// labelWeight
|
||||
//
|
||||
this.labelWeight.AutoSize = true;
|
||||
this.labelWeight.Location = new System.Drawing.Point(32, 125);
|
||||
this.labelWeight.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.labelWeight.Name = "labelWeight";
|
||||
this.labelWeight.Size = new System.Drawing.Size(43, 25);
|
||||
this.labelWeight.TabIndex = 9;
|
||||
this.labelWeight.Text = "Вес:";
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
this.numericUpDownSpeed.Location = new System.Drawing.Point(129, 50);
|
||||
this.numericUpDownSpeed.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
|
||||
1000,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
this.numericUpDownSpeed.Size = new System.Drawing.Size(113, 31);
|
||||
this.numericUpDownSpeed.TabIndex = 8;
|
||||
this.numericUpDownSpeed.Value = new decimal(new int[] {
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
//
|
||||
// labelSpeed
|
||||
//
|
||||
this.labelSpeed.AutoSize = true;
|
||||
this.labelSpeed.Location = new System.Drawing.Point(32, 55);
|
||||
this.labelSpeed.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.labelSpeed.Name = "labelSpeed";
|
||||
this.labelSpeed.Size = new System.Drawing.Size(93, 25);
|
||||
this.labelSpeed.TabIndex = 7;
|
||||
this.labelSpeed.Text = "Скорость:";
|
||||
//
|
||||
// FormShipConfig
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1157, 386);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonOk);
|
||||
this.Controls.Add(this.panelObject);
|
||||
this.Controls.Add(this.groupBoxConfig);
|
||||
this.Name = "FormShipConfig";
|
||||
this.Text = "Создание объекта";
|
||||
this.panelObject.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
|
||||
this.groupBoxConfig.ResumeLayout(false);
|
||||
this.groupBoxConfig.PerformLayout();
|
||||
this.groupBoxColors.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonCancel;
|
||||
private Button buttonOk;
|
||||
private Panel panelObject;
|
||||
private Label labelDopColor;
|
||||
private Label labelBaseColor;
|
||||
private PictureBox pictureBoxObject;
|
||||
private GroupBox groupBoxConfig;
|
||||
private Label labelModifiedObject;
|
||||
private Label labelSimpleObject;
|
||||
private GroupBox groupBoxColors;
|
||||
private Panel panelPurple;
|
||||
private Panel panelYellow;
|
||||
private Panel panelBlack;
|
||||
private Panel panelBlue;
|
||||
private Panel panelGray;
|
||||
private Panel panelGreen;
|
||||
private Panel panelWhite;
|
||||
private Panel panelRed;
|
||||
private CheckBox checkBoxContainers;
|
||||
private CheckBox checkBoxCrane;
|
||||
private NumericUpDown numericUpDownWeight;
|
||||
private Label labelWeight;
|
||||
private NumericUpDown numericUpDownSpeed;
|
||||
private Label labelSpeed;
|
||||
}
|
||||
}
|
112
ContainerShip/ContainerShip/FormShipConfig.cs
Normal file
112
ContainerShip/ContainerShip/FormShipConfig.cs
Normal file
@ -0,0 +1,112 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
public partial class FormShipConfig : Form
|
||||
{
|
||||
DrawingShip _ship = null;
|
||||
private event Action<DrawingShip> EventAddShip;
|
||||
public FormShipConfig()
|
||||
{
|
||||
InitializeComponent();
|
||||
panelBlack.MouseDown += PanelColor_MouseDown;
|
||||
panelPurple.MouseDown += PanelColor_MouseDown;
|
||||
panelGray.MouseDown += PanelColor_MouseDown;
|
||||
panelGreen.MouseDown += PanelColor_MouseDown;
|
||||
panelRed.MouseDown += PanelColor_MouseDown;
|
||||
panelWhite.MouseDown += PanelColor_MouseDown;
|
||||
panelYellow.MouseDown += PanelColor_MouseDown;
|
||||
panelBlue.MouseDown += PanelColor_MouseDown;
|
||||
buttonCancel.Click += (object sender, EventArgs e) => Close();
|
||||
}
|
||||
private void DrawShip()
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_ship?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
_ship?.DrawTransport(gr);
|
||||
pictureBoxObject.Image = bmp;
|
||||
}
|
||||
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(DataFormats.Text))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
public void AddEvent(Action<DrawingShip> ev)
|
||||
{
|
||||
if (EventAddShip == null)
|
||||
{
|
||||
EventAddShip = ev;
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddShip += ev;
|
||||
}
|
||||
}
|
||||
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
switch (e.Data.GetData(DataFormats.Text).ToString())
|
||||
{
|
||||
case "labelSimpleObject":
|
||||
_ship = new DrawingShip((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
|
||||
break;
|
||||
case "labelModifiedObject":
|
||||
_ship = new DrawingContainerShip((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black,
|
||||
checkBoxCrane.Checked, checkBoxContainers.Checked);
|
||||
break;
|
||||
}
|
||||
DrawShip();
|
||||
}
|
||||
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Control).DoDragDrop((sender as Control).BackColor.Name, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
private void LabelColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(String)))
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
_ship?.Ship?.setColor(Color.FromName(e.Data.GetData(DataFormats.Text).ToString()));
|
||||
DrawShip();
|
||||
}
|
||||
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_ship.Ship is EntityContainerShip ContainerShip)
|
||||
{
|
||||
ContainerShip.setDopColor(Color.FromName(e.Data.GetData(DataFormats.Text).ToString()));
|
||||
DrawShip();
|
||||
}
|
||||
}
|
||||
private void ButtonOk_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddShip?.Invoke(_ship);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
ContainerShip/ContainerShip/FormShipConfig.resx
Normal file
60
ContainerShip/ContainerShip/FormShipConfig.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
41
ContainerShip/ContainerShip/IDrawingObject.cs
Normal file
41
ContainerShip/ContainerShip/IDrawingObject.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal interface IDrawingObject: IEquatable<IDrawingObject>
|
||||
{
|
||||
/// <summary>
|
||||
/// Шаг перемещения объекта
|
||||
/// </summary>
|
||||
public float Step { get; }
|
||||
/// <summary>
|
||||
/// Установка позиции объекта
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина полотна</param>
|
||||
/// <param name="height">Высота полотна</param>
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
/// <summary>
|
||||
/// Изменение направления пермещения объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns></returns>
|
||||
void MoveObject(Direction direction);
|
||||
/// <summary>
|
||||
/// Отрисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
void DrawingObject(Graphics g);
|
||||
/// <summary>
|
||||
/// Получение текущей позиции объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
(float Left, float Top, float Right, float Bottom) GetCurrentPosition();
|
||||
string GetInfo();
|
||||
}
|
||||
}
|
200
ContainerShip/ContainerShip/MapWithSetShipsGeneric.cs
Normal file
200
ContainerShip/ContainerShip/MapWithSetShipsGeneric.cs
Normal file
@ -0,0 +1,200 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal class MapWithSetShipsGeneric<T, U>
|
||||
where T : class, IDrawingObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 135;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 70;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetShipsGeneric<T> _setShips;
|
||||
/// <summary>
|
||||
/// Карта
|
||||
/// </summary>
|
||||
private readonly U _map;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
/// <param name="map"></param>
|
||||
public MapWithSetShipsGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setShips = new SetShipsGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowSet()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawShips(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Просмотр объекта на карте
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
foreach (var ship in _setShips.GetShips())
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, ship);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
public string GetData(char separatorType, char separatorData)
|
||||
{
|
||||
string data = $"{_map.GetType().Name}{separatorType}";
|
||||
foreach (var ship in _setShips.GetShips())
|
||||
{
|
||||
data += $"{ship.GetInfo()}{separatorData}";
|
||||
}
|
||||
return data;
|
||||
}
|
||||
/// <summary>
|
||||
/// Загрузка списка из массива строк
|
||||
/// </summary>
|
||||
/// <param name="records"></param>
|
||||
public void LoadData(string[] records)
|
||||
{
|
||||
foreach (var rec in records)
|
||||
{
|
||||
_setShips.Insert(DrawingObjectShip.Create(rec) as T);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение объекта по крате
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
/// <summary>
|
||||
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
|
||||
/// </summary>
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setShips.Count - 1;
|
||||
for (int i = 0; i < _setShips.Count; i++)
|
||||
{
|
||||
if (_setShips[i] == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var ship = _setShips[j];
|
||||
if (ship != null)
|
||||
{
|
||||
_setShips.Insert(ship, i);
|
||||
_setShips.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Brown, 3);
|
||||
g.FillRectangle(Brushes.Aqua, 0, 0, _pictureWidth, _pictureHeight);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{//линия рамзетки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawShips(Graphics g)
|
||||
{
|
||||
int i = 0;
|
||||
int countOfShipsInLine = _pictureWidth / _placeSizeWidth;
|
||||
int countOfShipsInColumn = _pictureHeight / _placeSizeHeight;
|
||||
foreach (var ship in _setShips.GetShips())
|
||||
{
|
||||
ship.SetObject((countOfShipsInLine - (i % countOfShipsInLine) - 1) * _placeSizeWidth, (countOfShipsInColumn - (i / countOfShipsInLine) - 1) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||
ship.DrawingObject(g);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
public void Sort(IComparer<T> comparer)
|
||||
{
|
||||
_setShips.SortSet(comparer);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка операторов
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="ship"></param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(MapWithSetShipsGeneric<T, U> map, T ship)
|
||||
{
|
||||
return map._setShips.Insert(ship);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public static T operator -(MapWithSetShipsGeneric<T, U> map, int position)
|
||||
{
|
||||
return map._setShips.Remove(position);
|
||||
}
|
||||
public int add(T ship)
|
||||
{
|
||||
return _setShips.Insert(ship);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
165
ContainerShip/ContainerShip/MapsCollection.cs
Normal file
165
ContainerShip/ContainerShip/MapsCollection.cs
Normal file
@ -0,0 +1,165 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualBasic;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal class MapsCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с картами
|
||||
/// </summary>
|
||||
readonly Dictionary<string, MapWithSetShipsGeneric <IDrawingObject, AbstractMap>> _mapStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий карт
|
||||
/// </summary>
|
||||
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по элементу словаря в файл
|
||||
/// </summary>
|
||||
private readonly char separatorDict = '|';
|
||||
/// <summary>
|
||||
/// Разделитель для записей коллекции данных в файл
|
||||
/// </summary>
|
||||
private readonly char separatorData = ';';
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new Dictionary<string, MapWithSetShipsGeneric<IDrawingObject, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
/// <param name="map">Карта</param>
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
// TODO Прописать логику для добавления
|
||||
if (_mapStorages.ContainsKey(name)) return; //уникальное имя
|
||||
else
|
||||
{
|
||||
_mapStorages.Add(name, new MapWithSetShipsGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
public void DelMap(string name)
|
||||
{
|
||||
// TODO Прописать логику для удаления
|
||||
if (_mapStorages.ContainsKey(name))
|
||||
{
|
||||
_mapStorages.Remove(name);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к парковке
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public MapWithSetShipsGeneric<IDrawingObject, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
//TODO логика получения объекта
|
||||
if (_mapStorages.ContainsKey(ind)) return _mapStorages[ind];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод записи информации в файл
|
||||
/// </summary>
|
||||
/// <param name="text">Строка, которую следует записать</param>
|
||||
/// <param name="stream">Поток для записи</param>
|
||||
private static void WriteToFile(string text, FileStream stream)
|
||||
{
|
||||
byte[] info = new UTF8Encoding(true).GetBytes(text);
|
||||
stream.Write(info, 0, info.Length);
|
||||
}
|
||||
/// <summary>
|
||||
/// Сохранение информации по автомобилям в хранилище в файл
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns></returns>
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
using (FileStream fs = new(filename, FileMode.Create))
|
||||
using (StreamWriter sw = new StreamWriter(fs))
|
||||
{
|
||||
sw.Write($"MapsCollection{Environment.NewLine}", sw);
|
||||
foreach (var storage in _mapStorages)
|
||||
{
|
||||
sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}", sw);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Загрузка нформации по автомобилям на парковках из файла
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <returns></returns>
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
}
|
||||
using (FileStream fs = new(filename, FileMode.Open))
|
||||
using (StreamReader sr = new StreamReader(fs))
|
||||
{
|
||||
string line;
|
||||
line = sr.ReadLine();
|
||||
line.Trim();
|
||||
if (line != "MapsCollection")
|
||||
{
|
||||
throw new FileFormatException("Неправильный формат данных в файле");
|
||||
}
|
||||
_mapStorages.Clear();
|
||||
while ((line = sr.ReadLine()) != null)
|
||||
{
|
||||
line = line.Trim();
|
||||
var elem = line.Split(separatorDict);
|
||||
AbstractMap map = null;
|
||||
switch (elem[1])
|
||||
{
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "ModifyMap":
|
||||
map = new ModifyMap();
|
||||
break;
|
||||
}
|
||||
_mapStorages.Add(elem[0], new MapWithSetShipsGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
58
ContainerShip/ContainerShip/ModifyMap.cs
Normal file
58
ContainerShip/ContainerShip/ModifyMap.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Metrics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal class ModifyMap : AbstractMap
|
||||
{
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.WhiteSmoke);
|
||||
private readonly Brush roadColor = new SolidBrush(Color.Blue);
|
||||
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
Random random = new Random();
|
||||
int firstPointX;
|
||||
int secondPointX;
|
||||
int pointY;
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
while(counter < 15)
|
||||
{
|
||||
bool freePlace = true;
|
||||
firstPointX = random.Next(0, _map.GetLength(0)-10);
|
||||
secondPointX = random.Next(firstPointX, _map.GetLength(0)-10);
|
||||
pointY = random.Next(0, _map.GetLength(1)-10);
|
||||
for(int i = firstPointX; i <secondPointX; i++)
|
||||
{
|
||||
if (_map[i, pointY] == _barrier)
|
||||
{
|
||||
freePlace = false;
|
||||
break;
|
||||
}
|
||||
_map[i, pointY] = _barrier;
|
||||
}
|
||||
if (freePlace)
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,8 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using Serilog.Extensions.Logging;
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal static class Program
|
||||
@ -11,7 +16,27 @@ namespace ContainerShip
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormShip());
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||
{
|
||||
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetShips>());
|
||||
}
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<FormMapWithSetShips>()
|
||||
.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build();
|
||||
Serilog.Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
|
||||
option.AddSerilog();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
130
ContainerShip/ContainerShip/SetShipsGeneric.cs
Normal file
130
ContainerShip/ContainerShip/SetShipsGeneric.cs
Normal file
@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal class SetShipsGeneric<T>
|
||||
where T : class, IEquatable<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Список объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly List<T> _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в списке
|
||||
/// </summary>
|
||||
public int Count => _places.Count;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
private readonly int _maxCount;
|
||||
public SetShipsGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T>();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="car">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T ship)
|
||||
{
|
||||
return Insert(ship, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="ship">Добавляемый корабль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T ship, int position)
|
||||
{
|
||||
foreach (var checkShip in _places)
|
||||
{
|
||||
if (checkShip.Equals(ship)) {
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
}
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
throw new ShipNotFoundException(position);
|
||||
}
|
||||
if ( _places.Count >= _maxCount)
|
||||
{
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
}
|
||||
_places.Add(ship);
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
throw new ShipNotFoundException(position);
|
||||
}
|
||||
T ship = _places[position];
|
||||
_places.RemoveAt(position);
|
||||
return ship;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position < 0 || position > _maxCount) return null;
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position >= 0 || position < _maxCount)
|
||||
{
|
||||
Insert(value, position);
|
||||
}
|
||||
// TODO проверка позиции
|
||||
// TODO вставка в список по позиции
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проход по набору до первого пустого
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T> GetShips()
|
||||
{
|
||||
foreach (var ship in _places)
|
||||
{
|
||||
if (ship != null)
|
||||
{
|
||||
yield return ship;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void SortSet(IComparer<T> comparer)
|
||||
{
|
||||
if (comparer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.Sort(comparer);
|
||||
}
|
||||
}
|
||||
}
|
19
ContainerShip/ContainerShip/ShipNotFoundException.cs
Normal file
19
ContainerShip/ContainerShip/ShipNotFoundException.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
[Serializable]
|
||||
internal class ShipNotFoundException : ApplicationException
|
||||
{
|
||||
public ShipNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||
public ShipNotFoundException() : base() { }
|
||||
public ShipNotFoundException(string message) : base(message) { }
|
||||
public ShipNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
protected ShipNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
53
ContainerShip/ContainerShip/SimpleMap.cs
Normal file
53
ContainerShip/ContainerShip/SimpleMap.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
internal class SimpleMap : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.LightBlue);
|
||||
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y );
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 50)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
19
ContainerShip/ContainerShip/StorageOverflowException.cs
Normal file
19
ContainerShip/ContainerShip/StorageOverflowException.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
[Serializable]
|
||||
internal class StorageOverflowException : ApplicationException
|
||||
{
|
||||
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
|
||||
public StorageOverflowException() : base() { }
|
||||
public StorageOverflowException(string message) : base(message) { }
|
||||
public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
|
||||
protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
24
ContainerShip/ContainerShip/appsettings.json
Normal file
24
ContainerShip/ContainerShip/appsettings.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"exclude": [
|
||||
"/bin",
|
||||
"/bower_components",
|
||||
"/jspm_packages",
|
||||
"/node_modules",
|
||||
"/obj",
|
||||
"/platforms"
|
||||
],
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Debug",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": { "path": "Logs/log.txt" }
|
||||
}
|
||||
],
|
||||
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
|
||||
"Properties": {
|
||||
"Application": "Sample"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user