Компания
This commit is contained in:
parent
4947aac3ca
commit
948640a1ea
@ -1,9 +1,4 @@
|
||||
using ProjectStormtrooper.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper.CollectionGenericObjects;
|
||||
|
||||
@ -62,9 +57,9 @@ public abstract class AbstractCompany
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="car">Добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(AbstractCompany company, DrawningAirplane airplane)
|
||||
public static int operator +(AbstractCompany company, DrawningAirplane airplane)
|
||||
{
|
||||
return company._collection?.Insert(airplane) ?? false;
|
||||
return company._collection.Insert(airplane);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -73,9 +68,9 @@ public abstract class AbstractCompany
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">Номер удаляемого объекта</param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(AbstractCompany company, int position)
|
||||
public static DrawningAirplane operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection?.Remove(position) ?? false;
|
||||
return company._collection?.Remove(position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1,9 +1,5 @@
|
||||
using ProjectStormtrooper.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Drawing;
|
||||
|
||||
namespace ProjectStormtrooper.CollectionGenericObjects;
|
||||
|
||||
@ -23,10 +19,45 @@ public class AirplaneSharingService : AbstractCompany
|
||||
}
|
||||
protected override void DrawBackgound(Graphics g)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//рисуем пристань
|
||||
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()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper.CollectionGenericObjects;
|
||||
namespace ProjectStormtrooper.CollectionGenericObjects;
|
||||
|
||||
public interface ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
@ -23,23 +17,23 @@ public interface ICollectionGenericObjects<T>
|
||||
/// Добавление объекта в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
bool Insert(T obj);
|
||||
/// <returns>Код результата вставки</returns>
|
||||
int Insert(T obj);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
bool Insert(T obj, int position);
|
||||
/// <returns>Код результата вставки</returns>
|
||||
int Insert(T obj, int position);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||
bool Remove(int position);
|
||||
/// <returns>Код результата удаления</returns>
|
||||
T Remove(int position);
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта по позиции
|
||||
@ -47,4 +41,4 @@ public interface ICollectionGenericObjects<T>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>Объект</returns>
|
||||
T? Get(int position);
|
||||
}
|
||||
}
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectStormtrooper.CollectionGenericObjects;
|
||||
|
||||
namespace ProjectStormtrooper.CollectionGenericObjects;
|
||||
|
||||
@ -13,26 +9,8 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
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]; } } }
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
@ -42,32 +20,71 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
_collection = Array.Empty<T?>();
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
public T? Get(int position) // получение с позиции
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position < 0 || position >= _collection.Length) // если позиция передано неправильно
|
||||
return null;
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public bool Insert(T obj)
|
||||
public int Insert(T obj)
|
||||
{
|
||||
// TODO вставка в свободное место набора
|
||||
return false;
|
||||
int index = 0;
|
||||
while (index < _collection.Length)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// ищется свободное место после этой позиции и идет вставка туда
|
||||
// если нет после, ищем до
|
||||
// ищется свободное место после этой позиции и идет вставка туда
|
||||
// если нет после, ищем до
|
||||
// TODO вставка
|
||||
return false;
|
||||
if (position >= _collection.Length || position < 0)
|
||||
return -1;
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
}
|
||||
int index = position + 1;
|
||||
while (index < _collection.Length)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return index;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
index = position - 1;
|
||||
while (index >= 0)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return index;
|
||||
}
|
||||
--index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
public T Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||
return true;
|
||||
if (position >= _collection.Length || position < 0)
|
||||
return null;
|
||||
T obj = _collection[position];
|
||||
_collection[position] = null;
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
@ -23,5 +23,6 @@ public enum DirectionType
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
Right = 4,
|
||||
Unknow = 5
|
||||
}
|
@ -1,9 +1,4 @@
|
||||
using ProjectStormtrooper.Entites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper.Drawnings;
|
||||
|
||||
@ -94,8 +89,8 @@ public class DrawningAirplane
|
||||
/// <param name="drawningAirplaneHeight">Высота прорисовки самолета</param>
|
||||
protected DrawningAirplane(int drawningAirplaneWidth, int drawningAirplaneHeight) : this()
|
||||
{
|
||||
_drawningAirplaneWidth = drawningAirplaneWidth;
|
||||
_pictureHeight = drawningAirplaneHeight;
|
||||
this._drawningAirplaneWidth = drawningAirplaneWidth;
|
||||
this._pictureHeight = drawningAirplaneHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -108,8 +103,22 @@ public class DrawningAirplane
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
if (width < _drawningAirplaneWidth || height < _drawningAirplaneHeight) return false;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX != null || _startPosY != null)
|
||||
{
|
||||
if (_startPosX + _drawningAirplaneWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _startPosX - (_startPosX + _drawningAirplaneWidth - _pictureWidth);
|
||||
}
|
||||
else if (_startPosX < 0) _startPosX = 0;
|
||||
if (_startPosY + _drawningAirplaneHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _startPosY - (_startPosY + _drawningAirplaneHeight - _pictureHeight);
|
||||
}
|
||||
else if (_startPosY < 0) _startPosY = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -127,8 +136,18 @@ public class DrawningAirplane
|
||||
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
if (x + _drawningAirplaneWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = x - (x + _drawningAirplaneWidth - _pictureWidth);
|
||||
}
|
||||
else if (x < 0) _startPosX = 0;
|
||||
else _startPosX = x;
|
||||
if (y + _drawningAirplaneHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = y - (y + _drawningAirplaneHeight - _pictureHeight);
|
||||
}
|
||||
else if (y < 0) _startPosY = 0;
|
||||
else _startPosY = y;
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,6 @@ public class DrawningStormtrooper : DrawningAirplane
|
||||
EntityAirplane = new EntityStormtrooper(speed, weight, bodyColor, additionalColor, dvigatel, vint);
|
||||
}
|
||||
|
||||
public DrawningStormtrooper(int speed, double weight, Color bodyColor, Color additionalColor, bool dvigatel, bool vint, bool v) : this(speed, weight, bodyColor, additionalColor, dvigatel, vint)
|
||||
{
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAirplane == null || EntityAirplane is not EntityStormtrooper stormtrooper || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper.Entites;
|
||||
namespace ProjectStormtrooper.Entites;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Самолет"
|
||||
|
@ -6,54 +6,27 @@
|
||||
public class EntityStormtrooper : EntityAirplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// Дополнительтный цвет
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия обвеса
|
||||
/// </summary>
|
||||
public bool Dvigatel { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия антикрыла
|
||||
/// Признак наличия труб
|
||||
/// </summary>
|
||||
public bool Vint { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения самолета
|
||||
/// Признак наличия топливного бака
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
public bool Dvigatel { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса штурмовика
|
||||
/// Инициализация полей класса EntityStormtrooper
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="dvigatel">Признак наличия обвеса</param>
|
||||
/// <param name="vint">Признак наличия антикрыла</param>
|
||||
public EntityStormtrooper(int speed, double weight, Color bodyColor, Color additionalColor, bool dvigatel, bool vint) : base(speed, weight, bodyColor)
|
||||
/// <param name="additionalcolor"></param>
|
||||
/// <param name="vint"></param>
|
||||
/// <param name="dvigatel"></param>
|
||||
public EntityStormtrooper(int speed, double weight, Color bodycolor, Color additionalcolor, bool vint, bool dvigatel) : base(speed, weight, bodycolor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Dvigatel = dvigatel;
|
||||
AdditionalColor = additionalcolor;
|
||||
Vint = vint;
|
||||
Dvigatel = dvigatel;
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
|
||||
namespace ProjectStormtrooper
|
||||
namespace ProjectStormtrooper
|
||||
{
|
||||
partial class FormAirplaneCollection
|
||||
{
|
||||
@ -52,75 +51,84 @@ namespace ProjectStormtrooper
|
||||
groupBoxTools.Controls.Add(buttonAddAirplane);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(819, 0);
|
||||
groupBoxTools.Location = new Point(894, 0);
|
||||
groupBoxTools.Margin = new Padding(3, 4, 3, 4);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(235, 663);
|
||||
groupBoxTools.Padding = new Padding(3, 4, 3, 4);
|
||||
groupBoxTools.Size = new Size(205, 821);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
groupBoxTools.Enter += groupBoxTools_Enter;
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(6, 588);
|
||||
buttonRefresh.Location = new Point(7, 665);
|
||||
buttonRefresh.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(217, 63);
|
||||
buttonRefresh.Size = new Size(191, 53);
|
||||
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, 485);
|
||||
buttonGoToCheck.Location = new Point(7, 481);
|
||||
buttonGoToCheck.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(217, 63);
|
||||
buttonGoToCheck.Size = new Size(191, 53);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
buttonGoToCheck.Click += buttonGoToCheck_Click;
|
||||
//
|
||||
// buttonRemoveAirplane
|
||||
//
|
||||
buttonRemoveAirplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveAirplane.Location = new Point(6, 373);
|
||||
buttonRemoveAirplane.Location = new Point(7, 335);
|
||||
buttonRemoveAirplane.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonRemoveAirplane.Name = "buttonRemoveAirplane";
|
||||
buttonRemoveAirplane.Size = new Size(217, 63);
|
||||
buttonRemoveAirplane.Size = new Size(191, 53);
|
||||
buttonRemoveAirplane.TabIndex = 4;
|
||||
buttonRemoveAirplane.Text = "Удалить штурмовика";
|
||||
buttonRemoveAirplane.Text = "Удалить автомобиль";
|
||||
buttonRemoveAirplane.UseVisualStyleBackColor = true;
|
||||
buttonRemoveAirplane.Click += buttonRemoveAirplane_Click;
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new Point(6, 340);
|
||||
maskedTextBox.Location = new Point(7, 296);
|
||||
maskedTextBox.Margin = new Padding(3, 4, 3, 4);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(217, 27);
|
||||
maskedTextBox.Size = new Size(190, 27);
|
||||
maskedTextBox.TabIndex = 3;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonAddStormtrooper
|
||||
//
|
||||
buttonAddStormtrooper.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddStormtrooper.Location = new Point(6, 203);
|
||||
buttonAddStormtrooper.Location = new Point(7, 183);
|
||||
buttonAddStormtrooper.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonAddStormtrooper.Name = "buttonAddStormtrooper";
|
||||
buttonAddStormtrooper.Size = new Size(217, 63);
|
||||
buttonAddStormtrooper.Size = new Size(191, 53);
|
||||
buttonAddStormtrooper.TabIndex = 2;
|
||||
buttonAddStormtrooper.Text = "Добавление штурмовика";
|
||||
buttonAddStormtrooper.UseVisualStyleBackColor = true;
|
||||
buttonAddStormtrooper.Click += buttonAddStormtrooper_Click_1;
|
||||
buttonAddStormtrooper.Click += buttonAddStormtrooper_Click;
|
||||
//
|
||||
// buttonAddAirplane
|
||||
//
|
||||
buttonAddAirplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddAirplane.Location = new Point(6, 119);
|
||||
buttonAddAirplane.Location = new Point(7, 121);
|
||||
buttonAddAirplane.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonAddAirplane.Name = "buttonAddAirplane";
|
||||
buttonAddAirplane.Size = new Size(217, 63);
|
||||
buttonAddAirplane.Size = new Size(191, 53);
|
||||
buttonAddAirplane.TabIndex = 1;
|
||||
buttonAddAirplane.Text = "Добавление самолета";
|
||||
buttonAddAirplane.UseVisualStyleBackColor = true;
|
||||
buttonAddAirplane.Click += buttonAddAirplane_Click_1;
|
||||
buttonAddAirplane.Click += buttonAddAirplane_Click;
|
||||
//
|
||||
// comboBoxSelectorCompany
|
||||
//
|
||||
@ -128,51 +136,49 @@ namespace ProjectStormtrooper
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(6, 26);
|
||||
comboBoxSelectorCompany.Location = new Point(7, 29);
|
||||
comboBoxSelectorCompany.Margin = new Padding(3, 4, 3, 4);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(217, 28);
|
||||
comboBoxSelectorCompany.Size = new Size(190, 28);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Margin = new Padding(3, 4, 3, 4);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(819, 663);
|
||||
pictureBox.Size = new Size(894, 821);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
pictureBox.Click += pictureBox_Click;
|
||||
//
|
||||
// FormAirplaneCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1054, 663);
|
||||
ClientSize = new Size(1099, 821);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormAirplaneCollection";
|
||||
Text = "Коллекция самолетов";
|
||||
Text = "Коллекция автомобилей";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
private void buttonRemoveAirplane_Click(object sender, EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxTools;
|
||||
private ComboBox comboBoxSelectorCompany;
|
||||
private Button buttonAddStormtrooper;
|
||||
private Button buttonAddAirplane;
|
||||
private Button buttonRemoveAirplane;
|
||||
private MaskedTextBox maskedTextBox;
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonRemoveAirplane;
|
||||
private Button buttonRefresh;
|
||||
private Button buttonGoToCheck;
|
||||
private Button buttonRefresh;
|
||||
}
|
||||
}
|
@ -1,17 +1,11 @@
|
||||
using ProjectStormtrooper.CollectionGenericObjects;
|
||||
using ProjectStormtrooper.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ProjectStormtrooper;
|
||||
|
||||
/// <summary>
|
||||
/// Форма работы с компанией и ее коллекцией
|
||||
/// </summary>
|
||||
public partial class FormAirplaneCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
@ -47,44 +41,30 @@ public partial class FormAirplaneCollection : Form
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddAirplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirplane));
|
||||
|
||||
/// <summary>
|
||||
/// Добавление штурмовика
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddStormtrooper_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningStormtrooper));
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Random random = new();
|
||||
DrawningAirplane drawningAirplane;
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningAirplane):
|
||||
drawningAirplane = new DrawningAirplane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||||
drawningAirplane = new DrawningAirplane(random.Next(100, 300),
|
||||
random.Next(1000, 3000), GetColor(random));
|
||||
break;
|
||||
case nameof(DrawningStormtrooper):
|
||||
// TODO вызов диалогового окна для выбора цвета (made)
|
||||
drawningAirplane = new DrawningStormtrooper(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)));
|
||||
GetColor(random), GetColor(random),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (_company + drawningAirplane)
|
||||
if (_company + drawningAirplane != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
@ -111,26 +91,26 @@ public partial class FormAirplaneCollection : Form
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveCar_Click(object sender, EventArgs e)
|
||||
private void buttonAddAirplane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
|
||||
CreateObject(nameof(DrawningAirplane));
|
||||
}
|
||||
private void buttonAddStormtrooper_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObject(nameof(DrawningStormtrooper));
|
||||
}
|
||||
private void buttonRemoveAirplane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_company - pos)
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (_company - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
@ -140,24 +120,39 @@ public partial class FormAirplaneCollection : Form
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void groupBoxTools_Enter(object sender, EventArgs e)
|
||||
private void buttonGoToCheck_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawningAirplane? airplane = null;
|
||||
int counter = 100;
|
||||
while (airplane == null)
|
||||
{
|
||||
airplane = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (airplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormStormtrooper form = new()
|
||||
{
|
||||
SetAirplane = airplane
|
||||
};
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private void pictureBox_Click(object sender, EventArgs e)
|
||||
private void buttonRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void buttonAddAirplane_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void buttonAddStormtrooper_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
||||
|
125
ProjectStormtrooper/FormStormtrooper.Designer.cs
generated
125
ProjectStormtrooper/FormStormtrooper.Designer.cs
generated
@ -19,7 +19,6 @@ partial class FormStormtrooper
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
@ -29,12 +28,12 @@ partial class FormStormtrooper
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxStormtrooper = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonCreateAirplane = new Button();
|
||||
buttonRight = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxStormtrooper).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -47,85 +46,89 @@ partial class FormStormtrooper
|
||||
pictureBoxStormtrooper.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxStormtrooper.TabIndex = 0;
|
||||
pictureBoxStormtrooper.TabStop = false;
|
||||
pictureBoxStormtrooper.Click += pictureBoxStormtrooper_Click;
|
||||
//
|
||||
// buttonCreate
|
||||
// buttonLeft
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 477);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(325, 29);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "создать штурмовик";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreateStormtrooper_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonRight.Location = new Point(1163, 466);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(40, 40);
|
||||
buttonRight.TabIndex = 2;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonLeft.Location = new Point(787, 550);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(35, 35);
|
||||
buttonLeft.TabIndex = 2;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonUp.Location = new Point(1117, 420);
|
||||
buttonUp.Location = new Point(828, 509);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(40, 40);
|
||||
buttonUp.Size = new Size(35, 35);
|
||||
buttonUp.TabIndex = 3;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonLeft.Location = new Point(1071, 466);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(40, 40);
|
||||
buttonLeft.TabIndex = 4;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDown.Location = new Point(1117, 466);
|
||||
buttonDown.Location = new Point(828, 550);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(40, 40);
|
||||
buttonDown.TabIndex = 5;
|
||||
buttonDown.Size = new Size(35, 35);
|
||||
buttonDown.TabIndex = 4;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateAirplane
|
||||
// buttonRight
|
||||
//
|
||||
buttonCreateAirplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateAirplane.Location = new Point(343, 477);
|
||||
buttonCreateAirplane.Name = "buttonCreateAirplane";
|
||||
buttonCreateAirplane.Size = new Size(325, 29);
|
||||
buttonCreateAirplane.TabIndex = 6;
|
||||
buttonCreateAirplane.Text = "создать самолет";
|
||||
buttonCreateAirplane.UseVisualStyleBackColor = true;
|
||||
buttonCreateAirplane.Click += ButtonCreateAirplane_Click;
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonRight.Location = new Point(869, 550);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(35, 35);
|
||||
buttonRight.TabIndex = 5;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
|
||||
comboBoxStrategy.Location = new Point(790, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(121, 23);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStrategyStep
|
||||
//
|
||||
buttonStrategyStep.Location = new Point(836, 41);
|
||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||
buttonStrategyStep.Size = new Size(75, 23);
|
||||
buttonStrategyStep.TabIndex = 8;
|
||||
buttonStrategyStep.Text = "Шаг";
|
||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||
buttonStrategyStep.Click += ButtonStrategyStep_Click;
|
||||
//
|
||||
// FormStormtrooper
|
||||
//
|
||||
ClientSize = new Size(1268, 518);
|
||||
Controls.Add(buttonCreateAirplane);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonUp);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(923, 597);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(pictureBoxStormtrooper);
|
||||
Name = "FormStormtrooper";
|
||||
Text = "Штурмовик";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxStormtrooper).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
@ -134,11 +137,11 @@ partial class FormStormtrooper
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxStormtrooper;
|
||||
private Button buttonCreate;
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateAirplane;
|
||||
private Button buttonRight;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
|
||||
|
@ -1,25 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectStormtrooper.Drawnings;
|
||||
using ProjectStormtrooper.Drawnings;
|
||||
using ProjectStormtrooper.MovementStrategy;
|
||||
|
||||
namespace ProjectStormtrooper;
|
||||
|
||||
/// <summary>
|
||||
/// Форма работы с объектом "Штурмовик"
|
||||
/// </summary>
|
||||
public partial class FormStormtrooper : Form
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningAirplane? _drawningAirplane;
|
||||
|
||||
/// <summary>
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта
|
||||
/// </summary>
|
||||
public DrawningAirplane SetAirplane
|
||||
{
|
||||
set
|
||||
{
|
||||
_drawningAirplane = value;
|
||||
_drawningAirplane.SetPictureSize(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
/// </summary>
|
||||
public FormStormtrooper()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -36,50 +56,6 @@ public partial class FormStormtrooper : Form
|
||||
_drawningAirplane.DrawTransport(gr);
|
||||
pictureBoxStormtrooper.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningAirplane):
|
||||
_drawningAirplane = new DrawningAirplane(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(DrawningStormtrooper):
|
||||
_drawningAirplane = new DrawningStormtrooper(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;
|
||||
}
|
||||
|
||||
_drawningAirplane.SetPictureSize(pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
||||
_drawningAirplane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать штурмовик"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
|
||||
private void buttonCreateStormtrooper_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningStormtrooper));
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать самолет"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
///
|
||||
private void ButtonCreateAirplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirplane));
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
@ -119,15 +95,48 @@ public partial class FormStormtrooper : Form
|
||||
}
|
||||
}
|
||||
|
||||
private void pictureBoxStormtrooper_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Шаг"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
///
|
||||
|
||||
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAirplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableAirplane(_drawningAirplane), pictureBoxStormtrooper.Width, pictureBoxStormtrooper.Height);
|
||||
}
|
||||
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper.MovementStrategy;
|
||||
namespace ProjectStormtrooper.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-стратегия перемещения объекта
|
||||
@ -61,17 +55,12 @@ public abstract class AbstractStrategy
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_state != StrategyStatus.InProgress) return;
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = StrategyStatus.Finish;
|
||||
return;
|
||||
}
|
||||
|
||||
MoveToTarget();
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper.MovementStrategy;
|
||||
namespace ProjectStormtrooper.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с перемещаемым объектом
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper.MovementStrategy;
|
||||
namespace ProjectStormtrooper.MovementStrategy;
|
||||
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
@ -15,8 +9,10 @@ public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder <= FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder <= FieldHeight && objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
return objParams.LeftBorder - GetStep() <= 0 ||
|
||||
objParams.RightBorder + GetStep() >= FieldWidth ||
|
||||
objParams.TopBorder - GetStep() <= 0
|
||||
|| objParams.ObjectMiddleVertical + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
@ -26,29 +22,10 @@ public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
return;
|
||||
}
|
||||
int diffX = objParams.RightBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
int diffY = objParams.DownBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
//реализация в правый нижний угол
|
||||
int x = objParams.RightBorder;
|
||||
if (x + GetStep() < FieldWidth) MoveRight();
|
||||
int y = objParams.DownBorder;
|
||||
if (y + GetStep() < FieldHeight) MoveDown();
|
||||
}
|
||||
}
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper.MovementStrategy;
|
||||
namespace ProjectStormtrooper.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Стратегия перемещения объекта в центр экрана
|
||||
@ -18,9 +12,10 @@ public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2 && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2
|
||||
&& objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
@ -30,7 +25,6 @@ public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
@ -43,7 +37,6 @@ public class MoveToCenter : AbstractStrategy
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
|
||||
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
|
@ -1,55 +1,37 @@
|
||||
using ProjectStormtrooper.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-реализация IMoveableObject с использованием DrawningCar
|
||||
/// </summary>
|
||||
public class MoveableCar : IMoveableObject
|
||||
public class MoveableAirplane : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект класса DrawningCar или его наследника
|
||||
/// </summary>
|
||||
private readonly DrawningAirplane? _car = null;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="car">Объект класса DrawningCar</param>
|
||||
public MoveableCar(DrawningAirplane car)
|
||||
private DrawningAirplane? _drawningairplane;
|
||||
public MoveableAirplane(DrawningAirplane? drawningairplane)
|
||||
{
|
||||
_car = car;
|
||||
_drawningairplane = drawningairplane;
|
||||
}
|
||||
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_car == null || _car.EntityAirplane == null || !_car.GetPosX.HasValue || !_car.GetPosY.HasValue)
|
||||
if (_drawningairplane == null || _drawningairplane.EntityAirplane == null || !_drawningairplane.GetPosX.HasValue || !_drawningairplane.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_car.GetPosX.Value, _car.GetPosY.Value, _car.GetWidth, _car.GetHeight);
|
||||
return new ObjectParameters(_drawningairplane.GetPosX.Value, _drawningairplane.GetPosY.Value, _drawningairplane.GetWidth, _drawningairplane.GetHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetStep => (int)(_car?.EntityAirplane?.Step ?? 0);
|
||||
|
||||
public int GetStep => (int)(_drawningairplane?.EntityAirplane?.Step ?? 0);
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if (_car == null || _car.EntityAirplane == null)
|
||||
if (_drawningairplane == null || _drawningairplane.EntityAirplane == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _car.MoveTransport(GetDirectionType(direction));
|
||||
return _drawningairplane.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конвертация из MovementDirection в DirectionType
|
||||
/// </summary>
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper.MovementStrategy;
|
||||
namespace ProjectStormtrooper.MovementStrategy;
|
||||
|
||||
public enum MovementDirection
|
||||
{
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectStormtrooper.MovementStrategy;
|
||||
namespace ProjectStormtrooper.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Параметры-координаты объекта
|
||||
|
@ -11,7 +11,7 @@ namespace ProjectStormtrooper
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormStormtrooper());
|
||||
Application.Run(new FormAirplaneCollection());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user