Компания

This commit is contained in:
ikswi 2024-03-26 00:09:01 +04:00
parent d39c9e27bc
commit 9654506023
17 changed files with 760 additions and 106 deletions

View File

@ -0,0 +1,116 @@
using ProjectAirFighter.Drawnings;
namespace ProjectAirFighter.CollectionGenericObjects;
/// <summary>
/// Абстракция компании, хранящий коллекцию автомобилей
/// </summary>
public abstract class AbstractCompany
{
/// <summary>
/// Размер места (ширина)
/// </summary>
protected readonly int _placeSizeWidth = 100;
/// <summary>
/// Размер места (высота)
/// </summary>
protected readonly int _placeSizeHeight = 105;
/// <summary>
/// Ширина окна2
/// </summary>
protected readonly int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
protected readonly int _pictureHeight;
/// <summary>
/// Коллекция автомобилей
/// </summary>
protected ICollectionGenericObjects<DrawningPlane>? _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<DrawningPlane> collection)
{
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
_collection.SetMaxCount = GetMaxCount;
}
/// <summary>
/// Перегрузка оператора сложения для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="plane">Добавляемый объект</param>
/// <returns></returns>
public static int operator +(AbstractCompany company, DrawningPlane plane)
{
return company._collection.Insert(plane);
}
/// <summary>
/// Перегрузка оператора удаления для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="position">Номер удаляемого объекта</param>
/// <returns></returns>
public static DrawningPlane operator -(AbstractCompany company, int position)
{
return company._collection.Remove(position);
}
/// <summary>
/// Получение случайного объекта из коллекции
/// </summary>
/// <returns></returns>
public DrawningPlane? 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)
{
DrawningPlane? 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();
}

View File

@ -0,0 +1,64 @@
using ProjectAirFighter.Drawnings;
namespace ProjectAirFighter.CollectionGenericObjects;
/// <summary>
/// Реализация абстрактной компании - каршеринг
/// </summary>
public class Angar : AbstractCompany
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="collection"></param>
public Angar(int picWidth, int picHeight, ICollectionGenericObjects<DrawningPlane> 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 + 5, j * _placeSizeHeight, i * _placeSizeWidth + 5 + _placeSizeWidth - 30, j * _placeSizeHeight);
g.DrawLine(pen, i * _placeSizeWidth + 5, j * _placeSizeHeight, i * _placeSizeWidth + 5, j * _placeSizeHeight - _placeSizeHeight);
}
}
}
protected override void SetObjectsPosition()
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int curWidth = width - 1;
int curHeight = height - 1;
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 > 0)
curWidth--;
else
{
curWidth = width - 1;
curHeight--;
}
if (curHeight > height)
{
return;
}
}
}
}

View File

@ -22,7 +22,7 @@ public interface ICollectionGenericObjects<T>
/// </summary>
/// <param name="obj">Добавляемый объект</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
bool Insert(T obj);
int Insert(T obj);
/// <summary>
/// Добавление объекта в коллекцию на конкретную позицию
@ -30,14 +30,14 @@ public interface ICollectionGenericObjects<T>
/// <param name="obj">Добавляемый объект</param>
/// <param name="position">Позиция</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
bool Insert(T obj, int position);
int Insert(T obj, int position);
/// <summary>
/// Удаление объекта из коллекции с конкретной позиции
/// </summary>
/// <param name="position">Позиция</param>
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
bool Remove(int position);
T? Remove(int position);
/// <summary>
/// Получение объекта по позиции

View File

@ -43,29 +43,75 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
public T? Get(int position)
{
// TODO проверка позиции
if (position >= _collection.Length || position < 0)
{ 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;
}
public bool Insert(T obj, int position)
index++;
}
return -1;
}
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;
for (index = position + 1; index < _collection.Length; ++index)
{
if (_collection[index] == null)
{
_collection[position] = obj;
return position;
}
}
public bool Remove(int 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
return true;
if (position >= _collection.Length || position < 0)
{
return null;
}
T obj = _collection[position];
_collection[position] = null;
return obj;
}
}

View File

@ -5,7 +5,7 @@ namespace ProjectAirFighter.Drawnings;
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningAirFighter : DrawningFighter
public class DrawningAirFighter : DrawningPlane
{
/// <summary>
@ -19,22 +19,22 @@ public class DrawningAirFighter : DrawningFighter
/// <param name="rockets">Признак наличия ракет</param>
public DrawningAirFighter (int speed, double weight, Color bodyColor, Color additionalColor, bool wings, bool rockets) : base (70, 70)
{
EntityFighter = new EntityAirFighter(speed, weight, bodyColor, additionalColor, wings, rockets);
EntityPlane = new EntityAirFighter(speed, weight, bodyColor, additionalColor, wings, rockets);
}
public override void DrawTransport(Graphics g)
{
if (EntityFighter == null || EntityFighter is not EntityAirFighter airFighter || !_startPosX.HasValue || !_startPosY.HasValue)
if (EntityPlane == null || EntityPlane is not EntityAirFighter planeFighter || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(airFighter.AdditionalColor);
Brush additionalBrush = new SolidBrush(planeFighter.AdditionalColor);
base.DrawTransport(g);
if (airFighter.Wings)
if (planeFighter.Wings)
{
Point wings1 = new Point(_startPosX.Value + 45, _startPosY.Value + 30);
Point wings2 = new Point(_startPosX.Value + 45, _startPosY.Value + 15);
@ -53,7 +53,7 @@ public class DrawningAirFighter : DrawningFighter
g.DrawPolygon(pen, DownWing);
}
if (airFighter.Rockets)
if (planeFighter.Rockets)
{
Point rocket1 = new Point(_startPosX.Value + 40, _startPosY.Value + 5);
Point rocket2 = new Point(_startPosX.Value + 15, _startPosY.Value + 5);

View File

@ -5,12 +5,12 @@ namespace ProjectAirFighter.Drawnings;
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение базового объекта-сущности
/// </summary>
public class DrawningFighter
public class DrawningPlane
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityFighter? EntityFighter { get; protected set; }
public EntityPlane? EntityPlane { get; protected set; }
/// <summary>
/// Ширина окна
@ -65,7 +65,7 @@ public class DrawningFighter
/// <summary>
/// Пустой конструктор
/// </summary>
private DrawningFighter()
private DrawningPlane()
{
_pictureWidth = null;
_pictureHeight = null;
@ -79,9 +79,9 @@ public class DrawningFighter
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
public DrawningFighter (int speed, double weight, Color bodyColor) : this()
public DrawningPlane (int speed, double weight, Color bodyColor) : this()
{
EntityFighter = new EntityFighter(speed, weight, bodyColor);
EntityPlane = new EntityPlane(speed, weight, bodyColor);
}
/// <summary>
@ -89,7 +89,7 @@ public class DrawningFighter
/// </summary>
/// <param name="drawningCarWidth">Ширина прорисовки самолёта</param>
/// <param name="drawningCarHeight">Высота прорисовки самолёта</param>
protected DrawningFighter(int drawningFighterWidth, int drawningFighterHeight) : this()
protected DrawningPlane(int drawningFighterWidth, int drawningFighterHeight) : this()
{
_drawningFighterWidth = drawningFighterWidth;
_drawningFighterHeight = drawningFighterHeight;
@ -146,7 +146,7 @@ public class DrawningFighter
public bool MoveTransport(DirectionType direction)
{
if (EntityFighter == null || !_startPosX.HasValue || !_startPosY.HasValue)
if (EntityPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
@ -154,27 +154,27 @@ public class DrawningFighter
switch (direction)
{
case DirectionType.Left:
if (_startPosX.Value - EntityFighter.Step > 0)
if (_startPosX.Value - EntityPlane.Step > 0)
{
_startPosX -= (int)EntityFighter.Step;
_startPosX -= (int)EntityPlane.Step;
}
return true;
case DirectionType.Up:
if (_startPosY.Value - EntityFighter.Step > 0)
if (_startPosY.Value - EntityPlane.Step > 0)
{
_startPosY -= (int)EntityFighter.Step;
_startPosY -= (int)EntityPlane.Step;
}
return true;
case DirectionType.Right:
if (_startPosX.Value + _drawningFighterWidth + EntityFighter.Step < _pictureWidth)
if (_startPosX.Value + _drawningFighterWidth + EntityPlane.Step < _pictureWidth)
{
_startPosX += (int)EntityFighter.Step;
_startPosX += (int)EntityPlane.Step;
}
return true;
case DirectionType.Down:
if (_startPosY.Value + _drawningFighterHeight + EntityFighter.Step < _pictureHeight)
if (_startPosY.Value + _drawningFighterHeight + EntityPlane.Step < _pictureHeight)
{
_startPosY += (int)EntityFighter.Step;
_startPosY += (int)EntityPlane.Step;
}
return true;
default:
@ -184,13 +184,13 @@ public class DrawningFighter
public virtual void DrawTransport(Graphics g)
{
if (EntityFighter == null || !_startPosX.HasValue || !_startPosY.HasValue)
if (EntityPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Brush br = new SolidBrush(EntityFighter.BodyColor);
Brush br = new SolidBrush(EntityPlane.BodyColor);
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 30, 60, 10);
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 30, 60, 10);

View File

@ -3,7 +3,7 @@
/// <summary>
/// Класс-сущность "Истребитель"
/// </summary>
public class EntityAirFighter : EntityFighter
public class EntityAirFighter : EntityPlane
{
public Color AdditionalColor { get; private set; }
@ -11,7 +11,7 @@ public class EntityAirFighter : EntityFighter
public bool Rockets { get; private set; }
public EntityAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, bool wings, bool rockets) : base(5, 45, Color.Black)
public EntityAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, bool wings, bool rockets) : base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
Rockets = rockets;

View File

@ -3,7 +3,7 @@
/// <summary>
/// Класс-сущность "Истребитель"
/// </summary>
public class EntityFighter
public class EntityPlane
{
public int Speed { get; private set; }
@ -20,7 +20,7 @@ public class EntityFighter
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
public EntityFighter (int speed, double weight, Color bodyColor)
public EntityPlane (int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;

View File

@ -0,0 +1,173 @@
namespace ProjectAirFighter
{
partial class FormAirCollection
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonRemoveAir = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonAddAirFighter = new Button();
buttonAddAir = new Button();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
groupBoxTools.Controls.Add(buttonRefresh);
groupBoxTools.Controls.Add(buttonGoToCheck);
groupBoxTools.Controls.Add(buttonRemoveAir);
groupBoxTools.Controls.Add(maskedTextBoxPosition);
groupBoxTools.Controls.Add(buttonAddAirFighter);
groupBoxTools.Controls.Add(buttonAddAir);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(594, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(206, 450);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(6, 395);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(197, 29);
buttonRefresh.TabIndex = 7;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += buttonRefresh_Click;
//
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(6, 328);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(197, 29);
buttonGoToCheck.TabIndex = 6;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += buttonGoToCheck_Click;
//
// buttonRemoveAir
//
buttonRemoveAir.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveAir.Location = new Point(5, 211);
buttonRemoveAir.Name = "buttonRemoveAir";
buttonRemoveAir.Size = new Size(197, 29);
buttonRemoveAir.TabIndex = 5;
buttonRemoveAir.Text = "Удаление самолёта";
buttonRemoveAir.UseVisualStyleBackColor = true;
buttonRemoveAir.Click += buttonRemoveAir_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(6, 161);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(194, 27);
maskedTextBoxPosition.TabIndex = 4;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonAddAirFighter
//
buttonAddAirFighter.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddAirFighter.Location = new Point(6, 103);
buttonAddAirFighter.Name = "buttonAddAirFighter";
buttonAddAirFighter.Size = new Size(197, 31);
buttonAddAirFighter.TabIndex = 2;
buttonAddAirFighter.Text = "Добавление истребителя";
buttonAddAirFighter.UseVisualStyleBackColor = true;
buttonAddAirFighter.Click += buttonAddAirFighter_Click;
//
// buttonAddAir
//
buttonAddAir.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddAir.Location = new Point(6, 68);
buttonAddAir.Name = "buttonAddAir";
buttonAddAir.Size = new Size(197, 29);
buttonAddAir.TabIndex = 1;
buttonAddAir.Text = "Добавление самолёта";
buttonAddAir.UseVisualStyleBackColor = true;
buttonAddAir.Click += buttonAddAir_Click;
//
// comboBoxSelectorCompany
//
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(6, 26);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(194, 28);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
//
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(594, 450);
pictureBox.TabIndex = 3;
pictureBox.TabStop = false;
//
// FormAirCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormAirCollection";
Text = "Коллекция самолётов";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
private ComboBox comboBoxSelectorCompany;
private Button buttonAddAir;
private Button buttonAddAirFighter;
private PictureBox pictureBox;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonRemoveAir;
private Button buttonRefresh;
private Button buttonGoToCheck;
}
}

View File

@ -0,0 +1,181 @@
using ProjectAirFighter.CollectionGenericObjects;
using ProjectAirFighter.Drawnings;
namespace ProjectAirFighter;
public partial class FormAirCollection : Form
{
/// <summary>
/// Компания
/// </summary>
private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormAirCollection()
{
InitializeComponent();
}
/// <summary>
/// Выбор компании
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new Angar(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningPlane>());
break;
}
}
/// <summary>
/// Добавление самолёта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAddAir_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane));
/// <summary>
/// Добавление истребителя
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAddAirFighter_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirFighter));
private void CreateObject(string type)
{
if (_company == null)
{
return;
}
Random random = new();
DrawningPlane drawningFighter;
switch (type)
{
case nameof(DrawningPlane):
drawningFighter = new DrawningPlane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
break;
case nameof(DrawningAirFighter):
drawningFighter = new DrawningAirFighter(random.Next(100, 300), random.Next(1000, 3000),
GetColor(random), GetColor(random),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
if (_company + drawningFighter != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.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;
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonRemoveAir_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_company - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Передача объекта в другую форму
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonGoToCheck_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
DrawningPlane? plane = null;
int counter = 100;
while (plane == null)
{
plane = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
break;
}
}
if (plane == null)
{
return;
}
FormAirFighter form = new()
{
SetAir = plane
};
form.ShowDialog();
}
/// <summary>
/// Перерисовка коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonRefresh_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
pictureBox.Image = _company.Show();
}
}

View 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 pplanes.
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>

View File

@ -22,12 +22,10 @@
private void InitializeComponent()
{
pictureBoxAirFighter = new PictureBox();
buttonCreateAirFighter = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonCreateFighter = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxAirFighter).BeginInit();
@ -42,17 +40,6 @@
pictureBoxAirFighter.TabIndex = 0;
pictureBoxAirFighter.TabStop = false;
//
// buttonCreateAirFighter
//
buttonCreateAirFighter.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateAirFighter.Location = new Point(12, 409);
buttonCreateAirFighter.Name = "buttonCreateAirFighter";
buttonCreateAirFighter.Size = new Size(169, 29);
buttonCreateAirFighter.TabIndex = 1;
buttonCreateAirFighter.Text = "Создать истребитель";
buttonCreateAirFighter.UseVisualStyleBackColor = true;
buttonCreateAirFighter.Click += buttonCreateAirFighter_Click;
//
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@ -101,17 +88,6 @@
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
// buttonCreateFighter
//
buttonCreateFighter.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateFighter.Location = new Point(196, 409);
buttonCreateFighter.Name = "buttonCreateFighter";
buttonCreateFighter.Size = new Size(169, 29);
buttonCreateFighter.TabIndex = 6;
buttonCreateFighter.Text = "Создать самолёт";
buttonCreateFighter.UseVisualStyleBackColor = true;
buttonCreateFighter.Click += buttonCreateAir_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@ -139,12 +115,10 @@
ClientSize = new Size(800, 450);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateFighter);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonCreateAirFighter);
Controls.Add(pictureBoxAirFighter);
Name = "FormAirFighter";
Text = "Истребитель";
@ -155,12 +129,10 @@
#endregion
private PictureBox pictureBoxAirFighter;
private Button buttonCreateAirFighter;
private Button buttonDown;
private Button buttonRight;
private Button buttonLeft;
private Button buttonUp;
private Button buttonCreateFighter;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}

View File

@ -5,7 +5,7 @@ namespace ProjectAirFighter;
public partial class FormAirFighter : Form
{
private DrawningFighter? _drawningFighter;
private DrawningPlane? _drawningFighter;
private AbstractStrategy? _strategy;
@ -15,6 +15,18 @@ public partial class FormAirFighter : Form
_strategy = null;
}
public DrawningPlane SetAir
{
set
{
_drawningFighter = value;
_drawningFighter.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
private void Draw()
{
if (_drawningFighter == null)
@ -28,36 +40,6 @@ public partial class FormAirFighter : Form
pictureBoxAirFighter.Image = bmp;
}
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawningFighter):
_drawningFighter = new DrawningFighter(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(DrawningAirFighter):
_drawningFighter = new DrawningAirFighter(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
_drawningFighter.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
_drawningFighter.SetPosition(random.Next(10, 100), random.Next(10, 100));
_strategy = null;
comboBoxStrategy.Enabled = true;
Draw();
}
private void buttonCreateAirFighter_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirFighter));
private void buttonCreateAir_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningFighter));
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningFighter == null)

View File

@ -28,7 +28,7 @@
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
name/value pplanes.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support

View File

@ -10,39 +10,39 @@ public class MoveableAir : IMoveableObject
/// <summary>
/// Поле-объект класса DrawningCar или его наследника
/// </summary>
private readonly DrawningFighter? _air = null;
private readonly DrawningPlane? _plane = null;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="car">Объект класса DrawningCar</param>
public MoveableAir(DrawningFighter air)
public MoveableAir(DrawningPlane plane)
{
_air = air;
_plane = plane;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_air == null || _air.EntityFighter == null || !_air.GetPosX.HasValue || !_air.GetPosY.HasValue)
if (_plane == null || _plane.EntityPlane == null || !_plane.GetPosX.HasValue || !_plane.GetPosY.HasValue)
{
return null;
}
return new ObjectParameters(_air.GetPosX.Value, _air.GetPosY.Value, _air.GetWidth, _air.GetHeight);
return new ObjectParameters(_plane.GetPosX.Value, _plane.GetPosY.Value, _plane.GetWidth, _plane.GetHeight);
}
}
public int GetStep => (int)(_air?.EntityFighter?.Step ?? 0);
public int GetStep => (int)(_plane?.EntityPlane?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_air == null || _air.EntityFighter == null)
if (_plane == null || _plane.EntityPlane == null)
{
return false;
}
return _air.MoveTransport(GetDirectionType(direction));
return _plane.MoveTransport(GetDirectionType(direction));
}
/// <summary>

View File

@ -11,7 +11,7 @@ namespace ProjectAirFighter
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormAirFighter());
Application.Run(new FormAirCollection());
}
}
}

View File

@ -28,7 +28,7 @@
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
name/value pplanes.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support