Agliullov D. A. Lab Work 3 Advanced #4

Merged
eegov merged 13 commits from Lab3 into Lab2 2022-10-14 10:14:31 +04:00
15 changed files with 977 additions and 318 deletions

View File

@ -3,7 +3,7 @@
/// <summary>
/// Направление перемещения
/// </summary>
internal enum Direction
public enum Direction
{
None = 0,
Up = 1,

View File

@ -3,7 +3,7 @@
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
internal class DrawningAirplane
public class DrawningAirplane
{
/// <summary>
/// Класс-сущность
@ -47,7 +47,11 @@
Airplane = new EntityAirplane(speed, weight, bodyColor);
DrawningEngines = typeAirplaneEngines;
}
public DrawningAirplane(EntityAirplane entityAirplane, IAirplaneEngines? typeAirplaneEngines = null)
{
Airplane = entityAirplane;
DrawningEngines = typeAirplaneEngines;
}
/// <summary>
/// Инициализация свойств
/// </summary>

View File

@ -3,7 +3,7 @@
/// <summary>
/// Класс-сущность "Самолет"
/// </summary>
internal class EntityAirplane
public class EntityAirplane
{
/// <summary>
/// Скорость

View File

@ -42,6 +42,7 @@
this.countEngineBox = new System.Windows.Forms.NumericUpDown();
this.labelInformCountEngines = new System.Windows.Forms.Label();
this.comboTypeEngines = new System.Windows.Forms.ComboBox();
this.buttonSelectAirplane = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).BeginInit();
this.statusStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.countEngineBox)).BeginInit();
@ -189,11 +190,23 @@
this.comboTypeEngines.Size = new System.Drawing.Size(143, 23);
this.comboTypeEngines.TabIndex = 9;
//
// buttonSelectAirplane
//
this.buttonSelectAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonSelectAirplane.Location = new System.Drawing.Point(593, 390);
this.buttonSelectAirplane.Name = "buttonSelectAirplane";
this.buttonSelectAirplane.Size = new System.Drawing.Size(75, 23);
this.buttonSelectAirplane.TabIndex = 10;
this.buttonSelectAirplane.Text = "Выбрать";
this.buttonSelectAirplane.UseVisualStyleBackColor = true;
this.buttonSelectAirplane.Click += new System.EventHandler(this.buttonSelectAirplane_Click);
//
// FormAirBomber
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonSelectAirplane);
this.Controls.Add(this.comboTypeEngines);
this.Controls.Add(this.labelInformCountEngines);
this.Controls.Add(this.countEngineBox);
@ -231,5 +244,6 @@
private Label labelInformCountEngines;
private ToolStripStatusLabel toolStripStatusCountEngines;
private ComboBox comboTypeEngines;
private Button buttonSelectAirplane;
}
}

View File

@ -4,6 +4,12 @@ namespace AirBomber
{
private DrawningAirplane _airplane;
/// <summary>
/// Âűáđŕííűé ńŕěîëĺň
/// </summary>
public DrawningAirplane SelectedAirplane { get; private set; }
public FormAirBomber()
{
InitializeComponent();
@ -39,9 +45,13 @@ namespace AirBomber
break;
}
Random rnd = new();
_airplane = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
typeAirplaneEngines);
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_airplane = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), color, typeAirplaneEngines);
_airplane.DrawningEngines.CountEngines = (int)countEngineBox.Value;
_airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";
@ -86,5 +96,11 @@ namespace AirBomber
_airplane?.ChangeBorders(pictureBoxCar.Width, pictureBoxCar.Height);
Draw();
}
private void buttonSelectAirplane_Click(object sender, EventArgs e)
{
SelectedAirplane = _airplane;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -1,208 +0,0 @@
namespace AirBomber
{
partial class FormMap
{
/// <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()
{
this.pictureBoxCar = new System.Windows.Forms.PictureBox();
this.statusStrip = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
//
// pictureBoxCar
//
this.pictureBoxCar.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxCar.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCar.Name = "pictureBoxCar";
this.pictureBoxCar.Size = new System.Drawing.Size(800, 428);
this.pictureBoxCar.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxCar.TabIndex = 0;
this.pictureBoxCar.TabStop = false;
//
// statusStrip
//
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor});
this.statusStrip.Location = new System.Drawing.Point(0, 428);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(800, 22);
this.statusStrip.TabIndex = 1;
//
// toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 17);
this.toolStripStatusLabelSpeed.Text = "Скорость:";
//
// toolStripStatusLabelWeight
//
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(29, 17);
this.toolStripStatusLabelWeight.Text = "Вес:";
//
// toolStripStatusLabelBodyColor
//
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
this.toolStripStatusLabelBodyColor.Text = "Цвет:";
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(12, 390);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::AirBomber.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(722, 350);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 3;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AirBomber.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(686, 386);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 4;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::AirBomber.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(758, 386);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 5;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AirBomber.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(722, 386);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 6;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonCreateModif
//
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateModif.Location = new System.Drawing.Point(104, 390);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(110, 23);
this.buttonCreateModif.TabIndex = 7;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Карта со стенами"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23);
this.comboBoxSelectorMap.TabIndex = 8;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// FormMap
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.comboBoxSelectorMap);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxCar);
this.Controls.Add(this.statusStrip);
this.Name = "FormMap";
this.Text = "Карта";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).EndInit();
this.statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBoxCar;
private StatusStrip statusStrip;
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button buttonCreate;
private Button buttonUp;
private Button buttonLeft;
private Button buttonRight;
private Button buttonDown;
private Button buttonCreateModif;
private ComboBox comboBoxSelectorMap;
}
}

View File

@ -1,96 +0,0 @@
using AirBomber;
namespace AirBomber
{
public partial class FormMap : Form
{
private AbstractMap _abstractMap;
public FormMap()
{
InitializeComponent();
_abstractMap = new SimpleMap();
}
/// <summary>
/// Заполнение информации по объекту
/// </summary>
/// <param name="car"></param>
private void SetData(DrawningAirplane car)
{
toolStripStatusLabelSpeed.Text = $"Скорость: {car.Airplane.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {car.Airplane.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {car.Airplane.BodyColor.Name}";
pictureBoxCar.Image = _abstractMap.CreateMap(pictureBoxCar.Width, pictureBoxCar.Height,
new DrawningObject(car));
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
var car = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
SetData(car);
}
/// <summary>
/// Изменение размеров формы
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
//получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
Direction dir = Direction.None;
switch (name)
{
case "buttonUp":
dir = Direction.Up;
break;
case "buttonDown":
dir = Direction.Down;
break;
case "buttonLeft":
dir = Direction.Left;
break;
case "buttonRight":
dir = Direction.Right;
break;
}
pictureBoxCar.Image = _abstractMap?.MoveObject(dir);
}
/// <summary>
/// Обработка нажатия кнопки "Модификация"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
var car = new DrawningAirBomber(rnd.Next(100, 300), rnd.Next(1000, 2000),
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)));
SetData(car);
}
/// <summary>
/// Смена карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
_abstractMap = new SimpleMap();
break;
case "Карта со стенами":
_abstractMap = new WallMap();
break;
}
}
}
}

View File

@ -0,0 +1,355 @@
namespace AirBomber
{
partial class FormMapWithSetAirplanes
{
/// <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()
{
this.comboTypeEngines = new System.Windows.Forms.ComboBox();
this.groupBoxTools = new System.Windows.Forms.GroupBox();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonRemoveAirplane = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonAddAirplane = new System.Windows.Forms.Button();
this.groupBoxGenerate = new System.Windows.Forms.GroupBox();
this.btnAddTypeOfEngines = new System.Windows.Forms.Button();
this.labelSpeed = new System.Windows.Forms.Label();
this.numericSpeed = new System.Windows.Forms.NumericUpDown();
this.buttonAddTypeOfEntity = new System.Windows.Forms.Button();
this.labelWeight = new System.Windows.Forms.Label();
this.numericUpDownEngines = new System.Windows.Forms.NumericUpDown();
this.numericWeight = new System.Windows.Forms.NumericUpDown();
this.labelCountEngines = new System.Windows.Forms.Label();
this.btnGenerateAirplane = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBoxTools.SuspendLayout();
this.groupBoxGenerate.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericSpeed)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownEngines)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// comboTypeEngines
//
this.comboTypeEngines.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.comboTypeEngines.FormattingEnabled = true;
this.comboTypeEngines.Items.AddRange(new object[] {
"Закругленный",
"Квадратный",
"Стрелка"});
this.comboTypeEngines.Location = new System.Drawing.Point(19, 116);
this.comboTypeEngines.Name = "comboTypeEngines";
this.comboTypeEngines.Size = new System.Drawing.Size(175, 23);
this.comboTypeEngines.TabIndex = 9;
//
// groupBoxTools
//
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonRemoveAirplane);
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
this.groupBoxTools.Controls.Add(this.buttonAddAirplane);
this.groupBoxTools.Controls.Add(this.groupBoxGenerate);
this.groupBoxTools.Controls.Add(this.buttonDown);
this.groupBoxTools.Controls.Add(this.buttonRight);
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxTools.Controls.Add(this.buttonLeft);
this.groupBoxTools.Controls.Add(this.buttonUp);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(811, 0);
this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Size = new System.Drawing.Size(204, 594);
this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты";
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(23, 317);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
this.maskedTextBoxPosition.TabIndex = 22;
this.maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonRemoveAirplane
//
this.buttonRemoveAirplane.Location = new System.Drawing.Point(23, 346);
this.buttonRemoveAirplane.Name = "buttonRemoveAirplane";
this.buttonRemoveAirplane.Size = new System.Drawing.Size(175, 35);
this.buttonRemoveAirplane.TabIndex = 23;
this.buttonRemoveAirplane.Text = "Удалить самолет";
this.buttonRemoveAirplane.UseVisualStyleBackColor = true;
this.buttonRemoveAirplane.Click += new System.EventHandler(this.ButtonRemoveAirplane_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(23, 387);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
this.buttonShowStorage.TabIndex = 24;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(23, 424);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
this.buttonShowOnMap.TabIndex = 25;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonAddAirplane
//
this.buttonAddAirplane.Location = new System.Drawing.Point(23, 273);
this.buttonAddAirplane.Name = "buttonAddAirplane";
this.buttonAddAirplane.Size = new System.Drawing.Size(175, 35);
this.buttonAddAirplane.TabIndex = 21;
this.buttonAddAirplane.Text = "Добавить самолет вручную";
this.buttonAddAirplane.UseVisualStyleBackColor = true;
this.buttonAddAirplane.Click += new System.EventHandler(this.ButtonAddAirplane_Click);
//
// groupBoxGenerate
//
this.groupBoxGenerate.Controls.Add(this.comboTypeEngines);
this.groupBoxGenerate.Controls.Add(this.btnAddTypeOfEngines);
this.groupBoxGenerate.Controls.Add(this.labelSpeed);
this.groupBoxGenerate.Controls.Add(this.numericSpeed);
this.groupBoxGenerate.Controls.Add(this.buttonAddTypeOfEntity);
this.groupBoxGenerate.Controls.Add(this.labelWeight);
this.groupBoxGenerate.Controls.Add(this.numericUpDownEngines);
this.groupBoxGenerate.Controls.Add(this.numericWeight);
this.groupBoxGenerate.Controls.Add(this.labelCountEngines);
this.groupBoxGenerate.Controls.Add(this.btnGenerateAirplane);
this.groupBoxGenerate.Location = new System.Drawing.Point(6, 14);
this.groupBoxGenerate.Name = "groupBoxGenerate";
this.groupBoxGenerate.Size = new System.Drawing.Size(200, 253);
this.groupBoxGenerate.TabIndex = 20;
this.groupBoxGenerate.TabStop = false;
this.groupBoxGenerate.Text = "Генерация";
//
// btnAddTypeOfEngines
//
this.btnAddTypeOfEngines.Location = new System.Drawing.Point(17, 175);
this.btnAddTypeOfEngines.Name = "btnAddTypeOfEngines";
this.btnAddTypeOfEngines.Size = new System.Drawing.Size(175, 43);
this.btnAddTypeOfEngines.TabIndex = 12;
this.btnAddTypeOfEngines.Text = "Добавить тип двигателя и их кол-во для генерации";
this.btnAddTypeOfEngines.UseVisualStyleBackColor = true;
this.btnAddTypeOfEngines.Click += new System.EventHandler(this.btnAddTypeOfEngines_Click);
//
// labelSpeed
//
this.labelSpeed.AutoSize = true;
this.labelSpeed.Location = new System.Drawing.Point(17, 19);
this.labelSpeed.Name = "labelSpeed";
this.labelSpeed.Size = new System.Drawing.Size(117, 15);
this.labelSpeed.TabIndex = 19;
this.labelSpeed.Text = "Скорость самолета:";
//
// numericSpeed
//
this.numericSpeed.Location = new System.Drawing.Point(136, 17);
this.numericSpeed.Name = "numericSpeed";
this.numericSpeed.Size = new System.Drawing.Size(56, 23);
this.numericSpeed.TabIndex = 18;
//
// buttonAddTypeOfEntity
//
this.buttonAddTypeOfEntity.Location = new System.Drawing.Point(17, 71);
this.buttonAddTypeOfEntity.Name = "buttonAddTypeOfEntity";
this.buttonAddTypeOfEntity.Size = new System.Drawing.Size(175, 39);
this.buttonAddTypeOfEntity.TabIndex = 11;
this.buttonAddTypeOfEntity.Text = "Добавить свойства для генерации";
this.buttonAddTypeOfEntity.UseVisualStyleBackColor = true;
this.buttonAddTypeOfEntity.Click += new System.EventHandler(this.buttonAddTypeOfEntity_Click);
//
// labelWeight
//
this.labelWeight.AutoSize = true;
this.labelWeight.Location = new System.Drawing.Point(17, 44);
this.labelWeight.Name = "labelWeight";
this.labelWeight.Size = new System.Drawing.Size(100, 15);
this.labelWeight.TabIndex = 17;
this.labelWeight.Text = "Масса самолета:";
//
// numericUpDownEngines
//
this.numericUpDownEngines.Location = new System.Drawing.Point(136, 146);
this.numericUpDownEngines.Name = "numericUpDownEngines";
this.numericUpDownEngines.Size = new System.Drawing.Size(56, 23);
this.numericUpDownEngines.TabIndex = 13;
//
// numericWeight
//
this.numericWeight.Location = new System.Drawing.Point(136, 42);
this.numericWeight.Name = "numericWeight";
this.numericWeight.Size = new System.Drawing.Size(56, 23);
this.numericWeight.TabIndex = 16;
//
// labelCountEngines
//
this.labelCountEngines.AutoSize = true;
this.labelCountEngines.Location = new System.Drawing.Point(17, 148);
this.labelCountEngines.Name = "labelCountEngines";
this.labelCountEngines.Size = new System.Drawing.Size(113, 15);
this.labelCountEngines.TabIndex = 14;
this.labelCountEngines.Text = "Кол-во двигателей:";
//
// btnGenerateAirplane
//
this.btnGenerateAirplane.Location = new System.Drawing.Point(17, 224);
this.btnGenerateAirplane.Name = "btnGenerateAirplane";
this.btnGenerateAirplane.Size = new System.Drawing.Size(175, 23);
this.btnGenerateAirplane.TabIndex = 15;
this.btnGenerateAirplane.Text = "Сгенерировать самолет";
this.btnGenerateAirplane.UseVisualStyleBackColor = true;
this.btnGenerateAirplane.Click += new System.EventHandler(this.btnGenerateAirplane_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AirBomber.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(91, 544);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 10;
this.buttonDown.UseVisualStyleBackColor = true;
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::AirBomber.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(127, 544);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 9;
this.buttonRight.UseVisualStyleBackColor = true;
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Карта со стенами"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(23, 465);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AirBomber.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(55, 544);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 8;
this.buttonLeft.UseVisualStyleBackColor = true;
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::AirBomber.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(91, 508);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 7;
this.buttonUp.UseVisualStyleBackColor = true;
//
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(811, 594);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// FormGeneratorAirplane
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1015, 594);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
this.Name = "FormGeneratorAirplane";
this.Text = "Генератор самолетов";
this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout();
this.groupBoxGenerate.ResumeLayout(false);
this.groupBoxGenerate.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericSpeed)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownEngines)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
}
#endregion
private ComboBox comboTypeEngines;
private GroupBox groupBoxTools;
private PictureBox pictureBox;
private ComboBox comboBoxSelectorMap;
private Button buttonDown;
private Button buttonRight;
private Button buttonLeft;
private Button buttonUp;
private Button btnAddTypeOfEngines;
private Button buttonAddTypeOfEntity;
private Label labelCountEngines;
private NumericUpDown numericUpDownEngines;
private Button btnGenerateAirplane;
private Label labelSpeed;
private NumericUpDown numericSpeed;
private Label labelWeight;
private NumericUpDown numericWeight;
private GroupBox groupBoxGenerate;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonRemoveAirplane;
private Button buttonShowStorage;
private Button buttonShowOnMap;
private Button buttonAddAirplane;
}
}

View File

@ -0,0 +1,226 @@
using System.Windows.Forms;
namespace AirBomber
{
public partial class FormMapWithSetAirplanes : Form
{
/// <summary>
/// Объект от класса карты с набором объектов
/// </summary>
private MapWithSetAirplanesGeneric<DrawningObject, AbstractMap> _mapAirplanesCollectionGeneric;
private GeneratorAirplane<EntityAirplane, IAirplaneEngines> _generatorAirplane;
/// <summary>
/// Конструктор
/// </summary>
public FormMapWithSetAirplanes()
{
_generatorAirplane = new(100, 100);
InitializeComponent();
}
/// <summary>
/// Добавление самолета на карту
/// </summary>
/// <param name="airplane">самолет.</param>
private void AddAirplaneInMap(DrawningObject airplane)
{
if (airplane == null || (_mapAirplanesCollectionGeneric + airplane) == -1)
{
MessageBox.Show("Не удалось добавить объект");
}
else
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
}
}
/// <summary>
/// Выбор карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Карта со стенами":
map = new WallMap();
break;
}
if (map != null)
{
_mapAirplanesCollectionGeneric = new MapWithSetAirplanesGeneric<DrawningObject, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapAirplanesCollectionGeneric = null;
}
}
/// <summary>
/// Перемещение
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
//получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
Direction dir = Direction.None;
switch (name)
{
case "buttonUp":
dir = Direction.Up;
break;
case "buttonDown":
dir = Direction.Down;
break;
case "buttonLeft":
dir = Direction.Left;
break;
case "buttonRight":
dir = Direction.Right;
break;
}
pictureBox.Image = _mapAirplanesCollectionGeneric?.MoveObject(dir) ?? pictureBox.Image;
}
/// <summary>
/// Добавления типа двигателя и его количество в генератор
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAddTypeOfEntity_Click(object sender, EventArgs e)
{
Random rnd = new();
Color colorBody = Color.FromArgb(rnd.Next() % 256, rnd.Next() % 256, rnd.Next() % 256);
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
colorBody = dialog.Color;
}
var entity = new EntityAirplane((int)numericSpeed.Value, (int)numericWeight.Value, colorBody);
_generatorAirplane.AddTypeOfEntity(entity);
MessageBox.Show($"Добавлены свойства самолета:\n" +
$"Вес: {entity.Weight}\n" +
$"Скорость: {entity.Speed}\n" +
$"Цвет: {colorBody.Name}",
"Успешно добавлены свойства");
}
/// <summary>
/// Генерация самолета
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGenerateAirplane_Click(object sender, EventArgs e)
{
if (_mapAirplanesCollectionGeneric == null)
{
return;
}
var airplane = _generatorAirplane.Generate();
if (airplane == null)
{
MessageBox.Show("Не удалось сгенерировать самолет. Добавьте хотя бы по одному количество двигателей и свойств для генерации"
, "Генерация самолета");
return;
}
AddAirplaneInMap(airplane);
}
/// <summary>
/// Добавления сущности в генератор
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAddTypeOfEngines_Click(object sender, EventArgs e)
{
IAirplaneEngines? typeAirplaneEngines = null;
switch (comboTypeEngines.Text)
{
case "Квадратный":
typeAirplaneEngines = new AirplaneRectEngines();
break;
case "Стрелка":
typeAirplaneEngines = new AirplaneArrowEngines();
break;
default:
typeAirplaneEngines = new DrawningAirplaneEngines();
break;
}
typeAirplaneEngines.CountEngines = (int)numericUpDownEngines.Value;
_generatorAirplane.AddTypeOfEngines(typeAirplaneEngines);
}
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddAirplane_Click(object sender, EventArgs e)
{
if (_mapAirplanesCollectionGeneric == null)
{
return;
}
FormAirBomber form = new();
if (form.ShowDialog() == DialogResult.OK && form.SelectedAirplane != null)
{
AddAirplaneInMap(new(form.SelectedAirplane));
}
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveAirplane_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapAirplanesCollectionGeneric - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Вывод набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapAirplanesCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
}
/// <summary>
/// Вывод карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapAirplanesCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowOnMap();
}
}
}

View File

@ -57,7 +57,4 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber
{
/// <summary>
/// Класс, который генирирует самолет из разнообразного количества сущностей и типа двигателей
/// </summary>
/// <typeparam name="T">Класс Сущность самолет</typeparam>
/// <typeparam name="U">Класс двигателя самолета</typeparam>
internal class GeneratorAirplane<T, U>
where T : EntityAirplane
where U : class, IAirplaneEngines
{
private readonly T[] typesOfEntity;
private readonly U[] typesOfEngines;
public int NumTypesOfEntity { get; private set; }
public int NumTypesOfEngines { get; private set; }
public GeneratorAirplane(int countTypesOfEntity, int countTypesOfEngines)
{
typesOfEntity = new T[countTypesOfEntity];
typesOfEngines = new U[countTypesOfEngines];
}
/// <summary>
/// Добавляет возможный тип сущности при генерации самолета
/// </summary>
/// <param name="type">тип</param>
/// <returns>Успешно ли проведена операция</returns>
public virtual bool AddTypeOfEntity(T type)
Review

Методы не должны быть с пометкой virtual, от этого класса не предеполагается наследников
Методы должны были быть полиморные

Методы не должны быть с пометкой virtual, от этого класса не предеполагается наследников Методы должны были быть полиморные
{
if (NumTypesOfEntity >= typesOfEntity.Length)
{
return false;
}
typesOfEntity[NumTypesOfEntity++] = type;
return true;
}
/// <summary>
/// Добавляет возможный тип двигателей при генерации самолета
/// </summary>
/// <param name="type">тип</param>
/// <returns>Успешно ли проведена операция</returns>
public virtual bool AddTypeOfEngines(U type)
Review

Методы не должны быть с пометкой virtual, от этого класса не предеполагается наследников
Методы должны были быть полиморные

Методы не должны быть с пометкой virtual, от этого класса не предеполагается наследников Методы должны были быть полиморные
{
if (NumTypesOfEngines >= typesOfEngines.Length)
{
return false;
}
typesOfEngines[NumTypesOfEngines++] = type;
return true;
}
/// <summary>
/// Генерирует объект отрисовки
/// </summary>
/// <returns>Возвращает объект отрисовки, либо null, если не были добавлены типы для выборки</returns>
public DrawningObject? Generate()
{
if (NumTypesOfEngines == 0 || NumTypesOfEntity == 0)
{
return null;
}
var rnd = new Random();
var airplane = new DrawningAirplane(typesOfEntity[rnd.Next() % NumTypesOfEntity], typesOfEngines[rnd.Next() % NumTypesOfEngines]);
return new DrawningObject(airplane);
}
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AirBomber
{
internal interface IAirplaneEngines
public interface IAirplaneEngines
{
/// <summary>Получение действительного количества двигателей или установка поддерживаемого числа двигателей</summary>
/// <value>The count engines.</value>

View File

@ -0,0 +1,184 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber
{
internal class MapWithSetAirplanesGeneric<T, U>
where T : class, IDrawningObject
where U : AbstractMap
{
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 210;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 190;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetAirplanesGeneric<T> _setAirplanes;
/// <summary>
/// Карта
/// </summary>
private readonly U _map;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="map"></param>
public MapWithSetAirplanesGeneric(int picWidth, int picHeight, U map)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setAirplanes = new SetAirplanesGeneric<T>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
}
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="map"></param>
/// <param name="airplane"></param>
/// <returns>Возвращает позицию вставленого объекта либо -1, если не получилось его добавить</returns>
public static int operator +(MapWithSetAirplanesGeneric<T, U> map, T airplane)
{
return map._setAirplanes.Insert(airplane);
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="map"></param>
/// <param name="position"></param>
/// <returns>Возвращает удаленный объект, либо null если его не удалось удалить</returns>
public static T operator -(MapWithSetAirplanesGeneric<T, U> map, int position)
{
return map._setAirplanes.Remove(position);
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowSet()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawAirplanes(gr);
return bmp;
}
/// <summary>
/// Просмотр объекта на карте
/// </summary>
/// <returns></returns>
public Bitmap ShowOnMap()
{
Shaking();
for (int i = 0; i < _setAirplanes.Count; i++)
{
var airplane = _setAirplanes.Get(i);
if (airplane != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, airplane);
}
}
return new(_pictureWidth, _pictureHeight);
}
/// <summary>
/// Перемещение объекта по крате
/// </summary>
/// <param name="direction"></param>
/// <returns></returns>
public Bitmap MoveObject(Direction direction)
{
if (_map != null)
{
return _map.MoveObject(direction);
}
return new(_pictureWidth, _pictureHeight);
}
/// <summary>
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
/// </summary>
private void Shaking()
{
int j = _setAirplanes.Count - 1;
for (int i = 0; i < _setAirplanes.Count; i++)
{
if (_setAirplanes.Get(i) == null)
{
for (; j > i; j--)
{
var airplane = _setAirplanes.Get(j);
if (airplane != null)
{
_setAirplanes.Insert(airplane, i);
_setAirplanes.Remove(j);
break;
}
}
if (j <= i)
{
return;
}
}
}
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; j++)
{
DrawHangar(g, pen, new RectangleF(i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth / 1.8F, _placeSizeHeight / 1.6F));
// g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
}
}
}
private void DrawHangar(Graphics g, Pen pen, RectangleF rect)
{
g.DrawLine(pen, rect.Left , rect.Top , rect.Right, rect.Top );
g.DrawLine(pen, rect.Right, rect.Top , rect.Right, rect.Bottom);
g.DrawLine(pen, rect.Right, rect.Bottom, rect.Left , rect.Bottom);
// Края ворот ангара
g.DrawLine(pen, rect.Left, rect.Top , rect.Left, rect.Top + rect.Height / 10);
g.DrawLine(pen, rect.Left, rect.Bottom, rect.Left, rect.Bottom - rect.Height / 10);
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawAirplanes(Graphics g)
{
int countInLine = _pictureWidth / _placeSizeWidth;
int maxLeft = (countInLine - 1) * _placeSizeWidth;
for (int i = 0; i < _setAirplanes.Count; i++)
{
var airplane = _setAirplanes.Get(i);
airplane?.SetObject(maxLeft - i % countInLine * _placeSizeWidth, i / countInLine * _placeSizeHeight + 3, _pictureWidth, _pictureHeight);
airplane?.DrawObject(g);
}
}
}
}

View File

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

View File

@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber
{
/// <summary>
/// Параметризованный набор объектов
/// </summary>
/// <typeparam name="T"></typeparam>
internal class SetAirplanesGeneric<T>
where T : class
{
/// <summary>
/// Массив объектов, которые храним
/// </summary>
private readonly T[] _places;
/// <summary>
/// Количество объектов в массиве
/// </summary>
public int Count => _places.Length;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
public SetAirplanesGeneric(int count)
{
_places = new T[count];
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="airplane">Добавляемый самолет</param>
/// <returns>Возвращает позицию вставленого объекта либо -1, если не получилось его добавить</returns>
public int Insert(T airplane)
{
return Insert(airplane, 0);
}
private bool isCorrectPosition(int position)
{
return 0 <= position && position < Count;
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="airplane">Добавляемый самолет</param>
/// <param name="position">Позиция</param>
/// <returns>Возвращает позицию вставленого объекта либо -1, если не получилось его добавить</returns>
public int Insert(T airplane, int position)
{
int positionNullElement = position;
while (Get(positionNullElement) != null)
{
positionNullElement++;
}
// Если изначальная позиция была некорректной или пустых элементов справа не оказалось возвращаем false
if (!isCorrectPosition(positionNullElement))
{
return -1;
}
while (positionNullElement != position) // Смещение вправо
{
_places[positionNullElement] = _places[positionNullElement - 1];
positionNullElement--;
}
_places[position] = airplane;
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns>Возвращает удаленный объект, либо null если его не удалось удалить</returns>
public T Remove(int position)
{
if (!isCorrectPosition(position))
return null;
var result = _places[position];
_places[position] = null;
return result;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T Get(int position)
{
return isCorrectPosition(position) ? _places[position] : null;
}
}
}