lab3 commit
This commit is contained in:
parent
b10755b6bb
commit
e5df4eb3e6
@ -0,0 +1,122 @@
|
||||
using ProjectStormTrooper.Drawnings;
|
||||
|
||||
|
||||
namespace ProjectStormTrooper.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Абстракция компании, хранящий коллекцию автомобилей
|
||||
/// </summary>
|
||||
public abstract class AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Размер места (ширина)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeWidth = 150;
|
||||
|
||||
/// <summary>
|
||||
/// Размер места (высота)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeHeight = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Коллекция автомобилей
|
||||
/// </summary>
|
||||
protected ICollectionGenericObjects<DrawningWarPlane>? _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<DrawningWarPlane> 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, DrawningWarPlane plane)
|
||||
{
|
||||
if (company._collection.Insert(plane))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора удаления для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">Номер удаляемого объекта</param>
|
||||
/// <returns></returns>
|
||||
public static DrawningWarPlane operator -(AbstractCompany company, int position)
|
||||
{
|
||||
|
||||
return company._collection.Remove(position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение случайного объекта из коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DrawningWarPlane? 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)
|
||||
{
|
||||
DrawningWarPlane? 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,61 @@
|
||||
using ProjectStormTrooper.Drawnings;
|
||||
|
||||
|
||||
namespace ProjectStormTrooper.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Реализация абстрактной компании - каршеринг
|
||||
/// </summary>
|
||||
public class Hangar : AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
/// <param name="collection"></param>
|
||||
public Hangar(int picWidth, int picHeight, ICollectionGenericObjects<DrawningWarPlane> collection) : base(picWidth, picHeight, collection)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DrawBackgound(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
int posX = 0;
|
||||
for (int i = 0; i < _pictureWidth/_placeSizeWidth; i++)
|
||||
{
|
||||
int posY = 0;
|
||||
g.DrawLine(pen, posX, posY, posX, posY + _placeSizeHeight*(_pictureHeight/_placeSizeHeight));
|
||||
for(int j = 0; j <= _pictureHeight/_placeSizeHeight; j++)
|
||||
{
|
||||
g.DrawLine(pen, posX, posY, posX + _placeSizeWidth-30, posY);
|
||||
posY += _placeSizeHeight;
|
||||
}
|
||||
posX += _placeSizeWidth;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetObjectsPosition()
|
||||
{
|
||||
int posX = _pictureWidth / _placeSizeWidth-1;
|
||||
int posY = 0;
|
||||
for (int i = 0; i < _collection?.Count; i++)
|
||||
{
|
||||
if(_collection.Get(i) != null)
|
||||
{
|
||||
_collection?.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection?.Get(i).SetPosition(posX * _placeSizeWidth, posY * _placeSizeHeight);
|
||||
}
|
||||
if(posX > 0)
|
||||
{
|
||||
posX--;
|
||||
}
|
||||
else
|
||||
{
|
||||
posX = _pictureWidth / _placeSizeWidth-1;
|
||||
posY++;
|
||||
}
|
||||
if(posY >= _placeSizeHeight) { return; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
namespace ProjectStormTrooper.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>
|
||||
bool Insert(T obj);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
bool Insert(T obj, int position);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||
T Remove(int position);
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта по позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>Объект</returns>
|
||||
T? Get(int position);
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
|
||||
namespace ProjectStormTrooper.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)
|
||||
{
|
||||
if (_collection.Length > 0)
|
||||
{
|
||||
Array.Resize(ref _collection, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
_collection = new T?[value];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public MassiveGenericObjects()
|
||||
{
|
||||
_collection = Array.Empty<T?>();
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
|
||||
if (position<0 || position > _collection.Length - 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public bool Insert(T obj)
|
||||
{
|
||||
|
||||
for (int i = 0; i < _collection.Length; i++)
|
||||
{
|
||||
if (_collection[i] == null) {
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
|
||||
if(position < 0 || position > _collection.Length -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for(int i = position; i < _collection.Length; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (int i = position; i >= 0; i--)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
|
||||
if (position < 0 || position > _collection.Length - 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
T temp = _collection[position];
|
||||
_collection[position] = null;
|
||||
|
||||
return temp;
|
||||
}
|
||||
}
|
@ -29,12 +29,10 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxStormTrooper = new PictureBox();
|
||||
buttonCreateStormTrooper = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttoтCreateWarPlane = new Button();
|
||||
buttonStrategyStep = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxStormTrooper).BeginInit();
|
||||
@ -42,6 +40,7 @@
|
||||
//
|
||||
// pictureBoxStormTrooper
|
||||
//
|
||||
pictureBoxStormTrooper.BackColor = SystemColors.Window;
|
||||
pictureBoxStormTrooper.Dock = DockStyle.Fill;
|
||||
pictureBoxStormTrooper.Location = new Point(0, 0);
|
||||
pictureBoxStormTrooper.Margin = new Padding(3, 4, 3, 4);
|
||||
@ -50,18 +49,6 @@
|
||||
pictureBoxStormTrooper.TabIndex = 0;
|
||||
pictureBoxStormTrooper.TabStop = false;
|
||||
//
|
||||
// buttonCreateStormTrooper
|
||||
//
|
||||
buttonCreateStormTrooper.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateStormTrooper.Location = new Point(14, 493);
|
||||
buttonCreateStormTrooper.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCreateStormTrooper.Name = "buttonCreateStormTrooper";
|
||||
buttonCreateStormTrooper.Size = new Size(168, 31);
|
||||
buttonCreateStormTrooper.TabIndex = 1;
|
||||
buttonCreateStormTrooper.Text = "Создать штурмовик";
|
||||
buttonCreateStormTrooper.UseVisualStyleBackColor = true;
|
||||
buttonCreateStormTrooper.Click += ButtonCreateStormTrooper_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
@ -114,17 +101,6 @@
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttoтCreateWarPlane
|
||||
//
|
||||
buttoтCreateWarPlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttoтCreateWarPlane.Location = new Point(205, 493);
|
||||
buttoтCreateWarPlane.Name = "buttoтCreateWarPlane";
|
||||
buttoтCreateWarPlane.Size = new Size(237, 31);
|
||||
buttoтCreateWarPlane.TabIndex = 6;
|
||||
buttoтCreateWarPlane.Text = "Создать военный самолет";
|
||||
buttoтCreateWarPlane.UseVisualStyleBackColor = true;
|
||||
buttoтCreateWarPlane.Click += ButtonCreateWarPlane;
|
||||
//
|
||||
// buttonStrategyStep
|
||||
//
|
||||
buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
@ -154,12 +130,10 @@
|
||||
ClientSize = new Size(950, 540);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(buttoтCreateWarPlane);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreateStormTrooper);
|
||||
Controls.Add(pictureBoxStormTrooper);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormStormTrooper";
|
||||
@ -171,12 +145,10 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxStormTrooper;
|
||||
private Button buttonCreateStormTrooper;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttoтCreateWarPlane;
|
||||
private Button buttonStrategyStep;
|
||||
private ComboBox comboBoxStrategy;
|
||||
}
|
||||
|
@ -16,7 +16,20 @@ public partial class FormStormTrooper : Form
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта
|
||||
/// </summary>
|
||||
public DrawningWarPlane SetWarPlane
|
||||
{
|
||||
set
|
||||
{
|
||||
_drawningWarPlane = value;
|
||||
_drawningWarPlane.SetPictureSize(pictureBoxStormTrooper.Width, pictureBoxStormTrooper.Height);
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Инициализация формы
|
||||
/// </summary>
|
||||
@ -45,43 +58,8 @@ public partial class FormStormTrooper : Form
|
||||
_drawningWarPlane.DrawTransport(gr);
|
||||
pictureBoxStormTrooper.Image = bmp;
|
||||
}
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningWarPlane):
|
||||
_drawningWarPlane = new DrawningWarPlane(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)));
|
||||
break;
|
||||
case nameof(DrawningStormTrooper):
|
||||
_drawningWarPlane = 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)),
|
||||
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;
|
||||
}
|
||||
|
||||
_drawningWarPlane.SetPictureSize(pictureBoxStormTrooper.Width, pictureBoxStormTrooper.Height);
|
||||
_drawningWarPlane.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 ButtonCreateStormTrooper_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningStormTrooper));
|
||||
|
||||
private void ButtonCreateWarPlane(object sender, EventArgs e) => CreateObject(nameof(DrawningWarPlane));
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
/// </summary>
|
||||
|
166
ProjectStormTrooper/ProjectStormTrooper/FormWarPlaneCollection.Designer.cs
generated
Normal file
166
ProjectStormTrooper/ProjectStormTrooper/FormWarPlaneCollection.Designer.cs
generated
Normal file
@ -0,0 +1,166 @@
|
||||
namespace ProjectStormTrooper
|
||||
{
|
||||
partial class FormWarPlaneCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
groupBox1 = new GroupBox();
|
||||
buttonGoToCheck = new Button();
|
||||
buttonRefresh = new Button();
|
||||
buttonRemoveWarPlane = new Button();
|
||||
maskedTextBoxPosition = new MaskedTextBox();
|
||||
buttonAddStormTrooper = new Button();
|
||||
buttonAddWarPlane = new Button();
|
||||
comboBoxSelectorCompany = new ComboBox();
|
||||
pictureBox = new PictureBox();
|
||||
groupBox1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
groupBox1.Controls.Add(buttonGoToCheck);
|
||||
groupBox1.Controls.Add(buttonRefresh);
|
||||
groupBox1.Controls.Add(buttonRemoveWarPlane);
|
||||
groupBox1.Controls.Add(maskedTextBoxPosition);
|
||||
groupBox1.Controls.Add(buttonAddStormTrooper);
|
||||
groupBox1.Controls.Add(buttonAddWarPlane);
|
||||
groupBox1.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBox1.Dock = DockStyle.Right;
|
||||
groupBox1.Location = new Point(616, 0);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Size = new Size(197, 566);
|
||||
groupBox1.TabIndex = 0;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Location = new Point(19, 391);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(172, 29);
|
||||
buttonGoToCheck.TabIndex = 6;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
buttonGoToCheck.Click += ButtonGoToCheck_Click;
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Location = new Point(19, 456);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(172, 29);
|
||||
buttonRefresh.TabIndex = 5;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += ButtonRefresh_Click;
|
||||
//
|
||||
// buttonRemoveWarPlane
|
||||
//
|
||||
buttonRemoveWarPlane.Location = new Point(19, 311);
|
||||
buttonRemoveWarPlane.Name = "buttonRemoveWarPlane";
|
||||
buttonRemoveWarPlane.Size = new Size(172, 51);
|
||||
buttonRemoveWarPlane.TabIndex = 4;
|
||||
buttonRemoveWarPlane.Text = "Удалить военный самолет";
|
||||
buttonRemoveWarPlane.UseVisualStyleBackColor = true;
|
||||
buttonRemoveWarPlane.Click += ButtonRemoveWarPlane_Click;
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
maskedTextBoxPosition.Location = new Point(19, 236);
|
||||
maskedTextBoxPosition.Mask = "00";
|
||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
maskedTextBoxPosition.Size = new Size(172, 27);
|
||||
maskedTextBoxPosition.TabIndex = 3;
|
||||
//
|
||||
// buttonAddStormTrooper
|
||||
//
|
||||
buttonAddStormTrooper.Location = new Point(19, 182);
|
||||
buttonAddStormTrooper.Name = "buttonAddStormTrooper";
|
||||
buttonAddStormTrooper.Size = new Size(172, 29);
|
||||
buttonAddStormTrooper.TabIndex = 2;
|
||||
buttonAddStormTrooper.Text = "Добавить штурмовик";
|
||||
buttonAddStormTrooper.UseVisualStyleBackColor = true;
|
||||
buttonAddStormTrooper.Click += ButtonAddStormTrooper_Click;
|
||||
//
|
||||
// buttonAddWarPlane
|
||||
//
|
||||
buttonAddWarPlane.Location = new Point(19, 102);
|
||||
buttonAddWarPlane.Name = "buttonAddWarPlane";
|
||||
buttonAddWarPlane.Size = new Size(172, 50);
|
||||
buttonAddWarPlane.TabIndex = 1;
|
||||
buttonAddWarPlane.Text = "Добавить военный самолет";
|
||||
buttonAddWarPlane.UseVisualStyleBackColor = true;
|
||||
buttonAddWarPlane.Click += ButtonAddWarPlane_Click;
|
||||
//
|
||||
// comboBoxSelectorCompany
|
||||
//
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Ангар" });
|
||||
comboBoxSelectorCompany.Location = new Point(19, 44);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(172, 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(616, 566);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// FormWarPlaneCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(813, 566);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBox1);
|
||||
Name = "FormWarPlaneCollection";
|
||||
Text = "Коллекция военных самолетов";
|
||||
groupBox1.ResumeLayout(false);
|
||||
groupBox1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBox1;
|
||||
private ComboBox comboBoxSelectorCompany;
|
||||
private Button buttonAddStormTrooper;
|
||||
private Button buttonAddWarPlane;
|
||||
private Button buttonRefresh;
|
||||
private Button buttonRemoveWarPlane;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonGoToCheck;
|
||||
}
|
||||
}
|
@ -0,0 +1,177 @@
|
||||
using ProjectStormTrooper.CollectionGenericObjects;
|
||||
using ProjectStormTrooper.Drawnings;
|
||||
|
||||
|
||||
namespace ProjectStormTrooper
|
||||
{
|
||||
public partial class FormWarPlaneCollection : Form
|
||||
{
|
||||
private AbstractCompany? _company = null;
|
||||
|
||||
public FormWarPlaneCollection()
|
||||
{
|
||||
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 Hangar(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningWarPlane>());
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление обычного автомобиля
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddWarPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningWarPlane));
|
||||
|
||||
/// <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();
|
||||
DrawningWarPlane drawningWarPlane;
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningWarPlane):
|
||||
|
||||
drawningWarPlane = new DrawningWarPlane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random));
|
||||
break;
|
||||
case nameof(DrawningStormTrooper):
|
||||
|
||||
drawningWarPlane = new DrawningStormTrooper(random.Next(100, 300), random.Next(1000, 3000),
|
||||
GetColor(random), GetColor(random), GetColor(random),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (_company + drawningWarPlane == 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 ButtonRemoveWarPlane_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;
|
||||
}
|
||||
|
||||
DrawningWarPlane? warPlane = null;
|
||||
int counter = 100;
|
||||
while (warPlane == null)
|
||||
{
|
||||
warPlane = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (warPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FormStormTrooper form = new()
|
||||
{
|
||||
SetWarPlane = warPlane
|
||||
};
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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>
|
@ -12,7 +12,7 @@ namespace ProjectStormTrooper
|
||||
{
|
||||
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormStormTrooper());
|
||||
Application.Run(new FormWarPlaneCollection());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user