Compare commits
2 Commits
0619b0de35
...
82f06ed48b
Author | SHA1 | Date | |
---|---|---|---|
|
82f06ed48b | ||
|
ef90e5fc09 |
@ -0,0 +1,99 @@
|
|||||||
|
using ProjectWarmlyShip.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectWarmlyShip.CollectionGenericObjects;
|
||||||
|
|
||||||
|
public abstract class AbstractCompany
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Размер места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _placeSizeWidth = 210;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер места (высота)
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _placeSizeHeight = 150;
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Коллекция судов
|
||||||
|
/// </summary>
|
||||||
|
protected ICollectionGenericObjects<DrawningShip>? _collection = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Вычисление максимального количества элементов, который можно разместить в окне
|
||||||
|
/// </summary>
|
||||||
|
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth">Ширина окна</param>
|
||||||
|
/// <param name="picHeight">Высота окна</param>
|
||||||
|
/// <param name="collection">Коллекция автомобилей</param>
|
||||||
|
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningShip> collection)
|
||||||
|
{
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = collection;
|
||||||
|
_collection.SetMaxCount = GetMaxCount;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора сложения для класса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="company">Компания</param>
|
||||||
|
/// <param name="ship">Добавляемый объект</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool operator +(AbstractCompany company, DrawningShip ship)
|
||||||
|
{
|
||||||
|
return company._collection?.Insert(ship) ?? false;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора удаления для класса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="company">Компания</param>
|
||||||
|
/// <param name="position">Номер удаляемого объекта</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool operator -(AbstractCompany company, int position)
|
||||||
|
{
|
||||||
|
return company._collection?.Remove(position) ?? false;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение случайного объекта из коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public DrawningShip? GetRandomObject()
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
return _collection?.Get(rnd.Next(GetMaxCount));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод всей коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap? Show()
|
||||||
|
{
|
||||||
|
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
||||||
|
Graphics graphics = Graphics.FromImage(bitmap);
|
||||||
|
DrawBackgound(graphics);
|
||||||
|
SetObjectsPosition();
|
||||||
|
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||||
|
{
|
||||||
|
DrawningShip? obj = _collection?.Get(i);
|
||||||
|
obj?.DrawTransport(graphics);
|
||||||
|
}
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод заднего фона
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
protected abstract void DrawBackgound(Graphics g);
|
||||||
|
/// <summary>
|
||||||
|
/// Расстановка объектов
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void SetObjectsPosition();
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
namespace ProjectWarmlyShip.CollectionGenericObjects;
|
||||||
|
|
||||||
|
public interface ICollectionGenericObjects<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Количество объектов в коллекции
|
||||||
|
/// </summary>
|
||||||
|
int Count { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Установка максимального количества элементов
|
||||||
|
/// </summary>
|
||||||
|
int SetMaxCount { set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в коллекцию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
|
/// <returns>true - вставка прошла удачно, false - вставка неудалась</returns>
|
||||||
|
bool Insert(T obj);
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в коллекцию на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>true - вставка прошла удачно, false - вставка неудалась</returns>
|
||||||
|
bool Insert(T obj, int position);
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из коллекции с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>true - удаление прошло удачно, false - удаление неудалось</returns>
|
||||||
|
bool Remove(int position);
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>Объект</returns>
|
||||||
|
T? Get(int position);
|
||||||
|
}
|
@ -0,0 +1,84 @@
|
|||||||
|
namespace ProjectWarmlyShip.CollectionGenericObjects;
|
||||||
|
|
||||||
|
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Массив объектов, которые храним
|
||||||
|
/// </summary>
|
||||||
|
private T?[] _collection;
|
||||||
|
public int Count => _collection.Length;
|
||||||
|
public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public MassiveGenericObjects()
|
||||||
|
{
|
||||||
|
_collection = Array.Empty<T?>();
|
||||||
|
}
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
if (position >= _collection.Length || position < 0) return null;
|
||||||
|
return _collection[position];
|
||||||
|
}
|
||||||
|
public bool Insert(T obj)
|
||||||
|
{
|
||||||
|
// TODO вставка в свободное место набора
|
||||||
|
int index = 0;
|
||||||
|
while (index < _collection.Length)
|
||||||
|
{
|
||||||
|
if (_collection[index] == null)
|
||||||
|
{
|
||||||
|
_collection[index] = obj;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public bool Insert(T obj, int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||||
|
// ищется свободное место после этой позиции и идет вставка туда
|
||||||
|
// если нет после, ищем до
|
||||||
|
// TODO вставка
|
||||||
|
if (position >= _collection.Length || position < 0)
|
||||||
|
return false;
|
||||||
|
if (_collection[position] == null) {
|
||||||
|
_collection[position] = obj;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int index = position + 1;
|
||||||
|
while (index < _collection.Length)
|
||||||
|
{
|
||||||
|
if (_collection[index] == null)
|
||||||
|
{
|
||||||
|
_collection[index] = obj;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
index = position - 1;
|
||||||
|
while (index >= 0)
|
||||||
|
{
|
||||||
|
if (_collection[index] == null)
|
||||||
|
{
|
||||||
|
_collection[index] = obj;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
--index;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||||
|
if (position >= _collection.Length || position < 0)
|
||||||
|
return false;
|
||||||
|
_collection[position] = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
using ProjectWarmlyShip.Drawnings;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace ProjectWarmlyShip.CollectionGenericObjects;
|
||||||
|
|
||||||
|
public class ShipPortService : AbstractCompany
|
||||||
|
{
|
||||||
|
public ShipPortService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningShip> collection) : base(picWidth, picHeight, collection)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DrawBackgound(Graphics g)
|
||||||
|
{
|
||||||
|
//рисуем пристань
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
Pen pen = new(Color.Black, 3);
|
||||||
|
for (int i = 0; i < width; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < height + 1; ++j)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight,
|
||||||
|
i * _placeSizeWidth + _placeSizeWidth - 5, j * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void SetObjectsPosition()
|
||||||
|
{
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
|
||||||
|
int curWidth = width - 1;
|
||||||
|
int curHeight = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||||
|
{
|
||||||
|
if (_collection.Get(i) != null)
|
||||||
|
{
|
||||||
|
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||||
|
_collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 20, curHeight * _placeSizeHeight + 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curWidth > 0)
|
||||||
|
curWidth--;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
curWidth = width - 1;
|
||||||
|
curHeight++;
|
||||||
|
}
|
||||||
|
if (curHeight > height)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
173
ProjectWarmlyShip/ProjectWarmlyShip/FormShipCollection.Designer.cs
generated
Normal file
173
ProjectWarmlyShip/ProjectWarmlyShip/FormShipCollection.Designer.cs
generated
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
namespace ProjectWarmlyShip
|
||||||
|
{
|
||||||
|
partial class FormShipCollection
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
groupBoxTools = new GroupBox();
|
||||||
|
buttonRefresh = new Button();
|
||||||
|
buttonGoToCheck = new Button();
|
||||||
|
buttonRemoveShip = new Button();
|
||||||
|
maskedTextBox = new MaskedTextBox();
|
||||||
|
buttonAddWarmlyShip = new Button();
|
||||||
|
buttonAddShip = new Button();
|
||||||
|
comboBoxSelectorCompany = new ComboBox();
|
||||||
|
pictureBox = new PictureBox();
|
||||||
|
groupBoxTools.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxTools
|
||||||
|
//
|
||||||
|
groupBoxTools.Controls.Add(buttonRefresh);
|
||||||
|
groupBoxTools.Controls.Add(buttonGoToCheck);
|
||||||
|
groupBoxTools.Controls.Add(buttonRemoveShip);
|
||||||
|
groupBoxTools.Controls.Add(maskedTextBox);
|
||||||
|
groupBoxTools.Controls.Add(buttonAddWarmlyShip);
|
||||||
|
groupBoxTools.Controls.Add(buttonAddShip);
|
||||||
|
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||||
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
|
groupBoxTools.Location = new Point(887, 0);
|
||||||
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
|
groupBoxTools.Size = new Size(146, 596);
|
||||||
|
groupBoxTools.TabIndex = 0;
|
||||||
|
groupBoxTools.TabStop = false;
|
||||||
|
groupBoxTools.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// buttonRefresh
|
||||||
|
//
|
||||||
|
buttonRefresh.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonRefresh.Location = new Point(6, 544);
|
||||||
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
|
buttonRefresh.Size = new Size(128, 40);
|
||||||
|
buttonRefresh.TabIndex = 6;
|
||||||
|
buttonRefresh.Text = "Обновить";
|
||||||
|
buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
|
buttonRefresh.Click += buttonRefresh_Click;
|
||||||
|
//
|
||||||
|
// buttonGoToCheck
|
||||||
|
//
|
||||||
|
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonGoToCheck.Location = new Point(6, 324);
|
||||||
|
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||||
|
buttonGoToCheck.Size = new Size(128, 40);
|
||||||
|
buttonGoToCheck.TabIndex = 5;
|
||||||
|
buttonGoToCheck.Text = "Передать на тесты";
|
||||||
|
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||||
|
buttonGoToCheck.Click += buttonGoToCheck_Click;
|
||||||
|
//
|
||||||
|
// buttonRemoveShip
|
||||||
|
//
|
||||||
|
buttonRemoveShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonRemoveShip.Location = new Point(6, 250);
|
||||||
|
buttonRemoveShip.Name = "buttonRemoveShip";
|
||||||
|
buttonRemoveShip.Size = new Size(128, 40);
|
||||||
|
buttonRemoveShip.TabIndex = 4;
|
||||||
|
buttonRemoveShip.Text = "Удаление";
|
||||||
|
buttonRemoveShip.UseVisualStyleBackColor = true;
|
||||||
|
buttonRemoveShip.Click += buttonRemoveShip_Click;
|
||||||
|
//
|
||||||
|
// maskedTextBox
|
||||||
|
//
|
||||||
|
maskedTextBox.Location = new Point(6, 221);
|
||||||
|
maskedTextBox.Mask = "00";
|
||||||
|
maskedTextBox.Name = "maskedTextBox";
|
||||||
|
maskedTextBox.Size = new Size(128, 23);
|
||||||
|
maskedTextBox.TabIndex = 3;
|
||||||
|
maskedTextBox.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
|
// buttonAddWarmlyShip
|
||||||
|
//
|
||||||
|
buttonAddWarmlyShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonAddWarmlyShip.Location = new Point(6, 131);
|
||||||
|
buttonAddWarmlyShip.Name = "buttonAddWarmlyShip";
|
||||||
|
buttonAddWarmlyShip.Size = new Size(128, 40);
|
||||||
|
buttonAddWarmlyShip.TabIndex = 2;
|
||||||
|
buttonAddWarmlyShip.Text = "Добавление теплохода";
|
||||||
|
buttonAddWarmlyShip.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddWarmlyShip.Click += buttonAddWarmlyShip_Click;
|
||||||
|
//
|
||||||
|
// buttonAddShip
|
||||||
|
//
|
||||||
|
buttonAddShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonAddShip.Location = new Point(6, 87);
|
||||||
|
buttonAddShip.Name = "buttonAddShip";
|
||||||
|
buttonAddShip.Size = new Size(128, 38);
|
||||||
|
buttonAddShip.TabIndex = 1;
|
||||||
|
buttonAddShip.Text = "Добавление судна";
|
||||||
|
buttonAddShip.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddShip.Click += buttonAddShip_Click;
|
||||||
|
//
|
||||||
|
// comboBoxSelectorCompany
|
||||||
|
//
|
||||||
|
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||||
|
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||||
|
comboBoxSelectorCompany.Location = new Point(6, 22);
|
||||||
|
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||||
|
comboBoxSelectorCompany.Size = new Size(134, 23);
|
||||||
|
comboBoxSelectorCompany.TabIndex = 0;
|
||||||
|
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// pictureBox
|
||||||
|
//
|
||||||
|
pictureBox.Dock = DockStyle.Fill;
|
||||||
|
pictureBox.Location = new Point(0, 0);
|
||||||
|
pictureBox.Name = "pictureBox";
|
||||||
|
pictureBox.Size = new Size(887, 596);
|
||||||
|
pictureBox.TabIndex = 1;
|
||||||
|
pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormShipCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(1033, 596);
|
||||||
|
Controls.Add(pictureBox);
|
||||||
|
Controls.Add(groupBoxTools);
|
||||||
|
Name = "FormShipCollection";
|
||||||
|
Text = "Коллекция судов";
|
||||||
|
groupBoxTools.ResumeLayout(false);
|
||||||
|
groupBoxTools.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxTools;
|
||||||
|
private ComboBox comboBoxSelectorCompany;
|
||||||
|
private Button buttonAddWarmlyShip;
|
||||||
|
private Button buttonAddShip;
|
||||||
|
private Button buttonGoToCheck;
|
||||||
|
private Button buttonRemoveShip;
|
||||||
|
private MaskedTextBox maskedTextBox;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private Button buttonRefresh;
|
||||||
|
}
|
||||||
|
}
|
132
ProjectWarmlyShip/ProjectWarmlyShip/FormShipCollection.cs
Normal file
132
ProjectWarmlyShip/ProjectWarmlyShip/FormShipCollection.cs
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
using ProjectWarmlyShip.CollectionGenericObjects;
|
||||||
|
using ProjectWarmlyShip.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectWarmlyShip;
|
||||||
|
|
||||||
|
public partial class FormShipCollection : Form
|
||||||
|
{
|
||||||
|
private AbstractCompany? _company = null;
|
||||||
|
public FormShipCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
switch (comboBoxSelectorCompany.Text)
|
||||||
|
{
|
||||||
|
case "Хранилище":
|
||||||
|
_company = new ShipPortService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningShip>());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void CreateObject(string type)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Random random = new();
|
||||||
|
DrawningShip drawningShip;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case nameof(DrawningShip):
|
||||||
|
drawningShip = new DrawningShip(random.Next(100, 300),
|
||||||
|
random.Next(1000, 3000), GetColor(random));
|
||||||
|
break;
|
||||||
|
case nameof(DrawningWarmlyShip):
|
||||||
|
// TODO вызов диалогового окна для выбора цвета (made)
|
||||||
|
drawningShip = new DrawningWarmlyShip(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
|
GetColor(random), GetColor(random),
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_company + drawningShip)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static Color GetColor(Random random)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonAddShip_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CreateObject(nameof(DrawningShip));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonAddWarmlyShip_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CreateObject(nameof(DrawningWarmlyShip));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonRemoveShip_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||||
|
if (_company - pos)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void buttonGoToCheck_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DrawningShip? ship = null;
|
||||||
|
int counter = 100;
|
||||||
|
while (ship == null)
|
||||||
|
{
|
||||||
|
ship = _company.GetRandomObject();
|
||||||
|
counter--;
|
||||||
|
if (counter <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ship == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormWarmlyShip form = new()
|
||||||
|
{
|
||||||
|
SetShip = ship
|
||||||
|
};
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
private void buttonRefresh_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
}
|
120
ProjectWarmlyShip/ProjectWarmlyShip/FormShipCollection.resx
Normal file
120
ProjectWarmlyShip/ProjectWarmlyShip/FormShipCollection.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>
|
@ -29,12 +29,10 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
pictureBoxWarmlyShip = new PictureBox();
|
pictureBoxWarmlyShip = new PictureBox();
|
||||||
buttonCreate = new Button();
|
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonСreateShip = new Button();
|
|
||||||
comboBoxStrategy = new ComboBox();
|
comboBoxStrategy = new ComboBox();
|
||||||
buttonStrategyStep = new Button();
|
buttonStrategyStep = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyShip).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyShip).BeginInit();
|
||||||
@ -50,20 +48,6 @@
|
|||||||
pictureBoxWarmlyShip.TabIndex = 0;
|
pictureBoxWarmlyShip.TabIndex = 0;
|
||||||
pictureBoxWarmlyShip.TabStop = false;
|
pictureBoxWarmlyShip.TabStop = false;
|
||||||
//
|
//
|
||||||
// buttonCreate
|
|
||||||
//
|
|
||||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonCreate.BackColor = SystemColors.ButtonHighlight;
|
|
||||||
buttonCreate.Cursor = Cursors.IBeam;
|
|
||||||
buttonCreate.ForeColor = SystemColors.ControlText;
|
|
||||||
buttonCreate.Location = new Point(12, 331);
|
|
||||||
buttonCreate.Name = "buttonCreate";
|
|
||||||
buttonCreate.Size = new Size(118, 23);
|
|
||||||
buttonCreate.TabIndex = 1;
|
|
||||||
buttonCreate.Text = "Создать теплоход";
|
|
||||||
buttonCreate.UseVisualStyleBackColor = false;
|
|
||||||
buttonCreate.Click += ButtonCreate_Click;
|
|
||||||
//
|
|
||||||
// buttonUp
|
// buttonUp
|
||||||
//
|
//
|
||||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
@ -112,20 +96,6 @@
|
|||||||
buttonDown.UseVisualStyleBackColor = true;
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
buttonDown.Click += ButtonMove_Click;
|
buttonDown.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonСreateShip
|
|
||||||
//
|
|
||||||
buttonСreateShip.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonСreateShip.BackColor = SystemColors.ButtonHighlight;
|
|
||||||
buttonСreateShip.Cursor = Cursors.IBeam;
|
|
||||||
buttonСreateShip.ForeColor = SystemColors.ControlText;
|
|
||||||
buttonСreateShip.Location = new Point(146, 331);
|
|
||||||
buttonСreateShip.Name = "buttonСreateShip";
|
|
||||||
buttonСreateShip.Size = new Size(118, 23);
|
|
||||||
buttonСreateShip.TabIndex = 6;
|
|
||||||
buttonСreateShip.Text = "Создать судно";
|
|
||||||
buttonСreateShip.UseVisualStyleBackColor = false;
|
|
||||||
buttonСreateShip.Click += buttonСreateShip_Click;
|
|
||||||
//
|
|
||||||
// comboBoxStrategy
|
// comboBoxStrategy
|
||||||
//
|
//
|
||||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
@ -153,12 +123,10 @@
|
|||||||
ClientSize = new Size(830, 366);
|
ClientSize = new Size(830, 366);
|
||||||
Controls.Add(buttonStrategyStep);
|
Controls.Add(buttonStrategyStep);
|
||||||
Controls.Add(comboBoxStrategy);
|
Controls.Add(comboBoxStrategy);
|
||||||
Controls.Add(buttonСreateShip);
|
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonCreate);
|
|
||||||
Controls.Add(pictureBoxWarmlyShip);
|
Controls.Add(pictureBoxWarmlyShip);
|
||||||
Name = "FormWarmlyShip";
|
Name = "FormWarmlyShip";
|
||||||
Text = "WarmlyShip";
|
Text = "WarmlyShip";
|
||||||
@ -170,12 +138,10 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxWarmlyShip;
|
private PictureBox pictureBoxWarmlyShip;
|
||||||
private Button buttonCreate;
|
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonСreateShip;
|
|
||||||
private ComboBox comboBoxStrategy;
|
private ComboBox comboBoxStrategy;
|
||||||
private Button buttonStrategyStep;
|
private Button buttonStrategyStep;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,19 @@ namespace ProjectWarmlyShip
|
|||||||
{
|
{
|
||||||
private DrawningShip? _drawningShip;
|
private DrawningShip? _drawningShip;
|
||||||
private AbstractStrategy? _strategy;
|
private AbstractStrategy? _strategy;
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта
|
||||||
|
/// </summary>
|
||||||
|
public DrawningShip SetShip
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_drawningShip = value;
|
||||||
|
_drawningShip.SetPictureSize(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
public FormWarmlyShip()
|
public FormWarmlyShip()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -23,48 +36,6 @@ namespace ProjectWarmlyShip
|
|||||||
_drawningShip.DrawTransport(gr);
|
_drawningShip.DrawTransport(gr);
|
||||||
pictureBoxWarmlyShip.Image = bmp;
|
pictureBoxWarmlyShip.Image = bmp;
|
||||||
}
|
}
|
||||||
private void CreateObject(string type)
|
|
||||||
{
|
|
||||||
Random random = new Random();
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case nameof(DrawningShip):
|
|
||||||
_drawningShip = new DrawningShip(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(DrawningWarmlyShip):
|
|
||||||
_drawningShip = new DrawningWarmlyShip(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;
|
|
||||||
}
|
|
||||||
_drawningShip.SetPictureSize(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
|
||||||
_drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
||||||
_strategy = null;
|
|
||||||
comboBoxStrategy.Enabled = true;
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Кнопка создания теплохода
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
CreateObject(nameof(DrawningWarmlyShip));
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Кнопка создания судна
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void buttonСreateShip_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
CreateObject(nameof(DrawningShip));
|
|
||||||
}
|
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningShip == null)
|
if (_drawningShip == null)
|
||||||
|
@ -11,7 +11,7 @@ namespace ProjectWarmlyShip
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormWarmlyShip());
|
Application.Run(new FormShipCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user