в
This commit is contained in:
parent
97e3050cd2
commit
3ddf3c457e
@ -0,0 +1,115 @@
|
|||||||
|
using ProjectTank.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectTank.CollectionGenericObjects
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Абстракция компании, хранящий коллекцию автомобилей
|
||||||
|
/// </summary>
|
||||||
|
public abstract class AbstractCompany
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Размер места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _placeSizeWidth = 180;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Размер места (высота)
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _placeSizeHeight = 70;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _pictureWidth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _pictureHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Коллекция автомобилей
|
||||||
|
/// </summary>
|
||||||
|
protected ICollectionGenericObjects<DrawningTank>? _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<DrawningTank> collection)
|
||||||
|
{
|
||||||
|
_pictureWidth = picWidth;
|
||||||
|
_pictureHeight = picHeight;
|
||||||
|
_collection = collection;
|
||||||
|
_collection.SetMaxCount = GetMaxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора сложения для класса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="company">Компания</param>
|
||||||
|
/// <param name="сruiser">Добавляемый объект</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static int operator +(AbstractCompany company, DrawningTank сruiser)
|
||||||
|
{
|
||||||
|
return company._collection.Insert(сruiser);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора удаления для класса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="company">Компания</param>
|
||||||
|
/// <param name="position">Номер удаляемого объекта</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DrawningTank operator -(AbstractCompany company, int position)
|
||||||
|
{
|
||||||
|
return company._collection?.Remove(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение случайного объекта из коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public DrawningTank? 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)
|
||||||
|
{
|
||||||
|
DrawningTank? 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,45 @@
|
|||||||
|
namespace ProjectTank.CollectionGenericObjects
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Интерфейс описания действий для набора хранимых объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||||
|
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>
|
||||||
|
int Insert(T obj);
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в коллекцию на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||||
|
int Insert(T obj, int position);
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из коллекции с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||||
|
T? Remove(int position);
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>Объект</returns>
|
||||||
|
T? Get(int position);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,97 @@
|
|||||||
|
using ProjectTank.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectTank.CollectionGenericObjects
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный набор объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||||
|
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 int Insert(T obj)
|
||||||
|
{
|
||||||
|
// TODO вставка в свободное место набора
|
||||||
|
int index = 0;
|
||||||
|
while (index < _collection.Length)
|
||||||
|
{
|
||||||
|
if (_collection[index] == null)
|
||||||
|
{
|
||||||
|
_collection[index] = obj;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public int Insert(T obj, int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||||
|
// ищется свободное место после этой позиции и идет вставка туда
|
||||||
|
// если нет после, ищем до
|
||||||
|
// TODO вставка
|
||||||
|
if (position >= _collection.Length || position < 0)
|
||||||
|
{ return -1; }
|
||||||
|
|
||||||
|
if (_collection[position] == null)
|
||||||
|
{
|
||||||
|
_collection[position] = obj;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
int index;
|
||||||
|
|
||||||
|
for (index = position + 1; index < _collection.Length; ++index)
|
||||||
|
{
|
||||||
|
if (_collection[index] == null)
|
||||||
|
{
|
||||||
|
_collection[position] = obj;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (index = position - 1; index >= 0; --index)
|
||||||
|
{
|
||||||
|
if (_collection[index] == null)
|
||||||
|
{
|
||||||
|
_collection[position] = obj;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
public T Remove(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||||
|
if (position >= _collection.Length || position < 0)
|
||||||
|
{ return null; }
|
||||||
|
T drawningTank = _collection[position];
|
||||||
|
_collection[position] = null;
|
||||||
|
return drawningTank;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
using ProjectTank.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectTank.CollectionGenericObjects
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Реализация абстрактной компании - каршеринг
|
||||||
|
/// </summary>
|
||||||
|
public class TankDockingService : AbstractCompany
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
/// <param name="collection"></param>
|
||||||
|
public TankDockingService(int picWidth, int picHeight,
|
||||||
|
ICollectionGenericObjects<DrawningTank> collection) : base(picWidth, picHeight, collection)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
protected override void DrawBackgound(Graphics g)
|
||||||
|
{
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
Pen pen = new(Color.Black, 2);
|
||||||
|
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 - 20, j * _placeSizeHeight);
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight + _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override void SetObjectsPosition()
|
||||||
|
{
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
|
||||||
|
int curWidth = 0;
|
||||||
|
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 + 10, curHeight * _placeSizeHeight + 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curWidth < width - 1)
|
||||||
|
curWidth++;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
curWidth = 0;
|
||||||
|
curHeight ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curHeight >= height)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
68
ProjectTank/ProjectTank/FormTank.Designer.cs
generated
68
ProjectTank/ProjectTank/FormTank.Designer.cs
generated
@ -30,13 +30,11 @@
|
|||||||
{
|
{
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormTank));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormTank));
|
||||||
pictureBoxTank = new PictureBox();
|
pictureBoxTank = new PictureBox();
|
||||||
button1 = new Button();
|
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
comboBoxStrategy = new ComboBox();
|
comboBoxStrategy = new ComboBox();
|
||||||
buttonCretaeTank = new Button();
|
|
||||||
buttonStrategyStep = new Button();
|
buttonStrategyStep = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxTank).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxTank).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
@ -45,34 +43,20 @@
|
|||||||
//
|
//
|
||||||
pictureBoxTank.Dock = DockStyle.Fill;
|
pictureBoxTank.Dock = DockStyle.Fill;
|
||||||
pictureBoxTank.Location = new Point(0, 0);
|
pictureBoxTank.Location = new Point(0, 0);
|
||||||
pictureBoxTank.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
pictureBoxTank.Name = "pictureBoxTank";
|
pictureBoxTank.Name = "pictureBoxTank";
|
||||||
pictureBoxTank.Size = new Size(700, 338);
|
pictureBoxTank.Size = new Size(800, 450);
|
||||||
pictureBoxTank.SizeMode = PictureBoxSizeMode.AutoSize;
|
pictureBoxTank.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
pictureBoxTank.TabIndex = 0;
|
pictureBoxTank.TabIndex = 0;
|
||||||
pictureBoxTank.TabStop = false;
|
pictureBoxTank.TabStop = false;
|
||||||
//
|
//
|
||||||
// button1
|
|
||||||
//
|
|
||||||
button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
button1.Location = new Point(10, 307);
|
|
||||||
button1.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
button1.Name = "button1";
|
|
||||||
button1.Size = new Size(186, 22);
|
|
||||||
button1.TabIndex = 1;
|
|
||||||
button1.Text = "создать военный танк";
|
|
||||||
button1.UseVisualStyleBackColor = true;
|
|
||||||
button1.Click += ButtonCreateTank_Click;
|
|
||||||
//
|
|
||||||
// buttonUp
|
// buttonUp
|
||||||
//
|
//
|
||||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
||||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
buttonUp.Location = new Point(632, 280);
|
buttonUp.Location = new Point(722, 373);
|
||||||
buttonUp.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
buttonUp.Name = "buttonUp";
|
buttonUp.Name = "buttonUp";
|
||||||
buttonUp.Size = new Size(26, 22);
|
buttonUp.Size = new Size(30, 30);
|
||||||
buttonUp.TabIndex = 2;
|
buttonUp.TabIndex = 2;
|
||||||
buttonUp.UseVisualStyleBackColor = true;
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
buttonUp.Click += ButtonMove_Click;
|
buttonUp.Click += ButtonMove_Click;
|
||||||
@ -82,10 +66,9 @@
|
|||||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
|
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
|
||||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
buttonDown.Location = new Point(632, 307);
|
buttonDown.Location = new Point(722, 409);
|
||||||
buttonDown.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
buttonDown.Name = "buttonDown";
|
buttonDown.Name = "buttonDown";
|
||||||
buttonDown.Size = new Size(26, 22);
|
buttonDown.Size = new Size(30, 30);
|
||||||
buttonDown.TabIndex = 3;
|
buttonDown.TabIndex = 3;
|
||||||
buttonDown.UseVisualStyleBackColor = true;
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
buttonDown.Click += ButtonMove_Click;
|
buttonDown.Click += ButtonMove_Click;
|
||||||
@ -95,10 +78,9 @@
|
|||||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
|
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
|
||||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
buttonRight.Location = new Point(663, 307);
|
buttonRight.Location = new Point(758, 409);
|
||||||
buttonRight.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
buttonRight.Name = "buttonRight";
|
buttonRight.Name = "buttonRight";
|
||||||
buttonRight.Size = new Size(26, 22);
|
buttonRight.Size = new Size(30, 30);
|
||||||
buttonRight.TabIndex = 4;
|
buttonRight.TabIndex = 4;
|
||||||
buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
buttonRight.Click += ButtonMove_Click;
|
buttonRight.Click += ButtonMove_Click;
|
||||||
@ -108,10 +90,9 @@
|
|||||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
|
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
|
||||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
buttonLeft.Location = new Point(600, 307);
|
buttonLeft.Location = new Point(686, 409);
|
||||||
buttonLeft.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
buttonLeft.Name = "buttonLeft";
|
buttonLeft.Name = "buttonLeft";
|
||||||
buttonLeft.Size = new Size(26, 22);
|
buttonLeft.Size = new Size(30, 30);
|
||||||
buttonLeft.TabIndex = 5;
|
buttonLeft.TabIndex = 5;
|
||||||
buttonLeft.UseVisualStyleBackColor = true;
|
buttonLeft.UseVisualStyleBackColor = true;
|
||||||
buttonLeft.Click += ButtonMove_Click;
|
buttonLeft.Click += ButtonMove_Click;
|
||||||
@ -122,30 +103,16 @@
|
|||||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
comboBoxStrategy.FormattingEnabled = true;
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
comboBoxStrategy.Items.AddRange(new object[] { "к центру", "к краю" });
|
comboBoxStrategy.Items.AddRange(new object[] { "к центру", "к краю" });
|
||||||
comboBoxStrategy.Location = new Point(557, 9);
|
comboBoxStrategy.Location = new Point(637, 12);
|
||||||
comboBoxStrategy.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
comboBoxStrategy.Size = new Size(133, 23);
|
comboBoxStrategy.Size = new Size(151, 28);
|
||||||
comboBoxStrategy.TabIndex = 6;
|
comboBoxStrategy.TabIndex = 6;
|
||||||
//
|
//
|
||||||
// buttonCretaeTank
|
|
||||||
//
|
|
||||||
buttonCretaeTank.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonCretaeTank.Location = new Point(210, 308);
|
|
||||||
buttonCretaeTank.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
buttonCretaeTank.Name = "buttonCretaeTank";
|
|
||||||
buttonCretaeTank.Size = new Size(186, 22);
|
|
||||||
buttonCretaeTank.TabIndex = 7;
|
|
||||||
buttonCretaeTank.Text = "создать танк";
|
|
||||||
buttonCretaeTank.UseVisualStyleBackColor = true;
|
|
||||||
buttonCretaeTank.Click += buttonCretaeTank_Click;
|
|
||||||
//
|
|
||||||
// buttonStrategyStep
|
// buttonStrategyStep
|
||||||
//
|
//
|
||||||
buttonStrategyStep.Location = new Point(607, 34);
|
buttonStrategyStep.Location = new Point(694, 46);
|
||||||
buttonStrategyStep.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||||
buttonStrategyStep.Size = new Size(82, 22);
|
buttonStrategyStep.Size = new Size(94, 29);
|
||||||
buttonStrategyStep.TabIndex = 8;
|
buttonStrategyStep.TabIndex = 8;
|
||||||
buttonStrategyStep.Text = "шаг";
|
buttonStrategyStep.Text = "шаг";
|
||||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||||
@ -153,19 +120,16 @@
|
|||||||
//
|
//
|
||||||
// FormTank
|
// FormTank
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(700, 338);
|
ClientSize = new Size(800, 450);
|
||||||
Controls.Add(buttonStrategyStep);
|
Controls.Add(buttonStrategyStep);
|
||||||
Controls.Add(buttonCretaeTank);
|
|
||||||
Controls.Add(comboBoxStrategy);
|
Controls.Add(comboBoxStrategy);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(button1);
|
|
||||||
Controls.Add(pictureBoxTank);
|
Controls.Add(pictureBoxTank);
|
||||||
Margin = new Padding(3, 2, 3, 2);
|
|
||||||
Name = "FormTank";
|
Name = "FormTank";
|
||||||
Text = "FormTank";
|
Text = "FormTank";
|
||||||
Click += ButtonMove_Click;
|
Click += ButtonMove_Click;
|
||||||
@ -177,13 +141,11 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxTank;
|
private PictureBox pictureBoxTank;
|
||||||
private Button button1;
|
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private ComboBox comboBoxStrategy;
|
private ComboBox comboBoxStrategy;
|
||||||
private Button buttonCretaeTank;
|
|
||||||
private Button buttonStrategyStep;
|
private Button buttonStrategyStep;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,6 +15,25 @@ namespace ProjectTank
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private AbstractStrategy? _strategy;
|
private AbstractStrategy? _strategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта
|
||||||
|
/// </summary>
|
||||||
|
public DrawningTank SetTank
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_drawningTank = value;
|
||||||
|
_drawningTank.SetPictureSize(pictureBoxTank.Width,
|
||||||
|
pictureBoxTank.Height);
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор формы
|
||||||
|
/// </summary>
|
||||||
public FormTank()
|
public FormTank()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -37,57 +56,6 @@ namespace ProjectTank
|
|||||||
pictureBoxTank.Image = bmp;
|
pictureBoxTank.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Создание объекта класса-перемещения
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="type">Тип создаваемого объекта</param>
|
|
||||||
private void CreateObject(string type)
|
|
||||||
{
|
|
||||||
Random random = new();
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case nameof(DrawningTank):
|
|
||||||
_drawningTank = new DrawningTank(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(DrawningMilitaryTank):
|
|
||||||
_drawningTank = new DrawningMilitaryTank(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)), Convert.ToBoolean(random.Next(0, 2)));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_drawningTank.SetPictureSize(pictureBoxTank.Width,
|
|
||||||
pictureBoxTank.Height);
|
|
||||||
_drawningTank.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 ButtonCreateTank_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMilitaryTank));
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Обработка нажатия кнопки "Создать танк"
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void buttonCretaeTank_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTank));
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -104,16 +72,13 @@ namespace ProjectTank
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
result =
|
result = _drawningTank.MoveTransport(DirectionType.Up);
|
||||||
_drawningTank.MoveTransport(DirectionType.Up);
|
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
result =
|
result = _drawningTank.MoveTransport(DirectionType.Down);
|
||||||
_drawningTank.MoveTransport(DirectionType.Down);
|
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
result =
|
result = _drawningTank.MoveTransport(DirectionType.Left);
|
||||||
_drawningTank.MoveTransport(DirectionType.Left);
|
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
result =
|
result =
|
||||||
|
184
ProjectTank/ProjectTank/FormTanksCollection.Designer.cs
generated
Normal file
184
ProjectTank/ProjectTank/FormTanksCollection.Designer.cs
generated
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
namespace ProjectTank
|
||||||
|
{
|
||||||
|
partial class FormTanksCollection
|
||||||
|
{
|
||||||
|
/// <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();
|
||||||
|
maskedTextBoxPosision = new MaskedTextBox();
|
||||||
|
buttonRefresh = new Button();
|
||||||
|
buttonGetToTest = new Button();
|
||||||
|
ButtonRemoveTank = new Button();
|
||||||
|
ButtonAddMilitaryTank = new Button();
|
||||||
|
ButtonAddTank = new Button();
|
||||||
|
comboBoxSelectorCompany = new ComboBox();
|
||||||
|
pictureBoxTank = new PictureBox();
|
||||||
|
groupBoxTools.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxTank).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// groupBoxTools
|
||||||
|
//
|
||||||
|
groupBoxTools.Controls.Add(maskedTextBoxPosision);
|
||||||
|
groupBoxTools.Controls.Add(buttonRefresh);
|
||||||
|
groupBoxTools.Controls.Add(buttonGetToTest);
|
||||||
|
groupBoxTools.Controls.Add(ButtonRemoveTank);
|
||||||
|
groupBoxTools.Controls.Add(ButtonAddMilitaryTank);
|
||||||
|
groupBoxTools.Controls.Add(ButtonAddTank);
|
||||||
|
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||||
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
|
groupBoxTools.Location = new Point(522, 0);
|
||||||
|
groupBoxTools.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
|
groupBoxTools.Padding = new Padding(3, 2, 3, 2);
|
||||||
|
groupBoxTools.Size = new Size(194, 430);
|
||||||
|
groupBoxTools.TabIndex = 0;
|
||||||
|
groupBoxTools.TabStop = false;
|
||||||
|
groupBoxTools.Text = "инструменты";
|
||||||
|
//
|
||||||
|
// maskedTextBoxPosision
|
||||||
|
//
|
||||||
|
maskedTextBoxPosision.Location = new Point(18, 172);
|
||||||
|
maskedTextBoxPosision.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
maskedTextBoxPosision.Mask = "00";
|
||||||
|
maskedTextBoxPosision.Name = "maskedTextBoxPosision";
|
||||||
|
maskedTextBoxPosision.Size = new Size(163, 23);
|
||||||
|
maskedTextBoxPosision.TabIndex = 2;
|
||||||
|
maskedTextBoxPosision.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
|
// buttonRefresh
|
||||||
|
//
|
||||||
|
buttonRefresh.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonRefresh.Location = new Point(18, 359);
|
||||||
|
buttonRefresh.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
|
buttonRefresh.Size = new Size(163, 30);
|
||||||
|
buttonRefresh.TabIndex = 5;
|
||||||
|
buttonRefresh.Text = "обновить";
|
||||||
|
buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
|
buttonRefresh.Click += ButtonRefresh_Click;
|
||||||
|
//
|
||||||
|
// buttonGetToTest
|
||||||
|
//
|
||||||
|
buttonGetToTest.Anchor = AnchorStyles.Right;
|
||||||
|
buttonGetToTest.Location = new Point(18, 274);
|
||||||
|
buttonGetToTest.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
buttonGetToTest.Name = "buttonGetToTest";
|
||||||
|
buttonGetToTest.Size = new Size(163, 30);
|
||||||
|
buttonGetToTest.TabIndex = 4;
|
||||||
|
buttonGetToTest.Text = "передать на тесты";
|
||||||
|
buttonGetToTest.UseVisualStyleBackColor = true;
|
||||||
|
buttonGetToTest.Click += ButtonGetToTest_Click;
|
||||||
|
//
|
||||||
|
// ButtonRemoveTank
|
||||||
|
//
|
||||||
|
ButtonRemoveTank.Anchor = AnchorStyles.Right;
|
||||||
|
ButtonRemoveTank.Location = new Point(18, 203);
|
||||||
|
ButtonRemoveTank.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
ButtonRemoveTank.Name = "ButtonRemoveTank";
|
||||||
|
ButtonRemoveTank.Size = new Size(163, 30);
|
||||||
|
ButtonRemoveTank.TabIndex = 3;
|
||||||
|
ButtonRemoveTank.Text = "удалить танк";
|
||||||
|
ButtonRemoveTank.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRemoveTank.Click += ButtonRemoveTank_Click;
|
||||||
|
//
|
||||||
|
// ButtonAddMilitaryTank
|
||||||
|
//
|
||||||
|
ButtonAddMilitaryTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
ButtonAddMilitaryTank.Location = new Point(18, 114);
|
||||||
|
ButtonAddMilitaryTank.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
ButtonAddMilitaryTank.Name = "ButtonAddMilitaryTank";
|
||||||
|
ButtonAddMilitaryTank.Size = new Size(163, 38);
|
||||||
|
ButtonAddMilitaryTank.TabIndex = 2;
|
||||||
|
ButtonAddMilitaryTank.Text = "добавлене военного танка";
|
||||||
|
ButtonAddMilitaryTank.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddMilitaryTank.Click += ButtonAddMilitaryTank_Click;
|
||||||
|
//
|
||||||
|
// ButtonAddTank
|
||||||
|
//
|
||||||
|
ButtonAddTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
ButtonAddTank.BackgroundImageLayout = ImageLayout.Center;
|
||||||
|
ButtonAddTank.Location = new Point(18, 80);
|
||||||
|
ButtonAddTank.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
ButtonAddTank.Name = "ButtonAddTank";
|
||||||
|
ButtonAddTank.Size = new Size(163, 30);
|
||||||
|
ButtonAddTank.TabIndex = 1;
|
||||||
|
ButtonAddTank.Text = "добваление танк";
|
||||||
|
ButtonAddTank.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddTank.Click += ButtonAddTank_Click;
|
||||||
|
//
|
||||||
|
// comboBoxSelectorCompany
|
||||||
|
//
|
||||||
|
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||||
|
comboBoxSelectorCompany.Items.AddRange(new object[] { "хранилище" });
|
||||||
|
comboBoxSelectorCompany.Location = new Point(18, 20);
|
||||||
|
comboBoxSelectorCompany.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||||
|
comboBoxSelectorCompany.Size = new Size(163, 23);
|
||||||
|
comboBoxSelectorCompany.TabIndex = 0;
|
||||||
|
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged_1;
|
||||||
|
//
|
||||||
|
// pictureBoxTank
|
||||||
|
//
|
||||||
|
pictureBoxTank.Dock = DockStyle.Fill;
|
||||||
|
pictureBoxTank.Location = new Point(0, 0);
|
||||||
|
pictureBoxTank.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
pictureBoxTank.Name = "pictureBoxTank";
|
||||||
|
pictureBoxTank.Size = new Size(522, 430);
|
||||||
|
pictureBoxTank.TabIndex = 1;
|
||||||
|
pictureBoxTank.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormTanksCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(716, 430);
|
||||||
|
Controls.Add(pictureBoxTank);
|
||||||
|
Controls.Add(groupBoxTools);
|
||||||
|
Margin = new Padding(3, 2, 3, 2);
|
||||||
|
Name = "FormTanksCollection";
|
||||||
|
Text = "FormTanksCollection";
|
||||||
|
groupBoxTools.ResumeLayout(false);
|
||||||
|
groupBoxTools.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxTank).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxTools;
|
||||||
|
private ComboBox comboBoxSelectorCompany;
|
||||||
|
private Button ButtonAddMilitaryTank;
|
||||||
|
private Button ButtonAddTank;
|
||||||
|
private Button ButtonRemoveTank;
|
||||||
|
private Button buttonRefresh;
|
||||||
|
private Button buttonGetToTest;
|
||||||
|
private PictureBox pictureBoxTank;
|
||||||
|
private MaskedTextBox maskedTextBoxPosision;
|
||||||
|
}
|
||||||
|
}
|
169
ProjectTank/ProjectTank/FormTanksCollection.cs
Normal file
169
ProjectTank/ProjectTank/FormTanksCollection.cs
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
using ProjectTank.CollectionGenericObjects;
|
||||||
|
using ProjectTank.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectTank
|
||||||
|
{
|
||||||
|
public partial class FormTanksCollection : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Компания
|
||||||
|
/// </summary>
|
||||||
|
private AbstractCompany? _company = null;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormTanksCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
switch (comboBoxSelectorCompany.Text)
|
||||||
|
{
|
||||||
|
case "хранилище":
|
||||||
|
_company = new TankDockingService(pictureBoxTank.Width,
|
||||||
|
pictureBoxTank.Height, new MassiveGenericObjects<DrawningTank>());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта класса-перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">Тип создаваемого объекта</param>
|
||||||
|
private void CreateObject(string type)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Random random = new();
|
||||||
|
DrawningTank drawningTank;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case nameof(DrawningTank):
|
||||||
|
drawningTank = new DrawningTank(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||||||
|
break;
|
||||||
|
case nameof(DrawningMilitaryTank):
|
||||||
|
drawningTank = new DrawningMilitaryTank(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
|
GetColor(random),
|
||||||
|
GetColor(random),
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)),
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_company + drawningTank != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("объект добавлен");
|
||||||
|
pictureBoxTank.Image = _company.Show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение цвета
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="random">Генератор случайных чисел</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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 ButtonAddTank_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTank));
|
||||||
|
|
||||||
|
//private void ButtonAddMilitaryTank_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMilitaryTank));
|
||||||
|
private void ButtonAddTank_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CreateObject(nameof(DrawningTank));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonAddMilitaryTank_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CreateObject(nameof(DrawningMilitaryTank));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonRemoveTank_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(maskedTextBoxPosision.Text) || _company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("удалить объект?", "удаление",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxPosision.Text);
|
||||||
|
if (_company - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("объект удален");
|
||||||
|
pictureBoxTank.Image = _company.Show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonGetToTest_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawningTank? tank = null;
|
||||||
|
int counter = 100;
|
||||||
|
while (tank == null)
|
||||||
|
{
|
||||||
|
tank = _company.GetRandomObject();
|
||||||
|
counter--;
|
||||||
|
if (counter <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tank == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormTank form = new()
|
||||||
|
{
|
||||||
|
SetTank = tank
|
||||||
|
};
|
||||||
|
form.ShowDialog();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonRefresh_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pictureBoxTank.Image = _company.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
120
ProjectTank/ProjectTank/FormTanksCollection.resx
Normal file
120
ProjectTank/ProjectTank/FormTanksCollection.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>
|
@ -10,36 +10,36 @@ namespace ProjectTank.MovementStrategy
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Поле-объект класса DrawningTank или его наследника
|
/// Поле-объект класса DrawningTank или его наследника
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly DrawningTank? _cruiser = null;
|
private readonly DrawningTank? _tank = null;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cruiser">Объект класса DrawningTank</param>
|
/// <param name="tank">Объект класса DrawningTank</param>
|
||||||
public MoveableTank(DrawningTank cruiser)
|
public MoveableTank(DrawningTank tank)
|
||||||
{
|
{
|
||||||
_cruiser = cruiser;
|
_tank = tank;
|
||||||
}
|
}
|
||||||
public ObjectParameters? GetObjectPosition
|
public ObjectParameters? GetObjectPosition
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_cruiser == null || _cruiser.EntityTank == null ||
|
if (_tank == null || _tank.EntityTank == null ||
|
||||||
!_cruiser.GetPosX.HasValue || !_cruiser.GetPosY.HasValue)
|
!_tank.GetPosX.HasValue || !_tank.GetPosY.HasValue)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new ObjectParameters(_cruiser.GetPosX.Value,
|
return new ObjectParameters(_tank.GetPosX.Value,
|
||||||
_cruiser.GetPosY.Value, _cruiser.GetWidth, _cruiser.GetHeight);
|
_tank.GetPosY.Value, _tank.GetWidth, _tank.GetHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int GetStep => (int)(_cruiser?.EntityTank?.Step ?? 0);
|
public int GetStep => (int)(_tank?.EntityTank?.Step ?? 0);
|
||||||
public bool TryMoveObject(MovementDirection direction)
|
public bool TryMoveObject(MovementDirection direction)
|
||||||
{
|
{
|
||||||
if (_cruiser == null || _cruiser.EntityTank == null)
|
if (_tank == null || _tank.EntityTank == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return _cruiser.MoveTransport(GetDirectionType(direction));
|
return _tank.MoveTransport(GetDirectionType(direction));
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конвертация из MovementDirection в DirectionType
|
/// Конвертация из MovementDirection в DirectionType
|
||||||
|
@ -3,15 +3,14 @@ namespace ProjectTank
|
|||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
// 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 FormTank());
|
Application.Run(new FormTanksCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user