PIbd-14 Pruidze_I.K. LabWork05 Simple #5
70
ProjectCruiser/CollectionGenericObj/AbstractCompany.cs
Normal file
70
ProjectCruiser/CollectionGenericObj/AbstractCompany.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using ProjectCruiser.DrawningSamples;
|
||||
namespace ProjectCruiser.CollectionGenericObj;
|
||||
|
||||
/// Абстракция компании, хранящий коллекцию автомобилей
|
||||
/// </summary>
|
||||
public abstract class AbstractCompany
|
||||
{
|
||||
// Размеры места
|
||||
protected readonly int _placeSizeWidth = 312; // ширина
|
||||
|
||||
protected readonly int _placeSizeHeight = 56; // высота
|
||||
|
||||
// Ширина окна
|
||||
protected readonly int _pictureWidth;
|
||||
// Высота окна
|
||||
protected readonly int _pictureHeight;
|
||||
|
||||
// Коллекция автомобилей
|
||||
protected ICollectionGenObj<DrawningBase>? _collection = null;
|
||||
private int GetMaxCount => _pictureWidth * _pictureHeight /
|
||||
(_placeSizeWidth * _placeSizeHeight);
|
||||
|
||||
public AbstractCompany(int picWidth, int picHeight,
|
||||
ICollectionGenObj<DrawningBase>? collection)
|
||||
{
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount = GetMaxCount;
|
||||
}
|
||||
|
||||
// Перегрузка оператора сложения для класса
|
||||
// [ ! ] insted of bool:
|
||||
public static int operator +(AbstractCompany company,
|
||||
DrawningBase trasport) => company._collection.Insert(trasport);
|
||||
|
||||
// Перегрузка оператора удаления для класса
|
||||
public static DrawningBase operator -(AbstractCompany company,
|
||||
int pos) => company._collection.Remove(pos);
|
||||
|
||||
// Получение случайного объекта из коллекции
|
||||
public DrawningBase? GetRandomObject()
|
||||
{
|
||||
Random rnd = new();
|
||||
return _collection?.GetItem(rnd.Next(GetMaxCount));
|
||||
}
|
||||
|
||||
// Вывод всей коллекции
|
||||
public Bitmap? Show()
|
||||
{
|
||||
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
||||
Graphics graphics = Graphics.FromImage(bitmap);
|
||||
DrawBackground(graphics);
|
||||
SetObjectsPosition();
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||
{
|
||||
DrawningBase? obj = _collection?.GetItem(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
||||
// Вывод заднего фона
|
||||
protected abstract void DrawBackground(Graphics g);
|
||||
|
||||
// Расстановка объектов
|
||||
protected abstract void SetObjectsPosition();
|
||||
}
|
||||
|
94
ProjectCruiser/CollectionGenericObj/ArrayGenObj.cs
Normal file
94
ProjectCruiser/CollectionGenericObj/ArrayGenObj.cs
Normal file
@ -0,0 +1,94 @@
|
||||
namespace ProjectCruiser.CollectionGenericObj;
|
||||
|
||||
public class ArrayGenObj<T> : ICollectionGenObj<T>
|
||||
where T : class
|
||||
{
|
||||
// Массив объектов, которые храним
|
||||
private T?[] _collection;
|
||||
public int Count => _collection.Length;
|
||||
public int SetMaxCount
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value > 0)
|
||||
{
|
||||
if (_collection.Length > 0) Array.Resize(ref _collection, value);
|
||||
else _collection = new T?[value];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
|
||||
|
||||
public ArrayGenObj()
|
||||
{
|
||||
_collection = Array.Empty<T?>();
|
||||
}
|
||||
|
||||
// methods :
|
||||
|
||||
public T? GetItem(int index)
|
||||
{
|
||||
if (index > Count || index < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _collection[index];
|
||||
}
|
||||
|
||||
public int Insert(T? item)
|
||||
{
|
||||
// any empty place
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = item;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int Insert(T? item, int index)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[index] = item;
|
||||
return index;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
int min_diff = 100, min_index = 100;
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (_collection[i] == null
|
||||
&& min_diff > Math.Abs(index - i))
|
||||
{
|
||||
min_diff = Math.Abs(index - i);
|
||||
min_index = i;
|
||||
}
|
||||
}
|
||||
|
||||
_collection[min_index] = item;
|
||||
return min_index;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public T? Remove(int index)
|
||||
{
|
||||
T? item;
|
||||
if (index < Count && index >= 0)
|
||||
{
|
||||
item = _collection[index];
|
||||
_collection[index] = null;
|
||||
return item;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
8
ProjectCruiser/CollectionGenericObj/CollectionType.cs
Normal file
8
ProjectCruiser/CollectionGenericObj/CollectionType.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace ProjectCruiser.CollectionGenericObj;
|
||||
|
||||
public enum CollectionType
|
||||
{
|
||||
None = 0,
|
||||
Array = 1,
|
||||
List = 2
|
||||
}
|
24
ProjectCruiser/CollectionGenericObj/ICollectionGenObj.cs
Normal file
24
ProjectCruiser/CollectionGenericObj/ICollectionGenObj.cs
Normal file
@ -0,0 +1,24 @@
|
||||
namespace ProjectCruiser.CollectionGenericObj;
|
||||
|
||||
public interface ICollectionGenObj<T> where T : class
|
||||
{
|
||||
// Кол-во объектов в коллекции
|
||||
int Count { get; }
|
||||
|
||||
// Установка max кол-ва элементов
|
||||
int SetMaxCount { set; }
|
||||
|
||||
/// Добавление объекта в коллекцию
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj);
|
||||
int Insert(T obj, int position);
|
||||
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||
T? Remove(int position);
|
||||
|
||||
// Получение объекта по позиции
|
||||
T? GetItem(int position);
|
||||
}
|
70
ProjectCruiser/CollectionGenericObj/ListGenObj.cs
Normal file
70
ProjectCruiser/CollectionGenericObj/ListGenObj.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ProjectCruiser.CollectionGenericObj;
|
||||
|
||||
// Параметризованный набор объектов
|
||||
public class ListGenObj<T> : ICollectionGenObj<T>
|
||||
where T : class
|
||||
{
|
||||
// Список объектов, которые храним
|
||||
private readonly List<T?> _collection;
|
||||
|
||||
// Максимально допустимое число объектов в списке
|
||||
private int _maxCount;
|
||||
public int Count => _collection.Count;
|
||||
|
||||
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
|
||||
|
||||
public ListGenObj()
|
||||
{
|
||||
_collection = new();
|
||||
}
|
||||
|
||||
public T? GetItem(int position)
|
||||
{
|
||||
if (position >= Count || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
{
|
||||
if (Count >= _maxCount || obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
_collection.Add(obj);
|
||||
return Count;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
if (position >= _maxCount || Count >= _maxCount ||
|
||||
position < 0 || _collection[position] != null
|
||||
|| obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
_collection.Insert(position, obj);
|
||||
return position;
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
{
|
||||
if (position >= Count || position < 0)
|
||||
// on the other positions items don't exist
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
T? item = _collection[position];
|
||||
_collection.RemoveAt(position);
|
||||
return item;
|
||||
}
|
||||
}
|
69
ProjectCruiser/CollectionGenericObj/ShipSharingService.cs
Normal file
69
ProjectCruiser/CollectionGenericObj/ShipSharingService.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using ProjectCruiser.DrawningSamples;
|
||||
namespace ProjectCruiser.CollectionGenericObj;
|
||||
|
||||
public class ShipSharingService : AbstractCompany
|
||||
{
|
||||
protected int MaxInRow { get; private set; }
|
||||
protected int MaxInColon { get; private set; }
|
||||
|
||||
private int fromBorder = 20, fromCeiling = 20, between = 30;
|
||||
|
||||
public ShipSharingService(int picWidth, int picHeight,
|
||||
ICollectionGenObj<DrawningBase> collection)
|
||||
: base(picWidth, picHeight, collection)
|
||||
{
|
||||
MaxInRow = (picWidth - fromBorder - fromCeiling)
|
||||
/ (_placeSizeWidth + between);
|
||||
MaxInColon = (picHeight - fromBorder - fromCeiling)
|
||||
/ _placeSizeHeight;
|
||||
}
|
||||
|
||||
protected override void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 2);
|
||||
|
||||
int currentH = fromCeiling, currentW = fromBorder;
|
||||
|
||||
for (int i = 0; i < MaxInRow; i++)
|
||||
{
|
||||
currentH = fromCeiling;
|
||||
for (int j = 0; j < MaxInColon; j++)
|
||||
{
|
||||
g.DrawLine(pen, currentW + _placeSizeWidth,
|
||||
currentH, currentW, currentH);
|
||||
|
||||
g.DrawLine(pen, currentW, currentH,
|
||||
currentW, currentH + _placeSizeHeight);
|
||||
|
||||
currentH += _placeSizeHeight + 1;
|
||||
}
|
||||
currentW += _placeSizeWidth + between;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetObjectsPosition()
|
||||
{
|
||||
int index_collection = 0;
|
||||
int newX = fromBorder + 6, newY = fromCeiling + 6;
|
||||
|
||||
if (_collection != null)
|
||||
{
|
||||
for (int i = 0; i < MaxInColon; ++i)
|
||||
{
|
||||
newX = fromBorder + 2;
|
||||
for (int j = 0; j < MaxInRow; ++j)
|
||||
{
|
||||
if (_collection.GetItem(index_collection) != null)
|
||||
{
|
||||
_collection.GetItem(index_collection).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection.GetItem(index_collection).SetPosition(newX, newY);
|
||||
newX += _placeSizeWidth + between + 2;
|
||||
index_collection++;
|
||||
}
|
||||
}
|
||||
newY += _placeSizeHeight + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
51
ProjectCruiser/CollectionGenericObj/StorageCollection.cs
Normal file
51
ProjectCruiser/CollectionGenericObj/StorageCollection.cs
Normal file
@ -0,0 +1,51 @@
|
||||
namespace ProjectCruiser.CollectionGenericObj;
|
||||
|
||||
public class StorageCollection<T>
|
||||
where T : class
|
||||
{
|
||||
// Словарь (хранилище) с коллекциями < name, type (class) >
|
||||
readonly Dictionary<string, ICollectionGenObj<T>> _storages;
|
||||
|
||||
// Возвращение списка названий коллекций
|
||||
public List<string> Keys => _storages.Keys.ToList();
|
||||
|
||||
public StorageCollection()
|
||||
{
|
||||
_storages = new Dictionary<string, ICollectionGenObj<T>>();
|
||||
}
|
||||
|
||||
/// Добавление коллекции в хранилище
|
||||
/// <param name="name">Название коллекции</param>
|
||||
/// <param name="collectionType">тип коллекции</param>
|
||||
public void AddCollection(string name, CollectionType collType)
|
||||
{
|
||||
if (name == null || _storages.ContainsKey(name)
|
||||
|| collType == CollectionType.None)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (collType)
|
||||
{
|
||||
case CollectionType.List: _storages.Add(name, new ListGenObj<T>()); break;
|
||||
// _storages[name] = new ListGenericObjects<T>(); break; [*]
|
||||
|
||||
case CollectionType.Array: _storages.Add(name, new ArrayGenObj<T>()); break;
|
||||
}
|
||||
}
|
||||
|
||||
/// Удаление коллекции ( по ключу-строке - её имени )
|
||||
/// <param name="name">Название коллекции</param>
|
||||
public void DelCollection(string name)
|
||||
{
|
||||
if (_storages.ContainsKey(name)) _storages.Remove(name);
|
||||
return;
|
||||
}
|
||||
|
||||
/// Доступ к коллекции ( по ключу-строке - её имени )
|
||||
public ICollectionGenObj<T>? this[string name]
|
||||
{
|
||||
get => _storages.ContainsKey(name) ? _storages[name] : null;
|
||||
}
|
||||
}
|
||||
|
9
ProjectCruiser/DrawningSamples/DirectionType.cs
Normal file
9
ProjectCruiser/DrawningSamples/DirectionType.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace ProjectCruiser.DrawningSamples;
|
||||
public enum DirectionType
|
||||
{
|
||||
Unknown = -1,
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
Right = 4
|
||||
}
|
173
ProjectCruiser/DrawningSamples/DrawningBase.cs
Normal file
173
ProjectCruiser/DrawningSamples/DrawningBase.cs
Normal file
@ -0,0 +1,173 @@
|
||||
using ProjectCruiser.Entities;
|
||||
namespace ProjectCruiser.DrawningSamples;
|
||||
public class DrawningBase
|
||||
{
|
||||
// Класс-сущность
|
||||
public EntityBase? EntityTransport { get; protected set; }
|
||||
private int? _pictureWidth; // Ширина окна
|
||||
private int? _pictureHeight; // Высота окна
|
||||
|
||||
protected int? _startPosX; // < protected
|
||||
protected int? _startPosY; // < protected
|
||||
|
||||
private readonly int _drawningWidth = 302; // Ширина прорисовки автомобиля
|
||||
private readonly int _drawningHeight = 42; // Высота прорисовки автомобиля
|
||||
|
||||
// Инициализация свойств (теперь через конструктор)
|
||||
public DrawningBase(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityTransport = new EntityBase(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
private DrawningBase()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
// protected >
|
||||
protected DrawningBase(int drawningCarWidth, int drawningCarHeight) : this()
|
||||
{
|
||||
_drawningWidth = drawningCarWidth;
|
||||
_pictureHeight = drawningCarHeight;
|
||||
}
|
||||
|
||||
public int getHeight() // для создания объекта в нижнем левом углу (*)
|
||||
{
|
||||
return _drawningHeight;
|
||||
}
|
||||
|
||||
// Установка границ поля
|
||||
public bool SetPictureSize(int w, int h)
|
||||
{
|
||||
if (w < _drawningWidth || h < _drawningHeight)
|
||||
// canvas always bigger then obj to fit it
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_pictureWidth = w;
|
||||
_pictureHeight = h;
|
||||
|
||||
if (_startPosX != null || _startPosY != null)
|
||||
{
|
||||
SetPosition(_startPosX.Value, _startPosY.Value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (x > _pictureWidth - _drawningWidth) _startPosX =
|
||||
_pictureWidth - _drawningWidth;
|
||||
else if (x < 0) _startPosX = 0;
|
||||
else _startPosX = x;
|
||||
|
||||
if (y > _pictureHeight - _drawningHeight) _startPosY =
|
||||
_pictureHeight.Value - _drawningHeight;
|
||||
else if (y < 0) _startPosY = 0;
|
||||
else _startPosY = y;
|
||||
}
|
||||
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityTransport == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityTransport.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityTransport.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityTransport.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityTransport.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _drawningWidth + EntityTransport.Step
|
||||
< _pictureWidth.Value)
|
||||
{
|
||||
_startPosX += (int)EntityTransport.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawningHeight + EntityTransport.Step
|
||||
< _pictureHeight.Value)
|
||||
{
|
||||
_startPosY += (int)EntityTransport.Step;
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
// Перемещение объекта (удалось перемещение - true \ false)
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void DrawTransport(Graphics g) // < virtual
|
||||
{
|
||||
if (EntityTransport == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black, 2);
|
||||
Brush mainBrush = new SolidBrush(EntityTransport.MainColor);
|
||||
|
||||
//границы cruiser
|
||||
Point point0 = new Point(_startPosX.Value + 2, _startPosY.Value + 7);
|
||||
Point point1 = new Point(_startPosX.Value + 2, _startPosY.Value + 30);
|
||||
Point point2 = new Point(_startPosX.Value + 184, _startPosY.Value + 42);
|
||||
Point point3 = new Point(_startPosX.Value + 260, _startPosY.Value + 34);
|
||||
Point point4 = new Point(_startPosX.Value + 300, _startPosY.Value + 22);
|
||||
Point point5 = new Point(_startPosX.Value + 260, _startPosY.Value + 10);
|
||||
Point point6 = new Point(_startPosX.Value + 184, _startPosY.Value + 2);
|
||||
|
||||
Point[] boarders = {
|
||||
point0,
|
||||
point1,
|
||||
point2,
|
||||
point3,
|
||||
point4,
|
||||
point5,
|
||||
point6
|
||||
};
|
||||
|
||||
g.DrawPolygon(pen, boarders);
|
||||
g.FillPolygon(mainBrush, boarders);
|
||||
|
||||
// салон на верхней палубе
|
||||
int y_h = EntityTransport.values[1];
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + y_h, 38, 24);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 110, _startPosY.Value + y_h + 6, 20, 12);
|
||||
g.FillRectangle(mainBrush, _startPosX.Value + 110, _startPosY.Value + y_h + 6, 20, 12);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 117, _startPosY.Value + y_h + 18, 6, 20);
|
||||
g.FillRectangle(mainBrush, _startPosX.Value + 117, _startPosY.Value + y_h + 18, 6, 20);
|
||||
}
|
||||
|
||||
public int? GetPosX => _startPosX;
|
||||
public int? GetPosY => _startPosY;
|
||||
public int GetWidth => _drawningWidth;
|
||||
public int GetHeight => _drawningHeight;
|
||||
}
|
||||
|
48
ProjectCruiser/DrawningSamples/DrawningCruiser.cs
Normal file
48
ProjectCruiser/DrawningSamples/DrawningCruiser.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System.Drawing.Drawing2D;
|
||||
using ProjectCruiser.Entities;
|
||||
namespace ProjectCruiser.DrawningSamples;
|
||||
|
||||
public class DrawningCruiser : DrawningBase
|
||||
{
|
||||
// Инициализация свойств (все параметры класса (сущности))
|
||||
public DrawningCruiser(int speed, double weight, Color bodyColor,
|
||||
Color additionalColor, bool pad, bool hangars) : base(302, 42)
|
||||
{
|
||||
EntityTransport = new EntityCruiser(speed, weight,
|
||||
bodyColor, additionalColor, pad, hangars);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityTransport == null ||
|
||||
EntityTransport is not EntityCruiser ship ||
|
||||
!_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black, 2);
|
||||
Brush PadBrush = new HatchBrush(HatchStyle.DottedDiamond, Color.LightGray, Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(ship.AdditionalColor);
|
||||
|
||||
//границы cruiser <...>
|
||||
// &
|
||||
// салон на верхней палубе :
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
// вертолетная площадка - non-default
|
||||
if (ship.HelicopterPads)
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
|
||||
g.FillEllipse(PadBrush, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
|
||||
}
|
||||
// ангар(ы)
|
||||
if (ship.Hangars)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 10, 10, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value + 12, 8, 12);
|
||||
}
|
||||
else g.FillRectangle(additionalBrush, _startPosX.Value + 250, _startPosY.Value + 20, 14, 7);
|
||||
}
|
||||
}
|
344
ProjectCruiser/EditorForm3.Designer.cs
generated
Normal file
344
ProjectCruiser/EditorForm3.Designer.cs
generated
Normal file
@ -0,0 +1,344 @@
|
||||
namespace ProjectCruiser
|
||||
{
|
||||
partial class EditorForm3
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
ParametersBox = new GroupBox();
|
||||
AdvLabel = new Label();
|
||||
BaseLabel = new Label();
|
||||
groupBox2 = new GroupBox();
|
||||
PurpleP = new Panel();
|
||||
GreenP = new Panel();
|
||||
PinkP = new Panel();
|
||||
OrangeP = new Panel();
|
||||
CyanP = new Panel();
|
||||
YellowP = new Panel();
|
||||
RedP = new Panel();
|
||||
BlueP = new Panel();
|
||||
checkBoxPads = new CheckBox();
|
||||
checkBoxHangars = new CheckBox();
|
||||
WeightN = new NumericUpDown();
|
||||
SpeedN = new NumericUpDown();
|
||||
Label = new Label();
|
||||
Showcase = new PictureBox();
|
||||
btnAdd = new Button();
|
||||
btnCancel = new Button();
|
||||
panelObject = new Panel();
|
||||
labelAcolor = new Label();
|
||||
labelMcolor = new Label();
|
||||
ParametersBox.SuspendLayout();
|
||||
groupBox2.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)WeightN).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)SpeedN).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)Showcase).BeginInit();
|
||||
panelObject.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// ParametersBox
|
||||
//
|
||||
ParametersBox.Controls.Add(AdvLabel);
|
||||
ParametersBox.Controls.Add(BaseLabel);
|
||||
ParametersBox.Controls.Add(groupBox2);
|
||||
ParametersBox.Controls.Add(checkBoxPads);
|
||||
ParametersBox.Controls.Add(checkBoxHangars);
|
||||
ParametersBox.Controls.Add(WeightN);
|
||||
ParametersBox.Controls.Add(SpeedN);
|
||||
ParametersBox.Controls.Add(Label);
|
||||
ParametersBox.Location = new Point(12, 0);
|
||||
ParametersBox.Name = "ParametersBox";
|
||||
ParametersBox.Size = new Size(388, 495);
|
||||
ParametersBox.TabIndex = 0;
|
||||
ParametersBox.TabStop = false;
|
||||
ParametersBox.Text = "Parameters";
|
||||
//
|
||||
// AdvLabel
|
||||
//
|
||||
AdvLabel.BorderStyle = BorderStyle.FixedSingle;
|
||||
AdvLabel.Location = new Point(175, 428);
|
||||
AdvLabel.Name = "AdvLabel";
|
||||
AdvLabel.Size = new Size(184, 46);
|
||||
AdvLabel.TabIndex = 5;
|
||||
AdvLabel.Text = "Advanced";
|
||||
AdvLabel.TextAlign = ContentAlignment.MiddleCenter;
|
||||
AdvLabel.MouseDown += BaseAdvLabel_MouseDown;
|
||||
//
|
||||
// BaseLabel
|
||||
//
|
||||
BaseLabel.BorderStyle = BorderStyle.FixedSingle;
|
||||
BaseLabel.Location = new Point(17, 428);
|
||||
BaseLabel.Name = "BaseLabel";
|
||||
BaseLabel.Size = new Size(132, 46);
|
||||
BaseLabel.TabIndex = 4;
|
||||
BaseLabel.Text = "Base";
|
||||
BaseLabel.TextAlign = ContentAlignment.MiddleCenter;
|
||||
BaseLabel.MouseDown += BaseAdvLabel_MouseDown;
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
groupBox2.Controls.Add(PurpleP);
|
||||
groupBox2.Controls.Add(GreenP);
|
||||
groupBox2.Controls.Add(PinkP);
|
||||
groupBox2.Controls.Add(OrangeP);
|
||||
groupBox2.Controls.Add(CyanP);
|
||||
groupBox2.Controls.Add(YellowP);
|
||||
groupBox2.Controls.Add(RedP);
|
||||
groupBox2.Controls.Add(BlueP);
|
||||
groupBox2.Location = new Point(17, 197);
|
||||
groupBox2.Name = "groupBox2";
|
||||
groupBox2.Size = new Size(342, 213);
|
||||
groupBox2.TabIndex = 1;
|
||||
groupBox2.TabStop = false;
|
||||
groupBox2.Text = "Color picker";
|
||||
//
|
||||
// PurpleP
|
||||
//
|
||||
PurpleP.BackColor = Color.DarkViolet;
|
||||
PurpleP.Location = new Point(260, 126);
|
||||
PurpleP.Name = "PurpleP";
|
||||
PurpleP.Size = new Size(63, 59);
|
||||
PurpleP.TabIndex = 12;
|
||||
//
|
||||
// GreenP
|
||||
//
|
||||
GreenP.BackColor = Color.SpringGreen;
|
||||
GreenP.Location = new Point(259, 49);
|
||||
GreenP.Name = "GreenP";
|
||||
GreenP.Size = new Size(63, 59);
|
||||
GreenP.TabIndex = 9;
|
||||
//
|
||||
// PinkP
|
||||
//
|
||||
PinkP.BackColor = Color.DeepPink;
|
||||
PinkP.Location = new Point(180, 126);
|
||||
PinkP.Name = "PinkP";
|
||||
PinkP.Size = new Size(63, 59);
|
||||
PinkP.TabIndex = 11;
|
||||
//
|
||||
// OrangeP
|
||||
//
|
||||
OrangeP.BackColor = Color.DarkOrange;
|
||||
OrangeP.Location = new Point(180, 49);
|
||||
OrangeP.Name = "OrangeP";
|
||||
OrangeP.Size = new Size(63, 59);
|
||||
OrangeP.TabIndex = 8;
|
||||
//
|
||||
// CyanP
|
||||
//
|
||||
CyanP.BackColor = Color.Cyan;
|
||||
CyanP.Location = new Point(100, 126);
|
||||
CyanP.Name = "CyanP";
|
||||
CyanP.Size = new Size(63, 59);
|
||||
CyanP.TabIndex = 10;
|
||||
//
|
||||
// YellowP
|
||||
//
|
||||
YellowP.BackColor = Color.Gold;
|
||||
YellowP.Location = new Point(19, 126);
|
||||
YellowP.Name = "YellowP";
|
||||
YellowP.Size = new Size(63, 59);
|
||||
YellowP.TabIndex = 9;
|
||||
//
|
||||
// RedP
|
||||
//
|
||||
RedP.BackColor = Color.Firebrick;
|
||||
RedP.Location = new Point(100, 49);
|
||||
RedP.Name = "RedP";
|
||||
RedP.Size = new Size(63, 59);
|
||||
RedP.TabIndex = 7;
|
||||
//
|
||||
// BlueP
|
||||
//
|
||||
BlueP.BackColor = SystemColors.Highlight;
|
||||
BlueP.Location = new Point(19, 49);
|
||||
BlueP.Name = "BlueP";
|
||||
BlueP.Size = new Size(63, 59);
|
||||
BlueP.TabIndex = 6;
|
||||
//
|
||||
// checkBoxPads
|
||||
//
|
||||
checkBoxPads.AutoSize = true;
|
||||
checkBoxPads.Location = new Point(24, 142);
|
||||
checkBoxPads.Name = "checkBoxPads";
|
||||
checkBoxPads.Size = new Size(203, 36);
|
||||
checkBoxPads.TabIndex = 3;
|
||||
checkBoxPads.Text = "Helicopter pad";
|
||||
checkBoxPads.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxHangars
|
||||
//
|
||||
checkBoxHangars.AutoSize = true;
|
||||
checkBoxHangars.Location = new Point(234, 142);
|
||||
checkBoxHangars.Name = "checkBoxHangars";
|
||||
checkBoxHangars.Size = new Size(133, 36);
|
||||
checkBoxHangars.TabIndex = 1;
|
||||
checkBoxHangars.Text = "Hangars";
|
||||
checkBoxHangars.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// WeightN
|
||||
//
|
||||
WeightN.Location = new Point(198, 88);
|
||||
WeightN.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
WeightN.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
WeightN.Name = "WeightN";
|
||||
WeightN.Size = new Size(142, 39);
|
||||
WeightN.TabIndex = 2;
|
||||
WeightN.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// SpeedN
|
||||
//
|
||||
SpeedN.Location = new Point(36, 88);
|
||||
SpeedN.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
SpeedN.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
SpeedN.Name = "SpeedN";
|
||||
SpeedN.Size = new Size(142, 39);
|
||||
SpeedN.TabIndex = 1;
|
||||
SpeedN.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// Label
|
||||
//
|
||||
Label.AutoSize = true;
|
||||
Label.Location = new Point(36, 53);
|
||||
Label.Name = "Label";
|
||||
Label.Size = new Size(304, 32);
|
||||
Label.TabIndex = 1;
|
||||
Label.Text = "Speed Weight";
|
||||
//
|
||||
// Showcase
|
||||
//
|
||||
Showcase.Location = new Point(58, 98);
|
||||
Showcase.Name = "Showcase";
|
||||
Showcase.Size = new Size(458, 272);
|
||||
Showcase.TabIndex = 1;
|
||||
Showcase.TabStop = false;
|
||||
//
|
||||
// btnAdd
|
||||
//
|
||||
btnAdd.Location = new Point(419, 447);
|
||||
btnAdd.Name = "btnAdd";
|
||||
btnAdd.Size = new Size(268, 46);
|
||||
btnAdd.TabIndex = 2;
|
||||
btnAdd.Text = "Add";
|
||||
btnAdd.UseVisualStyleBackColor = true;
|
||||
btnAdd.Click += AddButton_Click;
|
||||
//
|
||||
// btnCancel
|
||||
//
|
||||
btnCancel.Location = new Point(694, 447);
|
||||
btnCancel.Name = "btnCancel";
|
||||
btnCancel.Size = new Size(286, 46);
|
||||
btnCancel.TabIndex = 3;
|
||||
btnCancel.Text = "Cancel";
|
||||
btnCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// panelObject
|
||||
//
|
||||
panelObject.AllowDrop = true;
|
||||
panelObject.Controls.Add(labelAcolor);
|
||||
panelObject.Controls.Add(labelMcolor);
|
||||
panelObject.Controls.Add(Showcase);
|
||||
panelObject.Location = new Point(419, 12);
|
||||
panelObject.Name = "panelObject";
|
||||
panelObject.Size = new Size(561, 410);
|
||||
panelObject.TabIndex = 4;
|
||||
panelObject.DragDrop += PanelObject_DragDrop;
|
||||
panelObject.DragEnter += PanelObject_DragEnter;
|
||||
//
|
||||
// labelAcolor
|
||||
//
|
||||
labelAcolor.AllowDrop = true;
|
||||
labelAcolor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelAcolor.Location = new Point(253, 39);
|
||||
labelAcolor.Name = "labelAcolor";
|
||||
labelAcolor.Size = new Size(263, 42);
|
||||
labelAcolor.TabIndex = 7;
|
||||
labelAcolor.Text = "Additional color";
|
||||
labelAcolor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelAcolor.DragDrop += AdditionalColor_DragDrop;
|
||||
labelAcolor.DragEnter += AdditionalColor_DragEnter;
|
||||
//
|
||||
// labelMcolor
|
||||
//
|
||||
labelMcolor.AllowDrop = true;
|
||||
labelMcolor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelMcolor.Location = new Point(58, 39);
|
||||
labelMcolor.Name = "labelMcolor";
|
||||
labelMcolor.Size = new Size(180, 42);
|
||||
labelMcolor.TabIndex = 6;
|
||||
labelMcolor.Text = "Main color";
|
||||
labelMcolor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
labelMcolor.DragDrop += BodyColor_DragDrop;
|
||||
labelMcolor.DragEnter += BodyColor_DragEnter;
|
||||
//
|
||||
// EditorForm3
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(992, 516);
|
||||
Controls.Add(panelObject);
|
||||
Controls.Add(btnCancel);
|
||||
Controls.Add(btnAdd);
|
||||
Controls.Add(ParametersBox);
|
||||
Name = "EditorForm3";
|
||||
Text = "FormTransportConfig";
|
||||
ParametersBox.ResumeLayout(false);
|
||||
ParametersBox.PerformLayout();
|
||||
groupBox2.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)WeightN).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)SpeedN).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)Showcase).EndInit();
|
||||
panelObject.ResumeLayout(false);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox ParametersBox;
|
||||
private Label Label;
|
||||
private CheckBox checkBoxPads;
|
||||
private CheckBox checkBoxHangars;
|
||||
private NumericUpDown WeightN;
|
||||
private NumericUpDown SpeedN;
|
||||
private GroupBox groupBox2;
|
||||
private Label BaseLabel;
|
||||
private Label AdvLabel;
|
||||
private Panel PurpleP;
|
||||
private Panel GreenP;
|
||||
private Panel PinkP;
|
||||
private Panel OrangeP;
|
||||
private Panel CyanP;
|
||||
private Panel YellowP;
|
||||
private Panel RedP;
|
||||
private Panel BlueP;
|
||||
private PictureBox Showcase;
|
||||
private Button btnAdd;
|
||||
private Button btnCancel;
|
||||
private Panel panelObject;
|
||||
private Label labelMcolor;
|
||||
private Label labelAcolor;
|
||||
}
|
||||
}
|
119
ProjectCruiser/EditorForm3.cs
Normal file
119
ProjectCruiser/EditorForm3.cs
Normal file
@ -0,0 +1,119 @@
|
||||
using ProjectCruiser.DrawningSamples;
|
||||
using ProjectCruiser.Entities;
|
||||
using System;
|
||||
|
||||
namespace ProjectCruiser;
|
||||
public partial class EditorForm3 : Form
|
||||
{
|
||||
private DrawningBase _cruiser;
|
||||
|
||||
// private event Action<DrawingBase>? shipDelegate;
|
||||
private event ShipDelegate? shipDelegate;
|
||||
|
||||
public EditorForm3()
|
||||
{
|
||||
InitializeComponent();
|
||||
BlueP.MouseDown += Panel_MouseDown;
|
||||
RedP.MouseDown += Panel_MouseDown;
|
||||
PinkP.MouseDown += Panel_MouseDown;
|
||||
YellowP.MouseDown += Panel_MouseDown;
|
||||
CyanP.MouseDown += Panel_MouseDown;
|
||||
PurpleP.MouseDown += Panel_MouseDown;
|
||||
GreenP.MouseDown += Panel_MouseDown;
|
||||
OrangeP.MouseDown += Panel_MouseDown;
|
||||
btnCancel.Click += (sender, e) => Close();
|
||||
}
|
||||
|
||||
public void AddEvent(ShipDelegate del)// Action<DrawingBase> delegator)
|
||||
{
|
||||
if (shipDelegate == null) shipDelegate = del;
|
||||
else shipDelegate += del;
|
||||
}
|
||||
|
||||
private void DrawObject()
|
||||
{
|
||||
Bitmap bmp = new(Showcase.Width, Showcase.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
|
||||
_cruiser?.SetPictureSize(Showcase.Width, Showcase.Height);
|
||||
_cruiser?.SetPosition(Showcase.Width - 400, Showcase.Height - 120);
|
||||
_cruiser?.DrawTransport(gr);
|
||||
Showcase.Image = bmp;
|
||||
}
|
||||
|
||||
private void Panel_MouseDown(object? sender, MouseEventArgs e)
|
||||
{
|
||||
// TODO отправка цвета в Drag&Drop
|
||||
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
private void BaseAdvLabel_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
(sender as Label)?.DoDragDrop((sender as Label)?.Name ?? string.Empty, DragDropEffects.Move | DragDropEffects.Copy);
|
||||
}
|
||||
|
||||
private void PanelObject_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) e.Effect = DragDropEffects.Copy;
|
||||
else e.Effect = DragDropEffects.None;
|
||||
}
|
||||
|
||||
private void PanelObject_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
switch (e.Data?.GetData(DataFormats.Text)?.ToString())
|
||||
{
|
||||
case "BaseLabel":
|
||||
_cruiser = new DrawningBase((int)SpeedN.Value, (double)WeightN.Value, Color.White);
|
||||
break;
|
||||
case "AdvLabel":
|
||||
Random rn = new Random();
|
||||
_cruiser = new DrawningCruiser((int)SpeedN.Value, (double)WeightN.Value,
|
||||
Color.White, Color.Black, checkBoxPads.Checked, checkBoxHangars.Checked);
|
||||
break;
|
||||
}
|
||||
labelMcolor.BackColor = Color.Empty;
|
||||
labelAcolor.BackColor = Color.Empty;
|
||||
DrawObject();
|
||||
}
|
||||
|
||||
// Логика смены цветов: основного и дополнительного (для продвинутого объекта)
|
||||
private void BodyColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(Color))) e.Effect = DragDropEffects.Copy;
|
||||
else e.Effect = DragDropEffects.None;
|
||||
}
|
||||
private void BodyColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_cruiser != null)
|
||||
{
|
||||
_cruiser.EntityTransport.setMainColor((Color)e.Data.GetData(typeof(Color)));
|
||||
DrawObject();
|
||||
}
|
||||
}
|
||||
|
||||
private void AdditionalColor_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_cruiser is DrawningCruiser)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(Color))) e.Effect = DragDropEffects.Copy;
|
||||
else e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
private void AdditionalColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (_cruiser.EntityTransport is EntityCruiser _ship)
|
||||
{
|
||||
_ship.setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
|
||||
}
|
||||
DrawObject();
|
||||
}
|
||||
|
||||
private void AddButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_cruiser != null)
|
||||
{
|
||||
shipDelegate?.Invoke(_cruiser);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
120
ProjectCruiser/EditorForm3.resx
Normal file
120
ProjectCruiser/EditorForm3.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>
|
32
ProjectCruiser/Entities/EntityBase.cs
Normal file
32
ProjectCruiser/Entities/EntityBase.cs
Normal file
@ -0,0 +1,32 @@
|
||||
namespace ProjectCruiser.Entities;
|
||||
|
||||
public class EntityBase
|
||||
{
|
||||
// свойства
|
||||
public int Speed { get; private set; } // скорость
|
||||
public double Weight { get; private set; } // вес
|
||||
public Color MainColor { get; private set; } // основной цвет
|
||||
|
||||
public void setMainColor(Color clr)
|
||||
{
|
||||
MainColor = clr;
|
||||
}
|
||||
|
||||
// public bool Deckhouse { get; private set; } // салон на верхней палубе
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
public int[] values = { 0, 0, 0 };
|
||||
|
||||
public EntityBase(int speed, double weight, Color mainc)
|
||||
// (bool) deckhouse -> default TRUE now
|
||||
{
|
||||
Random rn = new();
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
MainColor = mainc;
|
||||
// Deckhouse = deckhouse;
|
||||
values[0] = rn.Next(1, 4);
|
||||
values[1] = rn.Next(5, 10);
|
||||
values[2] = rn.Next(1, 3);
|
||||
}
|
||||
}
|
24
ProjectCruiser/Entities/EntityCruiser.cs
Normal file
24
ProjectCruiser/Entities/EntityCruiser.cs
Normal file
@ -0,0 +1,24 @@
|
||||
namespace ProjectCruiser.Entities;
|
||||
|
||||
public class EntityCruiser : EntityBase
|
||||
{
|
||||
public Color AdditionalColor { get; private set; } // доп. цвет
|
||||
|
||||
public void setAdditionalColor(Color clr)
|
||||
{
|
||||
AdditionalColor = clr;
|
||||
}
|
||||
|
||||
// признаки (наличия)
|
||||
public bool HelicopterPads { get; private set; } // вертолетная площадка
|
||||
public bool Hangars { get; private set; } // ангар
|
||||
|
||||
public EntityCruiser(int speed, double weight, Color mainc,
|
||||
Color additionalColor, bool pad, bool hangars)
|
||||
: base(speed, weight, mainc)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
HelicopterPads = pad; // non-default now for editor Form3
|
||||
Hangars = hangars;
|
||||
}
|
||||
}
|
88
ProjectCruiser/MoveStrategy/AbstractStrategy.cs
Normal file
88
ProjectCruiser/MoveStrategy/AbstractStrategy.cs
Normal file
@ -0,0 +1,88 @@
|
||||
namespace ProjectCruiser.MoveStrategy;
|
||||
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
// Перемещаемый объект
|
||||
private IMoveableObj? _moveableObject;
|
||||
|
||||
// Статус перемещения (default установка)
|
||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||
|
||||
// Ширина поля
|
||||
protected int FieldWidth { get; private set; }
|
||||
|
||||
// Высота поля
|
||||
protected int FieldHeight { get; private set; }
|
||||
|
||||
// Получение статуса
|
||||
public StrategyStatus GetStatus() { return _state; }
|
||||
|
||||
// Установка данных
|
||||
public void SetData(IMoveableObj moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = StrategyStatus.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = StrategyStatus.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
|
||||
// Шаг перемещения
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestination())
|
||||
{
|
||||
_state = StrategyStatus.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
// Результаты перемещения
|
||||
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
||||
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
||||
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
||||
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
||||
|
||||
|
||||
// Параметры объекта
|
||||
protected ObjParameters? GetObjectParameters =>
|
||||
_moveableObject?.GetObjectPosition;
|
||||
|
||||
// Шаг объекта
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
|
||||
// Перемещение к цели
|
||||
protected abstract void MoveToTarget();
|
||||
|
||||
// Проверка, достигнута ли цель
|
||||
protected abstract bool IsTargetDestination();
|
||||
|
||||
|
||||
/// Попытка перемещения в требуемом направлении
|
||||
/// <param name="movementDirection">Направление</param>
|
||||
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||
private bool MoveTo(MovementDirection movementDirection)
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
|
||||
}
|
||||
}
|
16
ProjectCruiser/MoveStrategy/IMoveableObj.cs
Normal file
16
ProjectCruiser/MoveStrategy/IMoveableObj.cs
Normal file
@ -0,0 +1,16 @@
|
||||
namespace ProjectCruiser.MoveStrategy;
|
||||
|
||||
// Интерфейс для работы с перемещаемым объектом
|
||||
public interface IMoveableObj
|
||||
{
|
||||
// Получение координат объекта
|
||||
ObjParameters? GetObjectPosition { get; }
|
||||
|
||||
// Получение шага объекта
|
||||
int GetStep { get; }
|
||||
|
||||
/// Попытка переместить объект в указанном направлении
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - объект перемещен, false - перемещение невозможно</returns>
|
||||
bool TryMoveObject(MovementDirection direction);
|
||||
}
|
47
ProjectCruiser/MoveStrategy/MoveToBorder.cs
Normal file
47
ProjectCruiser/MoveStrategy/MoveToBorder.cs
Normal file
@ -0,0 +1,47 @@
|
||||
namespace ProjectCruiser.MoveStrategy;
|
||||
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestination()
|
||||
{
|
||||
ObjParameters? objP = GetObjectParameters;
|
||||
if (objP == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return FieldWidth - GetStep() < objP.RightBorder
|
||||
&& FieldHeight - GetStep() < objP.DownBorder;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjParameters? objP = GetObjectParameters;
|
||||
if (objP == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int s = (int)GetStep();
|
||||
|
||||
int diffx = objP.RightBorder - FieldWidth;
|
||||
if (Math.Abs(diffx) > GetStep())
|
||||
{
|
||||
if (diffx > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else { MoveRight(); }
|
||||
}
|
||||
|
||||
int diffy = objP.DownBorder - FieldHeight; // (... - s) - step unnecessary
|
||||
if (Math.Abs(diffy) > GetStep())
|
||||
{
|
||||
if (diffy > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else { MoveDown(); }
|
||||
}
|
||||
}
|
||||
}
|
50
ProjectCruiser/MoveStrategy/MoveToCentre.cs
Normal file
50
ProjectCruiser/MoveStrategy/MoveToCentre.cs
Normal file
@ -0,0 +1,50 @@
|
||||
namespace ProjectCruiser.MoveStrategy;
|
||||
|
||||
public class MoveToCentre : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestination()
|
||||
{
|
||||
ObjParameters? objP = GetObjectParameters;
|
||||
if (objP == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return objP.ObjectMiddleHorizontal - GetStep()
|
||||
<= FieldWidth / 2 && objP.ObjectMiddleHorizontal
|
||||
+ GetStep() >= FieldWidth / 2
|
||||
|
||||
&& objP.ObjectMiddleVertical - GetStep()
|
||||
<= FieldHeight / 2 && objP.ObjectMiddleVertical
|
||||
+ GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjParameters? objP = GetObjectParameters;
|
||||
if (objP == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int diffx = objP.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffx) > GetStep())
|
||||
{
|
||||
if (diffx > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else { MoveRight(); }
|
||||
}
|
||||
|
||||
int diffy = objP.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffy) > GetStep())
|
||||
{
|
||||
if (diffy > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else { MoveDown(); }
|
||||
}
|
||||
}
|
||||
}
|
56
ProjectCruiser/MoveStrategy/MoveableTransport.cs
Normal file
56
ProjectCruiser/MoveStrategy/MoveableTransport.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using ProjectCruiser.DrawningSamples;
|
||||
|
||||
namespace ProjectCruiser.MoveStrategy;
|
||||
|
||||
// Класс-реализация IMoveableObject с использованием DrawningBase
|
||||
public class MoveableTransport : IMoveableObj
|
||||
{
|
||||
// Поле-объект класса Drawning(Transport) или его наследника
|
||||
private readonly DrawningBase? _car = null;
|
||||
|
||||
public MoveableTransport(DrawningBase car)
|
||||
{
|
||||
_car = car;
|
||||
}
|
||||
|
||||
public ObjParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_car == null || _car.EntityTransport == null ||
|
||||
!_car.GetPosX.HasValue || !_car.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjParameters(_car.GetPosX.Value,
|
||||
_car.GetPosY.Value, _car.GetWidth, _car.GetHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetStep => (int)(_car?.EntityTransport?.Step ?? 0);
|
||||
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if (_car == null || _car.EntityTransport == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _car.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
|
||||
/// Конвертация из MovementDirection в DirectionType
|
||||
/// <param name="direction">MovementDirection</param>
|
||||
/// <returns>DirectionType</returns>
|
||||
private static DirectionType GetDirectionType(MovementDirection direction)
|
||||
{
|
||||
return direction switch
|
||||
{
|
||||
MovementDirection.Left => DirectionType.Left,
|
||||
MovementDirection.Right => DirectionType.Right,
|
||||
MovementDirection.Up => DirectionType.Up,
|
||||
MovementDirection.Down => DirectionType.Down,
|
||||
_ => DirectionType.Unknown,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
10
ProjectCruiser/MoveStrategy/MovementDirection.cs
Normal file
10
ProjectCruiser/MoveStrategy/MovementDirection.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace ProjectCruiser.MoveStrategy;
|
||||
|
||||
// Направление перемещения
|
||||
public enum MovementDirection
|
||||
{
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
Right = 4
|
||||
}
|
29
ProjectCruiser/MoveStrategy/ObjParameters.cs
Normal file
29
ProjectCruiser/MoveStrategy/ObjParameters.cs
Normal file
@ -0,0 +1,29 @@
|
||||
namespace ProjectCruiser.MoveStrategy;
|
||||
|
||||
// Параметры-координаты объекта
|
||||
public class ObjParameters
|
||||
{
|
||||
private readonly int _x;
|
||||
private readonly int _y;
|
||||
|
||||
private readonly int _width; // Ширина объекта
|
||||
private readonly int _height; // Высота объекта
|
||||
|
||||
public int LeftBorder => _x; // Левая граница
|
||||
public int TopBorder => _y; // Верхняя граница
|
||||
public int RightBorder => _x + _width; // Правая граница
|
||||
public int DownBorder => _y + _height; // Нижняя граница
|
||||
|
||||
// Вертикальная середина объекта
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
// Горизонтальная середина объекта
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
|
||||
public ObjParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
13
ProjectCruiser/MoveStrategy/StrategyStatus.cs
Normal file
13
ProjectCruiser/MoveStrategy/StrategyStatus.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace ProjectCruiser.MoveStrategy;
|
||||
|
||||
// Статус выполнения операции перемещения
|
||||
public enum StrategyStatus
|
||||
{
|
||||
// готово к началу
|
||||
NotInit,
|
||||
// Выполняется
|
||||
InProgress,
|
||||
// Завершено
|
||||
Finish
|
||||
}
|
||||
|
152
ProjectCruiser/OceanForm1.Designer.cs
generated
Normal file
152
ProjectCruiser/OceanForm1.Designer.cs
generated
Normal file
@ -0,0 +1,152 @@
|
||||
namespace ProjectCruiser;
|
||||
partial class OceanForm1
|
||||
{
|
||||
/// Required designer variable.
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// Clean up any resources being used.
|
||||
/// <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
|
||||
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
private void InitializeComponent()
|
||||
{
|
||||
btnLeftArrow = new Button();
|
||||
btnDownArrow = new Button();
|
||||
btnRightArrow = new Button();
|
||||
btnUpArrow = new Button();
|
||||
btnCreateBase = new Button();
|
||||
pictureBoxCr = new PictureBox();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
btnCreateAdvanced = new Button();
|
||||
btnActivateStrategy = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCr).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// btnLeftArrow
|
||||
//
|
||||
btnLeftArrow.Location = new Point(926, 445);
|
||||
btnLeftArrow.Name = "btnLeftArrow";
|
||||
btnLeftArrow.Size = new Size(141, 132);
|
||||
btnLeftArrow.TabIndex = 0;
|
||||
btnLeftArrow.UseVisualStyleBackColor = true;
|
||||
btnLeftArrow.Click += BtnMove_Click;
|
||||
//
|
||||
// btnDownArrow
|
||||
//
|
||||
btnDownArrow.Location = new Point(1073, 445);
|
||||
btnDownArrow.Name = "btnDownArrow";
|
||||
btnDownArrow.Size = new Size(141, 132);
|
||||
btnDownArrow.TabIndex = 1;
|
||||
btnDownArrow.UseVisualStyleBackColor = true;
|
||||
btnDownArrow.Click += BtnMove_Click;
|
||||
//
|
||||
// btnRightArrow
|
||||
//
|
||||
btnRightArrow.Location = new Point(1220, 445);
|
||||
btnRightArrow.Name = "btnRightArrow";
|
||||
btnRightArrow.Size = new Size(141, 132);
|
||||
btnRightArrow.TabIndex = 2;
|
||||
btnRightArrow.UseVisualStyleBackColor = true;
|
||||
btnRightArrow.Click += BtnMove_Click;
|
||||
//
|
||||
// btnUpArrow
|
||||
//
|
||||
btnUpArrow.Location = new Point(1073, 307);
|
||||
btnUpArrow.Name = "btnUpArrow";
|
||||
btnUpArrow.Size = new Size(141, 132);
|
||||
btnUpArrow.TabIndex = 3;
|
||||
btnUpArrow.UseVisualStyleBackColor = true;
|
||||
btnUpArrow.Click += BtnMove_Click;
|
||||
//
|
||||
// btnCreateBase
|
||||
//
|
||||
btnCreateBase.Location = new Point(928, 12);
|
||||
btnCreateBase.Name = "btnCreateBase";
|
||||
btnCreateBase.Size = new Size(433, 46);
|
||||
btnCreateBase.TabIndex = 4;
|
||||
btnCreateBase.Text = "Create base object";
|
||||
btnCreateBase.UseVisualStyleBackColor = true;
|
||||
btnCreateBase.Click += btnCreateBase_Click;
|
||||
//
|
||||
// pictureBoxCr
|
||||
//
|
||||
pictureBoxCr.Dock = DockStyle.Fill;
|
||||
pictureBoxCr.Location = new Point(0, 0);
|
||||
pictureBoxCr.Name = "pictureBoxCr";
|
||||
pictureBoxCr.Size = new Size(1375, 778);
|
||||
pictureBoxCr.TabIndex = 5;
|
||||
pictureBoxCr.TabStop = false;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "centre", "border" });
|
||||
comboBoxStrategy.Location = new Point(928, 120);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(435, 40);
|
||||
comboBoxStrategy.TabIndex = 6;
|
||||
//
|
||||
// btnCreateAdvanced
|
||||
//
|
||||
btnCreateAdvanced.Location = new Point(928, 58);
|
||||
btnCreateAdvanced.Name = "btnCreateAdvanced";
|
||||
btnCreateAdvanced.Size = new Size(433, 46);
|
||||
btnCreateAdvanced.TabIndex = 7;
|
||||
btnCreateAdvanced.Text = "Create advanced object";
|
||||
btnCreateAdvanced.UseVisualStyleBackColor = true;
|
||||
btnCreateAdvanced.Click += btnCreateAdvanced_Click;
|
||||
//
|
||||
// btnActivateStrategy
|
||||
//
|
||||
btnActivateStrategy.Location = new Point(928, 166);
|
||||
btnActivateStrategy.Name = "btnActivateStrategy";
|
||||
btnActivateStrategy.Size = new Size(435, 46);
|
||||
btnActivateStrategy.TabIndex = 8;
|
||||
btnActivateStrategy.Text = "Activate path";
|
||||
btnActivateStrategy.UseVisualStyleBackColor = true;
|
||||
btnActivateStrategy.Click += ButtonStrategyStep_Click;
|
||||
//
|
||||
// OceanForm1
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
BackColor = Color.Turquoise;
|
||||
ClientSize = new Size(1375, 778);
|
||||
Controls.Add(btnActivateStrategy);
|
||||
Controls.Add(btnCreateAdvanced);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(btnCreateBase);
|
||||
Controls.Add(btnUpArrow);
|
||||
Controls.Add(btnRightArrow);
|
||||
Controls.Add(btnDownArrow);
|
||||
Controls.Add(btnLeftArrow);
|
||||
Controls.Add(pictureBoxCr);
|
||||
Name = "OceanForm1";
|
||||
Text = "OceanForm1";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCr).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button btnLeftArrow;
|
||||
private Button btnDownArrow;
|
||||
private Button btnRightArrow;
|
||||
private Button btnUpArrow;
|
||||
private Button btnCreateBase;
|
||||
private PictureBox pictureBoxCr;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button btnCreateAdvanced;
|
||||
private Button btnActivateStrategy;
|
||||
}
|
156
ProjectCruiser/OceanForm1.cs
Normal file
156
ProjectCruiser/OceanForm1.cs
Normal file
@ -0,0 +1,156 @@
|
||||
using ProjectCruiser.DrawningSamples;
|
||||
using ProjectCruiser.MoveStrategy;
|
||||
|
||||
namespace ProjectCruiser
|
||||
{
|
||||
public partial class OceanForm1 : Form
|
||||
{
|
||||
// Поле-объект для прорисовки объекта
|
||||
private DrawningBase? _drawningCruiser;
|
||||
|
||||
// Стратегия перемещения
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
// Получение объекта
|
||||
public DrawningBase SetShip
|
||||
{
|
||||
set
|
||||
{
|
||||
_drawningCruiser = value;
|
||||
_drawningCruiser.SetPictureSize(pictureBoxCr.Width, pictureBoxCr.Height);
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
public OceanForm1()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
}
|
||||
|
||||
// Метод прорисовки transport
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningCruiser == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxCr.Width, pictureBoxCr.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningCruiser.DrawTransport(gr);
|
||||
pictureBoxCr.Image = bmp;
|
||||
}
|
||||
|
||||
// Обработка нажатия кнопок "Create(...)"
|
||||
|
||||
private void btnCreateBase_Click(object sender, EventArgs e) =>
|
||||
CreateObject(nameof(DrawningBase));
|
||||
|
||||
private void btnCreateAdvanced_Click(object sender, EventArgs e) =>
|
||||
CreateObject(nameof(DrawningCruiser));
|
||||
|
||||
// Создание объекта класса-перемещения
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningBase):
|
||||
_drawningCruiser = new DrawningBase(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||
break;
|
||||
|
||||
case nameof(DrawningCruiser):
|
||||
_drawningCruiser = new DrawningCruiser(
|
||||
random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
_drawningCruiser.SetPictureSize(pictureBoxCr.Width, pictureBoxCr.Height);
|
||||
_drawningCruiser.SetPosition(random.Next(10, 100),
|
||||
pictureBoxCr.Height - random.Next(10, 100) - _drawningCruiser.getHeight());
|
||||
|
||||
_strategy = null;
|
||||
comboBoxStrategy.Enabled = true;
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void BtnMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningCruiser == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
case "btnUpArrow":
|
||||
result =
|
||||
_drawningCruiser.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "btnDownArrow":
|
||||
result =
|
||||
_drawningCruiser.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "btnLeftArrow":
|
||||
result =
|
||||
_drawningCruiser.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "btnRightArrow":
|
||||
result =
|
||||
_drawningCruiser.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningCruiser == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCentre(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableTransport(_drawningCruiser),
|
||||
pictureBoxCr.Width, pictureBoxCr.Height);
|
||||
}
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
ProjectCruiser/OceanForm1.resx
Normal file
120
ProjectCruiser/OceanForm1.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>
|
@ -11,7 +11,8 @@ namespace ProjectCruiser
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
Application.Run(new ServiceForm2());
|
||||
// -> OceanForm1() inside*
|
||||
}
|
||||
}
|
||||
}
|
289
ProjectCruiser/ServiceForm2.Designer.cs
generated
Normal file
289
ProjectCruiser/ServiceForm2.Designer.cs
generated
Normal file
@ -0,0 +1,289 @@
|
||||
namespace ProjectCruiser
|
||||
{
|
||||
partial class ServiceForm2
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
comboBoxArrList = new ComboBox();
|
||||
groupBox = new GroupBox();
|
||||
companyPanel = new Panel();
|
||||
btnDeleteCollection = new Button();
|
||||
listBox = new ListBox();
|
||||
btnAddCollection = new Button();
|
||||
rBtnList = new RadioButton();
|
||||
rBtnArray = new RadioButton();
|
||||
maskedTxtBoxCName = new MaskedTextBox();
|
||||
label = new Label();
|
||||
toolPanel = new Panel();
|
||||
btnUpdate = new Button();
|
||||
btnTest = new Button();
|
||||
maskedTextBoxPosition = new MaskedTextBox();
|
||||
btnDelete = new Button();
|
||||
btnAddCruiser = new Button();
|
||||
btnCreateCompany = new Button();
|
||||
pictureBox = new PictureBox();
|
||||
groupBox.SuspendLayout();
|
||||
companyPanel.SuspendLayout();
|
||||
toolPanel.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// comboBoxArrList
|
||||
//
|
||||
comboBoxArrList.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
comboBoxArrList.FormattingEnabled = true;
|
||||
comboBoxArrList.Items.AddRange(new object[] { "Storage" });
|
||||
comboBoxArrList.Location = new Point(17, 41);
|
||||
comboBoxArrList.Name = "comboBoxArrList";
|
||||
comboBoxArrList.Size = new Size(241, 40);
|
||||
comboBoxArrList.TabIndex = 0;
|
||||
comboBoxArrList.SelectedIndexChanged += SelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
// groupBox
|
||||
//
|
||||
groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
groupBox.Controls.Add(companyPanel);
|
||||
groupBox.Controls.Add(toolPanel);
|
||||
groupBox.Controls.Add(btnCreateCompany);
|
||||
groupBox.Controls.Add(comboBoxArrList);
|
||||
groupBox.Location = new Point(1421, 10);
|
||||
groupBox.Name = "groupBox";
|
||||
groupBox.Size = new Size(273, 986);
|
||||
groupBox.TabIndex = 2;
|
||||
groupBox.TabStop = false;
|
||||
groupBox.Text = "Tool panel";
|
||||
//
|
||||
// companyPanel
|
||||
//
|
||||
companyPanel.Controls.Add(btnDeleteCollection);
|
||||
companyPanel.Controls.Add(listBox);
|
||||
companyPanel.Controls.Add(btnAddCollection);
|
||||
companyPanel.Controls.Add(rBtnList);
|
||||
companyPanel.Controls.Add(rBtnArray);
|
||||
companyPanel.Controls.Add(maskedTxtBoxCName);
|
||||
companyPanel.Controls.Add(label);
|
||||
companyPanel.Location = new Point(17, 91);
|
||||
companyPanel.Name = "companyPanel";
|
||||
companyPanel.Size = new Size(243, 391);
|
||||
companyPanel.TabIndex = 7;
|
||||
//
|
||||
// btnDeleteCollection
|
||||
//
|
||||
btnDeleteCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnDeleteCollection.Location = new Point(15, 312);
|
||||
btnDeleteCollection.Name = "btnDeleteCollection";
|
||||
btnDeleteCollection.Size = new Size(214, 73);
|
||||
btnDeleteCollection.TabIndex = 11;
|
||||
btnDeleteCollection.Text = "Remove Collection";
|
||||
btnDeleteCollection.UseVisualStyleBackColor = true;
|
||||
btnDeleteCollection.Click += btnCollectionDel_Click;
|
||||
//
|
||||
// listBox
|
||||
//
|
||||
listBox.FormattingEnabled = true;
|
||||
listBox.Location = new Point(16, 174);
|
||||
listBox.Name = "listBox";
|
||||
listBox.Size = new Size(214, 132);
|
||||
listBox.TabIndex = 10;
|
||||
//
|
||||
// btnAddCollection
|
||||
//
|
||||
btnAddCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnAddCollection.Location = new Point(15, 119);
|
||||
btnAddCollection.Name = "btnAddCollection";
|
||||
btnAddCollection.Size = new Size(214, 50);
|
||||
btnAddCollection.TabIndex = 7;
|
||||
btnAddCollection.Text = "Add Collection";
|
||||
btnAddCollection.UseVisualStyleBackColor = true;
|
||||
btnAddCollection.Click += btnCollectionAdd_Click;
|
||||
//
|
||||
// rBtnList
|
||||
//
|
||||
rBtnList.AutoSize = true;
|
||||
rBtnList.Location = new Point(150, 80);
|
||||
rBtnList.Name = "rBtnList";
|
||||
rBtnList.Size = new Size(80, 36);
|
||||
rBtnList.TabIndex = 9;
|
||||
rBtnList.TabStop = true;
|
||||
rBtnList.Text = "List";
|
||||
rBtnList.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// rBtnArray
|
||||
//
|
||||
rBtnArray.AutoSize = true;
|
||||
rBtnArray.Location = new Point(16, 80);
|
||||
rBtnArray.Name = "rBtnArray";
|
||||
rBtnArray.Size = new Size(100, 36);
|
||||
rBtnArray.TabIndex = 8;
|
||||
rBtnArray.TabStop = true;
|
||||
rBtnArray.Text = "Array";
|
||||
rBtnArray.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// maskedTxtBoxCName
|
||||
//
|
||||
maskedTxtBoxCName.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
maskedTxtBoxCName.Location = new Point(16, 40);
|
||||
maskedTxtBoxCName.Name = "maskedTxtBoxCName";
|
||||
maskedTxtBoxCName.Size = new Size(214, 39);
|
||||
maskedTxtBoxCName.TabIndex = 7;
|
||||
//
|
||||
// label
|
||||
//
|
||||
label.AutoSize = true;
|
||||
label.Location = new Point(29, 5);
|
||||
label.Name = "label";
|
||||
label.Size = new Size(188, 32);
|
||||
label.TabIndex = 0;
|
||||
label.Text = "Collection name";
|
||||
//
|
||||
// toolPanel
|
||||
//
|
||||
toolPanel.Controls.Add(btnUpdate);
|
||||
toolPanel.Controls.Add(btnTest);
|
||||
toolPanel.Controls.Add(maskedTextBoxPosition);
|
||||
toolPanel.Controls.Add(btnDelete);
|
||||
toolPanel.Controls.Add(btnAddCruiser);
|
||||
toolPanel.Enabled = false;
|
||||
toolPanel.Location = new Point(26, 567);
|
||||
toolPanel.Name = "toolPanel";
|
||||
toolPanel.Size = new Size(226, 317);
|
||||
toolPanel.TabIndex = 13;
|
||||
//
|
||||
// btnUpdate
|
||||
//
|
||||
btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnUpdate.Location = new Point(16, 257);
|
||||
btnUpdate.Name = "btnUpdate";
|
||||
btnUpdate.Size = new Size(192, 41);
|
||||
btnUpdate.TabIndex = 6;
|
||||
btnUpdate.Text = "Update";
|
||||
btnUpdate.UseVisualStyleBackColor = true;
|
||||
btnUpdate.Click += btnRefresh_Click;
|
||||
//
|
||||
// btnTest
|
||||
//
|
||||
btnTest.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnTest.Location = new Point(17, 162);
|
||||
btnTest.Name = "btnTest";
|
||||
btnTest.Size = new Size(192, 89);
|
||||
btnTest.TabIndex = 5;
|
||||
btnTest.Text = "Choose\r\nfor testing";
|
||||
btnTest.UseVisualStyleBackColor = true;
|
||||
btnTest.Click += btnChooseforTest_Click;
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
maskedTextBoxPosition.Location = new Point(17, 68);
|
||||
maskedTextBoxPosition.Mask = "00";
|
||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
maskedTextBoxPosition.Size = new Size(192, 39);
|
||||
maskedTextBoxPosition.TabIndex = 3;
|
||||
maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||
//
|
||||
// btnDelete
|
||||
//
|
||||
btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnDelete.Location = new Point(16, 113);
|
||||
btnDelete.Name = "btnDelete";
|
||||
btnDelete.Size = new Size(192, 43);
|
||||
btnDelete.TabIndex = 4;
|
||||
btnDelete.Text = "Delete";
|
||||
btnDelete.UseVisualStyleBackColor = true;
|
||||
btnDelete.Click += btnRemoveCar_Click;
|
||||
//
|
||||
// btnAddCruiser
|
||||
//
|
||||
btnAddCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnAddCruiser.Location = new Point(17, 13);
|
||||
btnAddCruiser.Name = "btnAddCruiser";
|
||||
btnAddCruiser.Size = new Size(192, 49);
|
||||
btnAddCruiser.TabIndex = 2;
|
||||
btnAddCruiser.Text = "Add cruiser";
|
||||
btnAddCruiser.UseVisualStyleBackColor = true;
|
||||
btnAddCruiser.Click += btnAddTransport_Click;
|
||||
//
|
||||
// btnCreateCompany
|
||||
//
|
||||
btnCreateCompany.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnCreateCompany.Location = new Point(16, 488);
|
||||
btnCreateCompany.Name = "btnCreateCompany";
|
||||
btnCreateCompany.Size = new Size(245, 73);
|
||||
btnCreateCompany.TabIndex = 12;
|
||||
btnCreateCompany.Text = "Create or switch to Company";
|
||||
btnCreateCompany.UseVisualStyleBackColor = true;
|
||||
btnCreateCompany.Click += btnCreateCompany_Click;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Left;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(1415, 1007);
|
||||
pictureBox.TabIndex = 3;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// ServiceForm2
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1700, 1007);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBox);
|
||||
Name = "ServiceForm2";
|
||||
Text = "ServiceForm2";
|
||||
groupBox.ResumeLayout(false);
|
||||
companyPanel.ResumeLayout(false);
|
||||
companyPanel.PerformLayout();
|
||||
toolPanel.ResumeLayout(false);
|
||||
toolPanel.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox comboBoxArrList;
|
||||
private GroupBox groupBox;
|
||||
private Button btnAddCruiser;
|
||||
private Button btnUpdate;
|
||||
private Button btnTest;
|
||||
private Button btnDelete;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private PictureBox pictureBox;
|
||||
private Panel companyPanel;
|
||||
private RadioButton rBtnArray;
|
||||
private MaskedTextBox maskedTxtBoxCName;
|
||||
private Label label;
|
||||
private RadioButton rBtnList;
|
||||
private Button btnAddCollection;
|
||||
private ListBox listBox;
|
||||
private Button btnDeleteCollection;
|
||||
private Button btnCreateCompany;
|
||||
private Panel toolPanel;
|
||||
}
|
||||
}
|
197
ProjectCruiser/ServiceForm2.cs
Normal file
197
ProjectCruiser/ServiceForm2.cs
Normal file
@ -0,0 +1,197 @@
|
||||
using ProjectCruiser.CollectionGenericObj;
|
||||
using ProjectCruiser.DrawningSamples;
|
||||
namespace ProjectCruiser;
|
||||
|
||||
public partial class ServiceForm2 : Form
|
||||
{
|
||||
// Компания
|
||||
private AbstractCompany? _company = null;
|
||||
|
||||
private readonly StorageCollection<DrawningBase> _storageCollection;
|
||||
|
||||
public ServiceForm2()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storageCollection = new();
|
||||
}
|
||||
|
||||
// Выбор компании
|
||||
private void SelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
toolPanel.Enabled = false;
|
||||
}
|
||||
|
||||
// Color picker (default : random)
|
||||
private static Color pickColor(Random r)
|
||||
{
|
||||
Color cl = new Color();
|
||||
ColorDialog dialog = new();
|
||||
|
||||
if (dialog.ShowDialog() == DialogResult.OK) cl = dialog.Color;
|
||||
else Color.FromArgb(r.Next(0, 256), r.Next(0, 256), r.Next(0, 256));
|
||||
|
||||
return cl;
|
||||
}
|
||||
|
||||
// Добавление корабля
|
||||
private void btnAddTransport_Click(object sender, EventArgs e)
|
||||
{
|
||||
EditorForm3 form3 = new();
|
||||
// TODO передать метод :
|
||||
form3.AddEvent(CreateObject);
|
||||
form3.Show();
|
||||
}
|
||||
|
||||
// Создание объекта класса-перемещения
|
||||
private void CreateObject(DrawningBase? ship)
|
||||
{
|
||||
if (_company == null || ship == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_company + ship != -1)
|
||||
{
|
||||
MessageBox.Show("> Object was added");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("[!] Failed to add object");
|
||||
}
|
||||
}
|
||||
|
||||
// Удаление объекта
|
||||
private void btnRemoveCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)
|
||||
|| _company == null) return;
|
||||
|
||||
if (MessageBox.Show("[*] Remove object: Are you sure?", "Remove",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) return;
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
|
||||
if (_company - Convert.ToInt32(maskedTextBoxPosition.Text) != null)
|
||||
{
|
||||
MessageBox.Show("> Object was removed");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else MessageBox.Show("[!] Failed to remove object");
|
||||
}
|
||||
|
||||
// Передача объекта в другую форму
|
||||
private void btnChooseforTest_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawningBase? car = null;
|
||||
int counter = 100;
|
||||
while (car == null)
|
||||
{
|
||||
car = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (car == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
OceanForm1 form = new() { SetShip = car };
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
// Перерисовка коллекции
|
||||
private void btnRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
|
||||
private void btnCollectionAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTxtBoxCName.Text) || (!rBtnList.Checked && !rBtnArray.Checked))
|
||||
{
|
||||
MessageBox.Show("Enter correct data or choose an option", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
CollectionType collType = CollectionType.None;
|
||||
|
||||
if (rBtnArray.Checked)
|
||||
{
|
||||
collType = CollectionType.Array;
|
||||
}
|
||||
else if (rBtnList.Checked)
|
||||
{
|
||||
collType = CollectionType.List;
|
||||
}
|
||||
|
||||
_storageCollection.AddCollection(maskedTxtBoxCName.Text, collType);
|
||||
RefreshListBoxItems();
|
||||
}
|
||||
|
||||
private void btnCollectionDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBox.SelectedItem == null || listBox.SelectedIndex < 0)
|
||||
{
|
||||
MessageBox.Show("Collection was not choosed");
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Are you sure?", "Removing", MessageBoxButtons.OK, MessageBoxIcon.Question) != DialogResult.OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_storageCollection.DelCollection(listBox.SelectedItem.ToString());
|
||||
RefreshListBoxItems();
|
||||
}
|
||||
|
||||
private void RefreshListBoxItems()
|
||||
{
|
||||
listBox.Items.Clear();
|
||||
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
|
||||
{
|
||||
string? collName = _storageCollection.Keys?[i];
|
||||
if (!string.IsNullOrEmpty(collName))
|
||||
{
|
||||
listBox.Items.Add(collName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btnCreateCompany_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBox.SelectedIndex < 0 || listBox.SelectedItem == null)
|
||||
{
|
||||
MessageBox.Show("Collection wasn't choosed");
|
||||
return;
|
||||
}
|
||||
|
||||
ICollectionGenObj<DrawningBase>? collection =
|
||||
_storageCollection[listBox.SelectedItem.ToString() ?? string.Empty];
|
||||
|
||||
if (collection == null)
|
||||
{
|
||||
MessageBox.Show("Collection wasn't initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (comboBoxArrList.Text)
|
||||
{
|
||||
case "Storage":
|
||||
_company = new ShipSharingService(pictureBox.Width,
|
||||
pictureBox.Height, collection);
|
||||
break;
|
||||
}
|
||||
|
||||
toolPanel.Enabled = true; // block of buttons at the right bottom
|
||||
RefreshListBoxItems();
|
||||
}
|
||||
}
|
120
ProjectCruiser/ServiceForm2.resx
Normal file
120
ProjectCruiser/ServiceForm2.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>
|
6
ProjectCruiser/ShipDelegate.cs
Normal file
6
ProjectCruiser/ShipDelegate.cs
Normal file
@ -0,0 +1,6 @@
|
||||
using ProjectCruiser.DrawningSamples;
|
||||
|
||||
namespace ProjectCruiser
|
||||
{
|
||||
public delegate void ShipDelegate(DrawningBase transport);
|
||||
}
|
Loading…
Reference in New Issue
Block a user