ISEbd-12 KhaliullovRM LabWork03 Simple #3

Closed
rakhaliullov wants to merge 2 commits from LabWork3 into LabWork2
11 changed files with 796 additions and 93 deletions

View File

@ -0,0 +1,114 @@
using Stormtrooper.Drawnings;
namespace Stormtrooper.CollectionGenericObjects;
/// <summary>
/// Абстракция компании, хранящий коллекцию автомобилей
/// </summary>
public abstract class AbstractCompany
{
/// <summary>
/// Размер места (ширина)
/// </summary>
protected readonly int _placeSizeWidth = 155;
/// <summary>
/// Размер места (высота)
/// </summary>
protected readonly int _placeSizeHeight = 155;
/// <summary>
/// Ширина окна
/// </summary>
protected readonly int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
protected readonly int _pictureHeight;
/// <summary>
/// Коллекция автомобилей
/// </summary>
protected ICollectionGenericObjects<DrawningAircraft>? _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<DrawningAircraft> collection)
{
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
_collection.SetMaxCount = GetMaxCount;
}
/// <summary>
/// Перегрузка оператора сложения для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="сruiser">Добавляемый объект</param>
/// <returns></returns>
public static int operator +(AbstractCompany company, DrawningAircraft aircraft)
{
return company._collection.Insert(aircraft);
}
/// <summary>
/// Перегрузка оператора удаления для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="position">Номер удаляемого объекта</param>
/// <returns></returns>
public static DrawningAircraft operator -(AbstractCompany company, int position)
{
return company._collection?.Remove(position);
}
/// <summary>
/// Получение случайного объекта из коллекции
/// </summary>
/// <returns></returns>
public DrawningAircraft? 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)
{
DrawningAircraft? 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,65 @@
using Stormtrooper.Drawnings;
namespace Stormtrooper.CollectionGenericObjects
{
/// <summary>
/// Реализация абстрактной компании - каршеринг
/// </summary>
public class AircraftHangarService : AbstractCompany
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="collection"></param>
public AircraftHangarService(int picWidth, int picHeight,
ICollectionGenericObjects<DrawningAircraft> 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 + 1; i++)
{
for (int j = 0; j < height + 1; ++j)
{
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth - _placeSizeWidth + 8 , j * _placeSizeHeight);
g.DrawLine(pen, i * _placeSizeWidth - _placeSizeWidth + 8, j * _placeSizeHeight, i * _placeSizeWidth - _placeSizeWidth + 8, j * _placeSizeHeight - _placeSizeHeight);
}
}
}
protected override void SetObjectsPosition()
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int curWidth = width - 1;
int curHeight = 0;
for (int i = 0; i < (_collection?.Count ?? 0); i++)
{
if (_collection.Get(i) != null)
{
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
_collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 10, curHeight * _placeSizeHeight + 10);
}
if (curWidth > 0)
curWidth--;
else
{
curWidth = width - 1;
curHeight ++;
}
if (curHeight >= height)
{
return;
}
}
}
}
}

View File

@ -0,0 +1,43 @@
namespace Stormtrooper.CollectionGenericObjects;
/// <summary>
/// Интерфейс описания действий для набора хранимых объектов
/// </summary>
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
public interface ICollectionGenericObjects<T>
where T : class
{
/// <summary>
/// Количество объектов в коллекции
/// </summary>
int Count { get; }
/// <summary>
/// Установка максимального количества элементов
/// </summary>
int SetMaxCount { set; }
/// <summary>
/// Добавление объекта в коллекцию
/// </summary>
/// <param name="obj">Добавляемый объект</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
int Insert(T obj);
/// <summary>
/// Добавление объекта в коллекцию на конкретную позицию
/// </summary>
/// <param name="obj">Добавляемый объект</param>
/// <param name="position">Позиция</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
int Insert(T obj, int position);
/// <summary>
/// Удаление объекта из коллекции с конкретной позиции
/// </summary>
/// <param name="position">Позиция</param>
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
T? Remove(int position);
/// <summary>
/// Получение объекта по позиции
/// </summary>
/// <param name="position">Позиция</param>
/// <returns>Объект</returns>
T? Get(int position);
}

View File

@ -0,0 +1,90 @@
using Stormtrooper.Drawnings;
namespace Stormtrooper.CollectionGenericObjects;
/// <summary>
/// Параметризованный набор объектов
/// </summary>
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
where T : class
{
/// <summary>
/// Массив объектов, которые храним
/// </summary>
private T?[] _collection;
public int Count => _collection.Length;
public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
/// <summary>
/// Конструктор
/// </summary>
public MassiveGenericObjects()
{
_collection = Array.Empty<T?>();
}
public T? Get(int position)
{
// проверка позиции
if (position >= _collection.Length || position < 0)
{
return null;
}
return _collection[position];
}
public int Insert(T obj)
{
// вставка в свободное место набора
int index = 0;
Review

Правильнее было вызвать Insert(T obj, 0);

Правильнее было вызвать Insert(T obj, 0);
while (index < _collection.Length)
{
if (_collection[index] == null)
{
_collection[index] = obj;
return index;
}
index++;
}
return -1;
}
public int Insert(T obj, int position)
{
if (position >= _collection.Length || position < 0)
{ return -1; }
if (_collection[position] == null)
{
_collection[position] = obj;
return position;
}
int index;
for (index = position + 1; index < _collection.Length; ++index)
{
if (_collection[index] == null)
{
_collection[position] = obj;
return position;
}
}
for (index = position - 1; index >= 0; --index)
{
if (_collection[index] == null)
{
_collection[position] = obj;
return position;
}
}
return -1;
}
public T Remove(int position)
{
if (position >= _collection.Length || position < 0)
{ return null; }
T DrawningAircraft = _collection[position];
_collection[position] = null;
return DrawningAircraft;
}
}

View File

@ -0,0 +1,175 @@
namespace Stormtrooper
{
partial class FormAircraftCollection
{
/// <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();
buttonRemoveAircraft = new Button();
maskedTextBox = new MaskedTextBox();
buttonAddStormtrooper = new Button();
buttonAddAiracft = 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(buttonRemoveAircraft);
groupBoxTools.Controls.Add(maskedTextBox);
groupBoxTools.Controls.Add(buttonAddStormtrooper);
groupBoxTools.Controls.Add(buttonAddAiracft);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(980, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(264, 677);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Tag = "";
groupBoxTools.Text = "Инструменты";
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(6, 601);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(252, 41);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(6, 493);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(252, 41);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonRemoveAircraft
//
buttonRemoveAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveAircraft.Location = new Point(6, 323);
buttonRemoveAircraft.Name = "buttonRemoveAircraft";
buttonRemoveAircraft.Size = new Size(252, 41);
buttonRemoveAircraft.TabIndex = 4;
buttonRemoveAircraft.Text = "Удалить самолет";
buttonRemoveAircraft.UseVisualStyleBackColor = true;
buttonRemoveAircraft.Click += ButtonRemoveAircraft_Click;
//
// maskedTextBox
//
maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
maskedTextBox.Location = new Point(6, 274);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(252, 27);
maskedTextBox.TabIndex = 3;
maskedTextBox.ValidatingType = typeof(int);
//
// buttonAddStormtrooper
//
buttonAddStormtrooper.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddStormtrooper.Location = new Point(6, 172);
buttonAddStormtrooper.Name = "buttonAddStormtrooper";
buttonAddStormtrooper.Size = new Size(252, 41);
buttonAddStormtrooper.TabIndex = 2;
buttonAddStormtrooper.Text = "Добавление штурмовика";
buttonAddStormtrooper.UseVisualStyleBackColor = true;
buttonAddStormtrooper.Click += ButtonAddStormtrooper_Click;
//
// buttonAddAiracft
//
buttonAddAiracft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddAiracft.Location = new Point(6, 116);
buttonAddAiracft.Name = "buttonAddAiracft";
buttonAddAiracft.Size = new Size(252, 41);
buttonAddAiracft.TabIndex = 1;
buttonAddAiracft.Text = "Добавление самолета";
buttonAddAiracft.UseVisualStyleBackColor = true;
buttonAddAiracft.Click += ButtonAddAircraft_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(252, 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(980, 677);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// FormAircraftCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1244, 677);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormAircraftCollection";
Text = "Коллекция самолетов";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
private ComboBox comboBoxSelectorCompany;
private Button buttonAddStormtrooper;
private Button buttonAddAiracft;
private Button buttonRemoveAircraft;
private MaskedTextBox maskedTextBox;
private PictureBox pictureBox;
private Button buttonRefresh;
private Button buttonGoToCheck;
}
}

View File

@ -0,0 +1,164 @@
using Stormtrooper.CollectionGenericObjects;
using Stormtrooper.Drawnings;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Stormtrooper;
public partial class FormAircraftCollection : Form
{
/// <summary>
/// Компания
/// </summary>
private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormAircraftCollection()
{
InitializeComponent();
}
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new AircraftHangarService(pictureBox.Width,
pictureBox.Height, new MassiveGenericObjects<DrawningAircraft>());
break;
}
}
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
private void CreateObject(string type)
{
if (_company == null)
{
return;
}
Random random = new();
DrawningAircraft drawningAircraft;
switch (type)
{
case nameof(DrawningAircraft):
drawningAircraft = new DrawningAircraft(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
break;
case nameof(DrawningStormtrooper):
drawningAircraft = new DrawningStormtrooper(random.Next(100, 300), random.Next(1000, 3000),
GetColor(random),GetColor(random),Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
if (_company + drawningAircraft != -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;
}
//private void ButtonAddAircraft_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAicraft));
Review

Закомментированного кода быть не должно

Закомментированного кода быть не должно
//private void ButtonStormtrooper_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningStormtrooper));
private void ButtonAddAircraft_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawningAircraft));
}
private void ButtonAddStormtrooper_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawningStormtrooper));
}
private void ButtonRemoveAircraft_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;
}
DrawningAircraft? aircraft = null;
int counter = 100;
while (aircraft == null)
{
aircraft = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
break;
}
}
if (aircraft == null)
{
return;
}
FormStormtrooper form = new()
{
SetAircraft = aircraft
};
form.ShowDialog();
}
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 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>

View File

@ -29,12 +29,10 @@
private void InitializeComponent() private void InitializeComponent()
{ {
pictureBoxStormtrooper = new PictureBox(); pictureBoxStormtrooper = new PictureBox();
buttonCreate = new Button();
buttonUp = new Button(); buttonUp = new Button();
buttonDown = new Button(); buttonDown = new Button();
buttonLeft = new Button(); buttonLeft = new Button();
buttonRight = new Button(); buttonRight = new Button();
buttonCreateAircraft = new Button();
comboBoxStrategy = new ComboBox(); comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button(); buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxStormtrooper).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxStormtrooper).BeginInit();
@ -48,18 +46,7 @@
pictureBoxStormtrooper.Size = new Size(773, 439); pictureBoxStormtrooper.Size = new Size(773, 439);
pictureBoxStormtrooper.TabIndex = 0; pictureBoxStormtrooper.TabIndex = 0;
pictureBoxStormtrooper.TabStop = false; pictureBoxStormtrooper.TabStop = false;
pictureBoxStormtrooper.Click += pictureBoxStormtrooper_Click;
//
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 395);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(205, 32);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать штурмовик";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click;
// //
// buttonUp // buttonUp
// //
@ -109,17 +96,6 @@
buttonRight.UseVisualStyleBackColor = true; buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click; buttonRight.Click += ButtonMove_Click;
// //
// buttonCreateAircraft
//
buttonCreateAircraft.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateAircraft.Location = new Point(239, 395);
buttonCreateAircraft.Name = "buttonCreateAircraft";
buttonCreateAircraft.Size = new Size(205, 32);
buttonCreateAircraft.TabIndex = 7;
buttonCreateAircraft.Text = "Создать самолет";
buttonCreateAircraft.UseVisualStyleBackColor = true;
buttonCreateAircraft.Click += buttonCreateAircraft_Click;
//
// comboBoxStrategy // comboBoxStrategy
// //
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@ -129,7 +105,6 @@
comboBoxStrategy.Name = "comboBoxStrategy"; comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(151, 28); comboBoxStrategy.Size = new Size(151, 28);
comboBoxStrategy.TabIndex = 8; comboBoxStrategy.TabIndex = 8;
comboBoxStrategy.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
// //
// buttonStrategyStep // buttonStrategyStep
// //
@ -148,16 +123,13 @@
ClientSize = new Size(773, 439); ClientSize = new Size(773, 439);
Controls.Add(buttonStrategyStep); Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy); Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateAircraft);
Controls.Add(buttonRight); Controls.Add(buttonRight);
Controls.Add(buttonLeft); Controls.Add(buttonLeft);
Controls.Add(buttonDown); Controls.Add(buttonDown);
Controls.Add(buttonUp); Controls.Add(buttonUp);
Controls.Add(buttonCreate);
Controls.Add(pictureBoxStormtrooper); Controls.Add(pictureBoxStormtrooper);
Name = "FormStormtrooper"; Name = "FormStormtrooper";
Text = "Штурмовик"; Text = "Штурмовик";
Load += FormStormtrooper_Load;
Click += ButtonMove_Click; Click += ButtonMove_Click;
((System.ComponentModel.ISupportInitialize)pictureBoxStormtrooper).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxStormtrooper).EndInit();
ResumeLayout(false); ResumeLayout(false);
@ -166,12 +138,10 @@
#endregion #endregion
private PictureBox pictureBoxStormtrooper; private PictureBox pictureBoxStormtrooper;
private Button buttonCreate;
private Button buttonUp; private Button buttonUp;
private Button buttonDown; private Button buttonDown;
private Button buttonLeft; private Button buttonLeft;
private Button buttonRight; private Button buttonRight;
private Button buttonCreateAircraft;
private ComboBox comboBoxStrategy; private ComboBox comboBoxStrategy;
private Button buttonStrategyStep; private Button buttonStrategyStep;
} }

View File

@ -21,7 +21,18 @@ public partial class FormStormtrooper : Form
// Стратегия перемещения // Стратегия перемещения
private AbstractStrategy? _strategy; private AbstractStrategy? _strategy;
public DrawningAircraft SetAircraft
{
set
{
_drawningAircraft = value;
_drawningAircraft.SetPictureSize(pictureBoxStormtrooper.Width,
pictureBoxStormtrooper.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
// Конструктор формы // Конструктор формы
public FormStormtrooper() public FormStormtrooper()
{ {
@ -29,46 +40,6 @@ public partial class FormStormtrooper : Form
_strategy = null; _strategy = null;
} }
// Метод прорисовки машины
private void FormStormtrooper_Load(object sender, EventArgs e)
{
}
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawningAircraft):
_drawningAircraft = new DrawningAircraft(random.Next(100,
300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256),random.Next(0,256), random.Next(0, 256)));
break;
case nameof(DrawningStormtrooper):
_drawningAircraft = new DrawningStormtrooper(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
_drawningAircraft.SetPictureSize(pictureBoxStormtrooper.Width,
pictureBoxStormtrooper.Height);
_drawningAircraft.SetPosition(random.Next(10, 100), random.Next(10, 100));
_strategy = null;
Draw();
}
// Обработка нажатия кнопки Создать штурмовик
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningStormtrooper));
// Обработка нажатия кнопки Создать самолет
private void buttonCreateAircraft_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAircraft));
// Прорисовка // Прорисовка
private void Draw() private void Draw()
{ {
@ -113,15 +84,6 @@ public partial class FormStormtrooper : Form
} }
} }
private void pictureBoxStormtrooper_Click(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void buttonStrategyStep_Click(object sender, EventArgs e) private void buttonStrategyStep_Click(object sender, EventArgs e)
{ {
if (_drawningAircraft == null) if (_drawningAircraft == null)

View File

@ -11,36 +11,36 @@ public class MoveableAircraft : IMoveableObject
/// <summary> /// <summary>
/// Поле-объект класса DrawningAircraft или его наследника /// Поле-объект класса DrawningAircraft или его наследника
/// </summary> /// </summary>
private readonly DrawningAircraft? _cruiser = null; private readonly DrawningAircraft? _aircraft = null;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
/// <param name="cruiser">Объект класса DrawningAircraft</param> /// <param name="aircraft">Объект класса DrawningAircraft</param>
public MoveableAircraft(DrawningAircraft cruiser) public MoveableAircraft(DrawningAircraft aircraft)
{ {
_cruiser = cruiser; _aircraft = aircraft;
} }
public ObjectParameters? GetObjectPosition public ObjectParameters? GetObjectPosition
{ {
get get
{ {
if (_cruiser == null || _cruiser.EntityAircraft == null || if (_aircraft == null || _aircraft.EntityAircraft == null ||
!_cruiser.GetPosX.HasValue || !_cruiser.GetPosY.HasValue) !_aircraft.GetPosX.HasValue || !_aircraft.GetPosY.HasValue)
{ {
return null; return null;
} }
return new ObjectParameters(_cruiser.GetPosX.Value, return new ObjectParameters(_aircraft.GetPosX.Value,
_cruiser.GetPosY.Value, _cruiser.GetWidth, _cruiser.GetHeight); _aircraft.GetPosY.Value, _aircraft.GetWidth, _aircraft.GetHeight);
} }
} }
public int GetStep => (int)(_cruiser?.EntityAircraft?.Step ?? 0); public int GetStep => (int)(_aircraft?.EntityAircraft?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction) public bool TryMoveObject(MovementDirection direction)
{ {
if (_cruiser == null || _cruiser.EntityAircraft == null) if (_aircraft == null || _aircraft.EntityAircraft == null)
{ {
return false; return false;
} }
return _cruiser.MoveTransport(GetDirectionType(direction)); return _aircraft.MoveTransport(GetDirectionType(direction));
} }
/// <summary> /// <summary>
/// Конвертация из MovementDirection в DirectionType /// Конвертация из MovementDirection в DirectionType

View File

@ -11,7 +11,7 @@ namespace Stormtrooper
// 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 FormStormtrooper()); Application.Run(new FormAircraftCollection());
} }
} }
} }