Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
605ee63c40 | |||
fefc8beabb | |||
e8ec0d66e3 | |||
d1e9076ccb | |||
602107fced | |||
c711032928 | |||
aa83710ef8 | |||
e3d4e7c135 | |||
a87e9d0fe5 | |||
75e016e629 | |||
d7c9234ae8 | |||
51531902bc | |||
58b453a371 | |||
1da62721f7 | |||
196eb60f0c | |||
b8af73b6a6 | |||
755c0d2dd2 | |||
02c51ae801 | |||
8a3341f3ec |
135
Hydroplane/AbstractStrategy.cs
Normal file
135
Hydroplane/AbstractStrategy.cs
Normal file
@ -0,0 +1,135 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Hydroplane.DrawningObjects;
|
||||
|
||||
namespace Hydroplane.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-стратегия перемещения объекта
|
||||
/// </summary>
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObject? _moveableObject;
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
private Status _state = Status.NotInit;
|
||||
/// <summary>
|
||||
/// Ширина поля
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
/// <summary>
|
||||
/// Высота поля
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
public Status GetStatus() { return _state; }
|
||||
/// <summary>
|
||||
/// Установка данных
|
||||
/// </summary>
|
||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
public void SetData(IMoveableObject moveableObject, int width, int
|
||||
height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = Status.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false -неудача)</returns>
|
||||
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
|
||||
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||
/// <summary>
|
||||
/// Перемещение вверх
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться,false - неудача)</returns>
|
||||
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||
/// <summary>
|
||||
/// Перемещение вниз
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveDown() => MoveTo(DirectionType.Down);
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters? GetObjectParameters =>
|
||||
_moveableObject?.GetObjectPosition;
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
/// <summary>
|
||||
/// Достигнута ли цель
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
/// <summary>
|
||||
/// Попытка перемещения в требуемом направлении
|
||||
/// </summary>
|
||||
/// <param name="directionType">Направление</param>
|
||||
/// <returns>Результат попытки (true - удалось переместиться, false -неудача)</returns>
|
||||
private bool MoveTo(DirectionType directionType)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
20
Hydroplane/AppSettings.json
Normal file
20
Hydroplane/AppSettings.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Information",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/log_.log",
|
||||
"rollingInterval": "Day",
|
||||
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
|
||||
"Properties": {
|
||||
"Application": "Hydroplane"
|
||||
}
|
||||
}
|
||||
}
|
29
Hydroplane/Direction.cs
Normal file
29
Hydroplane/Direction.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hydroplane
|
||||
{
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
|
||||
}
|
||||
}
|
55
Hydroplane/DrawingPlaneEqutables.cs
Normal file
55
Hydroplane/DrawingPlaneEqutables.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
using Hydroplane.DrawningObjects;
|
||||
using Hydroplane.Entities;
|
||||
|
||||
namespace Hydroplane
|
||||
{
|
||||
internal class DrawingPlaneEqutables : IEqualityComparer<DrawningPlane?>
|
||||
{
|
||||
public bool Equals(DrawningPlane? x, DrawningPlane? y)
|
||||
{
|
||||
if (x == null || x.EntityPlane == null)
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
|
||||
if (y == null || y.EntityPlane == null)
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
return false;
|
||||
if (x.EntityPlane.Speed != y.EntityPlane.Speed)
|
||||
return false;
|
||||
if (x.EntityPlane.Weight != y.EntityPlane.Weight)
|
||||
return false;
|
||||
if (x.EntityPlane.BodyColor != y.EntityPlane.BodyColor)
|
||||
return false;
|
||||
// to do logic for "сравнения" additional parameters :)
|
||||
if (x is DrawningHydroplane && y is DrawningHydroplane)
|
||||
{
|
||||
if ((x.EntityPlane as EntityHydroplane).AdditionalColor != (y.EntityPlane as EntityHydroplane).AdditionalColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((x.EntityPlane as EntityHydroplane).Boat != (y.EntityPlane as EntityHydroplane).Boat)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((x.EntityPlane as EntityHydroplane).Bobber != (y.EntityPlane as EntityHydroplane).Bobber)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] DrawningPlane obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
95
Hydroplane/DrawningHydroplane.cs
Normal file
95
Hydroplane/DrawningHydroplane.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Hydroplane.Entities;
|
||||
|
||||
namespace Hydroplane.DrawningObjects
|
||||
{
|
||||
public class DrawningHydroplane : DrawningPlane
|
||||
{
|
||||
public DrawningHydroplane(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool boat, bool bobber, int width, int height) :
|
||||
base(speed, weight, bodyColor, width, height)
|
||||
{
|
||||
if (EntityPlane != null)
|
||||
{
|
||||
EntityPlane = new EntityHydroplane(speed, weight, bodyColor,
|
||||
additionalColor, boat, bobber);
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityPlane is not EntityHydroplane hydroplane)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush bodyBrush = new SolidBrush(EntityPlane.BodyColor);
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(hydroplane.AdditionalColor);
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
//раскраска иллюминаторов
|
||||
g.FillEllipse(additionalBrush, _startPosX + 40, _startPosY + 30, 10, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 60, _startPosY + 30, 10, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 80, _startPosY + 30, 10, 10);
|
||||
|
||||
//раскраска окна
|
||||
g.FillPolygon(additionalBrush, new[]
|
||||
{
|
||||
new Point(_startPosX + 160, _startPosY + 40),
|
||||
new Point(_startPosX + 130, _startPosY + 40),
|
||||
new Point(_startPosX + 130, _startPosY + 25) });
|
||||
|
||||
//раскраска ножек
|
||||
g.FillRectangle(bodyBrush, _startPosX + 65, _startPosY + 55, 5, 15);
|
||||
g.FillRectangle(bodyBrush, _startPosX + 125, _startPosY + 55, 5, 15);
|
||||
|
||||
//ножки снизу
|
||||
g.DrawLine(pen, _startPosX + 65, _startPosY + 55, _startPosX + 65, _startPosY + 70);
|
||||
g.DrawLine(pen, _startPosX + 70, _startPosY + 55, _startPosX + 70, _startPosY + 70);
|
||||
g.DrawLine(pen, _startPosX + 125, _startPosY + 55, _startPosX + 125, _startPosY + 70);
|
||||
g.DrawLine(pen, _startPosX + 130, _startPosY + 55, _startPosX + 130, _startPosY + 70);
|
||||
|
||||
|
||||
//поплавки(лыжи) или колеса
|
||||
if (hydroplane.Bobber)
|
||||
{
|
||||
g.FillPolygon(additionalBrush, new[]
|
||||
{
|
||||
new Point(_startPosX + 55, _startPosY + 70),
|
||||
new Point(_startPosX + 55, _startPosY + 80),
|
||||
new Point(_startPosX + 155, _startPosY + 80),
|
||||
new Point(_startPosX + 175, _startPosY + 70) });
|
||||
|
||||
g.DrawPolygon(pen, new[]
|
||||
{
|
||||
new Point(_startPosX + 55, _startPosY + 70),
|
||||
new Point(_startPosX + 55, _startPosY + 80),
|
||||
new Point(_startPosX + 155, _startPosY + 80),
|
||||
new Point(_startPosX + 175, _startPosY + 70) });
|
||||
}
|
||||
else
|
||||
{
|
||||
g.FillEllipse(additionalBrush, _startPosX + 60, _startPosY + 70, 15, 15);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 120, _startPosY + 70, 15, 15);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX + 60, _startPosY + 70, 15, 15);
|
||||
g.DrawEllipse(pen, _startPosX + 120, _startPosY + 70, 15, 15);
|
||||
}
|
||||
|
||||
//надувная лодка
|
||||
if (hydroplane.Boat)
|
||||
{
|
||||
g.FillEllipse(additionalBrush, _startPosX, _startPosY + 21, 32, 8);
|
||||
g.DrawEllipse(pen, _startPosX, _startPosY + 21, 32, 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
36
Hydroplane/DrawningObjectPlane.cs
Normal file
36
Hydroplane/DrawningObjectPlane.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Hydroplane.DrawningObjects;
|
||||
|
||||
namespace Hydroplane.MovementStrategy
|
||||
{
|
||||
public class DrawningObjectPlane : IMoveableObject
|
||||
{
|
||||
private readonly DrawningPlane? _drawingPlane = null;
|
||||
public DrawningObjectPlane(DrawningPlane drawingPlane)
|
||||
{
|
||||
_drawingPlane = drawingPlane;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawingPlane == null || _drawingPlane.EntityPlane == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawingPlane.GetPosX,
|
||||
_drawingPlane.GetPosY, _drawingPlane.GetWidth, _drawingPlane.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawingPlane?.EntityPlane?.Step ?? 0);
|
||||
public bool CheckCanMove(DirectionType direction) =>
|
||||
_drawingPlane?.CanMove(direction) ?? false;
|
||||
public void MoveObject(DirectionType direction) =>
|
||||
_drawingPlane?.MoveTransport(direction);
|
||||
|
||||
}
|
||||
}
|
163
Hydroplane/DrawningPlane.cs
Normal file
163
Hydroplane/DrawningPlane.cs
Normal file
@ -0,0 +1,163 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Hydroplane.Entities;
|
||||
using Hydroplane.MovementStrategy;
|
||||
|
||||
namespace Hydroplane.DrawningObjects
|
||||
{
|
||||
public class DrawningPlane
|
||||
{
|
||||
public EntityPlane? EntityPlane { get; protected set; }
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
private readonly int _planeWidth = 175;
|
||||
private readonly int _planeHeight = 80;
|
||||
public int GetPosX => _startPosX;
|
||||
public int GetPosY => _startPosY;
|
||||
public int GetWidth => _planeWidth;
|
||||
public int GetHeight => _planeHeight;
|
||||
public DrawningPlane(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (width < _pictureWidth || height < _pictureHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
protected DrawningPlane(int speed, double weight, Color bodyColor, int width, int height, int planeWidth, int planeHeight)
|
||||
{
|
||||
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_pictureWidth = planeWidth;
|
||||
_pictureHeight = planeHeight;
|
||||
if (width < _pictureWidth || height < _pictureHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectPlane(this);
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
_startPosX = Math.Min(x, _pictureWidth - _planeWidth);
|
||||
_startPosY = Math.Min(y, _pictureHeight - _planeHeight);
|
||||
}
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityPlane == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
//влево
|
||||
DirectionType.Left => _startPosX - EntityPlane.Step > 0,
|
||||
//вверх
|
||||
DirectionType.Up => _startPosY - EntityPlane.Step > 0,
|
||||
// вправо
|
||||
DirectionType.Right => _startPosX + EntityPlane.Step < _pictureWidth,
|
||||
//вниз
|
||||
DirectionType.Down => _startPosY + EntityPlane.Step < _pictureHeight,
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (!CanMove(direction) || EntityPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntityPlane.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityPlane.Step;
|
||||
}
|
||||
break;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityPlane.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityPlane.Step;
|
||||
}
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + EntityPlane.Step + _planeWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityPlane.Step;
|
||||
}
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + EntityPlane.Step + _planeHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityPlane.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush bodyBrush = new SolidBrush(EntityPlane.BodyColor);
|
||||
|
||||
//раскраска основы
|
||||
g.FillPolygon(bodyBrush, new[] {
|
||||
new Point(_startPosX + 5, _startPosY),
|
||||
new Point(_startPosX + 5, _startPosY + 55),
|
||||
new Point(_startPosX + 130, _startPosY + 55),
|
||||
new Point(_startPosX + 160, _startPosY + 40),
|
||||
new Point(_startPosX + 130, _startPosY + 40),
|
||||
new Point(_startPosX + 130, _startPosY + 25),
|
||||
new Point(_startPosX + 55, _startPosY + 25) });
|
||||
|
||||
|
||||
|
||||
//основа
|
||||
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 25, 125, 30);
|
||||
|
||||
//хвост
|
||||
g.DrawLine(pen, _startPosX + 5, _startPosY + 25, _startPosX + 5, _startPosY);
|
||||
g.DrawLine(pen, _startPosX + 55, _startPosY + 25, _startPosX + 5, _startPosY);
|
||||
|
||||
//нос
|
||||
g.DrawLine(pen, _startPosX + 130, _startPosY + 25, _startPosX + 160, _startPosY + 40);
|
||||
g.DrawLine(pen, _startPosX + 130, _startPosY + 55, _startPosX + 160, _startPosY + 40);
|
||||
g.DrawLine(pen, _startPosX + 130, _startPosY + 40, _startPosX + 160, _startPosY + 40);
|
||||
|
||||
//иллюминаторы
|
||||
g.DrawEllipse(pen, _startPosX + 40, _startPosY + 30, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX + 60, _startPosY + 30, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 30, 10, 10);
|
||||
|
||||
//крыло сбоку
|
||||
g.DrawEllipse(pen, _startPosX + 35, _startPosY + 43, 80, 7);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
26
Hydroplane/EntityHydroplane.cs
Normal file
26
Hydroplane/EntityHydroplane.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hydroplane.Entities
|
||||
{
|
||||
public class EntityHydroplane : EntityPlane
|
||||
{
|
||||
public Color AdditionalColor { get; set; }
|
||||
public bool Boat { get; private set; }
|
||||
public bool Bobber { get; private set; }
|
||||
public EntityHydroplane(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool boat, bool bobber) : base(speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Boat = boat;
|
||||
Bobber = bobber;
|
||||
}
|
||||
public void setAdditionalColor(Color color)
|
||||
{
|
||||
AdditionalColor = color;
|
||||
}
|
||||
}
|
||||
}
|
26
Hydroplane/EntityPlane.cs
Normal file
26
Hydroplane/EntityPlane.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hydroplane.Entities
|
||||
{
|
||||
public class EntityPlane
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
public double Weight { get; private set; }
|
||||
public Color BodyColor { get; set; }
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
public EntityPlane(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
public void setBodyColor(Color color)
|
||||
{
|
||||
BodyColor = color;
|
||||
}
|
||||
}
|
||||
}
|
50
Hydroplane/ExtentionDrawningPlane.cs
Normal file
50
Hydroplane/ExtentionDrawningPlane.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Hydroplane.Entities;
|
||||
|
||||
namespace Hydroplane.DrawningObjects
|
||||
{
|
||||
public static class ExtentionDrawningPlane
|
||||
{
|
||||
public static DrawningPlane? CreateDrawningPlane(this string info, char
|
||||
separatorForObject, int width, int height)
|
||||
{
|
||||
string[] strs = info.Split(separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawningPlane(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||
}
|
||||
if (strs.Length == 6)
|
||||
{
|
||||
return new DrawningHydroplane(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]),
|
||||
Color.FromName(strs[2]),
|
||||
Color.FromName(strs[3]),
|
||||
Convert.ToBoolean(strs[4]),
|
||||
Convert.ToBoolean(strs[5]), width, height);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetDataForSave(this DrawningPlane drawningPlane,
|
||||
char separatorForObject)
|
||||
{
|
||||
var plane = drawningPlane.EntityPlane;
|
||||
if (plane == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str = $"{plane.Speed}{separatorForObject}{plane.Weight}{separatorForObject}{plane.BodyColor.Name}";
|
||||
if (plane is not EntityHydroplane hydroplane)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return
|
||||
$"{str}{separatorForObject}{hydroplane.AdditionalColor.Name}{separatorForObject}{hydroplane.Boat}{separatorForObject}{hydroplane.Bobber}";
|
||||
}
|
||||
}
|
||||
}
|
39
Hydroplane/Form1.Designer.cs
generated
39
Hydroplane/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace Hydroplane
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <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.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace Hydroplane
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
189
Hydroplane/FormHydroplane.Designer.cs
generated
Normal file
189
Hydroplane/FormHydroplane.Designer.cs
generated
Normal file
@ -0,0 +1,189 @@
|
||||
namespace Hydroplane
|
||||
{
|
||||
partial class FormHydroplane
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
pictureBoxHydroplane = new PictureBox();
|
||||
buttonCreatePlane = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonCreateHydroplane = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStep = new Button();
|
||||
buttonChoose = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxHydroplane).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxHydroplane
|
||||
//
|
||||
pictureBoxHydroplane.Dock = DockStyle.Fill;
|
||||
pictureBoxHydroplane.Location = new Point(0, 0);
|
||||
pictureBoxHydroplane.Name = "pictureBoxHydroplane";
|
||||
pictureBoxHydroplane.Size = new Size(884, 461);
|
||||
pictureBoxHydroplane.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxHydroplane.TabIndex = 0;
|
||||
pictureBoxHydroplane.TabStop = false;
|
||||
//
|
||||
// buttonCreatePlane
|
||||
//
|
||||
buttonCreatePlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreatePlane.Location = new Point(24, 398);
|
||||
buttonCreatePlane.Name = "buttonCreatePlane";
|
||||
buttonCreatePlane.Size = new Size(108, 35);
|
||||
buttonCreatePlane.TabIndex = 1;
|
||||
buttonCreatePlane.Text = "Create plane";
|
||||
buttonCreatePlane.UseVisualStyleBackColor = true;
|
||||
buttonCreatePlane.Click += buttonCreatePlane_Click;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = Properties.Resources.up;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(774, 331);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(30, 30);
|
||||
buttonUp.TabIndex = 2;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.left;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Location = new Point(728, 366);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(30, 30);
|
||||
buttonLeft.TabIndex = 3;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = Properties.Resources.down;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(774, 403);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(30, 30);
|
||||
buttonDown.TabIndex = 4;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = Properties.Resources.right;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Location = new Point(816, 366);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(30, 30);
|
||||
buttonRight.TabIndex = 5;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonCreateHydroplane
|
||||
//
|
||||
buttonCreateHydroplane.Location = new Point(157, 398);
|
||||
buttonCreateHydroplane.Name = "buttonCreateHydroplane";
|
||||
buttonCreateHydroplane.Size = new Size(125, 35);
|
||||
buttonCreateHydroplane.TabIndex = 6;
|
||||
buttonCreateHydroplane.Text = "Create hydroplane";
|
||||
buttonCreateHydroplane.UseVisualStyleBackColor = true;
|
||||
buttonCreateHydroplane.Click += buttonCreateHydroplane_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "В центр", "Вниз" });
|
||||
comboBoxStrategy.Location = new Point(751, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(121, 23);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
buttonStep.Location = new Point(797, 41);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(75, 23);
|
||||
buttonStep.TabIndex = 8;
|
||||
buttonStep.Text = "Step";
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += buttonStep_Click;
|
||||
//
|
||||
// buttonChoose
|
||||
//
|
||||
buttonChoose.Location = new Point(309, 398);
|
||||
buttonChoose.Name = "buttonChoose";
|
||||
buttonChoose.Size = new Size(125, 35);
|
||||
buttonChoose.TabIndex = 9;
|
||||
buttonChoose.Text = "Choose";
|
||||
buttonChoose.UseVisualStyleBackColor = true;
|
||||
buttonChoose.Click += ButtonSelectPLane_Click;
|
||||
//
|
||||
// FormHydroplane
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(884, 461);
|
||||
Controls.Add(buttonChoose);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateHydroplane);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonCreatePlane);
|
||||
Controls.Add(pictureBoxHydroplane);
|
||||
Name = "FormHydroplane";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Hydroplane";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxHydroplane).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxHydroplane;
|
||||
private Button buttonCreatePlane;
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonCreateHydroplane;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
private Button buttonChoose;
|
||||
}
|
||||
}
|
141
Hydroplane/FormHydroplane.cs
Normal file
141
Hydroplane/FormHydroplane.cs
Normal file
@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Hydroplane.Entities;
|
||||
using Hydroplane.DrawningObjects;
|
||||
using Hydroplane.MovementStrategy;
|
||||
|
||||
namespace Hydroplane
|
||||
{
|
||||
public partial class FormHydroplane : Form
|
||||
{
|
||||
private DrawningPlane? _drawingPlane;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawningPlane? SelectedPlane { get; private set; }
|
||||
|
||||
public FormHydroplane()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedPlane = null;
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxHydroplane.Width,
|
||||
pictureBoxHydroplane.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawingPlane.DrawTransport(gr);
|
||||
pictureBoxHydroplane.Image = bmp;
|
||||
}
|
||||
private void buttonCreatePlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_drawingPlane = new DrawningPlane(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxHydroplane.Width, pictureBoxHydroplane.Height);
|
||||
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
}
|
||||
private void buttonCreateHydroplane_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color mainColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
mainColor = dialog.Color;
|
||||
}
|
||||
Color addColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
addColor = dialog.Color;
|
||||
}
|
||||
_drawingPlane = new DrawningHydroplane(random.Next(100, 300), random.Next(1000, 3000), mainColor, addColor,
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), pictureBoxHydroplane.Width, pictureBoxHydroplane.Height);
|
||||
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawingPlane.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawingPlane.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawingPlane.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawingPlane.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(_drawingPlane.GetMoveableObject, pictureBoxHydroplane.Width, pictureBoxHydroplane.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSelectPLane_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedPlane = _drawingPlane;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
120
Hydroplane/FormHydroplane.resx
Normal file
120
Hydroplane/FormHydroplane.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
304
Hydroplane/FormHydroplaneCollection.Designer.cs
generated
Normal file
304
Hydroplane/FormHydroplaneCollection.Designer.cs
generated
Normal file
@ -0,0 +1,304 @@
|
||||
namespace Hydroplane
|
||||
{
|
||||
partial class FormHydroplaneCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
panel1 = new Panel();
|
||||
panel2 = new Panel();
|
||||
DeleteCollectButton = new Button();
|
||||
CollectionListBox = new ListBox();
|
||||
AddCollectButton = new Button();
|
||||
SetTextBox = new TextBox();
|
||||
label2 = new Label();
|
||||
UpdateButton = new Button();
|
||||
DeleteButton = new Button();
|
||||
AddButton = new Button();
|
||||
PlaneTextBox = new TextBox();
|
||||
label1 = new Label();
|
||||
DrawPlane = new PictureBox();
|
||||
StripMenu = new MenuStrip();
|
||||
fileToolStripMenuItem = new ToolStripMenuItem();
|
||||
saveToolStripMenuItem = new ToolStripMenuItem();
|
||||
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||
SaveFileDialog = new SaveFileDialog();
|
||||
OpenFileDialog = new OpenFileDialog();
|
||||
buttonSortByType = new Button();
|
||||
buttonSortByColor = new Button();
|
||||
panel1.SuspendLayout();
|
||||
panel2.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)DrawPlane).BeginInit();
|
||||
StripMenu.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
panel1.Controls.Add(buttonSortByColor);
|
||||
panel1.Controls.Add(buttonSortByType);
|
||||
panel1.Controls.Add(panel2);
|
||||
panel1.Controls.Add(UpdateButton);
|
||||
panel1.Controls.Add(DeleteButton);
|
||||
panel1.Controls.Add(AddButton);
|
||||
panel1.Controls.Add(PlaneTextBox);
|
||||
panel1.Controls.Add(label1);
|
||||
panel1.Dock = DockStyle.Right;
|
||||
panel1.Location = new Point(646, 24);
|
||||
panel1.Margin = new Padding(3, 2, 3, 2);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(219, 432);
|
||||
panel1.TabIndex = 0;
|
||||
//
|
||||
// panel2
|
||||
//
|
||||
panel2.Controls.Add(DeleteCollectButton);
|
||||
panel2.Controls.Add(CollectionListBox);
|
||||
panel2.Controls.Add(AddCollectButton);
|
||||
panel2.Controls.Add(SetTextBox);
|
||||
panel2.Controls.Add(label2);
|
||||
panel2.Location = new Point(14, 28);
|
||||
panel2.Margin = new Padding(3, 2, 3, 2);
|
||||
panel2.Name = "panel2";
|
||||
panel2.Size = new Size(187, 165);
|
||||
panel2.TabIndex = 5;
|
||||
//
|
||||
// DeleteCollectButton
|
||||
//
|
||||
DeleteCollectButton.Location = new Point(3, 136);
|
||||
DeleteCollectButton.Margin = new Padding(3, 2, 3, 2);
|
||||
DeleteCollectButton.Name = "DeleteCollectButton";
|
||||
DeleteCollectButton.Size = new Size(182, 22);
|
||||
DeleteCollectButton.TabIndex = 4;
|
||||
DeleteCollectButton.Text = "Удалить набор";
|
||||
DeleteCollectButton.UseVisualStyleBackColor = true;
|
||||
DeleteCollectButton.Click += ButtonDelObject_Click;
|
||||
//
|
||||
// CollectionListBox
|
||||
//
|
||||
CollectionListBox.FormattingEnabled = true;
|
||||
CollectionListBox.ItemHeight = 15;
|
||||
CollectionListBox.Location = new Point(3, 68);
|
||||
CollectionListBox.Margin = new Padding(3, 2, 3, 2);
|
||||
CollectionListBox.Name = "CollectionListBox";
|
||||
CollectionListBox.Size = new Size(182, 64);
|
||||
CollectionListBox.TabIndex = 3;
|
||||
CollectionListBox.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged;
|
||||
//
|
||||
// AddCollectButton
|
||||
//
|
||||
AddCollectButton.Location = new Point(3, 42);
|
||||
AddCollectButton.Margin = new Padding(3, 2, 3, 2);
|
||||
AddCollectButton.Name = "AddCollectButton";
|
||||
AddCollectButton.Size = new Size(182, 22);
|
||||
AddCollectButton.TabIndex = 2;
|
||||
AddCollectButton.Text = "Добавить набор";
|
||||
AddCollectButton.UseVisualStyleBackColor = true;
|
||||
AddCollectButton.Click += ButtonAddObject_Click;
|
||||
//
|
||||
// SetTextBox
|
||||
//
|
||||
SetTextBox.Location = new Point(2, 17);
|
||||
SetTextBox.Margin = new Padding(3, 2, 3, 2);
|
||||
SetTextBox.Name = "SetTextBox";
|
||||
SetTextBox.Size = new Size(183, 23);
|
||||
SetTextBox.TabIndex = 1;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(3, 0);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(52, 15);
|
||||
label2.TabIndex = 0;
|
||||
label2.Text = "Наборы";
|
||||
//
|
||||
// UpdateButton
|
||||
//
|
||||
UpdateButton.Location = new Point(14, 389);
|
||||
UpdateButton.Margin = new Padding(3, 2, 3, 2);
|
||||
UpdateButton.Name = "UpdateButton";
|
||||
UpdateButton.Size = new Size(187, 28);
|
||||
UpdateButton.TabIndex = 4;
|
||||
UpdateButton.Text = "Обновить коллекцию";
|
||||
UpdateButton.UseVisualStyleBackColor = true;
|
||||
UpdateButton.Click += ButtonRefreshCollection_Click;
|
||||
//
|
||||
// DeleteButton
|
||||
//
|
||||
DeleteButton.Location = new Point(14, 356);
|
||||
DeleteButton.Margin = new Padding(3, 2, 3, 2);
|
||||
DeleteButton.Name = "DeleteButton";
|
||||
DeleteButton.Size = new Size(187, 28);
|
||||
DeleteButton.TabIndex = 3;
|
||||
DeleteButton.Text = "Удалить самолёт";
|
||||
DeleteButton.UseVisualStyleBackColor = true;
|
||||
DeleteButton.Click += ButtonRemovePlane_Click;
|
||||
//
|
||||
// AddButton
|
||||
//
|
||||
AddButton.Location = new Point(14, 300);
|
||||
AddButton.Margin = new Padding(3, 2, 3, 2);
|
||||
AddButton.Name = "AddButton";
|
||||
AddButton.Size = new Size(187, 28);
|
||||
AddButton.TabIndex = 2;
|
||||
AddButton.Text = "Добавить самолёт";
|
||||
AddButton.UseVisualStyleBackColor = true;
|
||||
AddButton.Click += ButtonAddPlane_Click;
|
||||
//
|
||||
// PlaneTextBox
|
||||
//
|
||||
PlaneTextBox.Location = new Point(14, 332);
|
||||
PlaneTextBox.Margin = new Padding(3, 2, 3, 2);
|
||||
PlaneTextBox.Name = "PlaneTextBox";
|
||||
PlaneTextBox.Size = new Size(187, 23);
|
||||
PlaneTextBox.TabIndex = 1;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(2, 2);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(83, 15);
|
||||
label1.TabIndex = 0;
|
||||
label1.Text = "Инструменты";
|
||||
//
|
||||
// DrawPlane
|
||||
//
|
||||
DrawPlane.Dock = DockStyle.Fill;
|
||||
DrawPlane.Location = new Point(0, 24);
|
||||
DrawPlane.Margin = new Padding(3, 2, 3, 2);
|
||||
DrawPlane.Name = "DrawPlane";
|
||||
DrawPlane.Size = new Size(646, 432);
|
||||
DrawPlane.TabIndex = 1;
|
||||
DrawPlane.TabStop = false;
|
||||
//
|
||||
// StripMenu
|
||||
//
|
||||
StripMenu.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem });
|
||||
StripMenu.Location = new Point(0, 0);
|
||||
StripMenu.Name = "StripMenu";
|
||||
StripMenu.Size = new Size(865, 24);
|
||||
StripMenu.TabIndex = 2;
|
||||
StripMenu.Text = "menuStrip1";
|
||||
//
|
||||
// fileToolStripMenuItem
|
||||
//
|
||||
fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
|
||||
fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
||||
fileToolStripMenuItem.Size = new Size(37, 20);
|
||||
fileToolStripMenuItem.Text = "File";
|
||||
//
|
||||
// saveToolStripMenuItem
|
||||
//
|
||||
saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||
saveToolStripMenuItem.Size = new Size(100, 22);
|
||||
saveToolStripMenuItem.Text = "Save";
|
||||
saveToolStripMenuItem.Click += SaveToolStripMenu_Click;
|
||||
//
|
||||
// loadToolStripMenuItem
|
||||
//
|
||||
loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||
loadToolStripMenuItem.Size = new Size(100, 22);
|
||||
loadToolStripMenuItem.Text = "Load";
|
||||
loadToolStripMenuItem.Click += LoadToolStripMenu_Click;
|
||||
//
|
||||
// SaveFileDialog
|
||||
//
|
||||
SaveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// OpenFileDialog
|
||||
//
|
||||
OpenFileDialog.FileName = "openFileDialog1";
|
||||
OpenFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
buttonSortByType.Location = new Point(14, 220);
|
||||
buttonSortByType.Name = "buttonSortByType";
|
||||
buttonSortByType.Size = new Size(187, 27);
|
||||
buttonSortByType.TabIndex = 6;
|
||||
buttonSortByType.Text = "Сортировка по типу";
|
||||
buttonSortByType.UseVisualStyleBackColor = true;
|
||||
buttonSortByType.Click += buttonSortByType_Click;
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
buttonSortByColor.Location = new Point(14, 253);
|
||||
buttonSortByColor.Name = "buttonSortByColor";
|
||||
buttonSortByColor.Size = new Size(187, 27);
|
||||
buttonSortByColor.TabIndex = 7;
|
||||
buttonSortByColor.Text = "Сортировка по цвету";
|
||||
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||
//
|
||||
// FormHydroplaneCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(865, 456);
|
||||
Controls.Add(DrawPlane);
|
||||
Controls.Add(panel1);
|
||||
Controls.Add(StripMenu);
|
||||
MainMenuStrip = StripMenu;
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "FormHydroplaneCollection";
|
||||
Text = "Гаражи гидропланов";
|
||||
panel1.ResumeLayout(false);
|
||||
panel1.PerformLayout();
|
||||
panel2.ResumeLayout(false);
|
||||
panel2.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)DrawPlane).EndInit();
|
||||
StripMenu.ResumeLayout(false);
|
||||
StripMenu.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Panel panel1;
|
||||
private Button UpdateButton;
|
||||
private Button DeleteButton;
|
||||
private Button AddButton;
|
||||
private TextBox PlaneTextBox;
|
||||
private Label label1;
|
||||
private PictureBox DrawPlane;
|
||||
private Panel panel2;
|
||||
private Button DeleteCollectButton;
|
||||
private ListBox CollectionListBox;
|
||||
private Button AddCollectButton;
|
||||
private TextBox SetTextBox;
|
||||
private Label label2;
|
||||
private MenuStrip StripMenu;
|
||||
private ToolStripMenuItem fileToolStripMenuItem;
|
||||
private ToolStripMenuItem saveToolStripMenuItem;
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private SaveFileDialog SaveFileDialog;
|
||||
private OpenFileDialog OpenFileDialog;
|
||||
private Button buttonSortByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
265
Hydroplane/FormHydroplaneCollection.cs
Normal file
265
Hydroplane/FormHydroplaneCollection.cs
Normal file
@ -0,0 +1,265 @@
|
||||
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;
|
||||
|
||||
using Hydroplane.Exceptions;
|
||||
using Hydroplane.DrawningObjects;
|
||||
using Hydroplane.Generics;
|
||||
using Hydroplane.MovementStrategy;
|
||||
|
||||
namespace Hydroplane
|
||||
{
|
||||
public partial class FormHydroplaneCollection : Form
|
||||
{
|
||||
private readonly PlanesGenericStorage _storage;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormHydroplaneCollection(ILogger<FormHydroplaneCollection> logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new PlanesGenericStorage(DrawPlane.Width, DrawPlane.Height);
|
||||
_logger = logger;
|
||||
}
|
||||
/// <summary>
|
||||
/// Заполнение listBoxObjects
|
||||
/// </summary>
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = CollectionListBox.SelectedIndex;
|
||||
CollectionListBox.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
CollectionListBox.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
if (CollectionListBox.Items.Count > 0 && (index == -1 || index
|
||||
>= CollectionListBox.Items.Count))
|
||||
{
|
||||
CollectionListBox.SelectedIndex = 0;
|
||||
}
|
||||
else if (CollectionListBox.Items.Count > 0 && index > -1 &&
|
||||
index < CollectionListBox.Items.Count)
|
||||
{
|
||||
CollectionListBox.SelectedIndex = index;
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(SetTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Input not complete", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(SetTextBox.Text.ToString());
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Added set: {SetTextBox.Text}");
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
DrawPlane.Image =
|
||||
_storage[CollectionListBox.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes();
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (CollectionListBox.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = CollectionListBox.SelectedItem.ToString() ?? string.Empty;
|
||||
if (MessageBox.Show($"Delete Object {name}?", "Deleting",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(name);
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Deleted set: {name}");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonAddPlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (CollectionListBox.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[CollectionListBox.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormPlaneConfig formPlaneConfig = new FormPlaneConfig();
|
||||
formPlaneConfig.AddEvent(AddPlane);
|
||||
formPlaneConfig.Show();
|
||||
}
|
||||
|
||||
private void AddPlane(DrawningPlane plane)
|
||||
{
|
||||
if (CollectionListBox.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[CollectionListBox.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
_logger.LogWarning("Добавление пустого объекта");
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_ = obj + plane;
|
||||
MessageBox.Show("Объект добавлен");
|
||||
DrawPlane.Image = obj.ShowPlanes();
|
||||
_logger.LogInformation($"plane added in set {CollectionListBox.SelectedItem.ToString()}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"plane not added in set {CollectionListBox.SelectedItem.ToString()}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemovePlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (CollectionListBox.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[CollectionListBox.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Delete Object?", "Delete", MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
int pos = Convert.ToInt32(PlaneTextBox.Text);
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Object deleted");
|
||||
DrawPlane.Image = obj.ShowPlanes();
|
||||
_logger.LogInformation($"plane deleted in set {CollectionListBox.SelectedItem.ToString()}");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Object not deleted");
|
||||
_logger.LogWarning($"plane not deleted in set {CollectionListBox.SelectedItem.ToString()}");
|
||||
}
|
||||
}
|
||||
catch (PlaneNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"PlaneNotFound: {ex.Message} in set {CollectionListBox.SelectedItem.ToString()}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Not input");
|
||||
_logger.LogWarning("Not input");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обновление рисунка по набору
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (CollectionListBox.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[CollectionListBox.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawPlane.Image = obj.ShowPlanes();
|
||||
}
|
||||
|
||||
private void SaveToolStripMenu_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (SaveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_storage.SaveData(SaveFileDialog.FileName);
|
||||
MessageBox.Show("Saving complete", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation($"save in file {SaveFileDialog.FileName}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Not saved: {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning($"Save to file {SaveFileDialog.FileName} not complete");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadToolStripMenu_Click(object sender, EventArgs args)
|
||||
{
|
||||
if (OpenFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_storage.LoadData(OpenFileDialog.FileName);
|
||||
MessageBox.Show("Load complete", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"load from file {OpenFileDialog.FileName}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Not loaded: {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning($"load from file {OpenFileDialog.FileName} not complete");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSortByType_Click(object sender, EventArgs e) => ComparePlanes(new PlaneCompareByType());
|
||||
|
||||
private void buttonSortByColor_Click(object sender, EventArgs e) => ComparePlanes(new PlaneCompareByColor());
|
||||
|
||||
public void ComparePlanes(IComparer<DrawningPlane?> comparer)
|
||||
{
|
||||
if (CollectionListBox.SelectedIndex == -1) return;
|
||||
|
||||
var obj = _storage[CollectionListBox.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null) return;
|
||||
|
||||
obj.Sort(comparer);
|
||||
DrawPlane.Image = obj.ShowPlanes();
|
||||
}
|
||||
}
|
||||
}
|
132
Hydroplane/FormHydroplaneCollection.resx
Normal file
132
Hydroplane/FormHydroplaneCollection.resx
Normal file
@ -0,0 +1,132 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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="StripMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>282, 17</value>
|
||||
</metadata>
|
||||
<metadata name="SaveFileDialog.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>147, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>52</value>
|
||||
</metadata>
|
||||
</root>
|
399
Hydroplane/FormPlaneConfig.Designer.cs
generated
Normal file
399
Hydroplane/FormPlaneConfig.Designer.cs
generated
Normal file
@ -0,0 +1,399 @@
|
||||
namespace Hydroplane
|
||||
{
|
||||
partial class FormPlaneConfig
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
groupBox_param = new GroupBox();
|
||||
checkBox_boat = new CheckBox();
|
||||
checkBox_bobber = new CheckBox();
|
||||
label_weight = new Label();
|
||||
groupBox_colors = new GroupBox();
|
||||
panelGray = new Panel();
|
||||
panelCian = new Panel();
|
||||
panelPurple = new Panel();
|
||||
panelBlack = new Panel();
|
||||
panelBlue = new Panel();
|
||||
panelGreen = new Panel();
|
||||
panelYellow = new Panel();
|
||||
panelRed = new Panel();
|
||||
numericUpDownWeight = new NumericUpDown();
|
||||
numericUpDownSpeed = new NumericUpDown();
|
||||
label_speed = new Label();
|
||||
labelOriginalObject = new Label();
|
||||
labelModifiedObject = new Label();
|
||||
pictureBox = new PictureBox();
|
||||
Panel = new Panel();
|
||||
button_close = new Button();
|
||||
button_add = new Button();
|
||||
label_color = new Label();
|
||||
panel_color = new Panel();
|
||||
panel_addit_color = new Panel();
|
||||
label1 = new Label();
|
||||
groupBox_param.SuspendLayout();
|
||||
groupBox_colors.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
Panel.SuspendLayout();
|
||||
panel_color.SuspendLayout();
|
||||
panel_addit_color.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBox_param
|
||||
//
|
||||
groupBox_param.Controls.Add(checkBox_boat);
|
||||
groupBox_param.Controls.Add(checkBox_bobber);
|
||||
groupBox_param.Controls.Add(label_weight);
|
||||
groupBox_param.Controls.Add(groupBox_colors);
|
||||
groupBox_param.Controls.Add(numericUpDownWeight);
|
||||
groupBox_param.Controls.Add(numericUpDownSpeed);
|
||||
groupBox_param.Controls.Add(label_speed);
|
||||
groupBox_param.Location = new Point(525, 9);
|
||||
groupBox_param.Margin = new Padding(3, 2, 3, 2);
|
||||
groupBox_param.Name = "groupBox_param";
|
||||
groupBox_param.Padding = new Padding(3, 2, 3, 2);
|
||||
groupBox_param.Size = new Size(164, 301);
|
||||
groupBox_param.TabIndex = 0;
|
||||
groupBox_param.TabStop = false;
|
||||
groupBox_param.Text = "Параметры";
|
||||
//
|
||||
// checkBox_boat
|
||||
//
|
||||
checkBox_boat.AutoSize = true;
|
||||
checkBox_boat.Location = new Point(89, 116);
|
||||
checkBox_boat.Margin = new Padding(3, 2, 3, 2);
|
||||
checkBox_boat.Name = "checkBox_boat";
|
||||
checkBox_boat.Size = new Size(59, 19);
|
||||
checkBox_boat.TabIndex = 5;
|
||||
checkBox_boat.Text = "Лодка";
|
||||
checkBox_boat.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBox_bobber
|
||||
//
|
||||
checkBox_bobber.AutoSize = true;
|
||||
checkBox_bobber.Location = new Point(5, 116);
|
||||
checkBox_bobber.Margin = new Padding(3, 2, 3, 2);
|
||||
checkBox_bobber.Name = "checkBox_bobber";
|
||||
checkBox_bobber.Size = new Size(59, 19);
|
||||
checkBox_bobber.TabIndex = 6;
|
||||
checkBox_bobber.Text = "Лыжи";
|
||||
//
|
||||
// label_weight
|
||||
//
|
||||
label_weight.AutoSize = true;
|
||||
label_weight.Location = new Point(5, 64);
|
||||
label_weight.Name = "label_weight";
|
||||
label_weight.Size = new Size(26, 15);
|
||||
label_weight.TabIndex = 3;
|
||||
label_weight.Text = "Вес";
|
||||
//
|
||||
// groupBox_colors
|
||||
//
|
||||
groupBox_colors.Controls.Add(panelGray);
|
||||
groupBox_colors.Controls.Add(panelCian);
|
||||
groupBox_colors.Controls.Add(panelPurple);
|
||||
groupBox_colors.Controls.Add(panelBlack);
|
||||
groupBox_colors.Controls.Add(panelBlue);
|
||||
groupBox_colors.Controls.Add(panelGreen);
|
||||
groupBox_colors.Controls.Add(panelYellow);
|
||||
groupBox_colors.Controls.Add(panelRed);
|
||||
groupBox_colors.Location = new Point(9, 138);
|
||||
groupBox_colors.Margin = new Padding(3, 2, 3, 2);
|
||||
groupBox_colors.Name = "groupBox_colors";
|
||||
groupBox_colors.Padding = new Padding(3, 2, 3, 2);
|
||||
groupBox_colors.Size = new Size(145, 152);
|
||||
groupBox_colors.TabIndex = 1;
|
||||
groupBox_colors.TabStop = false;
|
||||
groupBox_colors.Text = "Цвета";
|
||||
//
|
||||
// panelGray
|
||||
//
|
||||
panelGray.BackColor = Color.Silver;
|
||||
panelGray.Location = new Point(80, 122);
|
||||
panelGray.Margin = new Padding(3, 2, 3, 2);
|
||||
panelGray.Name = "panelGray";
|
||||
panelGray.Size = new Size(52, 19);
|
||||
panelGray.TabIndex = 7;
|
||||
//
|
||||
// panelCian
|
||||
//
|
||||
panelCian.BackColor = Color.Cyan;
|
||||
panelCian.Location = new Point(8, 122);
|
||||
panelCian.Margin = new Padding(3, 2, 3, 2);
|
||||
panelCian.Name = "panelCian";
|
||||
panelCian.Size = new Size(52, 19);
|
||||
panelCian.TabIndex = 6;
|
||||
//
|
||||
// panelPurple
|
||||
//
|
||||
panelPurple.BackColor = Color.FromArgb(192, 0, 192);
|
||||
panelPurple.Location = new Point(80, 92);
|
||||
panelPurple.Margin = new Padding(3, 2, 3, 2);
|
||||
panelPurple.Name = "panelPurple";
|
||||
panelPurple.Size = new Size(52, 19);
|
||||
panelPurple.TabIndex = 5;
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
panelBlack.BackColor = Color.Black;
|
||||
panelBlack.Location = new Point(8, 92);
|
||||
panelBlack.Margin = new Padding(3, 2, 3, 2);
|
||||
panelBlack.Name = "panelBlack";
|
||||
panelBlack.Size = new Size(52, 19);
|
||||
panelBlack.TabIndex = 4;
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
panelBlue.BackColor = Color.Blue;
|
||||
panelBlue.Location = new Point(80, 59);
|
||||
panelBlue.Margin = new Padding(3, 2, 3, 2);
|
||||
panelBlue.Name = "panelBlue";
|
||||
panelBlue.Size = new Size(52, 19);
|
||||
panelBlue.TabIndex = 3;
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
panelGreen.BackColor = Color.Lime;
|
||||
panelGreen.Location = new Point(8, 59);
|
||||
panelGreen.Margin = new Padding(3, 2, 3, 2);
|
||||
panelGreen.Name = "panelGreen";
|
||||
panelGreen.Size = new Size(52, 19);
|
||||
panelGreen.TabIndex = 2;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
panelYellow.BackColor = Color.Yellow;
|
||||
panelYellow.Location = new Point(80, 27);
|
||||
panelYellow.Margin = new Padding(3, 2, 3, 2);
|
||||
panelYellow.Name = "panelYellow";
|
||||
panelYellow.Size = new Size(52, 19);
|
||||
panelYellow.TabIndex = 1;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
panelRed.BackColor = Color.Red;
|
||||
panelRed.Location = new Point(7, 28);
|
||||
panelRed.Margin = new Padding(3, 2, 3, 2);
|
||||
panelRed.Name = "panelRed";
|
||||
panelRed.Size = new Size(52, 19);
|
||||
panelRed.TabIndex = 0;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
numericUpDownWeight.Location = new Point(5, 82);
|
||||
numericUpDownWeight.Margin = new Padding(3, 2, 3, 2);
|
||||
numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
numericUpDownWeight.Size = new Size(46, 23);
|
||||
numericUpDownWeight.TabIndex = 2;
|
||||
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
numericUpDownSpeed.Location = new Point(5, 42);
|
||||
numericUpDownSpeed.Margin = new Padding(3, 2, 3, 2);
|
||||
numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
numericUpDownSpeed.Size = new Size(49, 23);
|
||||
numericUpDownSpeed.TabIndex = 1;
|
||||
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// label_speed
|
||||
//
|
||||
label_speed.AutoSize = true;
|
||||
label_speed.Location = new Point(5, 25);
|
||||
label_speed.Name = "label_speed";
|
||||
label_speed.Size = new Size(59, 15);
|
||||
label_speed.TabIndex = 0;
|
||||
label_speed.Text = "Скорость";
|
||||
//
|
||||
// labelOriginalObject
|
||||
//
|
||||
labelOriginalObject.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelOriginalObject.Location = new Point(530, 312);
|
||||
labelOriginalObject.Name = "labelOriginalObject";
|
||||
labelOriginalObject.Size = new Size(71, 22);
|
||||
labelOriginalObject.TabIndex = 2;
|
||||
labelOriginalObject.Text = "Простой";
|
||||
labelOriginalObject.MouseDown += Label_MouseDown;
|
||||
//
|
||||
// labelModifiedObject
|
||||
//
|
||||
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelModifiedObject.Location = new Point(622, 312);
|
||||
labelModifiedObject.Name = "labelModifiedObject";
|
||||
labelModifiedObject.Size = new Size(68, 22);
|
||||
labelModifiedObject.TabIndex = 3;
|
||||
labelModifiedObject.Text = "Потомок";
|
||||
labelModifiedObject.MouseDown += Label_MouseDown;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Location = new Point(3, 16);
|
||||
pictureBox.Margin = new Padding(3, 2, 3, 2);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(514, 274);
|
||||
pictureBox.TabIndex = 4;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// Panel
|
||||
//
|
||||
Panel.AllowDrop = true;
|
||||
Panel.Controls.Add(pictureBox);
|
||||
Panel.Location = new Point(0, 44);
|
||||
Panel.Margin = new Padding(3, 2, 3, 2);
|
||||
Panel.Name = "Panel";
|
||||
Panel.Size = new Size(525, 294);
|
||||
Panel.TabIndex = 5;
|
||||
Panel.DragDrop += panel_dragDrop;
|
||||
Panel.DragEnter += panel_dragEnter;
|
||||
//
|
||||
// button_close
|
||||
//
|
||||
button_close.Location = new Point(447, 9);
|
||||
button_close.Margin = new Padding(3, 2, 3, 2);
|
||||
button_close.Name = "button_close";
|
||||
button_close.Size = new Size(70, 22);
|
||||
button_close.TabIndex = 8;
|
||||
button_close.Text = "Отмена";
|
||||
button_close.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// button_add
|
||||
//
|
||||
button_add.Location = new Point(359, 9);
|
||||
button_add.Margin = new Padding(3, 2, 3, 2);
|
||||
button_add.Name = "button_add";
|
||||
button_add.Size = new Size(83, 22);
|
||||
button_add.TabIndex = 7;
|
||||
button_add.Text = "Добавить";
|
||||
button_add.UseVisualStyleBackColor = true;
|
||||
button_add.Click += button_add_Click;
|
||||
//
|
||||
// label_color
|
||||
//
|
||||
label_color.BorderStyle = BorderStyle.FixedSingle;
|
||||
label_color.Location = new Point(4, 5);
|
||||
label_color.Name = "label_color";
|
||||
label_color.Size = new Size(150, 35);
|
||||
label_color.TabIndex = 5;
|
||||
label_color.Text = "Основной цвет";
|
||||
//
|
||||
// panel_color
|
||||
//
|
||||
panel_color.AllowDrop = true;
|
||||
panel_color.Controls.Add(label_color);
|
||||
panel_color.Location = new Point(0, 2);
|
||||
panel_color.Margin = new Padding(3, 2, 3, 2);
|
||||
panel_color.Name = "panel_color";
|
||||
panel_color.Size = new Size(157, 40);
|
||||
panel_color.TabIndex = 6;
|
||||
panel_color.DragDrop += labelColor_dragDrop;
|
||||
panel_color.DragEnter += labelColor_dragEnter;
|
||||
//
|
||||
// panel_addit_color
|
||||
//
|
||||
panel_addit_color.AllowDrop = true;
|
||||
panel_addit_color.Controls.Add(label1);
|
||||
panel_addit_color.Location = new Point(164, 2);
|
||||
panel_addit_color.Margin = new Padding(3, 2, 3, 2);
|
||||
panel_addit_color.Name = "panel_addit_color";
|
||||
panel_addit_color.Size = new Size(157, 40);
|
||||
panel_addit_color.TabIndex = 7;
|
||||
panel_addit_color.DragDrop += labelColor_dragDrop;
|
||||
panel_addit_color.DragEnter += labelColor_dragEnter;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.BorderStyle = BorderStyle.FixedSingle;
|
||||
label1.Location = new Point(3, 5);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(152, 35);
|
||||
label1.TabIndex = 6;
|
||||
label1.Text = "Дополнительный цвет";
|
||||
//
|
||||
// FormPlaneConfig
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(700, 338);
|
||||
Controls.Add(panel_addit_color);
|
||||
Controls.Add(panel_color);
|
||||
Controls.Add(button_close);
|
||||
Controls.Add(Panel);
|
||||
Controls.Add(button_add);
|
||||
Controls.Add(labelModifiedObject);
|
||||
Controls.Add(labelOriginalObject);
|
||||
Controls.Add(groupBox_param);
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "FormPlaneConfig";
|
||||
Text = "FormSPAUConfig";
|
||||
groupBox_param.ResumeLayout(false);
|
||||
groupBox_param.PerformLayout();
|
||||
groupBox_colors.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
Panel.ResumeLayout(false);
|
||||
panel_color.ResumeLayout(false);
|
||||
panel_addit_color.ResumeLayout(false);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBox_param;
|
||||
private Label label_weight;
|
||||
private NumericUpDown numericUpDownWeight;
|
||||
private NumericUpDown numericUpDownSpeed;
|
||||
private Label label_speed;
|
||||
private CheckBox checkBox_boat;
|
||||
private CheckBox checkBox_bobber;
|
||||
private GroupBox groupBox_colors;
|
||||
private Panel panelGreen;
|
||||
private Panel panelYellow;
|
||||
private Panel panelRed;
|
||||
private Panel panelGray;
|
||||
private Panel panelCian;
|
||||
private Panel panelPurple;
|
||||
private Panel panelBlack;
|
||||
private Panel panelBlue;
|
||||
private Label labelOriginalObject;
|
||||
private Label labelModifiedObject;
|
||||
private PictureBox pictureBox;
|
||||
private Panel Panel;
|
||||
private Button button_close;
|
||||
private Button button_add;
|
||||
private Label label_color;
|
||||
private Label label_addit_color;
|
||||
private Panel panel_color;
|
||||
private Panel panel_addit_color;
|
||||
private Label label1;
|
||||
}
|
||||
}
|
169
Hydroplane/FormPlaneConfig.cs
Normal file
169
Hydroplane/FormPlaneConfig.cs
Normal file
@ -0,0 +1,169 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Hydroplane.DrawningObjects;
|
||||
using Hydroplane.Entities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace Hydroplane
|
||||
{
|
||||
public partial class FormPlaneConfig : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Переменная-выбранная машина
|
||||
/// </summary>
|
||||
DrawningPlane? _plane = null;
|
||||
/// <summary>
|
||||
/// Событие
|
||||
/// </summary>
|
||||
public event Action<DrawningPlane>? EventAddPlane;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormPlaneConfig()
|
||||
{
|
||||
|
||||
InitializeComponent();
|
||||
panelBlack.MouseDown += panelColor_MouseDown;
|
||||
panelPurple.MouseDown += panelColor_MouseDown;
|
||||
panelGray.MouseDown += panelColor_MouseDown;
|
||||
panelGreen.MouseDown += panelColor_MouseDown;
|
||||
panelRed.MouseDown += panelColor_MouseDown;
|
||||
panelCian.MouseDown += panelColor_MouseDown;
|
||||
panelYellow.MouseDown += panelColor_MouseDown;
|
||||
panelBlue.MouseDown += panelColor_MouseDown;
|
||||
|
||||
button_close.Click += (s, e) => Close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Отрисовать машину
|
||||
/// </summary>
|
||||
private void DrawPlane()
|
||||
{
|
||||
Bitmap bmp = new(pictureBox.Width, pictureBox.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_plane?.SetPosition(5, 5);
|
||||
_plane?.DrawTransport(gr);
|
||||
pictureBox.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление события
|
||||
/// </summary>
|
||||
/// <param name="ev">Привязанный метод</param>
|
||||
public void AddEvent(Action<DrawningPlane> ev)
|
||||
{
|
||||
if (EventAddPlane == null)
|
||||
{
|
||||
EventAddPlane = ev;
|
||||
}
|
||||
else
|
||||
{
|
||||
EventAddPlane += ev;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Передаем информацию при нажатии на Label
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void Label_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 panel_dragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Действия при приеме перетаскиваемой информации
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void panel_dragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
ILogger<FormHydroplaneCollection> logger = new NullLogger<FormHydroplaneCollection>();
|
||||
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||
{
|
||||
case "labelOriginalObject":
|
||||
_plane = new DrawningPlane((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, pictureBox.Width, pictureBox.Height);
|
||||
break;
|
||||
case "labelModifiedObject":
|
||||
_plane = new DrawningHydroplane((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBox_boat.Checked, checkBox_bobber.Checked, pictureBox.Width, pictureBox.Height);
|
||||
break;
|
||||
}
|
||||
DrawPlane();
|
||||
}
|
||||
|
||||
public void panelColor_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
private void labelColor_dragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(typeof(Color)) ?? false)
|
||||
{
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
private void labelColor_dragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_plane == null)
|
||||
return;
|
||||
switch (((Panel)sender).Name)
|
||||
{
|
||||
case "panel_color":
|
||||
_plane?.EntityPlane?.setBodyColor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
case "panel_addit_color":
|
||||
if (!(_plane is DrawningHydroplane))
|
||||
return;
|
||||
(_plane.EntityPlane as EntityHydroplane)?.setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
||||
break;
|
||||
}
|
||||
DrawPlane();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление машины
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
private void button_add_Click(object sender, EventArgs e)
|
||||
{
|
||||
EventAddPlane?.Invoke(_plane);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
120
Hydroplane/FormPlaneConfig.resx
Normal file
120
Hydroplane/FormPlaneConfig.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
@ -8,4 +8,29 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.5" />
|
||||
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
32
Hydroplane/IMoveableObject.cs
Normal file
32
Hydroplane/IMoveableObject.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Hydroplane.DrawningObjects;
|
||||
|
||||
namespace Hydroplane.MovementStrategy
|
||||
{
|
||||
public interface IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты X объекта
|
||||
/// </summary>
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
/// <summary>
|
||||
/// Проверка, можно ли переместиться по нужному направлению
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
bool CheckCanMove(DirectionType direction);
|
||||
/// <summary>
|
||||
/// Изменение направления пермещения объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
void MoveObject(DirectionType direction);
|
||||
}
|
||||
}
|
57
Hydroplane/MoveToBorder.cs
Normal file
57
Hydroplane/MoveToBorder.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hydroplane.MovementStrategy
|
||||
{
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder <= FieldWidth &&
|
||||
objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder <= FieldHeight &&
|
||||
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.RightBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.DownBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
Hydroplane/MoveToCenter.cs
Normal file
56
Hydroplane/MoveToCenter.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hydroplane.MovementStrategy
|
||||
{
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
55
Hydroplane/ObjectParameters.cs
Normal file
55
Hydroplane/ObjectParameters.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hydroplane.MovementStrategy
|
||||
{
|
||||
public class ObjectParameters
|
||||
{
|
||||
private readonly int _x;
|
||||
private readonly int _y;
|
||||
private readonly int _width;
|
||||
private readonly int _height;
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
public int LeftBorder => _x;
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
public int TopBorder => _y;
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
public int RightBorder => _x + _width;
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
public int DownBorder => _y + _height;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
37
Hydroplane/PlaneCompareByColor.cs
Normal file
37
Hydroplane/PlaneCompareByColor.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Hydroplane.DrawningObjects;
|
||||
using Hydroplane.Entities;
|
||||
|
||||
namespace Hydroplane
|
||||
{
|
||||
internal class PlaneCompareByColor : IComparer<DrawningPlane?>
|
||||
{
|
||||
public int Compare(DrawningPlane? x, DrawningPlane? y)
|
||||
{
|
||||
|
||||
if (x == null || x.EntityPlane == null)
|
||||
throw new NotImplementedException(nameof(x));
|
||||
|
||||
if (y == null || y.EntityPlane == null)
|
||||
throw new NotImplementedException(nameof(y));
|
||||
|
||||
var bodyColor = x.EntityPlane.BodyColor.Name.CompareTo(y.EntityPlane.BodyColor.Name);
|
||||
|
||||
if (bodyColor != 0) return bodyColor;
|
||||
|
||||
if (x.EntityPlane is EntityHydroplane &&
|
||||
y.EntityPlane is EntityHydroplane)
|
||||
{
|
||||
var addcolor = (x.EntityPlane as EntityHydroplane).AdditionalColor.Name.CompareTo((y.EntityPlane
|
||||
as EntityHydroplane).AdditionalColor.Name);
|
||||
if (addcolor != 0) return addcolor;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
35
Hydroplane/PlaneCompareByType.cs
Normal file
35
Hydroplane/PlaneCompareByType.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Hydroplane.DrawningObjects;
|
||||
|
||||
namespace Hydroplane
|
||||
{
|
||||
internal class PlaneCompareByType : IComparer<DrawningPlane?>
|
||||
{
|
||||
public int Compare(DrawningPlane? x, DrawningPlane? y)
|
||||
{
|
||||
if (x == null || x.EntityPlane == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityPlane == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
var speedCompare = x.EntityPlane.Speed.CompareTo(y.EntityPlane.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityPlane.Weight.CompareTo(y.EntityPlane.Weight);
|
||||
}
|
||||
}
|
||||
}
|
19
Hydroplane/PlaneNotFoundException .cs
Normal file
19
Hydroplane/PlaneNotFoundException .cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hydroplane.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
internal class PlaneNotFoundException : ApplicationException
|
||||
{
|
||||
public PlaneNotFoundException(int i) : base($"Not found object on position {i}") { }
|
||||
public PlaneNotFoundException() : base() { }
|
||||
public PlaneNotFoundException(string message) : base(message) { }
|
||||
public PlaneNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
protected PlaneNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
}
|
||||
}
|
36
Hydroplane/PlanesCollectionInfo.cs
Normal file
36
Hydroplane/PlanesCollectionInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hydroplane
|
||||
{
|
||||
internal class PlanesCollectionInfo : IEquatable<PlanesCollectionInfo>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
public PlanesCollectionInfo(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
|
||||
public bool Equals(PlanesCollectionInfo other)
|
||||
{
|
||||
if (Name != other?.Name)
|
||||
throw new NotImplementedException(nameof(Name));
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Name.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
96
Hydroplane/PlanesGenericCollection.cs
Normal file
96
Hydroplane/PlanesGenericCollection.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Hydroplane.DrawningObjects;
|
||||
using Hydroplane.MovementStrategy;
|
||||
|
||||
namespace Hydroplane.Generics
|
||||
{
|
||||
internal class PlanesGenericCollection<T, U>
|
||||
where T : DrawningPlane
|
||||
where U : IMoveableObject
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly int _placeSizeWidth = 175;
|
||||
private readonly int _placeSizeHeight = 85;
|
||||
private readonly SetGeneric<T> _collection;
|
||||
|
||||
public PlanesGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
|
||||
public static bool operator +(PlanesGenericCollection<T, U> collect, T obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect._collection.Insert(obj, new DrawingPlaneEqutables());
|
||||
}
|
||||
|
||||
public static T? operator -(PlanesGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
public Bitmap ShowPlanes()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
|
||||
1; ++j)
|
||||
{//линия рамзетки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||
_placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
T? t = _collection[i];
|
||||
if (t != null)
|
||||
{
|
||||
t.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
|
||||
if (t is DrawningPlane) (t as DrawningPlane).DrawTransport(g);
|
||||
else t.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<T?> GetPlanes => _collection.GetPlanes();
|
||||
|
||||
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||
}
|
||||
}
|
140
Hydroplane/PlanesGenericStorage.cs
Normal file
140
Hydroplane/PlanesGenericStorage.cs
Normal file
@ -0,0 +1,140 @@
|
||||
using Hydroplane.DrawningObjects;
|
||||
using Hydroplane.MovementStrategy;
|
||||
using Hydroplane.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.DirectoryServices.ActiveDirectory;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hydroplane.Generics
|
||||
{
|
||||
internal class PlanesGenericStorage
|
||||
{
|
||||
readonly Dictionary<string, PlanesGenericCollection<DrawningPlane, DrawningObjectPlane>> _planeStorages;
|
||||
public List<string> Keys => _planeStorages.Keys.ToList();
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
public PlanesGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_planeStorages = new Dictionary<string, PlanesGenericCollection<DrawningPlane, DrawningObjectPlane>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
public void AddSet(string name)
|
||||
{
|
||||
if (_planeStorages.ContainsKey(name)) return;
|
||||
_planeStorages[name] = new PlanesGenericCollection<DrawningPlane, DrawningObjectPlane>(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (!_planeStorages.ContainsKey(name)) return;
|
||||
_planeStorages.Remove(name);
|
||||
}
|
||||
|
||||
public PlanesGenericCollection<DrawningPlane, DrawningObjectPlane>?
|
||||
this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_planeStorages.ContainsKey(ind)) return _planeStorages[ind];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
private readonly char _separatorRecords = ';';
|
||||
private static readonly char _separatorForObject = ':';
|
||||
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string, PlanesGenericCollection<DrawningPlane, DrawningObjectPlane>> record in _planeStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawningPlane? elem in record.Value.GetPlanes)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
throw new ArgumentException("Invalid operation, there isn't any data");
|
||||
}
|
||||
using (StreamWriter writer = new StreamWriter(filename))
|
||||
{
|
||||
writer.Write($"PlaneStorage{Environment.NewLine}{data}");
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new FileNotFoundException("File not found");
|
||||
}
|
||||
|
||||
using (StreamReader fs = File.OpenText(filename))
|
||||
{
|
||||
string str = fs.ReadLine();
|
||||
if (str == null || str.Length == 0)
|
||||
{
|
||||
throw new ArgumentException("There isn't any data for load");
|
||||
}
|
||||
if (!str.StartsWith("PlaneStorage"))
|
||||
{
|
||||
throw new InvalidDataException("Invalid format of data");
|
||||
}
|
||||
|
||||
_planeStorages.Clear();
|
||||
string strs = "";
|
||||
|
||||
while ((strs = fs.ReadLine()) != null)
|
||||
{
|
||||
if (strs == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
PlanesGenericCollection<DrawningPlane, DrawningObjectPlane> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
DrawningPlane? plane = elem?.CreateDrawningPlane(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (plane != null)
|
||||
{
|
||||
if (!(collection + plane))
|
||||
{
|
||||
try
|
||||
{
|
||||
_ = collection + plane;
|
||||
}
|
||||
catch (PlaneNotFoundException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (StorageOverflowException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_planeStorages.Add(record[0], collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,9 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
using Serilog;
|
||||
|
||||
namespace Hydroplane
|
||||
{
|
||||
internal static class Program
|
||||
@ -11,7 +17,28 @@ namespace Hydroplane
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||
{
|
||||
Application.Run(serviceProvider.GetRequiredService<FormHydroplaneCollection>());
|
||||
}
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<FormHydroplaneCollection>().AddLogging(option =>
|
||||
{
|
||||
string[] path = Directory.GetCurrentDirectory().Split('\\');
|
||||
string pathNeed = "";
|
||||
for (int i = 0; i < path.Length - 3; i++)
|
||||
{
|
||||
pathNeed += path[i] + "\\";
|
||||
}
|
||||
var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(path: $"{pathNeed}appsettings.json", optional: false, reloadOnChange: true).Build();
|
||||
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddSerilog(logger);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
103
Hydroplane/Properties/Resources.Designer.cs
generated
Normal file
103
Hydroplane/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,103 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Hydroplane.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||
/// </summary>
|
||||
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||
// с помощью такого средства, как ResGen или Visual Studio.
|
||||
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||
// с параметром /str или перестройте свой проект VS.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Hydroplane.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap down {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("down", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap left {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("left", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap right {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("right", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap up {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("up", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
133
Hydroplane/Properties/Resources.resx
Normal file
133
Hydroplane/Properties/Resources.resx
Normal file
@ -0,0 +1,133 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="down" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\down.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="left" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\left.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="right" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\right.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="up" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\up.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
BIN
Hydroplane/Resources/down.png
Normal file
BIN
Hydroplane/Resources/down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
BIN
Hydroplane/Resources/left.png
Normal file
BIN
Hydroplane/Resources/left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.8 KiB |
BIN
Hydroplane/Resources/right.png
Normal file
BIN
Hydroplane/Resources/right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 KiB |
BIN
Hydroplane/Resources/up.png
Normal file
BIN
Hydroplane/Resources/up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
98
Hydroplane/SetGeneric.cs
Normal file
98
Hydroplane/SetGeneric.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Hydroplane.Exceptions;
|
||||
|
||||
namespace Hydroplane.Generics
|
||||
{
|
||||
internal class SetGeneric<T> where T : class
|
||||
{
|
||||
private readonly List<T?> _places;
|
||||
public int Count => _places.Count;
|
||||
|
||||
private readonly int _maxCount;
|
||||
|
||||
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(_maxCount);
|
||||
}
|
||||
|
||||
public bool Insert(T plane, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
if (equal != null)
|
||||
{
|
||||
foreach (var secondPlane in _places)
|
||||
{
|
||||
if (equal.Equals(plane, secondPlane))
|
||||
{
|
||||
throw new Exception("Такой объект уже есть в коллекции");
|
||||
}
|
||||
}
|
||||
}
|
||||
return Insert(plane, 0);
|
||||
}
|
||||
public bool Insert(T plane, int position, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
throw new StorageOverflowException("Impossible to insert");
|
||||
|
||||
if (Count >= _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
if (equal != null)
|
||||
{
|
||||
foreach (var secondPlane in _places)
|
||||
{
|
||||
if (equal.Equals(plane, secondPlane))
|
||||
{
|
||||
throw new ApplicationException("Такой объект уже есть в коллекции");
|
||||
}
|
||||
}
|
||||
}
|
||||
_places.Insert(position, plane);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position >= Count || position < 0)
|
||||
throw new PlaneNotFoundException("Invalid operation");
|
||||
if (_places[position] == null)
|
||||
throw new PlaneNotFoundException(position);
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
public T? this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position < 0 || position > _maxCount)
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position < 0 || position > _maxCount)
|
||||
return;
|
||||
_places[position] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<T?> GetPlanes(int? maxPlanes = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxPlanes.HasValue && i == maxPlanes.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
15
Hydroplane/Status.cs
Normal file
15
Hydroplane/Status.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hydroplane.MovementStrategy
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
}
|
19
Hydroplane/StorageOverflowException.cs
Normal file
19
Hydroplane/StorageOverflowException.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Hydroplane.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
internal class StorageOverflowException : ApplicationException
|
||||
{
|
||||
public StorageOverflowException(int count) : base($"There is exceeded a limit of allowed number: {count}") { }
|
||||
public StorageOverflowException() : base() { }
|
||||
public StorageOverflowException(string message) : base(message) { }
|
||||
public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
|
||||
protected StorageOverflowException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user