Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
f4b4408c24 |
@ -1,238 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
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 _freeWater = 0;
|
|
||||||
protected readonly int _barrier = 1;
|
|
||||||
/// <summary>
|
|
||||||
/// Функция инициализирует карту,
|
|
||||||
/// устанавливает объект и отрисовывает карту с объектом
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="width"></param>
|
|
||||||
/// <param name="height"></param>
|
|
||||||
/// <param name="drawingObject"></param>
|
|
||||||
/// <returns>Bitmap карты с объектом</returns>
|
|
||||||
public Bitmap CreateMap(int width, int height, IDrawingObject drawingObject)
|
|
||||||
{
|
|
||||||
_width = width;
|
|
||||||
_height = height;
|
|
||||||
_drawingObject = drawingObject;
|
|
||||||
GenerateMap();
|
|
||||||
while (!SetObjectOnMap())
|
|
||||||
{
|
|
||||||
GenerateMap();
|
|
||||||
}
|
|
||||||
return DrawMapWithObject();
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Функция для передвижения объекта по карте
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="direction"></param>
|
|
||||||
/// <returns>Bitmap карты с объектом</returns>
|
|
||||||
public Bitmap MoveObject(Direction direction)
|
|
||||||
{
|
|
||||||
// Проверка, что объект может переместится в требуемом направлении
|
|
||||||
// Получаем текщую позицию объекта
|
|
||||||
var objectPos = _drawingObject.GetCurrentPosition();
|
|
||||||
float currentX = objectPos.Left;
|
|
||||||
float currentY = objectPos.Top;
|
|
||||||
|
|
||||||
// В зависимости от направления уставналиваем dx, dy
|
|
||||||
float dx = 0;
|
|
||||||
float dy = 0;
|
|
||||||
switch (direction)
|
|
||||||
{
|
|
||||||
case Direction.None:
|
|
||||||
break;
|
|
||||||
case Direction.Up:
|
|
||||||
{
|
|
||||||
dy = -_drawingObject.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Direction.Down:
|
|
||||||
{
|
|
||||||
dy = _drawingObject.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Direction.Left:
|
|
||||||
{
|
|
||||||
dx = -_drawingObject.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Direction.Right:
|
|
||||||
{
|
|
||||||
dx = _drawingObject.Step;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// ЕСли нет коллизии, то перемещаем объект
|
|
||||||
if (!CheckCollision(currentX + dx, currentY + dy))
|
|
||||||
{
|
|
||||||
_drawingObject.MoveObject(direction);
|
|
||||||
}
|
|
||||||
return DrawMapWithObject();
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Функция пытается поместить объект на карту
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Если удачно возвращает true, иначе - false</returns>
|
|
||||||
private bool SetObjectOnMap()
|
|
||||||
{
|
|
||||||
if (_drawingObject == null || _map == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Генерируем новые координаты объекта
|
|
||||||
int x = _random.Next(100, 200);
|
|
||||||
int y = _random.Next(100, 200);
|
|
||||||
_drawingObject.SetObject(x, y, _width, _height);
|
|
||||||
|
|
||||||
// Проверка, что объект не "накладывается" на закрытые участки
|
|
||||||
return !CheckCollision(x, y);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Функция для проверки коллизии объекта с препятствиями на карте.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="x">Координата x объекта</param>
|
|
||||||
/// <param name="y">Координата y объекта</param>
|
|
||||||
/// <returns>Возвращает true если есть коллизия и false - если ее нет</returns>
|
|
||||||
protected bool CheckCollision(float x, float y)
|
|
||||||
{
|
|
||||||
// Получаем ширину и высоту отображаемого объекта
|
|
||||||
var objectPos = _drawingObject.GetCurrentPosition();
|
|
||||||
float objectWidth = objectPos.Right - objectPos.Left;
|
|
||||||
float objectHeight = objectPos.Bottom - objectPos.Top;
|
|
||||||
|
|
||||||
// Теперь узнаем сколько клеток в ширину и высоту объект занимает на карте
|
|
||||||
int objectCellsCountX = (int)Math.Ceiling(objectWidth / _size_x);
|
|
||||||
int objectCellsCountY = (int)Math.Ceiling(objectHeight / _size_y);
|
|
||||||
|
|
||||||
// Получим координаты объекта в сетке карты
|
|
||||||
int objectMapX = (int)Math.Floor((float)x / _size_x);
|
|
||||||
int objectMapY = (int)Math.Floor((float)y / _size_y);
|
|
||||||
|
|
||||||
// В цикле проверяем все клетки карты на коллизию с объектом
|
|
||||||
int dy = 0;
|
|
||||||
int mapCellsX = _map.GetLength(1);
|
|
||||||
int mapCellsY = _map.GetLength(0);
|
|
||||||
int mapState = _freeWater;
|
|
||||||
|
|
||||||
while (objectMapY + dy < mapCellsY && dy <= objectCellsCountY)
|
|
||||||
{
|
|
||||||
int dx = 0;
|
|
||||||
while (objectMapX + dx < mapCellsX && dx <= objectCellsCountX)
|
|
||||||
{
|
|
||||||
mapState = _map[objectMapX + dx, objectMapY + dy];
|
|
||||||
if (mapState == _barrier)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
dx++;
|
|
||||||
}
|
|
||||||
dy++;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Функция для отрисовки карты с объектом
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
private Bitmap DrawMapWithObject()
|
|
||||||
{
|
|
||||||
Bitmap bmp = new(_width, _height);
|
|
||||||
if (_drawingObject == null || _map == null)
|
|
||||||
{
|
|
||||||
return bmp;
|
|
||||||
}
|
|
||||||
Graphics g = 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] == _freeWater)
|
|
||||||
{
|
|
||||||
DrawWaterPart(g, i, j);
|
|
||||||
}
|
|
||||||
else if (_map[i, j] == _barrier)
|
|
||||||
{
|
|
||||||
DrawBarrierPart(g, i, j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_drawingObject.DrawingObject(g);
|
|
||||||
return bmp;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Метод для генерации карты
|
|
||||||
/// </summary>
|
|
||||||
protected abstract void GenerateMap();
|
|
||||||
/// <summary>
|
|
||||||
/// Метод для отрисовки свободного участка на экране
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
/// <param name="i"></param>
|
|
||||||
/// <param name="j"></param>
|
|
||||||
protected abstract void DrawWaterPart(Graphics g, int i, int j);
|
|
||||||
/// <summary>
|
|
||||||
/// Метод для отрисовки закрытого участка на экране
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
/// <param name="i"></param>
|
|
||||||
/// <param name="j"></param>
|
|
||||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
|
||||||
|
|
||||||
public bool Equals(AbstractMap? other)
|
|
||||||
{
|
|
||||||
if (other == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
var otherMap = other as AbstractMap;
|
|
||||||
if (otherMap == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (_width != otherMap._width)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (_height != otherMap._height)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (_size_x != otherMap._size_x)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (_size_y != otherMap._size_y)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < _map.GetLength(0); i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < _map.GetLength(1); j++)
|
|
||||||
{
|
|
||||||
if (_map[i, j] != otherMap._map[i, j])
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
internal class BoatCompareByColor : 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 xBoat = x as DrawingObjectBoat;
|
|
||||||
var yBoat = y as DrawingObjectBoat;
|
|
||||||
if (xBoat == null && yBoat == null)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (xBoat == null && yBoat != null)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (xBoat != null && yBoat == null)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
string xBoatColor = xBoat.GetBoat.Boat.BodyColor.Name;
|
|
||||||
string yBoatColor = yBoat.GetBoat.Boat.BodyColor.Name;
|
|
||||||
if (xBoatColor != yBoatColor)
|
|
||||||
{
|
|
||||||
return xBoatColor.CompareTo(yBoatColor);
|
|
||||||
}
|
|
||||||
if (xBoat.GetBoat.GetType().Name != yBoat.GetBoat.GetType().Name)
|
|
||||||
{
|
|
||||||
if (xBoat.GetBoat.GetType().Name == "DrawingBoat")
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (xBoat.GetBoat.Boat is EntityCatamaran xCatamaran &&
|
|
||||||
yBoat.GetBoat.Boat is EntityCatamaran yCatamaran)
|
|
||||||
{
|
|
||||||
string xBoatDopColor = xCatamaran.DopColor.Name;
|
|
||||||
string yBoatDopColor = yCatamaran.DopColor.Name;
|
|
||||||
var dopColorCompare = xBoatDopColor.CompareTo(yBoatDopColor);
|
|
||||||
if (dopColorCompare != 0)
|
|
||||||
{
|
|
||||||
return dopColorCompare;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var speedCompare = xBoat.GetBoat.Boat.Speed.CompareTo(yBoat.GetBoat.Boat.Speed);
|
|
||||||
if (speedCompare != 0)
|
|
||||||
{
|
|
||||||
return speedCompare;
|
|
||||||
}
|
|
||||||
return xBoat.GetBoat.Boat.Weight.CompareTo(yBoat.GetBoat.Boat.Weight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
internal class BoatCompareByType : 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 xBoat = x as DrawingObjectBoat;
|
|
||||||
var yBoat = y as DrawingObjectBoat;
|
|
||||||
if (xBoat == null && yBoat == null)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (xBoat == null && yBoat != null)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (xBoat != null && yBoat == null)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (xBoat.GetBoat.GetType().Name != yBoat.GetBoat.GetType().Name)
|
|
||||||
{
|
|
||||||
if (xBoat.GetBoat.GetType().Name == "DrawingBoat")
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
var speedCompare = xBoat.GetBoat.Boat.Speed.CompareTo(yBoat.GetBoat.Boat.Speed);
|
|
||||||
if (speedCompare != 0)
|
|
||||||
{
|
|
||||||
return speedCompare;
|
|
||||||
}
|
|
||||||
return xBoat.GetBoat.Boat.Weight.CompareTo(yBoat.GetBoat.Boat.Weight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Делегат для передачи объекта-лодки
|
|
||||||
/// </summary>
|
|
||||||
public delegate void BoatDelegate(DrawingBoat boat);
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
[Serializable]
|
|
||||||
internal class BoatNotFoundException : ApplicationException
|
|
||||||
{
|
|
||||||
public BoatNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
|
||||||
public BoatNotFoundException() : base() { }
|
|
||||||
public BoatNotFoundException(string message) : base(message) { }
|
|
||||||
public BoatNotFoundException(string message, Exception exception) : base(message, exception) { }
|
|
||||||
protected BoatNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,29 +8,6 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Remove="appSettings.json" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<EmbeddedResource Include="appSettings.json">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</EmbeddedResource>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Update="Properties\Resources.Designer.cs">
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
@ -46,6 +23,4 @@
|
|||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ProjectExtensions><VisualStudio><UserProperties jsconfig1_1json__JsonSchema="{" /></VisualStudio></ProjectExtensions>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
@ -9,9 +9,8 @@ namespace Boats
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Направление перемещения
|
/// Направление перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum Direction
|
internal enum Direction
|
||||||
{
|
{
|
||||||
None = 0,
|
|
||||||
Up = 1,
|
Up = 1,
|
||||||
Down = 2,
|
Down = 2,
|
||||||
Left = 3,
|
Left = 3,
|
||||||
|
@ -9,20 +9,20 @@ namespace Boats
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DrawingBoat
|
internal class DrawingBoat
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityBoat Boat { protected set; get; }
|
public EntityBoat Boat { private set; get; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата отрисовки лодки
|
/// Левая координата отрисовки лодки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected float _startPosX;
|
private float _startPosX;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната отрисовки лодки
|
/// Верхняя кооридната отрисовки лодки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected float _startPosY;
|
private float _startPosY;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -34,34 +34,21 @@ namespace Boats
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина отрисовки лодки
|
/// Ширина отрисовки лодки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly int _boatWidth = 100;
|
private readonly int _boatWidth = 100;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота отрисовки лодки
|
/// Высота отрисовки лодки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly int _boatHeight = 40;
|
private readonly int _boatHeight = 40;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Инициализация свойств
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">Вес лодки</param>
|
/// <param name="weight">Вес лодки</param>
|
||||||
/// <param name="bodyColor">Цвет корпуса</param>
|
/// <param name="bodyColor">Цвет корпуса</param>
|
||||||
public DrawingBoat(int speed, float weight, Color bodyColor)
|
public void Init(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Boat = new EntityBoat(speed, weight, bodyColor);
|
Boat = new EntityBoat();
|
||||||
}
|
Boat.Init(speed, weight, bodyColor);
|
||||||
/// <summary>
|
|
||||||
/// Инициализация свойств
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес лодки</param>
|
|
||||||
/// <param name="bodyColor">Цвет корпуса</param>
|
|
||||||
/// <param name="boatWidth">Ширина отрисовки лодки</param>
|
|
||||||
/// <param name="boatHeight">Высота отрисовки лодки</param>
|
|
||||||
protected DrawingBoat(int speed, float weight, Color bodyColor, int boatWidth, int boatHeight) :
|
|
||||||
this(speed, weight, bodyColor)
|
|
||||||
{
|
|
||||||
_boatWidth = boatWidth;
|
|
||||||
_boatHeight = boatHeight;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиции лодки
|
/// Установка позиции лодки
|
||||||
@ -127,7 +114,7 @@ namespace Boats
|
|||||||
/// Отрисовка лодки
|
/// Отрисовка лодки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public virtual void DrawTransport(Graphics g)
|
public void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (_startPosX < 0 || _startPosY < 0
|
if (_startPosX < 0 || _startPosY < 0
|
||||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||||
@ -178,13 +165,5 @@ namespace Boats
|
|||||||
_startPosY = _pictureHeight.Value - _boatHeight;
|
_startPosY = _pictureHeight.Value - _boatHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Получение текущей позиции объекта
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public (float Left, float Top, float Right, float Bottom) GetCurrentPosition()
|
|
||||||
{
|
|
||||||
return (_startPosX, _startPosY, _startPosX + _boatWidth, _startPosY + _boatHeight);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,82 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Класс для отрисовки катамарана
|
|
||||||
/// </summary>
|
|
||||||
internal class DrawingCatamaran : DrawingBoat
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Инициализация свойств
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес катамарана</param>
|
|
||||||
/// <param name="bodyColor">Цвет корпуса</param>
|
|
||||||
/// <param name="dopColor">Дополнительный цвет</param>
|
|
||||||
/// <param name="bobbers">Признак наличия поплавков</param>
|
|
||||||
/// <param name="sail">Признак наличия паруса</param>
|
|
||||||
public DrawingCatamaran(int speed, float weight, Color bodyColor,
|
|
||||||
Color dopColor, bool bobbers, bool sail) :
|
|
||||||
base(speed, weight, bodyColor, 110, 60)
|
|
||||||
{
|
|
||||||
Boat = new EntityCatamaran(speed, weight, bodyColor, dopColor, bobbers, sail);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Метод для отрисовки катамарана
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
public override void DrawTransport(Graphics g)
|
|
||||||
{
|
|
||||||
if (Boat is not EntityCatamaran catamaran)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Brush dopBrush = new SolidBrush(catamaran.DopColor);
|
|
||||||
|
|
||||||
int bobbersWidth = _boatWidth / 4;
|
|
||||||
int bobbersHeight = _boatHeight / 5;
|
|
||||||
|
|
||||||
base.DrawTransport(g);
|
|
||||||
|
|
||||||
if (catamaran.Bobbers)
|
|
||||||
{
|
|
||||||
// Отрисовка верхних поплавков
|
|
||||||
g.FillRectangle(dopBrush, _startPosX, _startPosY, bobbersWidth, bobbersHeight);
|
|
||||||
g.DrawRectangle(Pens.Black, _startPosX, _startPosY, bobbersWidth, bobbersHeight);
|
|
||||||
g.DrawRectangle(Pens.Black, _startPosX + bobbersWidth / 4, _startPosY, bobbersWidth / 2, bobbersHeight);
|
|
||||||
|
|
||||||
g.FillRectangle(dopBrush, _startPosX + _boatWidth / 2, _startPosY, _boatWidth / 4, bobbersHeight);
|
|
||||||
g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2, _startPosY, _boatWidth / 4, bobbersHeight);
|
|
||||||
g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2 + bobbersWidth / 4, _startPosY, bobbersWidth / 2, bobbersHeight);
|
|
||||||
|
|
||||||
// Отрисовка нижних поплавков
|
|
||||||
g.FillRectangle(dopBrush, _startPosX, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight);
|
|
||||||
g.DrawRectangle(Pens.Black, _startPosX, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight);
|
|
||||||
g.DrawRectangle(Pens.Black, _startPosX + bobbersWidth / 4, _startPosY + _boatHeight - bobbersHeight, bobbersWidth / 2, bobbersHeight);
|
|
||||||
|
|
||||||
g.FillRectangle(dopBrush, _startPosX + _boatWidth / 2, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight);
|
|
||||||
g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight);
|
|
||||||
g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2 + bobbersWidth / 4, _startPosY + _boatHeight - bobbersHeight, bobbersWidth / 2, bobbersHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (catamaran.Sail)
|
|
||||||
{
|
|
||||||
float downPointSailX = _startPosX + _boatWidth / 2 - _boatWidth / 8;
|
|
||||||
float downPointSailY = _startPosY + _boatHeight / 2 + _boatWidth / 8;
|
|
||||||
|
|
||||||
PointF[] sailPoints = new PointF[3];
|
|
||||||
sailPoints[0] = new PointF(downPointSailX, downPointSailY);
|
|
||||||
sailPoints[1] = new PointF(downPointSailX, _startPosY);
|
|
||||||
sailPoints[2] = new PointF(downPointSailX - _boatWidth / 4, downPointSailY - _boatHeight / 4);
|
|
||||||
// Отрисовка паруса
|
|
||||||
g.FillPolygon(dopBrush, sailPoints);
|
|
||||||
g.DrawPolygon(Pens.Black, sailPoints);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
internal class DrawingObjectBoat : IDrawingObject
|
|
||||||
{
|
|
||||||
private DrawingBoat _boat = null;
|
|
||||||
public DrawingBoat GetBoat => _boat;
|
|
||||||
public DrawingObjectBoat(DrawingBoat boat)
|
|
||||||
{
|
|
||||||
_boat = boat;
|
|
||||||
}
|
|
||||||
public float Step => _boat?.Boat?.Step ?? 0;
|
|
||||||
public (float Left, float Top, float Right, float Bottom) GetCurrentPosition()
|
|
||||||
{
|
|
||||||
return _boat?.GetCurrentPosition() ?? default;
|
|
||||||
}
|
|
||||||
public void MoveObject(Direction direction)
|
|
||||||
{
|
|
||||||
_boat?.MoveTransport(direction);
|
|
||||||
}
|
|
||||||
public void SetObject(int x, int y, int width, int height)
|
|
||||||
{
|
|
||||||
_boat.SetPosition(x, y, width, height);
|
|
||||||
}
|
|
||||||
public void DrawingObject(Graphics g)
|
|
||||||
{
|
|
||||||
_boat.DrawTransport(g);
|
|
||||||
}
|
|
||||||
public string GetInfo() => _boat?.GetDataForSave();
|
|
||||||
public static IDrawingObject Create(string data) => new DrawingObjectBoat(data.CreateDrawingBoat());
|
|
||||||
|
|
||||||
public bool Equals(IDrawingObject? other)
|
|
||||||
{
|
|
||||||
if (other == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
var otherBoat = other as DrawingObjectBoat;
|
|
||||||
if (otherBoat == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
var boat = _boat.Boat;
|
|
||||||
var otherBoatBoat = otherBoat._boat.Boat;
|
|
||||||
if (boat.Speed != otherBoatBoat.Speed)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (boat.Weight != otherBoatBoat.Weight)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (boat.BodyColor != otherBoatBoat.BodyColor)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (boat is EntityCatamaran catamaran)
|
|
||||||
{
|
|
||||||
if (otherBoatBoat is EntityCatamaran otherCatamaran)
|
|
||||||
{
|
|
||||||
if (catamaran.Sail != otherCatamaran.Sail)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (catamaran.Bobbers != otherCatamaran.Bobbers)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (catamaran.DopColor != otherCatamaran.DopColor)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,7 +9,7 @@ namespace Boats
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность "Лодка"
|
/// Класс-сущность "Лодка"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EntityBoat
|
internal class EntityBoat
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Скорость
|
/// Скорость
|
||||||
@ -22,7 +22,7 @@ namespace Boats
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Цвет корпуса
|
/// Цвет корпуса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Color BodyColor { get; set; }
|
public Color BodyColor { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Шаг перемещения лодки
|
/// Шаг перемещения лодки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -34,7 +34,7 @@ namespace Boats
|
|||||||
/// <param name="weight"></param>
|
/// <param name="weight"></param>
|
||||||
/// <param name="bodyColor"></param>
|
/// <param name="bodyColor"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public EntityBoat(int speed, float weight, Color bodyColor)
|
public void Init(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
internal class EntityCatamaran : EntityBoat
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Дополнительный цвет
|
|
||||||
/// </summary>
|
|
||||||
public Color DopColor { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Признак наличия поплавков
|
|
||||||
/// </summary>
|
|
||||||
public bool Bobbers { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Признак наличия паруса
|
|
||||||
/// </summary>
|
|
||||||
public bool Sail { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Инициализация свойств
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес катамарана</param>
|
|
||||||
/// <param name="bodyColor">Цвет корпуса</param>
|
|
||||||
/// <param name="dopColor">Дополнительный цвет</param>
|
|
||||||
/// <param name="bobbers">Признак наличия поплавков</param>
|
|
||||||
/// <param name="sail">Признак наличия паруса</param>
|
|
||||||
public EntityCatamaran(int speed, float weight, Color bodyColor,
|
|
||||||
Color dopColor, bool bobbers, bool sail) :
|
|
||||||
base(speed, weight, bodyColor)
|
|
||||||
{
|
|
||||||
DopColor = dopColor;
|
|
||||||
Bobbers = bobbers;
|
|
||||||
Sail = sail;
|
|
||||||
}
|
|
||||||
public void SetDopColor(Color color)
|
|
||||||
{
|
|
||||||
DopColor = color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Расширение для класса DrawingBoat
|
|
||||||
/// </summary>
|
|
||||||
internal static class ExtentionBoat
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Разделитель для записи информации по объекту в файл
|
|
||||||
/// </summary>
|
|
||||||
private static readonly char _separatorForObject = ':';
|
|
||||||
/// <summary>
|
|
||||||
/// Создание объекта из строки
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="info"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static DrawingBoat CreateDrawingBoat(this string info)
|
|
||||||
{
|
|
||||||
string[] strs = info.Split(_separatorForObject);
|
|
||||||
if (strs.Length == 3)
|
|
||||||
{
|
|
||||||
return new DrawingBoat(
|
|
||||||
Convert.ToInt32(strs[0]),
|
|
||||||
Convert.ToInt32(strs[1]),
|
|
||||||
Color.FromName(strs[2])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (strs.Length == 6)
|
|
||||||
{
|
|
||||||
return new DrawingCatamaran(
|
|
||||||
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="drawingBoat"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static string GetDataForSave(this DrawingBoat drawingBoat)
|
|
||||||
{
|
|
||||||
var boat = drawingBoat.Boat;
|
|
||||||
var str = $"{boat.Speed}{_separatorForObject}{boat.Weight}{_separatorForObject}{boat.BodyColor.Name}";
|
|
||||||
if (boat is not EntityCatamaran catamaran)
|
|
||||||
{
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
return $"{str}{_separatorForObject}{catamaran.DopColor.Name}{_separatorForObject}{catamaran.Bobbers}{_separatorForObject}{catamaran.Sail}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
28
Boats/Boats/FormBoat.Designer.cs
generated
28
Boats/Boats/FormBoat.Designer.cs
generated
@ -38,8 +38,6 @@
|
|||||||
this.ButtonLeft = new System.Windows.Forms.Button();
|
this.ButtonLeft = new System.Windows.Forms.Button();
|
||||||
this.ButtonRight = new System.Windows.Forms.Button();
|
this.ButtonRight = new System.Windows.Forms.Button();
|
||||||
this.ButtonDown = new System.Windows.Forms.Button();
|
this.ButtonDown = new System.Windows.Forms.Button();
|
||||||
this.ButtonCreateModificate = new System.Windows.Forms.Button();
|
|
||||||
this.ButtonSelectBoat = new System.Windows.Forms.Button();
|
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBoat)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBoat)).BeginInit();
|
||||||
this.statusStrip.SuspendLayout();
|
this.statusStrip.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -145,35 +143,11 @@
|
|||||||
this.ButtonDown.UseVisualStyleBackColor = true;
|
this.ButtonDown.UseVisualStyleBackColor = true;
|
||||||
this.ButtonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
this.ButtonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
// ButtonCreateModificate
|
|
||||||
//
|
|
||||||
this.ButtonCreateModificate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
|
||||||
this.ButtonCreateModificate.Location = new System.Drawing.Point(138, 381);
|
|
||||||
this.ButtonCreateModificate.Name = "ButtonCreateModificate";
|
|
||||||
this.ButtonCreateModificate.Size = new System.Drawing.Size(117, 29);
|
|
||||||
this.ButtonCreateModificate.TabIndex = 7;
|
|
||||||
this.ButtonCreateModificate.Text = "Модификация";
|
|
||||||
this.ButtonCreateModificate.UseVisualStyleBackColor = true;
|
|
||||||
this.ButtonCreateModificate.Click += new System.EventHandler(this.ButtonCreateModificate_Click);
|
|
||||||
//
|
|
||||||
// ButtonSelectBoat
|
|
||||||
//
|
|
||||||
this.ButtonSelectBoat.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
|
||||||
this.ButtonSelectBoat.Location = new System.Drawing.Point(491, 381);
|
|
||||||
this.ButtonSelectBoat.Name = "ButtonSelectBoat";
|
|
||||||
this.ButtonSelectBoat.Size = new System.Drawing.Size(117, 29);
|
|
||||||
this.ButtonSelectBoat.TabIndex = 8;
|
|
||||||
this.ButtonSelectBoat.Text = "Выбрать";
|
|
||||||
this.ButtonSelectBoat.UseVisualStyleBackColor = true;
|
|
||||||
this.ButtonSelectBoat.Click += new System.EventHandler(this.ButtonSelectBoat_Click);
|
|
||||||
//
|
|
||||||
// FormBoat
|
// FormBoat
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
this.Controls.Add(this.ButtonSelectBoat);
|
|
||||||
this.Controls.Add(this.ButtonCreateModificate);
|
|
||||||
this.Controls.Add(this.ButtonDown);
|
this.Controls.Add(this.ButtonDown);
|
||||||
this.Controls.Add(this.ButtonRight);
|
this.Controls.Add(this.ButtonRight);
|
||||||
this.Controls.Add(this.ButtonLeft);
|
this.Controls.Add(this.ButtonLeft);
|
||||||
@ -203,7 +177,5 @@
|
|||||||
private Button ButtonLeft;
|
private Button ButtonLeft;
|
||||||
private Button ButtonRight;
|
private Button ButtonRight;
|
||||||
private Button ButtonDown;
|
private Button ButtonDown;
|
||||||
private Button ButtonCreateModificate;
|
|
||||||
private Button ButtonSelectBoat;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,29 +12,12 @@ namespace Boats
|
|||||||
{
|
{
|
||||||
public partial class FormBoat : Form
|
public partial class FormBoat : Form
|
||||||
{
|
{
|
||||||
DrawingBoat _boat;
|
private DrawingBoat _boat;
|
||||||
public DrawingBoat SelectedBoat { get; private set; }
|
|
||||||
public FormBoat()
|
public FormBoat()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Метод установки данных
|
|
||||||
/// </summary>
|
|
||||||
private void SetData()
|
|
||||||
{
|
|
||||||
Random rnd = new Random();
|
|
||||||
_boat.SetPosition(
|
|
||||||
rnd.Next(10, 100),
|
|
||||||
rnd.Next(10, 100),
|
|
||||||
pictureBoxBoat.Width,
|
|
||||||
pictureBoxBoat.Height
|
|
||||||
);
|
|
||||||
toolStripStatusLabelSpeed.Text = $"Скорость: {_boat.Boat.Speed}";
|
|
||||||
toolStripStatusLabelWeight.Text = $"Вес: {_boat.Boat.Weight}";
|
|
||||||
toolStripStatusLabelBodyColor.Text = $"Цвет: {_boat.Boat.BodyColor.Name}";
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Метод прорисовки лодки
|
/// Метод прорисовки лодки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Draw()
|
private void Draw()
|
||||||
@ -45,23 +28,29 @@ namespace Boats
|
|||||||
pictureBoxBoat.Image = bmp;
|
pictureBoxBoat.Image = bmp;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обработчик нажатия кнопки "Создать"
|
/// Обработка нажатия кнопки "Создать"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new Random();
|
Random rnd = new();
|
||||||
Color color = Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255));
|
_boat = new DrawingBoat();
|
||||||
ColorDialog dialog = new ColorDialog();
|
_boat.Init(
|
||||||
if (dialog.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
color = dialog.Color;
|
|
||||||
}
|
|
||||||
_boat = new DrawingBoat(
|
|
||||||
rnd.Next(100, 300),
|
rnd.Next(100, 300),
|
||||||
rnd.Next(1000, 3000),
|
rnd.Next(1000, 2000),
|
||||||
color
|
Color.FromArgb(rnd.Next(0, 256),
|
||||||
|
rnd.Next(0, 256), rnd.Next(0, 256))
|
||||||
);
|
);
|
||||||
SetData();
|
_boat.SetPosition(
|
||||||
|
rnd.Next(10, 100),
|
||||||
|
rnd.Next(10, 100),
|
||||||
|
pictureBoxBoat.Width,
|
||||||
|
pictureBoxBoat.Height
|
||||||
|
);
|
||||||
|
toolStripStatusLabelSpeed.Text = $"Скорость: {_boat.Boat.Speed}";
|
||||||
|
toolStripStatusLabelWeight.Text = $"Вес: {_boat.Boat.Weight}";
|
||||||
|
toolStripStatusLabelBodyColor.Text = $"Цвет: {_boat.Boat.BodyColor.Name}";
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -71,34 +60,21 @@ namespace Boats
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_boat == null)
|
//получаем имя кнопки
|
||||||
return;
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
switch (name)
|
||||||
string btnName = ((Button)sender).Name;
|
|
||||||
|
|
||||||
switch (btnName)
|
|
||||||
{
|
{
|
||||||
case "ButtonUp":
|
case "ButtonUp":
|
||||||
{
|
_boat?.MoveTransport(Direction.Up);
|
||||||
_boat.MoveTransport(Direction.Up);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "ButtonDown":
|
case "ButtonDown":
|
||||||
{
|
_boat?.MoveTransport(Direction.Down);
|
||||||
_boat.MoveTransport(Direction.Down);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "ButtonLeft":
|
case "ButtonLeft":
|
||||||
{
|
_boat?.MoveTransport(Direction.Left);
|
||||||
_boat.MoveTransport(Direction.Left);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "ButtonRight":
|
case "ButtonRight":
|
||||||
{
|
_boat?.MoveTransport(Direction.Right);
|
||||||
_boat.MoveTransport(Direction.Right);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
@ -113,52 +89,5 @@ namespace Boats
|
|||||||
_boat?.ChangeBorders(pictureBoxBoat.Width, pictureBoxBoat.Height);
|
_boat?.ChangeBorders(pictureBoxBoat.Width, pictureBoxBoat.Height);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Обработка нажатия кнопки "Модификация"
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ButtonCreateModificate_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Random rnd = new Random();
|
|
||||||
|
|
||||||
// Предлагаем установить свой основной цвет
|
|
||||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
|
||||||
ColorDialog dialog = new ColorDialog();
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
_boat = new DrawingCatamaran(
|
|
||||||
rnd.Next(100, 300),
|
|
||||||
rnd.Next(1000, 3000),
|
|
||||||
color,
|
|
||||||
dopColor,
|
|
||||||
Convert.ToBoolean(rnd.Next(0, 2)),
|
|
||||||
Convert.ToBoolean(rnd.Next(0, 2))
|
|
||||||
);
|
|
||||||
|
|
||||||
SetData();
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Обработка нажатия кнопки "Выбрать"
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ButtonSelectBoat_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
SelectedBoat = _boat;
|
|
||||||
DialogResult = DialogResult.OK;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
369
Boats/Boats/FormBoatConfig.Designer.cs
generated
369
Boats/Boats/FormBoatConfig.Designer.cs
generated
@ -1,369 +0,0 @@
|
|||||||
namespace Boats
|
|
||||||
{
|
|
||||||
partial class FormBoatConfig
|
|
||||||
{
|
|
||||||
/// <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.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.panelNavy = new System.Windows.Forms.Panel();
|
|
||||||
this.panelBlack = new System.Windows.Forms.Panel();
|
|
||||||
this.panelGray = new System.Windows.Forms.Panel();
|
|
||||||
this.panelWhite = new System.Windows.Forms.Panel();
|
|
||||||
this.panelYellow = new System.Windows.Forms.Panel();
|
|
||||||
this.panelBlue = new System.Windows.Forms.Panel();
|
|
||||||
this.panelGreen = new System.Windows.Forms.Panel();
|
|
||||||
this.panelRed = new System.Windows.Forms.Panel();
|
|
||||||
this.checkBoxSail = new System.Windows.Forms.CheckBox();
|
|
||||||
this.checkBoxBobbers = new System.Windows.Forms.CheckBox();
|
|
||||||
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
|
|
||||||
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
|
|
||||||
this.labelWeight = new System.Windows.Forms.Label();
|
|
||||||
this.labelSpeed = new System.Windows.Forms.Label();
|
|
||||||
this.buttonOk = new System.Windows.Forms.Button();
|
|
||||||
this.panelObject = new System.Windows.Forms.Panel();
|
|
||||||
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
|
|
||||||
this.labelDopColor = new System.Windows.Forms.Label();
|
|
||||||
this.labelBaseColor = new System.Windows.Forms.Label();
|
|
||||||
this.buttonCancel = new System.Windows.Forms.Button();
|
|
||||||
this.groupBoxConfig.SuspendLayout();
|
|
||||||
this.groupBoxColors.SuspendLayout();
|
|
||||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
|
|
||||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
|
|
||||||
this.panelObject.SuspendLayout();
|
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
|
|
||||||
this.SuspendLayout();
|
|
||||||
//
|
|
||||||
// groupBoxConfig
|
|
||||||
//
|
|
||||||
this.groupBoxConfig.Controls.Add(this.labelModifiedObject);
|
|
||||||
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
|
|
||||||
this.groupBoxConfig.Controls.Add(this.groupBoxColors);
|
|
||||||
this.groupBoxConfig.Controls.Add(this.checkBoxSail);
|
|
||||||
this.groupBoxConfig.Controls.Add(this.checkBoxBobbers);
|
|
||||||
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
|
|
||||||
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
|
|
||||||
this.groupBoxConfig.Controls.Add(this.labelWeight);
|
|
||||||
this.groupBoxConfig.Controls.Add(this.labelSpeed);
|
|
||||||
this.groupBoxConfig.Location = new System.Drawing.Point(12, 12);
|
|
||||||
this.groupBoxConfig.Name = "groupBoxConfig";
|
|
||||||
this.groupBoxConfig.Size = new System.Drawing.Size(551, 243);
|
|
||||||
this.groupBoxConfig.TabIndex = 0;
|
|
||||||
this.groupBoxConfig.TabStop = false;
|
|
||||||
this.groupBoxConfig.Text = "Параметры";
|
|
||||||
//
|
|
||||||
// labelModifiedObject
|
|
||||||
//
|
|
||||||
this.labelModifiedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
|
||||||
this.labelModifiedObject.Location = new System.Drawing.Point(406, 178);
|
|
||||||
this.labelModifiedObject.Name = "labelModifiedObject";
|
|
||||||
this.labelModifiedObject.Size = new System.Drawing.Size(119, 48);
|
|
||||||
this.labelModifiedObject.TabIndex = 6;
|
|
||||||
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(267, 178);
|
|
||||||
this.labelSimpleObject.Name = "labelSimpleObject";
|
|
||||||
this.labelSimpleObject.Size = new System.Drawing.Size(119, 48);
|
|
||||||
this.labelSimpleObject.TabIndex = 1;
|
|
||||||
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.panelNavy);
|
|
||||||
this.groupBoxColors.Controls.Add(this.panelBlack);
|
|
||||||
this.groupBoxColors.Controls.Add(this.panelGray);
|
|
||||||
this.groupBoxColors.Controls.Add(this.panelWhite);
|
|
||||||
this.groupBoxColors.Controls.Add(this.panelYellow);
|
|
||||||
this.groupBoxColors.Controls.Add(this.panelBlue);
|
|
||||||
this.groupBoxColors.Controls.Add(this.panelGreen);
|
|
||||||
this.groupBoxColors.Controls.Add(this.panelRed);
|
|
||||||
this.groupBoxColors.Location = new System.Drawing.Point(251, 8);
|
|
||||||
this.groupBoxColors.Name = "groupBoxColors";
|
|
||||||
this.groupBoxColors.Size = new System.Drawing.Size(288, 155);
|
|
||||||
this.groupBoxColors.TabIndex = 1;
|
|
||||||
this.groupBoxColors.TabStop = false;
|
|
||||||
this.groupBoxColors.Text = "Цвета";
|
|
||||||
//
|
|
||||||
// panelNavy
|
|
||||||
//
|
|
||||||
this.panelNavy.AllowDrop = true;
|
|
||||||
this.panelNavy.BackColor = System.Drawing.Color.Navy;
|
|
||||||
this.panelNavy.Location = new System.Drawing.Point(220, 94);
|
|
||||||
this.panelNavy.Name = "panelNavy";
|
|
||||||
this.panelNavy.Size = new System.Drawing.Size(50, 50);
|
|
||||||
this.panelNavy.TabIndex = 6;
|
|
||||||
//
|
|
||||||
// panelBlack
|
|
||||||
//
|
|
||||||
this.panelBlack.AllowDrop = true;
|
|
||||||
this.panelBlack.BackColor = System.Drawing.Color.Black;
|
|
||||||
this.panelBlack.Location = new System.Drawing.Point(155, 94);
|
|
||||||
this.panelBlack.Name = "panelBlack";
|
|
||||||
this.panelBlack.Size = new System.Drawing.Size(50, 50);
|
|
||||||
this.panelBlack.TabIndex = 5;
|
|
||||||
//
|
|
||||||
// panelGray
|
|
||||||
//
|
|
||||||
this.panelGray.AllowDrop = true;
|
|
||||||
this.panelGray.BackColor = System.Drawing.Color.Gray;
|
|
||||||
this.panelGray.Location = new System.Drawing.Point(85, 94);
|
|
||||||
this.panelGray.Name = "panelGray";
|
|
||||||
this.panelGray.Size = new System.Drawing.Size(50, 50);
|
|
||||||
this.panelGray.TabIndex = 4;
|
|
||||||
//
|
|
||||||
// panelWhite
|
|
||||||
//
|
|
||||||
this.panelWhite.AllowDrop = true;
|
|
||||||
this.panelWhite.BackColor = System.Drawing.Color.White;
|
|
||||||
this.panelWhite.Location = new System.Drawing.Point(16, 94);
|
|
||||||
this.panelWhite.Name = "panelWhite";
|
|
||||||
this.panelWhite.Size = new System.Drawing.Size(50, 50);
|
|
||||||
this.panelWhite.TabIndex = 3;
|
|
||||||
//
|
|
||||||
// panelYellow
|
|
||||||
//
|
|
||||||
this.panelYellow.AllowDrop = true;
|
|
||||||
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
|
|
||||||
this.panelYellow.Location = new System.Drawing.Point(220, 26);
|
|
||||||
this.panelYellow.Name = "panelYellow";
|
|
||||||
this.panelYellow.Size = new System.Drawing.Size(50, 50);
|
|
||||||
this.panelYellow.TabIndex = 1;
|
|
||||||
//
|
|
||||||
// panelBlue
|
|
||||||
//
|
|
||||||
this.panelBlue.AllowDrop = true;
|
|
||||||
this.panelBlue.BackColor = System.Drawing.Color.Blue;
|
|
||||||
this.panelBlue.Location = new System.Drawing.Point(155, 26);
|
|
||||||
this.panelBlue.Name = "panelBlue";
|
|
||||||
this.panelBlue.Size = new System.Drawing.Size(50, 50);
|
|
||||||
this.panelBlue.TabIndex = 2;
|
|
||||||
//
|
|
||||||
// panelGreen
|
|
||||||
//
|
|
||||||
this.panelGreen.AllowDrop = true;
|
|
||||||
this.panelGreen.BackColor = System.Drawing.Color.Green;
|
|
||||||
this.panelGreen.Location = new System.Drawing.Point(85, 26);
|
|
||||||
this.panelGreen.Name = "panelGreen";
|
|
||||||
this.panelGreen.Size = new System.Drawing.Size(50, 50);
|
|
||||||
this.panelGreen.TabIndex = 1;
|
|
||||||
//
|
|
||||||
// panelRed
|
|
||||||
//
|
|
||||||
this.panelRed.AllowDrop = true;
|
|
||||||
this.panelRed.BackColor = System.Drawing.Color.Red;
|
|
||||||
this.panelRed.Location = new System.Drawing.Point(16, 26);
|
|
||||||
this.panelRed.Name = "panelRed";
|
|
||||||
this.panelRed.Size = new System.Drawing.Size(50, 50);
|
|
||||||
this.panelRed.TabIndex = 0;
|
|
||||||
//
|
|
||||||
// checkBoxSail
|
|
||||||
//
|
|
||||||
this.checkBoxSail.AutoSize = true;
|
|
||||||
this.checkBoxSail.Location = new System.Drawing.Point(12, 184);
|
|
||||||
this.checkBoxSail.Name = "checkBoxSail";
|
|
||||||
this.checkBoxSail.Size = new System.Drawing.Size(206, 24);
|
|
||||||
this.checkBoxSail.TabIndex = 5;
|
|
||||||
this.checkBoxSail.Text = "Признак наличия паруса";
|
|
||||||
this.checkBoxSail.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// checkBoxBobbers
|
|
||||||
//
|
|
||||||
this.checkBoxBobbers.AutoSize = true;
|
|
||||||
this.checkBoxBobbers.Location = new System.Drawing.Point(12, 139);
|
|
||||||
this.checkBoxBobbers.Name = "checkBoxBobbers";
|
|
||||||
this.checkBoxBobbers.Size = new System.Drawing.Size(233, 24);
|
|
||||||
this.checkBoxBobbers.TabIndex = 4;
|
|
||||||
this.checkBoxBobbers.Text = "Признак наличия поплавков";
|
|
||||||
this.checkBoxBobbers.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// numericUpDownWeight
|
|
||||||
//
|
|
||||||
this.numericUpDownWeight.Location = new System.Drawing.Point(85, 96);
|
|
||||||
this.numericUpDownWeight.Name = "numericUpDownWeight";
|
|
||||||
this.numericUpDownWeight.Size = new System.Drawing.Size(102, 27);
|
|
||||||
this.numericUpDownWeight.TabIndex = 3;
|
|
||||||
this.numericUpDownWeight.Value = new decimal(new int[] {
|
|
||||||
100,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0});
|
|
||||||
//
|
|
||||||
// numericUpDownSpeed
|
|
||||||
//
|
|
||||||
this.numericUpDownSpeed.Location = new System.Drawing.Point(85, 42);
|
|
||||||
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
|
|
||||||
this.numericUpDownSpeed.Size = new System.Drawing.Size(102, 27);
|
|
||||||
this.numericUpDownSpeed.TabIndex = 2;
|
|
||||||
this.numericUpDownSpeed.Value = new decimal(new int[] {
|
|
||||||
100,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0});
|
|
||||||
//
|
|
||||||
// labelWeight
|
|
||||||
//
|
|
||||||
this.labelWeight.AutoSize = true;
|
|
||||||
this.labelWeight.Location = new System.Drawing.Point(9, 96);
|
|
||||||
this.labelWeight.Name = "labelWeight";
|
|
||||||
this.labelWeight.Size = new System.Drawing.Size(36, 20);
|
|
||||||
this.labelWeight.TabIndex = 1;
|
|
||||||
this.labelWeight.Text = "Вес:";
|
|
||||||
//
|
|
||||||
// labelSpeed
|
|
||||||
//
|
|
||||||
this.labelSpeed.AutoSize = true;
|
|
||||||
this.labelSpeed.Location = new System.Drawing.Point(9, 44);
|
|
||||||
this.labelSpeed.Name = "labelSpeed";
|
|
||||||
this.labelSpeed.Size = new System.Drawing.Size(76, 20);
|
|
||||||
this.labelSpeed.TabIndex = 0;
|
|
||||||
this.labelSpeed.Text = "Скорость:";
|
|
||||||
//
|
|
||||||
// buttonOk
|
|
||||||
//
|
|
||||||
this.buttonOk.Location = new System.Drawing.Point(595, 216);
|
|
||||||
this.buttonOk.Name = "buttonOk";
|
|
||||||
this.buttonOk.Size = new System.Drawing.Size(119, 29);
|
|
||||||
this.buttonOk.TabIndex = 7;
|
|
||||||
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.pictureBoxObject);
|
|
||||||
this.panelObject.Controls.Add(this.labelDopColor);
|
|
||||||
this.panelObject.Controls.Add(this.labelBaseColor);
|
|
||||||
this.panelObject.Location = new System.Drawing.Point(569, 12);
|
|
||||||
this.panelObject.Name = "panelObject";
|
|
||||||
this.panelObject.Size = new System.Drawing.Size(315, 183);
|
|
||||||
this.panelObject.TabIndex = 2;
|
|
||||||
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
|
|
||||||
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
|
|
||||||
//
|
|
||||||
// pictureBoxObject
|
|
||||||
//
|
|
||||||
this.pictureBoxObject.Location = new System.Drawing.Point(26, 67);
|
|
||||||
this.pictureBoxObject.Name = "pictureBoxObject";
|
|
||||||
this.pictureBoxObject.Size = new System.Drawing.Size(260, 104);
|
|
||||||
this.pictureBoxObject.TabIndex = 1;
|
|
||||||
this.pictureBoxObject.TabStop = false;
|
|
||||||
//
|
|
||||||
// labelDopColor
|
|
||||||
//
|
|
||||||
this.labelDopColor.AllowDrop = true;
|
|
||||||
this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
|
||||||
this.labelDopColor.Location = new System.Drawing.Point(167, 13);
|
|
||||||
this.labelDopColor.Name = "labelDopColor";
|
|
||||||
this.labelDopColor.Size = new System.Drawing.Size(119, 48);
|
|
||||||
this.labelDopColor.TabIndex = 3;
|
|
||||||
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.LabelDopColor_DragEnter);
|
|
||||||
//
|
|
||||||
// labelBaseColor
|
|
||||||
//
|
|
||||||
this.labelBaseColor.AllowDrop = true;
|
|
||||||
this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
|
||||||
this.labelBaseColor.Location = new System.Drawing.Point(26, 13);
|
|
||||||
this.labelBaseColor.Name = "labelBaseColor";
|
|
||||||
this.labelBaseColor.Size = new System.Drawing.Size(119, 48);
|
|
||||||
this.labelBaseColor.TabIndex = 2;
|
|
||||||
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.LabelBaseColor_DragEnter);
|
|
||||||
//
|
|
||||||
// buttonCancel
|
|
||||||
//
|
|
||||||
this.buttonCancel.Location = new System.Drawing.Point(736, 217);
|
|
||||||
this.buttonCancel.Name = "buttonCancel";
|
|
||||||
this.buttonCancel.Size = new System.Drawing.Size(119, 29);
|
|
||||||
this.buttonCancel.TabIndex = 8;
|
|
||||||
this.buttonCancel.Text = "Отмена";
|
|
||||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// FormBoatConfig
|
|
||||||
//
|
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
||||||
this.ClientSize = new System.Drawing.Size(888, 258);
|
|
||||||
this.Controls.Add(this.buttonCancel);
|
|
||||||
this.Controls.Add(this.panelObject);
|
|
||||||
this.Controls.Add(this.groupBoxConfig);
|
|
||||||
this.Controls.Add(this.buttonOk);
|
|
||||||
this.Name = "FormBoatConfig";
|
|
||||||
this.Text = "Создание объекта";
|
|
||||||
this.groupBoxConfig.ResumeLayout(false);
|
|
||||||
this.groupBoxConfig.PerformLayout();
|
|
||||||
this.groupBoxColors.ResumeLayout(false);
|
|
||||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
|
|
||||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
|
|
||||||
this.panelObject.ResumeLayout(false);
|
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
|
|
||||||
this.ResumeLayout(false);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private GroupBox groupBoxConfig;
|
|
||||||
private Label labelModifiedObject;
|
|
||||||
private Label labelSimpleObject;
|
|
||||||
private GroupBox groupBoxColors;
|
|
||||||
private Panel panelNavy;
|
|
||||||
private Panel panelBlack;
|
|
||||||
private Panel panelGray;
|
|
||||||
private Panel panelWhite;
|
|
||||||
private Panel panelYellow;
|
|
||||||
private Panel panelBlue;
|
|
||||||
private Panel panelGreen;
|
|
||||||
private Panel panelRed;
|
|
||||||
private CheckBox checkBoxSail;
|
|
||||||
private CheckBox checkBoxBobbers;
|
|
||||||
private NumericUpDown numericUpDownWeight;
|
|
||||||
private NumericUpDown numericUpDownSpeed;
|
|
||||||
private Label labelWeight;
|
|
||||||
private Label labelSpeed;
|
|
||||||
private Button buttonOk;
|
|
||||||
private Panel panelObject;
|
|
||||||
private PictureBox pictureBoxObject;
|
|
||||||
private Label labelBaseColor;
|
|
||||||
private Label labelDopColor;
|
|
||||||
private Button buttonCancel;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,194 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.CodeDom;
|
|
||||||
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 Boats
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Класс формы-конфигуратора
|
|
||||||
/// </summary>
|
|
||||||
public partial class FormBoatConfig : Form
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Переменная - выбранная лодка
|
|
||||||
/// </summary>
|
|
||||||
DrawingBoat _boat = null;
|
|
||||||
/// <summary>
|
|
||||||
/// Событие
|
|
||||||
/// </summary>
|
|
||||||
private event BoatDelegate EventAddBoat;
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
public FormBoatConfig()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
panelRed.MouseDown += PanelColor_MouseDown;
|
|
||||||
panelGreen.MouseDown += PanelColor_MouseDown;
|
|
||||||
panelBlue.MouseDown += PanelColor_MouseDown;
|
|
||||||
panelYellow.MouseDown += PanelColor_MouseDown;
|
|
||||||
panelWhite.MouseDown += PanelColor_MouseDown;
|
|
||||||
panelGray.MouseDown += PanelColor_MouseDown;
|
|
||||||
panelBlack.MouseDown += PanelColor_MouseDown;
|
|
||||||
panelNavy.MouseDown += PanelColor_MouseDown;
|
|
||||||
|
|
||||||
buttonCancel.Click += (sender, e) => Close();
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Отрисовка лодки
|
|
||||||
/// </summary>
|
|
||||||
private void DrawBoat()
|
|
||||||
{
|
|
||||||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
|
||||||
Graphics g = Graphics.FromImage(bmp);
|
|
||||||
_boat?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
|
|
||||||
_boat?.DrawTransport(g);
|
|
||||||
pictureBoxObject.Image = bmp;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Добавление события
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
public void AddEvent(BoatDelegate e)
|
|
||||||
{
|
|
||||||
if (EventAddBoat == null)
|
|
||||||
{
|
|
||||||
EventAddBoat = new BoatDelegate(e);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
EventAddBoat += e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Применяем соответствующий объект
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
|
|
||||||
{
|
|
||||||
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Проверяем тип получаемой информации
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
|
||||||
{
|
|
||||||
if (e.Data.GetDataPresent(DataFormats.Text))
|
|
||||||
{
|
|
||||||
e.Effect = DragDropEffects.Copy;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
e.Effect = DragDropEffects.None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Применяем необходимый объект
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
|
||||||
{
|
|
||||||
switch (e.Data.GetData(DataFormats.Text).ToString())
|
|
||||||
{
|
|
||||||
case "labelSimpleObject":
|
|
||||||
_boat = new DrawingBoat((int)numericUpDownSpeed.Value,
|
|
||||||
(int)numericUpDownWeight.Value,
|
|
||||||
Color.Red
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
case "labelModifiedObject":
|
|
||||||
_boat = new DrawingCatamaran((int)numericUpDownSpeed.Value,
|
|
||||||
(int)numericUpDownWeight.Value,
|
|
||||||
Color.Red,
|
|
||||||
Color.Blue,
|
|
||||||
checkBoxBobbers.Checked,
|
|
||||||
checkBoxSail.Checked
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
DrawBoat();
|
|
||||||
}
|
|
||||||
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
|
|
||||||
{
|
|
||||||
(sender as Control).DoDragDrop((sender as Control).BackColor,
|
|
||||||
DragDropEffects.Move | DragDropEffects.Copy);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Проверка получаемой информации
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void LabelBaseColor_DragEnter(object sender, DragEventArgs e)
|
|
||||||
{
|
|
||||||
if (e.Data.GetDataPresent(typeof(Color)))
|
|
||||||
{
|
|
||||||
e.Effect = DragDropEffects.Copy;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
e.Effect = DragDropEffects.None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Принимаем основной цвет
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
|
|
||||||
{
|
|
||||||
if (_boat == null)
|
|
||||||
return;
|
|
||||||
_boat.Boat.BodyColor = (Color)e.Data.GetData(typeof(Color).ToString());
|
|
||||||
DrawBoat();
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Проверка получаемой информации
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void LabelDopColor_DragEnter(object sender, DragEventArgs e)
|
|
||||||
{
|
|
||||||
if (e.Data.GetDataPresent(typeof(Color)))
|
|
||||||
{
|
|
||||||
e.Effect = DragDropEffects.Copy;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
e.Effect = DragDropEffects.None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Принимаем дополнительный цвет
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
|
|
||||||
{
|
|
||||||
if (_boat == null || _boat is not DrawingCatamaran)
|
|
||||||
return;
|
|
||||||
(_boat.Boat as EntityCatamaran).SetDopColor((Color)e.Data.GetData(typeof(Color).ToString()));
|
|
||||||
DrawBoat();
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Добавление лодки
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ButtonOk_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
EventAddBoat?.Invoke(_boat);
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
<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>
|
|
369
Boats/Boats/FormMapWithSetBoats.Designer.cs
generated
369
Boats/Boats/FormMapWithSetBoats.Designer.cs
generated
@ -1,369 +0,0 @@
|
|||||||
namespace Boats
|
|
||||||
{
|
|
||||||
partial class FormMapWithSetBoats
|
|
||||||
{
|
|
||||||
/// <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.groupBoxInstruments = new System.Windows.Forms.GroupBox();
|
|
||||||
this.buttonSortByColor = new System.Windows.Forms.Button();
|
|
||||||
this.buttonSortByType = new System.Windows.Forms.Button();
|
|
||||||
this.ButtonDown = 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.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
|
||||||
this.ButtonShowOnMap = new System.Windows.Forms.Button();
|
|
||||||
this.ButtonShowStorage = new System.Windows.Forms.Button();
|
|
||||||
this.ButtonRemoveBoat = new System.Windows.Forms.Button();
|
|
||||||
this.ButtonAddBoat = new System.Windows.Forms.Button();
|
|
||||||
this.ComboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
|
||||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
|
||||||
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
|
|
||||||
this.ButtonDeleteMap = new System.Windows.Forms.Button();
|
|
||||||
this.listBoxMaps = new System.Windows.Forms.ListBox();
|
|
||||||
this.ButtonAddMap = new System.Windows.Forms.Button();
|
|
||||||
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
|
|
||||||
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
|
||||||
this.FileToolStripMenuItem = 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.groupBoxInstruments.SuspendLayout();
|
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
|
||||||
this.groupBoxMaps.SuspendLayout();
|
|
||||||
this.menuStrip.SuspendLayout();
|
|
||||||
this.SuspendLayout();
|
|
||||||
//
|
|
||||||
// groupBoxInstruments
|
|
||||||
//
|
|
||||||
this.groupBoxInstruments.Controls.Add(this.buttonSortByColor);
|
|
||||||
this.groupBoxInstruments.Controls.Add(this.buttonSortByType);
|
|
||||||
this.groupBoxInstruments.Controls.Add(this.ButtonDown);
|
|
||||||
this.groupBoxInstruments.Controls.Add(this.ButtonRight);
|
|
||||||
this.groupBoxInstruments.Controls.Add(this.ButtonLeft);
|
|
||||||
this.groupBoxInstruments.Controls.Add(this.ButtonUp);
|
|
||||||
this.groupBoxInstruments.Controls.Add(this.maskedTextBoxPosition);
|
|
||||||
this.groupBoxInstruments.Controls.Add(this.ButtonShowOnMap);
|
|
||||||
this.groupBoxInstruments.Controls.Add(this.ButtonShowStorage);
|
|
||||||
this.groupBoxInstruments.Controls.Add(this.ButtonRemoveBoat);
|
|
||||||
this.groupBoxInstruments.Controls.Add(this.ButtonAddBoat);
|
|
||||||
this.groupBoxInstruments.Dock = System.Windows.Forms.DockStyle.Right;
|
|
||||||
this.groupBoxInstruments.Location = new System.Drawing.Point(901, 28);
|
|
||||||
this.groupBoxInstruments.Name = "groupBoxInstruments";
|
|
||||||
this.groupBoxInstruments.Size = new System.Drawing.Size(250, 783);
|
|
||||||
this.groupBoxInstruments.TabIndex = 0;
|
|
||||||
this.groupBoxInstruments.TabStop = false;
|
|
||||||
this.groupBoxInstruments.Text = "Инструменты";
|
|
||||||
//
|
|
||||||
// buttonSortByColor
|
|
||||||
//
|
|
||||||
this.buttonSortByColor.Location = new System.Drawing.Point(9, 354);
|
|
||||||
this.buttonSortByColor.Name = "buttonSortByColor";
|
|
||||||
this.buttonSortByColor.Size = new System.Drawing.Size(232, 29);
|
|
||||||
this.buttonSortByColor.TabIndex = 12;
|
|
||||||
this.buttonSortByColor.Text = "Сортировать по цвету";
|
|
||||||
this.buttonSortByColor.UseVisualStyleBackColor = true;
|
|
||||||
this.buttonSortByColor.Click += new System.EventHandler(this.buttonSortByColor_Click);
|
|
||||||
//
|
|
||||||
// buttonSortByType
|
|
||||||
//
|
|
||||||
this.buttonSortByType.Location = new System.Drawing.Point(9, 321);
|
|
||||||
this.buttonSortByType.Name = "buttonSortByType";
|
|
||||||
this.buttonSortByType.Size = new System.Drawing.Size(232, 29);
|
|
||||||
this.buttonSortByType.TabIndex = 11;
|
|
||||||
this.buttonSortByType.Text = "Сортировать по типу";
|
|
||||||
this.buttonSortByType.UseVisualStyleBackColor = true;
|
|
||||||
this.buttonSortByType.Click += new System.EventHandler(this.buttonSortByType_Click);
|
|
||||||
//
|
|
||||||
// ButtonDown
|
|
||||||
//
|
|
||||||
this.ButtonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
|
||||||
this.ButtonDown.BackgroundImage = global::Boats.Properties.Resources.arrow_down;
|
|
||||||
this.ButtonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
|
||||||
this.ButtonDown.Location = new System.Drawing.Point(99, 716);
|
|
||||||
this.ButtonDown.Name = "ButtonDown";
|
|
||||||
this.ButtonDown.Size = new System.Drawing.Size(30, 30);
|
|
||||||
this.ButtonDown.TabIndex = 10;
|
|
||||||
this.ButtonDown.UseVisualStyleBackColor = true;
|
|
||||||
this.ButtonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
|
||||||
//
|
|
||||||
// ButtonRight
|
|
||||||
//
|
|
||||||
this.ButtonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
|
||||||
this.ButtonRight.BackgroundImage = global::Boats.Properties.Resources.arrow_right;
|
|
||||||
this.ButtonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
|
||||||
this.ButtonRight.Location = new System.Drawing.Point(135, 716);
|
|
||||||
this.ButtonRight.Name = "ButtonRight";
|
|
||||||
this.ButtonRight.Size = new System.Drawing.Size(30, 30);
|
|
||||||
this.ButtonRight.TabIndex = 9;
|
|
||||||
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.Top | System.Windows.Forms.AnchorStyles.Right)));
|
|
||||||
this.ButtonLeft.BackgroundImage = global::Boats.Properties.Resources.arrow_left;
|
|
||||||
this.ButtonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
|
||||||
this.ButtonLeft.Location = new System.Drawing.Point(63, 716);
|
|
||||||
this.ButtonLeft.Name = "ButtonLeft";
|
|
||||||
this.ButtonLeft.Size = new System.Drawing.Size(30, 30);
|
|
||||||
this.ButtonLeft.TabIndex = 8;
|
|
||||||
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.Top | System.Windows.Forms.AnchorStyles.Right)));
|
|
||||||
this.ButtonUp.BackgroundImage = global::Boats.Properties.Resources.arrow_up;
|
|
||||||
this.ButtonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
|
||||||
this.ButtonUp.Location = new System.Drawing.Point(99, 680);
|
|
||||||
this.ButtonUp.Name = "ButtonUp";
|
|
||||||
this.ButtonUp.Size = new System.Drawing.Size(30, 30);
|
|
||||||
this.ButtonUp.TabIndex = 7;
|
|
||||||
this.ButtonUp.UseVisualStyleBackColor = true;
|
|
||||||
this.ButtonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
|
||||||
//
|
|
||||||
// maskedTextBoxPosition
|
|
||||||
//
|
|
||||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 449);
|
|
||||||
this.maskedTextBoxPosition.Mask = "00";
|
|
||||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
|
||||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(232, 27);
|
|
||||||
this.maskedTextBoxPosition.TabIndex = 5;
|
|
||||||
//
|
|
||||||
// ButtonShowOnMap
|
|
||||||
//
|
|
||||||
this.ButtonShowOnMap.Location = new System.Drawing.Point(6, 613);
|
|
||||||
this.ButtonShowOnMap.Name = "ButtonShowOnMap";
|
|
||||||
this.ButtonShowOnMap.Size = new System.Drawing.Size(232, 40);
|
|
||||||
this.ButtonShowOnMap.TabIndex = 4;
|
|
||||||
this.ButtonShowOnMap.Text = "Просмотреть карту";
|
|
||||||
this.ButtonShowOnMap.UseVisualStyleBackColor = true;
|
|
||||||
this.ButtonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
|
||||||
//
|
|
||||||
// ButtonShowStorage
|
|
||||||
//
|
|
||||||
this.ButtonShowStorage.Location = new System.Drawing.Point(6, 555);
|
|
||||||
this.ButtonShowStorage.Name = "ButtonShowStorage";
|
|
||||||
this.ButtonShowStorage.Size = new System.Drawing.Size(232, 40);
|
|
||||||
this.ButtonShowStorage.TabIndex = 3;
|
|
||||||
this.ButtonShowStorage.Text = "Просмотреть хранилище";
|
|
||||||
this.ButtonShowStorage.UseVisualStyleBackColor = true;
|
|
||||||
this.ButtonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
|
||||||
//
|
|
||||||
// ButtonRemoveBoat
|
|
||||||
//
|
|
||||||
this.ButtonRemoveBoat.Location = new System.Drawing.Point(6, 496);
|
|
||||||
this.ButtonRemoveBoat.Name = "ButtonRemoveBoat";
|
|
||||||
this.ButtonRemoveBoat.Size = new System.Drawing.Size(232, 40);
|
|
||||||
this.ButtonRemoveBoat.TabIndex = 2;
|
|
||||||
this.ButtonRemoveBoat.Text = "Удалить лодку";
|
|
||||||
this.ButtonRemoveBoat.UseVisualStyleBackColor = true;
|
|
||||||
this.ButtonRemoveBoat.Click += new System.EventHandler(this.ButtonRemoveBoat_Click);
|
|
||||||
//
|
|
||||||
// ButtonAddBoat
|
|
||||||
//
|
|
||||||
this.ButtonAddBoat.Location = new System.Drawing.Point(6, 391);
|
|
||||||
this.ButtonAddBoat.Name = "ButtonAddBoat";
|
|
||||||
this.ButtonAddBoat.Size = new System.Drawing.Size(232, 40);
|
|
||||||
this.ButtonAddBoat.TabIndex = 1;
|
|
||||||
this.ButtonAddBoat.Text = "Добавить лодку";
|
|
||||||
this.ButtonAddBoat.UseVisualStyleBackColor = true;
|
|
||||||
this.ButtonAddBoat.Click += new System.EventHandler(this.ButtonAddBoat_Click);
|
|
||||||
//
|
|
||||||
// ComboBoxSelectorMap
|
|
||||||
//
|
|
||||||
this.ComboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
|
||||||
this.ComboBoxSelectorMap.FormattingEnabled = true;
|
|
||||||
this.ComboBoxSelectorMap.Items.AddRange(new object[] {
|
|
||||||
"Простая карта",
|
|
||||||
"Океан карта",
|
|
||||||
"Линии карта"});
|
|
||||||
this.ComboBoxSelectorMap.Location = new System.Drawing.Point(6, 59);
|
|
||||||
this.ComboBoxSelectorMap.Name = "ComboBoxSelectorMap";
|
|
||||||
this.ComboBoxSelectorMap.Size = new System.Drawing.Size(220, 28);
|
|
||||||
this.ComboBoxSelectorMap.TabIndex = 0;
|
|
||||||
this.ComboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
|
||||||
//
|
|
||||||
// pictureBox
|
|
||||||
//
|
|
||||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
|
||||||
this.pictureBox.Location = new System.Drawing.Point(0, 28);
|
|
||||||
this.pictureBox.Name = "pictureBox";
|
|
||||||
this.pictureBox.Size = new System.Drawing.Size(901, 783);
|
|
||||||
this.pictureBox.TabIndex = 1;
|
|
||||||
this.pictureBox.TabStop = false;
|
|
||||||
//
|
|
||||||
// groupBoxMaps
|
|
||||||
//
|
|
||||||
this.groupBoxMaps.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
|
||||||
this.groupBoxMaps.Controls.Add(this.ButtonDeleteMap);
|
|
||||||
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
|
|
||||||
this.groupBoxMaps.Controls.Add(this.ButtonAddMap);
|
|
||||||
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
|
|
||||||
this.groupBoxMaps.Controls.Add(this.ComboBoxSelectorMap);
|
|
||||||
this.groupBoxMaps.Location = new System.Drawing.Point(907, 26);
|
|
||||||
this.groupBoxMaps.Name = "groupBoxMaps";
|
|
||||||
this.groupBoxMaps.Size = new System.Drawing.Size(232, 318);
|
|
||||||
this.groupBoxMaps.TabIndex = 11;
|
|
||||||
this.groupBoxMaps.TabStop = false;
|
|
||||||
this.groupBoxMaps.Text = "Карты";
|
|
||||||
//
|
|
||||||
// ButtonDeleteMap
|
|
||||||
//
|
|
||||||
this.ButtonDeleteMap.Location = new System.Drawing.Point(6, 272);
|
|
||||||
this.ButtonDeleteMap.Name = "ButtonDeleteMap";
|
|
||||||
this.ButtonDeleteMap.Size = new System.Drawing.Size(220, 40);
|
|
||||||
this.ButtonDeleteMap.TabIndex = 4;
|
|
||||||
this.ButtonDeleteMap.Text = "Удалить карту";
|
|
||||||
this.ButtonDeleteMap.UseVisualStyleBackColor = true;
|
|
||||||
this.ButtonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
|
|
||||||
//
|
|
||||||
// listBoxMaps
|
|
||||||
//
|
|
||||||
this.listBoxMaps.FormattingEnabled = true;
|
|
||||||
this.listBoxMaps.ItemHeight = 20;
|
|
||||||
this.listBoxMaps.Location = new System.Drawing.Point(6, 153);
|
|
||||||
this.listBoxMaps.Name = "listBoxMaps";
|
|
||||||
this.listBoxMaps.Size = new System.Drawing.Size(220, 104);
|
|
||||||
this.listBoxMaps.TabIndex = 3;
|
|
||||||
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
|
|
||||||
//
|
|
||||||
// ButtonAddMap
|
|
||||||
//
|
|
||||||
this.ButtonAddMap.Location = new System.Drawing.Point(6, 93);
|
|
||||||
this.ButtonAddMap.Name = "ButtonAddMap";
|
|
||||||
this.ButtonAddMap.Size = new System.Drawing.Size(220, 40);
|
|
||||||
this.ButtonAddMap.TabIndex = 2;
|
|
||||||
this.ButtonAddMap.Text = "Добавить карту";
|
|
||||||
this.ButtonAddMap.UseVisualStyleBackColor = true;
|
|
||||||
this.ButtonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
|
|
||||||
//
|
|
||||||
// textBoxNewMapName
|
|
||||||
//
|
|
||||||
this.textBoxNewMapName.Location = new System.Drawing.Point(6, 26);
|
|
||||||
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
|
||||||
this.textBoxNewMapName.Size = new System.Drawing.Size(220, 27);
|
|
||||||
this.textBoxNewMapName.TabIndex = 0;
|
|
||||||
//
|
|
||||||
// menuStrip
|
|
||||||
//
|
|
||||||
this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
|
|
||||||
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
|
||||||
this.FileToolStripMenuItem});
|
|
||||||
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
|
||||||
this.menuStrip.Name = "menuStrip";
|
|
||||||
this.menuStrip.Size = new System.Drawing.Size(1151, 28);
|
|
||||||
this.menuStrip.TabIndex = 12;
|
|
||||||
this.menuStrip.Text = "menuStrip1";
|
|
||||||
//
|
|
||||||
// FileToolStripMenuItem
|
|
||||||
//
|
|
||||||
this.FileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
|
||||||
this.SaveToolStripMenuItem,
|
|
||||||
this.LoadToolStripMenuItem});
|
|
||||||
this.FileToolStripMenuItem.Name = "FileToolStripMenuItem";
|
|
||||||
this.FileToolStripMenuItem.Size = new System.Drawing.Size(59, 24);
|
|
||||||
this.FileToolStripMenuItem.Text = "Файл";
|
|
||||||
//
|
|
||||||
// SaveToolStripMenuItem
|
|
||||||
//
|
|
||||||
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
|
||||||
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(166, 26);
|
|
||||||
this.SaveToolStripMenuItem.Text = "Сохранить";
|
|
||||||
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
|
|
||||||
//
|
|
||||||
// LoadToolStripMenuItem
|
|
||||||
//
|
|
||||||
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
|
||||||
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(166, 26);
|
|
||||||
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";
|
|
||||||
//
|
|
||||||
// FormMapWithSetBoats
|
|
||||||
//
|
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
||||||
this.ClientSize = new System.Drawing.Size(1151, 811);
|
|
||||||
this.Controls.Add(this.groupBoxMaps);
|
|
||||||
this.Controls.Add(this.pictureBox);
|
|
||||||
this.Controls.Add(this.groupBoxInstruments);
|
|
||||||
this.Controls.Add(this.menuStrip);
|
|
||||||
this.MainMenuStrip = this.menuStrip;
|
|
||||||
this.Name = "FormMapWithSetBoats";
|
|
||||||
this.Text = "Карта с набором элементов";
|
|
||||||
this.groupBoxInstruments.ResumeLayout(false);
|
|
||||||
this.groupBoxInstruments.PerformLayout();
|
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
|
||||||
this.groupBoxMaps.ResumeLayout(false);
|
|
||||||
this.groupBoxMaps.PerformLayout();
|
|
||||||
this.menuStrip.ResumeLayout(false);
|
|
||||||
this.menuStrip.PerformLayout();
|
|
||||||
this.ResumeLayout(false);
|
|
||||||
this.PerformLayout();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private GroupBox groupBoxInstruments;
|
|
||||||
private MaskedTextBox maskedTextBoxPosition;
|
|
||||||
private Button ButtonShowOnMap;
|
|
||||||
private Button ButtonShowStorage;
|
|
||||||
private Button ButtonRemoveBoat;
|
|
||||||
private Button ButtonAddBoat;
|
|
||||||
private ComboBox ComboBoxSelectorMap;
|
|
||||||
private PictureBox pictureBox;
|
|
||||||
private Button ButtonDown;
|
|
||||||
private Button ButtonRight;
|
|
||||||
private Button ButtonLeft;
|
|
||||||
private Button ButtonUp;
|
|
||||||
private GroupBox groupBoxMaps;
|
|
||||||
private Button ButtonDeleteMap;
|
|
||||||
private ListBox listBoxMaps;
|
|
||||||
private Button ButtonAddMap;
|
|
||||||
private TextBox textBoxNewMapName;
|
|
||||||
private MenuStrip menuStrip;
|
|
||||||
private ToolStripMenuItem FileToolStripMenuItem;
|
|
||||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
|
||||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
|
||||||
private OpenFileDialog openFileDialog;
|
|
||||||
private SaveFileDialog saveFileDialog;
|
|
||||||
private Button buttonSortByColor;
|
|
||||||
private Button buttonSortByType;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,344 +0,0 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
|
||||||
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 Boats
|
|
||||||
{
|
|
||||||
public partial class FormMapWithSetBoats : Form
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Словарь для выпадающего списка
|
|
||||||
/// </summary>
|
|
||||||
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
|
||||||
{
|
|
||||||
{ "Простая карта", new SimpleMap() },
|
|
||||||
{ "Линии карта", new LineMap() },
|
|
||||||
{ "Океан карта", new OceanMap() },
|
|
||||||
};
|
|
||||||
/// <summary>
|
|
||||||
/// Объект от коллекции карт
|
|
||||||
/// </summary>
|
|
||||||
private readonly MapsCollection _mapsCollection;
|
|
||||||
private readonly ILogger _logger;
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
public FormMapWithSetBoats(ILogger<FormMapWithSetBoats> logger)
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
_logger = logger;
|
|
||||||
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
|
||||||
ComboBoxSelectorMap.Items.Clear();
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Выбор карты
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ComboBoxSelectorMap_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 ButtonAddBoat_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
var formBoatConfig = new FormBoatConfig();
|
|
||||||
formBoatConfig.AddEvent(new BoatDelegate(AddBoatListener));
|
|
||||||
formBoatConfig.Show();
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Удаление объекта
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ButtonRemoveBoat_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
|
|
||||||
{
|
|
||||||
var deletedBoat = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos;
|
|
||||||
if (deletedBoat != null)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Объект удален");
|
|
||||||
_logger.LogInformation($"Удален объект {deletedBoat.GetType().Name}");
|
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.LogInformation($"Не удалось удалить объект по позиции {pos}: объект равен null");
|
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (BoatNotFoundException ex)
|
|
||||||
{
|
|
||||||
_logger.LogWarning($"Ошибка удаления объекта: {ex.Message}");
|
|
||||||
MessageBox.Show($"Ошибка удаления: {ex.Message}");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show($"Неизвестная ошибка: {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);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Добавление карты
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
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 ButtonDeleteMap_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (listBoxMaps.SelectedIndex == -1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление",
|
|
||||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
||||||
{
|
|
||||||
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
|
||||||
_logger.LogInformation($"Удалена карта {listBoxMaps.SelectedItem?.ToString() ?? ""}");
|
|
||||||
ReloadMaps();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <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() ?? ""}");
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Listener для добавления новой лодки из формы
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="drawingBoat"></param>
|
|
||||||
private void AddBoatListener(DrawingBoat drawingBoat)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (listBoxMaps.SelectedIndex == -1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DrawingObjectBoat boat = new(drawingBoat);
|
|
||||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + boat != -1)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Объект добавлен");
|
|
||||||
_logger.LogInformation($"Добавлен объект {drawingBoat.GetType().Name}");
|
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
|
||||||
_logger.LogInformation("Не удалось добавить объект");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (StorageOverflowException ex)
|
|
||||||
{
|
|
||||||
_logger.LogWarning($"Ошибка переполнения хранилища: {ex.Message}");
|
|
||||||
MessageBox.Show($"Ошибка переполнения хранилища: {ex.Message}",
|
|
||||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
catch (ArgumentException ex)
|
|
||||||
{
|
|
||||||
_logger.LogWarning($"Ошибка добавления объекта: {ex.Message}");
|
|
||||||
MessageBox.Show($"Ошибка добавления объекта: {ex.Message}",
|
|
||||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Обработка нажатия "Сохранить"
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_mapsCollection.SaveData(saveFileDialog.FileName);
|
|
||||||
_logger.LogInformation($"Сохранение прошло успешно. Файл: {saveFileDialog.FileName}");
|
|
||||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
_logger.LogWarning($"Не удалось сохранить файл '{saveFileDialog.FileName}'. Ошибка: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Обработка нажатия "Загрузить"
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_mapsCollection.LoadData(openFileDialog.FileName);
|
|
||||||
ReloadMaps();
|
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
|
||||||
MessageBox.Show("Загрузка прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
_logger.LogInformation($"Открытие файла '{openFileDialog.FileName}' прошло успешно");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
_logger.LogWarning($"Не удалось открыть файл {openFileDialog.FileName}. Ошибка: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonSortByType_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (listBoxMaps.SelectedIndex == -1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new BoatCompareByType());
|
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buttonSortByColor_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (listBoxMaps.SelectedIndex == -1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new BoatCompareByColor());
|
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
<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>152, 17</value>
|
|
||||||
</metadata>
|
|
||||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
|
||||||
<value>319, 17</value>
|
|
||||||
</metadata>
|
|
||||||
</root>
|
|
@ -1,47 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Интерфейс для работы с объектом, прорисовываемым на форме
|
|
||||||
/// </summary>
|
|
||||||
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>
|
|
||||||
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();
|
|
||||||
/// <summary>
|
|
||||||
/// Получение информации по объекту
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
string GetInfo();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Класс линейной карты
|
|
||||||
/// </summary>
|
|
||||||
internal class LineMap : AbstractMap
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Цвет участка закрытого
|
|
||||||
/// </summary>
|
|
||||||
private readonly Brush barrierColor = new SolidBrush(Color.White);
|
|
||||||
/// <summary>
|
|
||||||
/// Цвет участка открытого
|
|
||||||
/// </summary>
|
|
||||||
private readonly Brush roadColor = new SolidBrush(Color.Black);
|
|
||||||
/// <summary>
|
|
||||||
/// Метод для отрисовки закрытого участка карты
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
/// <param name="i"></param>
|
|
||||||
/// <param name="j"></param>
|
|
||||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
|
||||||
{
|
|
||||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Метод для отрисовки открытого участка карты
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
/// <param name="i"></param>
|
|
||||||
/// <param name="j"></param>
|
|
||||||
protected override void DrawWaterPart(Graphics g, int i, int j)
|
|
||||||
{
|
|
||||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Метод генерации карты
|
|
||||||
/// </summary>
|
|
||||||
protected override void GenerateMap()
|
|
||||||
{
|
|
||||||
_map = new int[100, 100];
|
|
||||||
_size_x = (float)_width / _map.GetLength(0);
|
|
||||||
_size_y = (float)_height / _map.GetLength(1);
|
|
||||||
|
|
||||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
|
||||||
{
|
|
||||||
_map[i, j] = _freeWater;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Будем рисовать линии
|
|
||||||
// из непроходимых блоков
|
|
||||||
int counter = 0;
|
|
||||||
while (counter < 20)
|
|
||||||
{
|
|
||||||
int x = _random.Next(0, 100);
|
|
||||||
int y = _random.Next(0, 100);
|
|
||||||
|
|
||||||
int lineLength = 5;
|
|
||||||
|
|
||||||
if (_map[x, y] == _freeWater)
|
|
||||||
{
|
|
||||||
int d = 0;
|
|
||||||
if (Convert.ToBoolean(_random.Next(0, 2)))
|
|
||||||
{
|
|
||||||
while (y + d < _map.GetLength(0) && d < lineLength * 2)
|
|
||||||
{
|
|
||||||
_map[x, y + d] = _barrier;
|
|
||||||
d++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (x + d < _map.GetLength(1) && d < lineLength)
|
|
||||||
{
|
|
||||||
_map[x + d, y] = _barrier;
|
|
||||||
d++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,272 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Карта с набром объектов
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T"></typeparam>
|
|
||||||
/// <typeparam name="U"></typeparam>
|
|
||||||
internal class MapWithSetBoatsGeneric<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 = 130;
|
|
||||||
/// <summary>
|
|
||||||
/// Размер занимаемого объектом места (высота)
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _placeSizeHeight = 80;
|
|
||||||
/// <summary>
|
|
||||||
/// Набор объектов
|
|
||||||
/// </summary>
|
|
||||||
private readonly SetBoatsGeneric<T> _setBoats;
|
|
||||||
/// <summary>
|
|
||||||
/// Карта
|
|
||||||
/// </summary>
|
|
||||||
private readonly U _map;
|
|
||||||
/// <summary>
|
|
||||||
/// Массив точек установки лодок в гавани
|
|
||||||
/// </summary>
|
|
||||||
private Point[]? _placesPoints;
|
|
||||||
private readonly int _placesCount = 18;
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="picWidth"></param>
|
|
||||||
/// <param name="picHeight"></param>
|
|
||||||
/// <param name="map"></param>
|
|
||||||
public MapWithSetBoatsGeneric(int picWidth, int picHeight, U map)
|
|
||||||
{
|
|
||||||
int width = picWidth / _placeSizeWidth;
|
|
||||||
int height = picHeight / _placeSizeHeight;
|
|
||||||
_setBoats = new SetBoatsGeneric<T>(_placesCount);
|
|
||||||
_pictureWidth = picWidth;
|
|
||||||
_pictureHeight = picHeight;
|
|
||||||
_map = map;
|
|
||||||
_placesPoints = null;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Перегрузка оператора сложения
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="map"></param>
|
|
||||||
/// <param name="boat"></param>
|
|
||||||
/// <returns>Возвращает позицию объекта в массиве или
|
|
||||||
/// -1, если установить объект не удплось</returns>
|
|
||||||
public static int operator +(MapWithSetBoatsGeneric<T, U> map, T boat)
|
|
||||||
{
|
|
||||||
return map._setBoats.Insert(boat);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Перегрузка оператора вычитания
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="map"></param>
|
|
||||||
/// <param name="position"></param>
|
|
||||||
/// <returns>Возвращает удаляемый объект или
|
|
||||||
/// null, если удалить не удалось</returns>
|
|
||||||
public static T operator -(MapWithSetBoatsGeneric<T, U> map, int position)
|
|
||||||
{
|
|
||||||
return map._setBoats.Remove(position);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Вывод всего набора объектов
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Возвращает Bitmap с гаванью и лодками</returns>
|
|
||||||
public Bitmap ShowSet()
|
|
||||||
{
|
|
||||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
|
||||||
Graphics g = Graphics.FromImage(bmp);
|
|
||||||
DrawBackground(g);
|
|
||||||
DrawBoats(g);
|
|
||||||
return bmp;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Просмотр объекта на карте
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Возвращает Bitmap с картой и объектом на ней</returns>
|
|
||||||
public Bitmap ShowOnMap()
|
|
||||||
{
|
|
||||||
Shaking();
|
|
||||||
foreach (var boat in _setBoats.GetBoats())
|
|
||||||
{
|
|
||||||
return _map.CreateMap(_pictureWidth, _pictureHeight, boat);
|
|
||||||
}
|
|
||||||
return new(_pictureWidth, _pictureHeight);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещение объекта по карте
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="direction"></param>
|
|
||||||
/// <returns>Возвращает Bitmap с картой и перемещенным объектом на ней</returns>
|
|
||||||
public Bitmap MoveObject(Direction direction)
|
|
||||||
{
|
|
||||||
if (_map != null)
|
|
||||||
{
|
|
||||||
return _map.MoveObject(direction);
|
|
||||||
}
|
|
||||||
return new(_pictureWidth, _pictureHeight);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
|
|
||||||
/// </summary>
|
|
||||||
private void Shaking()
|
|
||||||
{
|
|
||||||
int j = _setBoats.Count - 1;
|
|
||||||
for (int i = 0; i < _setBoats.Count; i++)
|
|
||||||
{
|
|
||||||
if (_setBoats[i] == null)
|
|
||||||
{
|
|
||||||
for (; j > i; j--)
|
|
||||||
{
|
|
||||||
var boat = _setBoats[j];
|
|
||||||
if (boat != null)
|
|
||||||
{
|
|
||||||
_setBoats.Insert(boat, i);
|
|
||||||
_setBoats.Remove(j);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (j <= i)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Метод отрисовки фона
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
private void DrawBackground(Graphics g)
|
|
||||||
{
|
|
||||||
bool pointsInit = false;
|
|
||||||
// если массив точек null, то рисуем фон первый раз
|
|
||||||
// инициализируем массив для его заполнения
|
|
||||||
if (_placesPoints == null)
|
|
||||||
{
|
|
||||||
_placesPoints = new Point[_placesCount];
|
|
||||||
pointsInit = true;
|
|
||||||
}
|
|
||||||
// рисуем фон
|
|
||||||
g.FillRectangle(Brushes.Aqua, 0, 0, _pictureWidth * _placeSizeWidth,
|
|
||||||
_pictureHeight * _placeSizeHeight);
|
|
||||||
|
|
||||||
// рисуем основной пирс
|
|
||||||
g.FillRectangle(Brushes.Gray, 0, 0, _placeSizeWidth * 5 / 4, _placeSizeHeight * 3 / 2);
|
|
||||||
g.FillRectangle(Brushes.Gray, _pictureWidth - _placeSizeWidth * 5 / 4, 0,
|
|
||||||
_placeSizeWidth * 5 / 4, _placeSizeHeight * 3 / 2);
|
|
||||||
|
|
||||||
g.FillRectangle(Brushes.Gray, 0, _placeSizeHeight * 3 / 2,
|
|
||||||
_placeSizeWidth * 1 / 4, _pictureHeight - _placeSizeHeight * 3 / 2);
|
|
||||||
g.FillRectangle(Brushes.Gray, _pictureWidth - _placeSizeWidth * 1 / 4, _placeSizeHeight * 3 / 2,
|
|
||||||
_placeSizeWidth * 1 / 4, _pictureHeight - _placeSizeHeight * 3 / 2);
|
|
||||||
|
|
||||||
g.FillRectangle(Brushes.Gray, 0, 0, _pictureWidth, _placeSizeHeight * 1 / 2);
|
|
||||||
|
|
||||||
// рисуем плавучие пирсы
|
|
||||||
// горизонтальные
|
|
||||||
int w = _placeSizeWidth;
|
|
||||||
int h = _placeSizeHeight;
|
|
||||||
int x = w * 1 / 4;
|
|
||||||
int y = h * 5 / 2;
|
|
||||||
int pirsSize = h * 1 / 6;
|
|
||||||
int i = 0;
|
|
||||||
while (y + h + pirsSize < _pictureHeight)
|
|
||||||
{
|
|
||||||
g.FillRectangle(Brushes.Brown, x, y, w, pirsSize);
|
|
||||||
g.FillRectangle(Brushes.Brown, _pictureWidth - x - w, y, w, pirsSize);
|
|
||||||
if (pointsInit)
|
|
||||||
{
|
|
||||||
_placesPoints[11 + i] = new Point(x + 5, y - _placeSizeHeight + 5);
|
|
||||||
_placesPoints[6 - i] = new Point(_pictureWidth - x - w + 5, y - _placeSizeHeight + 5);
|
|
||||||
}
|
|
||||||
y += h + pirsSize;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (pointsInit)
|
|
||||||
{
|
|
||||||
_placesPoints[11 + i] = new Point(x + 5, y - _placeSizeHeight + 5);
|
|
||||||
_placesPoints[6 - i] = new Point(_pictureWidth - x - w + 5, y - _placeSizeHeight + 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
// вертикальные
|
|
||||||
x = _placeSizeWidth * 5 / 4 + w;
|
|
||||||
y = _placeSizeHeight * 1 / 2;
|
|
||||||
h = _placeSizeHeight;
|
|
||||||
i = 0;
|
|
||||||
while (x + w + pirsSize < _pictureWidth - _placeSizeWidth * 5 / 4)
|
|
||||||
{
|
|
||||||
g.FillRectangle(Brushes.Brown, x, y, pirsSize, h);
|
|
||||||
if (pointsInit)
|
|
||||||
{
|
|
||||||
_placesPoints[10 - i] = new Point(x - w + 5, y + 5);
|
|
||||||
}
|
|
||||||
x += w + pirsSize;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (pointsInit)
|
|
||||||
{
|
|
||||||
_placesPoints[10 - i] = new Point(x - w + 5, y + 5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Метод отрисовки лодок
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
private void DrawBoats(Graphics g)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
foreach (var boat in _setBoats.GetBoats())
|
|
||||||
{
|
|
||||||
// Установка позиции
|
|
||||||
boat.SetObject(_placesPoints[i].X, _placesPoints[i].Y,
|
|
||||||
_pictureWidth, _pictureHeight);
|
|
||||||
boat.DrawingObject(g);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Получение данных в виде строки
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sep"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public string GetData(char separatorType, char separatorData)
|
|
||||||
{
|
|
||||||
string data = $"{_map.GetType().Name}{separatorType}";
|
|
||||||
foreach (var boat in _setBoats.GetBoats())
|
|
||||||
{
|
|
||||||
data += $"{boat.GetInfo()}{separatorData}";
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Загрузка списка из массива строк
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="records"></param>
|
|
||||||
public void LoadData(string[] records)
|
|
||||||
{
|
|
||||||
foreach (var rec in records)
|
|
||||||
{
|
|
||||||
_setBoats.Insert(DrawingObjectBoat.Create(rec) as T);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void Sort(IComparer<T> comparer)
|
|
||||||
{
|
|
||||||
_setBoats.SortSet(comparer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,160 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using static System.Net.Mime.MediaTypeNames;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Класс для хранения коллекции карт
|
|
||||||
/// </summary>
|
|
||||||
internal class MapsCollection
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Словарь (хранилище) с картами
|
|
||||||
/// </summary>
|
|
||||||
readonly Dictionary<string, MapWithSetBoatsGeneric<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, MapWithSetBoatsGeneric<IDrawingObject, AbstractMap>>();
|
|
||||||
_pictureWidth = pictureWidth;
|
|
||||||
_pictureHeight = pictureHeight;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Добавление карты
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">Название карты</param>
|
|
||||||
/// <param name="map">Карта</param>
|
|
||||||
public void AddMap(string name, AbstractMap map)
|
|
||||||
{
|
|
||||||
// Добавление карты
|
|
||||||
MapWithSetBoatsGeneric<IDrawingObject, AbstractMap> newMap = new(_pictureWidth, _pictureHeight, map);
|
|
||||||
_mapStorages.Add(name, newMap);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Удаление карты
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">Название карты</param>
|
|
||||||
public void DelMap(string name)
|
|
||||||
{
|
|
||||||
// Удаление карты
|
|
||||||
if (!_mapStorages.ContainsKey(name))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_mapStorages.Remove(name);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Доступ к гавани
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ind"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public MapWithSetBoatsGeneric<IDrawingObject, AbstractMap> this[string index]
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
// Получение объекта
|
|
||||||
if (_mapStorages.ContainsKey(index))
|
|
||||||
{
|
|
||||||
return _mapStorages[index];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Сохранение информации по лодкам в хранилище в файл
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filename">Путь и имя файла</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public void SaveData(string filename)
|
|
||||||
{
|
|
||||||
if (File.Exists(filename))
|
|
||||||
{
|
|
||||||
File.Delete(filename);
|
|
||||||
}
|
|
||||||
using (StreamWriter sw = File.CreateText(filename))
|
|
||||||
{
|
|
||||||
sw.WriteLine($"MapsCollection");
|
|
||||||
foreach (var storage in _mapStorages)
|
|
||||||
{
|
|
||||||
sw.WriteLine($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Загрузка нформации по лодкам в гавани из файла
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filename"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public void LoadData(string filename)
|
|
||||||
{
|
|
||||||
if (!File.Exists(filename))
|
|
||||||
{
|
|
||||||
throw new FileNotFoundException("Файл не найден");
|
|
||||||
}
|
|
||||||
using (StreamReader sr = File.OpenText(filename))
|
|
||||||
{
|
|
||||||
string? currentLine = sr.ReadLine();
|
|
||||||
if (currentLine == null || !currentLine.Contains("MapsCollection"))
|
|
||||||
{
|
|
||||||
//если нет такой записи, то это не те данные
|
|
||||||
throw new FileFormatException("Формат данных в файле не правильный");
|
|
||||||
}
|
|
||||||
//очищаем записи
|
|
||||||
_mapStorages.Clear();
|
|
||||||
currentLine = sr.ReadLine();
|
|
||||||
while (currentLine != null)
|
|
||||||
{
|
|
||||||
var elem = currentLine.Split(separatorDict);
|
|
||||||
AbstractMap map = null;
|
|
||||||
switch (elem[1])
|
|
||||||
{
|
|
||||||
case "SimpleMap":
|
|
||||||
map = new SimpleMap();
|
|
||||||
break;
|
|
||||||
case "OceanMap":
|
|
||||||
map = new OceanMap();
|
|
||||||
break;
|
|
||||||
case "LineMap":
|
|
||||||
map = new LineMap();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
_mapStorages.Add(
|
|
||||||
elem[0],
|
|
||||||
new MapWithSetBoatsGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map)
|
|
||||||
);
|
|
||||||
_mapStorages[elem[0]].LoadData(
|
|
||||||
elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
|
||||||
currentLine = sr.ReadLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Класс океанической карты
|
|
||||||
/// </summary>
|
|
||||||
internal class OceanMap : AbstractMap
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Количество мин воруг центральной мины
|
|
||||||
/// </summary>
|
|
||||||
private readonly int minesAroundCount = 6;
|
|
||||||
/// <summary>
|
|
||||||
/// Количество центральных мин
|
|
||||||
/// </summary>
|
|
||||||
private readonly int circlesCount = 12;
|
|
||||||
/// <summary>
|
|
||||||
/// Цвет участка закрытого
|
|
||||||
/// </summary>
|
|
||||||
private readonly Brush mineColor = Brushes.Silver;
|
|
||||||
/// <summary>
|
|
||||||
/// Цвет участка открытого
|
|
||||||
/// </summary>
|
|
||||||
private readonly Brush openColor = Brushes.Aqua;
|
|
||||||
/// <summary>
|
|
||||||
/// Метод для отрисовки закрытого участка карты
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
/// <param name="i"></param>
|
|
||||||
/// <param name="j"></param>
|
|
||||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
|
||||||
{
|
|
||||||
g.FillRectangle(openColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
|
||||||
g.FillEllipse(mineColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
|
||||||
g.FillEllipse(Brushes.Black, i * _size_x + _size_x * 0.25f, j * _size_y + _size_y * 0.25f, _size_x * 0.5f, _size_y * 0.5f);
|
|
||||||
g.FillEllipse(Brushes.Red, i * _size_x + _size_x * 0.375f, j * _size_y + _size_y * 0.375f, _size_x * 0.25f, _size_y * 0.25f);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Метод для отрисовки открытого участка карты
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
/// <param name="i"></param>
|
|
||||||
/// <param name="j"></param>
|
|
||||||
protected override void DrawWaterPart(Graphics g, int i, int j)
|
|
||||||
{
|
|
||||||
g.FillRectangle(openColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Метод генерации карты
|
|
||||||
/// </summary>
|
|
||||||
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] = _freeWater;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Отрисовка "мин"
|
|
||||||
double radius = Math.Min(_size_x, _size_y);
|
|
||||||
while (counter < circlesCount)
|
|
||||||
{
|
|
||||||
int x = _random.Next(0, 99);
|
|
||||||
int y = _random.Next(0, 99);
|
|
||||||
_map[y, x] = _barrier;
|
|
||||||
for (int i = 0; i < minesAroundCount; i++)
|
|
||||||
{
|
|
||||||
int row = (int)Math.Ceiling(radius * Math.Sin(Math.PI * 2 / minesAroundCount * i)) + y;
|
|
||||||
int col = (int)Math.Ceiling(radius * Math.Cos(Math.PI * 2 / minesAroundCount * i)) + x;
|
|
||||||
|
|
||||||
if (row > -1 && col > -1 && row < _map.GetLength(0) && col < _map.GetLength(1))
|
|
||||||
{
|
|
||||||
_map[row, col] = _barrier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +1,3 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Serilog;
|
|
||||||
using Serilog.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace Boats
|
namespace Boats
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
@ -17,30 +11,7 @@ namespace Boats
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
var services = new ServiceCollection();
|
Application.Run(new FormBoat());
|
||||||
ConfigureServices(services);
|
|
||||||
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
|
||||||
{
|
|
||||||
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetBoats>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private static void ConfigureServices(ServiceCollection services)
|
|
||||||
{
|
|
||||||
services.AddSingleton<FormMapWithSetBoats>()
|
|
||||||
.AddLogging(option =>
|
|
||||||
{
|
|
||||||
var configuration = new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile(path: "appSettings.json", optional: false, reloadOnChange: true)
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
var logger = new LoggerConfiguration()
|
|
||||||
.ReadFrom.Configuration(configuration)
|
|
||||||
.CreateLogger();
|
|
||||||
|
|
||||||
option.SetMinimumLevel(LogLevel.Information);
|
|
||||||
option.AddSerilog(logger);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,131 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Параметризованный набор объектов
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T"></typeparam>
|
|
||||||
internal class SetBoatsGeneric<T>
|
|
||||||
where T : class, IEquatable<T>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Массив объектов, которые храним
|
|
||||||
/// </summary>
|
|
||||||
private readonly List<T> _places;
|
|
||||||
/// <summary>
|
|
||||||
/// Количество объектов в массиве
|
|
||||||
/// </summary>
|
|
||||||
public int Count => _places.Count;
|
|
||||||
/// <summary>
|
|
||||||
/// Максимальное количество элементов в списке
|
|
||||||
/// </summary>
|
|
||||||
private readonly int _maxCount;
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="count"></param>
|
|
||||||
public SetBoatsGeneric(int count)
|
|
||||||
{
|
|
||||||
_places = new List<T>();
|
|
||||||
_maxCount = count;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Добавление объекта в набор
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="boat">Добавляемая лодка</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public int Insert(T boat)
|
|
||||||
{
|
|
||||||
// Проверка на _maxCount
|
|
||||||
// Если достигли максимального значения - выбрасываем исключение
|
|
||||||
if (Count == _maxCount)
|
|
||||||
throw new StorageOverflowException(_maxCount);
|
|
||||||
// Вставка в начало набора
|
|
||||||
return Insert(boat, 0);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Добавление объекта в набор на конкретную позицию
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="boat">Добавляемая лодка</param>
|
|
||||||
/// <param name="position">Позиция</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public int Insert(T boat, int position)
|
|
||||||
{
|
|
||||||
// Проверка на уникальность
|
|
||||||
if (_places.Contains(boat))
|
|
||||||
{
|
|
||||||
throw new ArgumentException($"Объект {boat} уже есть");
|
|
||||||
}
|
|
||||||
// Проверка позиции
|
|
||||||
if (position < 0 || position >= _maxCount - 1)
|
|
||||||
return -1;
|
|
||||||
_places.Insert(position, boat);
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Удаление объекта из набора с конкретной позиции
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="position"></param>
|
|
||||||
/// <returns>Возвращает удаляемый объект или null, если не удалось удалить</returns>
|
|
||||||
public T Remove(int position)
|
|
||||||
{
|
|
||||||
// Проверка позиции
|
|
||||||
// Если позиция неверная (пустой быть не может, потому что у нас список),
|
|
||||||
// то выбрасываем исключение
|
|
||||||
if (position < 0 || position >= Count)
|
|
||||||
throw new BoatNotFoundException(position);
|
|
||||||
T boat = _places[position];
|
|
||||||
_places.RemoveAt(position);
|
|
||||||
return boat;
|
|
||||||
}
|
|
||||||
public T this[int position]
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
// Проверка позиции
|
|
||||||
if (position < 0 || position >= Count)
|
|
||||||
return null;
|
|
||||||
return _places[position];
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
// Проверка позиции
|
|
||||||
if (position < 0 || position >= Count)
|
|
||||||
return;
|
|
||||||
// Вставка по позиции
|
|
||||||
_places[position] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Проход по набору до первого пустого
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public IEnumerable<T> GetBoats()
|
|
||||||
{
|
|
||||||
foreach (var boat in _places)
|
|
||||||
{
|
|
||||||
if (boat != null)
|
|
||||||
{
|
|
||||||
yield return boat;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void SortSet(IComparer<T> comparer)
|
|
||||||
{
|
|
||||||
if (comparer == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_places.Sort(comparer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Класс стандартной карты
|
|
||||||
/// </summary>
|
|
||||||
internal class SimpleMap : AbstractMap
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Цвет участка закрытого
|
|
||||||
/// </summary>
|
|
||||||
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
|
||||||
/// <summary>
|
|
||||||
/// Цвет участка открытого
|
|
||||||
/// </summary>
|
|
||||||
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
|
||||||
/// <summary>
|
|
||||||
/// Метод для отрисовки закрытого участка карты
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
/// <param name="i"></param>
|
|
||||||
/// <param name="j"></param>
|
|
||||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
|
||||||
{
|
|
||||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Метод для отрисовки открытого участка карты
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="g"></param>
|
|
||||||
/// <param name="i"></param>
|
|
||||||
/// <param name="j"></param>
|
|
||||||
protected override void DrawWaterPart(Graphics g, int i, int j)
|
|
||||||
{
|
|
||||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Метод генерации карты
|
|
||||||
/// </summary>
|
|
||||||
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] = _freeWater;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (counter < 50)
|
|
||||||
{
|
|
||||||
int x = _random.Next(0, 100);
|
|
||||||
int y = _random.Next(0, 100);
|
|
||||||
if (_map[x, y] == _freeWater)
|
|
||||||
{
|
|
||||||
_map[x, y] = _barrier;
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.Serialization;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Boats
|
|
||||||
{
|
|
||||||
[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) { }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"Serilog": {
|
|
||||||
"Using": [ "Serilog.Sinks.File" ],
|
|
||||||
"MinimumLevel": "Information",
|
|
||||||
"WriteTo": [
|
|
||||||
{
|
|
||||||
"Name": "File",
|
|
||||||
"Args": {
|
|
||||||
"path": "log_.log",
|
|
||||||
"rollingInterval": "Day",
|
|
||||||
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
|
|
||||||
"Properties": {
|
|
||||||
"Application": "Boats"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user