Лабораторная работа №3
This commit is contained in:
parent
de00b215e2
commit
762633bc54
@ -0,0 +1,105 @@
|
|||||||
|
using ProjectAirBomber.CollectionGenericObject;
|
||||||
|
using ProjectAirBomber.Drawnings;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAirBomber.CollectionGenericObject;
|
||||||
|
|
||||||
|
public abstract class AbstractCompany
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Размер места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _placeSizeWidth = 180;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер места (высота)
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _placeSizeHeight = 170;
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Коллекция автомобилей
|
||||||
|
/// </summary>
|
||||||
|
protected ICollectionGenericObject<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, ICollectionGenericObject<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?.DrawPlane(graphics);
|
||||||
|
}
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод заднего фона
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
protected abstract void DrawBackgound(Graphics g);
|
||||||
|
/// <summary>
|
||||||
|
/// Расстановка объектов
|
||||||
|
/// </summary>
|
||||||
|
protected abstract void SetObjectsPosition();
|
||||||
|
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ProjectAirBomber.CollectionGenericObject;
|
namespace ProjectAirBomber.CollectionGenericObject;
|
||||||
|
|
||||||
public interface ICollectionGenericObjects<T>
|
public interface ICollectionGenericObject<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -22,7 +22,7 @@ where T : class
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj">Добавляемый объект</param>
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||||
bool Insert(T obj);
|
int Insert(T obj);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в коллекцию на конкретную позицию
|
/// Добавление объекта в коллекцию на конкретную позицию
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace ProjectAirBomber.CollectionGenericObject;
|
namespace ProjectAirBomber.CollectionGenericObject;
|
||||||
|
|
||||||
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
public class MassiveGenericObject<T> : ICollectionGenericObject<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -34,7 +34,7 @@ where T : class
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MassiveGenericObjects()
|
public MassiveGenericObject()
|
||||||
{
|
{
|
||||||
_collection = Array.Empty<T?>();
|
_collection = Array.Empty<T?>();
|
||||||
}
|
}
|
||||||
@ -44,17 +44,17 @@ where T : class
|
|||||||
return null;
|
return null;
|
||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
public bool Insert(T obj) // вставка объекта на свободное место
|
public int Insert(T obj) // вставка объекта на свободное место
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _collection.Length; ++i)
|
for (int i = 0; i < _collection.Length; ++i)
|
||||||
{
|
{
|
||||||
if (_collection[i] == null)
|
if (_collection[i] == null)
|
||||||
{
|
{
|
||||||
_collection[i] = obj;
|
_collection[i] = obj;
|
||||||
return true;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
public bool? Insert(T obj, int position) // вставка объекта на место
|
public bool? Insert(T obj, int position) // вставка объекта на место
|
||||||
{
|
{
|
@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectAirBomber.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectAirBomber.CollectionGenericObject;
|
||||||
|
|
||||||
|
public class PlaneHangar : AbstractCompany
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
/// <param name="collection"></param>
|
||||||
|
public PlaneHangar(int picWidth, int picHeight, ICollectionGenericObject<DrawningPlane> 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 + 5, posY * _placeSizeHeight + 5);
|
||||||
|
}
|
||||||
|
if (posX > 0)
|
||||||
|
{
|
||||||
|
posX--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
posY++;
|
||||||
|
posX = _pictureWidth / _placeSizeWidth - 1;
|
||||||
|
}
|
||||||
|
if (posX < 0) { return; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -33,12 +33,10 @@ namespace ProjectAirBomber
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
pictureBoxAirBomber = new PictureBox();
|
pictureBoxAirBomber = new PictureBox();
|
||||||
buttonCreate = new Button();
|
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonCreatePlane = new Button();
|
|
||||||
comboBoxStrategy = new ComboBox();
|
comboBoxStrategy = new ComboBox();
|
||||||
buttonStrategyStep = new Button();
|
buttonStrategyStep = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit();
|
||||||
@ -53,17 +51,6 @@ namespace ProjectAirBomber
|
|||||||
pictureBoxAirBomber.TabIndex = 0;
|
pictureBoxAirBomber.TabIndex = 0;
|
||||||
pictureBoxAirBomber.TabStop = false;
|
pictureBoxAirBomber.TabStop = false;
|
||||||
//
|
//
|
||||||
// buttonCreate
|
|
||||||
//
|
|
||||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonCreate.Location = new Point(0, 655);
|
|
||||||
buttonCreate.Name = "buttonCreate";
|
|
||||||
buttonCreate.Size = new Size(247, 29);
|
|
||||||
buttonCreate.TabIndex = 1;
|
|
||||||
buttonCreate.Text = "Создать бомбардировщик";
|
|
||||||
buttonCreate.UseVisualStyleBackColor = true;
|
|
||||||
buttonCreate.Click += ButtonCreate_Click;
|
|
||||||
//
|
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
@ -113,17 +100,6 @@ namespace ProjectAirBomber
|
|||||||
buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
buttonRight.Click += ButtonMove_Click;
|
buttonRight.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
// buttonCreatePlane
|
|
||||||
//
|
|
||||||
buttonCreatePlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonCreatePlane.Location = new Point(253, 655);
|
|
||||||
buttonCreatePlane.Name = "buttonCreatePlane";
|
|
||||||
buttonCreatePlane.Size = new Size(247, 29);
|
|
||||||
buttonCreatePlane.TabIndex = 6;
|
|
||||||
buttonCreatePlane.Text = "Создать самолет";
|
|
||||||
buttonCreatePlane.UseVisualStyleBackColor = true;
|
|
||||||
buttonCreatePlane.Click += ButtonCreatePlane_Click;
|
|
||||||
//
|
|
||||||
// comboBoxStrategy
|
// comboBoxStrategy
|
||||||
//
|
//
|
||||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
@ -151,12 +127,10 @@ namespace ProjectAirBomber
|
|||||||
ClientSize = new Size(1555, 684);
|
ClientSize = new Size(1555, 684);
|
||||||
Controls.Add(buttonStrategyStep);
|
Controls.Add(buttonStrategyStep);
|
||||||
Controls.Add(comboBoxStrategy);
|
Controls.Add(comboBoxStrategy);
|
||||||
Controls.Add(buttonCreatePlane);
|
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(buttonCreate);
|
|
||||||
Controls.Add(pictureBoxAirBomber);
|
Controls.Add(pictureBoxAirBomber);
|
||||||
Name = "ProjectAirBomber";
|
Name = "ProjectAirBomber";
|
||||||
Text = "Бомбардировщик";
|
Text = "Бомбардировщик";
|
||||||
@ -167,12 +141,10 @@ namespace ProjectAirBomber
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxAirBomber;
|
private PictureBox pictureBoxAirBomber;
|
||||||
private Button buttonCreate;
|
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonCreatePlane;
|
|
||||||
private ComboBox comboBoxStrategy;
|
private ComboBox comboBoxStrategy;
|
||||||
private Button buttonStrategyStep;
|
private Button buttonStrategyStep;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,20 @@ namespace ProjectAirBomber
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private AbstractStategy? _strategy;
|
private AbstractStategy? _strategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта
|
||||||
|
/// </summary>
|
||||||
|
public DrawningPlane SetPlane
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_drawningPlane = value;
|
||||||
|
_drawningPlane.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор формы
|
/// Конструктор формы
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -38,46 +52,6 @@ namespace ProjectAirBomber
|
|||||||
pictureBoxAirBomber.Image = bmp;
|
pictureBoxAirBomber.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateObject(string type)
|
|
||||||
{
|
|
||||||
Random rnd = new Random();
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case nameof(DrawningPlane):
|
|
||||||
_drawningPlane = new DrawningPlane(rnd.Next(100, 300), rnd.Next(1000, 3000),
|
|
||||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
|
||||||
break;
|
|
||||||
case nameof(DrawingAirBomber):
|
|
||||||
_drawningPlane = new DrawingAirBomber(rnd.Next(650, 700), rnd.Next(15760, 16130),
|
|
||||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
|
||||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
|
||||||
Convert.ToBoolean(rnd.Next(0, 2)),
|
|
||||||
Convert.ToBoolean(rnd.Next(0, 2)));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_drawningPlane.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
|
||||||
_drawningPlane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
|
|
||||||
_strategy = null;
|
|
||||||
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Обработка нажатия кнопки "Создать автобус с гармошкой"
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingAirBomber));
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Обработка нажатия кнопки "Создать автобус"
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
public void ButtonCreatePlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane));
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
169
ProjectBomber/ProjectBomber/FormPlaneCollection.Designer.cs
generated
Normal file
169
ProjectBomber/ProjectBomber/FormPlaneCollection.Designer.cs
generated
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
namespace ProjectAirBomber
|
||||||
|
{
|
||||||
|
partial class FormPlaneCollection
|
||||||
|
{
|
||||||
|
/// <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();
|
||||||
|
buttonDelPlane = new Button();
|
||||||
|
maskedTextBox = new MaskedTextBox();
|
||||||
|
buttonAddAirBomber = new Button();
|
||||||
|
buttonAddPlane = new Button();
|
||||||
|
comboBoxSelectionCompany = 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(buttonDelPlane);
|
||||||
|
groupBoxTools.Controls.Add(maskedTextBox);
|
||||||
|
groupBoxTools.Controls.Add(buttonAddAirBomber);
|
||||||
|
groupBoxTools.Controls.Add(buttonAddPlane);
|
||||||
|
groupBoxTools.Controls.Add(comboBoxSelectionCompany);
|
||||||
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
|
groupBoxTools.Location = new Point(1035, 0);
|
||||||
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
|
groupBoxTools.Size = new Size(250, 667);
|
||||||
|
groupBoxTools.TabIndex = 0;
|
||||||
|
groupBoxTools.TabStop = false;
|
||||||
|
groupBoxTools.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// buttonRefresh
|
||||||
|
//
|
||||||
|
buttonRefresh.Location = new Point(6, 291);
|
||||||
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
|
buttonRefresh.Size = new Size(232, 32);
|
||||||
|
buttonRefresh.TabIndex = 7;
|
||||||
|
buttonRefresh.Text = "Обновить";
|
||||||
|
buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
|
buttonRefresh.Click += ButtonRefresh_Click;
|
||||||
|
//
|
||||||
|
// buttonGoToCheck
|
||||||
|
//
|
||||||
|
buttonGoToCheck.Location = new Point(6, 253);
|
||||||
|
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||||
|
buttonGoToCheck.Size = new Size(232, 32);
|
||||||
|
buttonGoToCheck.TabIndex = 6;
|
||||||
|
buttonGoToCheck.Text = "Передать на тесты";
|
||||||
|
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||||
|
buttonGoToCheck.Click += ButtonGoToCheck_Click;
|
||||||
|
//
|
||||||
|
// buttonDelPlane
|
||||||
|
//
|
||||||
|
buttonDelPlane.Location = new Point(9, 211);
|
||||||
|
buttonDelPlane.Name = "buttonDelPlane";
|
||||||
|
buttonDelPlane.Size = new Size(232, 36);
|
||||||
|
buttonDelPlane.TabIndex = 5;
|
||||||
|
buttonDelPlane.Text = "Удаление бомбардировщика";
|
||||||
|
buttonDelPlane.UseVisualStyleBackColor = true;
|
||||||
|
buttonDelPlane.Click += ButtonDelPlane_Click;
|
||||||
|
//
|
||||||
|
// maskedTextBox
|
||||||
|
//
|
||||||
|
maskedTextBox.Location = new Point(9, 178);
|
||||||
|
maskedTextBox.Mask = "00";
|
||||||
|
maskedTextBox.Name = "maskedTextBox";
|
||||||
|
maskedTextBox.Size = new Size(229, 27);
|
||||||
|
maskedTextBox.TabIndex = 4;
|
||||||
|
maskedTextBox.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
|
// buttonAddAirBomber
|
||||||
|
//
|
||||||
|
buttonAddAirBomber.Location = new Point(9, 113);
|
||||||
|
buttonAddAirBomber.Name = "buttonAddAirBomber";
|
||||||
|
buttonAddAirBomber.Size = new Size(232, 59);
|
||||||
|
buttonAddAirBomber.TabIndex = 2;
|
||||||
|
buttonAddAirBomber.Text = "Добавление бомбардировщика";
|
||||||
|
buttonAddAirBomber.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddAirBomber.Click += ButtonAddAirBomber_Click;
|
||||||
|
//
|
||||||
|
// buttonAddPlane
|
||||||
|
//
|
||||||
|
buttonAddPlane.Location = new Point(9, 60);
|
||||||
|
buttonAddPlane.Name = "buttonAddPlane";
|
||||||
|
buttonAddPlane.Size = new Size(232, 47);
|
||||||
|
buttonAddPlane.TabIndex = 1;
|
||||||
|
buttonAddPlane.Text = "Добавление самолетов";
|
||||||
|
buttonAddPlane.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddPlane.Click += ButtonAddPlane_Click;
|
||||||
|
//
|
||||||
|
// comboBoxSelectionCompany
|
||||||
|
//
|
||||||
|
comboBoxSelectionCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
comboBoxSelectionCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxSelectionCompany.FormattingEnabled = true;
|
||||||
|
comboBoxSelectionCompany.Items.AddRange(new object[] { "Ангар" });
|
||||||
|
comboBoxSelectionCompany.Location = new Point(6, 26);
|
||||||
|
comboBoxSelectionCompany.Name = "comboBoxSelectionCompany";
|
||||||
|
comboBoxSelectionCompany.Size = new Size(232, 28);
|
||||||
|
comboBoxSelectionCompany.TabIndex = 0;
|
||||||
|
comboBoxSelectionCompany.SelectedIndexChanged += ComboBoxSelectionCompany_SelectedIndexChanged;
|
||||||
|
comboBoxSelectionCompany.Click += ComboBoxSelectionCompany_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// pictureBox
|
||||||
|
//
|
||||||
|
pictureBox.Dock = DockStyle.Fill;
|
||||||
|
pictureBox.Location = new Point(0, 0);
|
||||||
|
pictureBox.Name = "pictureBox";
|
||||||
|
pictureBox.Size = new Size(1035, 667);
|
||||||
|
pictureBox.TabIndex = 3;
|
||||||
|
pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormPlaneCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(1285, 667);
|
||||||
|
Controls.Add(pictureBox);
|
||||||
|
Controls.Add(groupBoxTools);
|
||||||
|
Name = "FormPlaneCollection";
|
||||||
|
Text = "Коллекция Самолетов";
|
||||||
|
groupBoxTools.ResumeLayout(false);
|
||||||
|
groupBoxTools.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private GroupBox groupBoxTools;
|
||||||
|
private ComboBox comboBoxSelectionCompany;
|
||||||
|
private Button buttonAddPlane;
|
||||||
|
private Button buttonAddAirBomber;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private Button buttonDelPlane;
|
||||||
|
private MaskedTextBox maskedTextBox;
|
||||||
|
private Button buttonRefresh;
|
||||||
|
private Button buttonGoToCheck;
|
||||||
|
}
|
||||||
|
}
|
163
ProjectBomber/ProjectBomber/FormPlaneCollection.cs
Normal file
163
ProjectBomber/ProjectBomber/FormPlaneCollection.cs
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
using ProjectAirBomber.CollectionGenericObject;
|
||||||
|
using ProjectAirBomber;
|
||||||
|
using ProjectAirBomber.Drawnings;
|
||||||
|
using ProjectAirBomber.MovementStrategy;
|
||||||
|
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 ProjectAirBomber
|
||||||
|
{
|
||||||
|
public partial class FormPlaneCollection : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Стратегия перемещения
|
||||||
|
/// </summary>
|
||||||
|
private AbstractCompany? _company = null;
|
||||||
|
|
||||||
|
public FormPlaneCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ComboBoxSelectionCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
switch (comboBoxSelectionCompany.Text)
|
||||||
|
{
|
||||||
|
case "Ангар":
|
||||||
|
_company = new PlaneHangar(pictureBox.Width,
|
||||||
|
pictureBox.Height, new MassiveGenericObject<DrawningPlane>());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void CreateObject(string type)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Random random = new();
|
||||||
|
DrawningPlane drawningPlane;
|
||||||
|
|
||||||
|
Random rnd = new Random();
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case nameof(DrawningPlane):
|
||||||
|
drawningPlane = new DrawningPlane(rnd.Next(100, 300), rnd.Next(1000, 3000), GetColor(random));
|
||||||
|
break;
|
||||||
|
case nameof(DrawingAirBomber):
|
||||||
|
drawningPlane = new DrawingAirBomber(rnd.Next(650, 700), rnd.Next(15760, 16130),
|
||||||
|
GetColor(random), GetColor(random),
|
||||||
|
Convert.ToBoolean(rnd.Next(0, 2)),
|
||||||
|
Convert.ToBoolean(rnd.Next(0, 2)));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_company + drawningPlane)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Color GetColor(Random random)
|
||||||
|
{
|
||||||
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0,
|
||||||
|
256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// кнопка добавления самолета
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane));
|
||||||
|
/// <summary>
|
||||||
|
/// кнопка добавления бомбардировщика
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddAirBomber_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingAirBomber));
|
||||||
|
/// <summary>
|
||||||
|
/// кнопка удаления
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonDelPlane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||||
|
if (_company - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
ProjectAirBomber form = new()
|
||||||
|
{
|
||||||
|
SetPlane = plane
|
||||||
|
};
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
private void ButtonRefresh_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
120
ProjectBomber/ProjectBomber/FormPlaneCollection.resx
Normal file
120
ProjectBomber/ProjectBomber/FormPlaneCollection.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
@ -11,7 +11,7 @@ namespace ProjectAirBomber
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new ProjectAirBomber());
|
Application.Run(new FormPlaneCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user