Реализована форма генерации самолетов
This commit is contained in:
parent
3d0fd13bec
commit
7259d846ed
@ -1,6 +1,6 @@
|
|||||||
namespace AirBomber
|
namespace AirBomber
|
||||||
{
|
{
|
||||||
partial class FormMapWithSetAirplanes
|
partial class FormGeneratorAirplane
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
@ -29,32 +29,43 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
||||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
this.labelSpeed = new System.Windows.Forms.Label();
|
||||||
this.buttonRemoveAirplane = new System.Windows.Forms.Button();
|
this.numericSpeed = new System.Windows.Forms.NumericUpDown();
|
||||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
this.labelWeight = new System.Windows.Forms.Label();
|
||||||
|
this.numericWeight = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.btnGenerateAirplane = new System.Windows.Forms.Button();
|
||||||
|
this.labelCountEngines = new System.Windows.Forms.Label();
|
||||||
|
this.numericUpDownEngines = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.btnAddCountEngines = new System.Windows.Forms.Button();
|
||||||
|
this.buttonAddTypeOfEntity = new System.Windows.Forms.Button();
|
||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonUp = new System.Windows.Forms.Button();
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
|
||||||
this.buttonAddAirplane = new System.Windows.Forms.Button();
|
|
||||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||||
this.groupBoxTools.SuspendLayout();
|
this.groupBoxTools.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericSpeed)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericWeight)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownEngines)).BeginInit();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// groupBoxTools
|
// groupBoxTools
|
||||||
//
|
//
|
||||||
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
this.groupBoxTools.Controls.Add(this.labelSpeed);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonRemoveAirplane);
|
this.groupBoxTools.Controls.Add(this.numericSpeed);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
this.groupBoxTools.Controls.Add(this.labelWeight);
|
||||||
|
this.groupBoxTools.Controls.Add(this.numericWeight);
|
||||||
|
this.groupBoxTools.Controls.Add(this.btnGenerateAirplane);
|
||||||
|
this.groupBoxTools.Controls.Add(this.labelCountEngines);
|
||||||
|
this.groupBoxTools.Controls.Add(this.numericUpDownEngines);
|
||||||
|
this.groupBoxTools.Controls.Add(this.btnAddCountEngines);
|
||||||
|
this.groupBoxTools.Controls.Add(this.buttonAddTypeOfEntity);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonDown);
|
this.groupBoxTools.Controls.Add(this.buttonDown);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonRight);
|
this.groupBoxTools.Controls.Add(this.buttonRight);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonUp);
|
this.groupBoxTools.Controls.Add(this.buttonUp);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
|
||||||
this.groupBoxTools.Controls.Add(this.buttonAddAirplane);
|
|
||||||
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
|
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
|
||||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||||
this.groupBoxTools.Location = new System.Drawing.Point(811, 0);
|
this.groupBoxTools.Location = new System.Drawing.Point(811, 0);
|
||||||
@ -64,34 +75,83 @@
|
|||||||
this.groupBoxTools.TabStop = false;
|
this.groupBoxTools.TabStop = false;
|
||||||
this.groupBoxTools.Text = "Инструменты";
|
this.groupBoxTools.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
// maskedTextBoxPosition
|
// labelSpeed
|
||||||
//
|
//
|
||||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 166);
|
this.labelSpeed.AutoSize = true;
|
||||||
this.maskedTextBoxPosition.Mask = "00";
|
this.labelSpeed.Location = new System.Drawing.Point(17, 58);
|
||||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
this.labelSpeed.Name = "labelSpeed";
|
||||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
|
this.labelSpeed.Size = new System.Drawing.Size(117, 15);
|
||||||
this.maskedTextBoxPosition.TabIndex = 2;
|
this.labelSpeed.TabIndex = 19;
|
||||||
this.maskedTextBoxPosition.ValidatingType = typeof(int);
|
this.labelSpeed.Text = "Скорость самолета:";
|
||||||
//
|
//
|
||||||
// buttonRemoveAirplane
|
// numericSpeed
|
||||||
//
|
//
|
||||||
this.buttonRemoveAirplane.Location = new System.Drawing.Point(17, 195);
|
this.numericSpeed.Location = new System.Drawing.Point(136, 56);
|
||||||
this.buttonRemoveAirplane.Name = "buttonRemoveAirplane";
|
this.numericSpeed.Name = "numericSpeed";
|
||||||
this.buttonRemoveAirplane.Size = new System.Drawing.Size(175, 35);
|
this.numericSpeed.Size = new System.Drawing.Size(56, 23);
|
||||||
this.buttonRemoveAirplane.TabIndex = 3;
|
this.numericSpeed.TabIndex = 18;
|
||||||
this.buttonRemoveAirplane.Text = "Удалить самолет";
|
|
||||||
this.buttonRemoveAirplane.UseVisualStyleBackColor = true;
|
|
||||||
this.buttonRemoveAirplane.Click += new System.EventHandler(this.ButtonRemoveAirplane_Click);
|
|
||||||
//
|
//
|
||||||
// buttonShowStorage
|
// labelWeight
|
||||||
//
|
//
|
||||||
this.buttonShowStorage.Location = new System.Drawing.Point(17, 287);
|
this.labelWeight.AutoSize = true;
|
||||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
this.labelWeight.Location = new System.Drawing.Point(17, 83);
|
||||||
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
|
this.labelWeight.Name = "labelWeight";
|
||||||
this.buttonShowStorage.TabIndex = 4;
|
this.labelWeight.Size = new System.Drawing.Size(100, 15);
|
||||||
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
this.labelWeight.TabIndex = 17;
|
||||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
this.labelWeight.Text = "Масса самолета:";
|
||||||
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
//
|
||||||
|
// numericWeight
|
||||||
|
//
|
||||||
|
this.numericWeight.Location = new System.Drawing.Point(136, 81);
|
||||||
|
this.numericWeight.Name = "numericWeight";
|
||||||
|
this.numericWeight.Size = new System.Drawing.Size(56, 23);
|
||||||
|
this.numericWeight.TabIndex = 16;
|
||||||
|
//
|
||||||
|
// btnGenerateAirplane
|
||||||
|
//
|
||||||
|
this.btnGenerateAirplane.Location = new System.Drawing.Point(17, 233);
|
||||||
|
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);
|
||||||
|
//
|
||||||
|
// labelCountEngines
|
||||||
|
//
|
||||||
|
this.labelCountEngines.AutoSize = true;
|
||||||
|
this.labelCountEngines.Location = new System.Drawing.Point(17, 157);
|
||||||
|
this.labelCountEngines.Name = "labelCountEngines";
|
||||||
|
this.labelCountEngines.Size = new System.Drawing.Size(113, 15);
|
||||||
|
this.labelCountEngines.TabIndex = 14;
|
||||||
|
this.labelCountEngines.Text = "Кол-во двигателей:";
|
||||||
|
//
|
||||||
|
// numericUpDownEngines
|
||||||
|
//
|
||||||
|
this.numericUpDownEngines.Location = new System.Drawing.Point(136, 155);
|
||||||
|
this.numericUpDownEngines.Name = "numericUpDownEngines";
|
||||||
|
this.numericUpDownEngines.Size = new System.Drawing.Size(56, 23);
|
||||||
|
this.numericUpDownEngines.TabIndex = 13;
|
||||||
|
//
|
||||||
|
// btnAddCountEngines
|
||||||
|
//
|
||||||
|
this.btnAddCountEngines.Location = new System.Drawing.Point(17, 184);
|
||||||
|
this.btnAddCountEngines.Name = "btnAddCountEngines";
|
||||||
|
this.btnAddCountEngines.Size = new System.Drawing.Size(175, 43);
|
||||||
|
this.btnAddCountEngines.TabIndex = 12;
|
||||||
|
this.btnAddCountEngines.Text = "Добавить кол-во двигателей для генерации";
|
||||||
|
this.btnAddCountEngines.UseVisualStyleBackColor = true;
|
||||||
|
this.btnAddCountEngines.Click += new System.EventHandler(this.btnAddCountEngines_Click);
|
||||||
|
//
|
||||||
|
// buttonAddTypeOfEntity
|
||||||
|
//
|
||||||
|
this.buttonAddTypeOfEntity.Location = new System.Drawing.Point(17, 110);
|
||||||
|
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);
|
||||||
//
|
//
|
||||||
// buttonDown
|
// buttonDown
|
||||||
//
|
//
|
||||||
@ -137,33 +197,14 @@
|
|||||||
this.buttonUp.TabIndex = 7;
|
this.buttonUp.TabIndex = 7;
|
||||||
this.buttonUp.UseVisualStyleBackColor = true;
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
// buttonShowOnMap
|
|
||||||
//
|
|
||||||
this.buttonShowOnMap.Location = new System.Drawing.Point(17, 391);
|
|
||||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
|
||||||
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
|
|
||||||
this.buttonShowOnMap.TabIndex = 5;
|
|
||||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
|
||||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
|
||||||
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
|
||||||
//
|
|
||||||
// buttonAddAirplane
|
|
||||||
//
|
|
||||||
this.buttonAddAirplane.Location = new System.Drawing.Point(17, 106);
|
|
||||||
this.buttonAddAirplane.Name = "buttonAddAirplane";
|
|
||||||
this.buttonAddAirplane.Size = new System.Drawing.Size(175, 35);
|
|
||||||
this.buttonAddAirplane.TabIndex = 1;
|
|
||||||
this.buttonAddAirplane.Text = "Добавить самолет";
|
|
||||||
this.buttonAddAirplane.UseVisualStyleBackColor = true;
|
|
||||||
this.buttonAddAirplane.Click += new System.EventHandler(this.ButtonAddAirplane_Click);
|
|
||||||
//
|
|
||||||
// comboBoxSelectorMap
|
// comboBoxSelectorMap
|
||||||
//
|
//
|
||||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||||
"Простая карта", "Карта со стенами"});
|
"Простая карта",
|
||||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 32);
|
"Карта со стенами"});
|
||||||
|
this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 27);
|
||||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
|
this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
|
||||||
this.comboBoxSelectorMap.TabIndex = 0;
|
this.comboBoxSelectorMap.TabIndex = 0;
|
||||||
@ -178,17 +219,20 @@
|
|||||||
this.pictureBox.TabIndex = 1;
|
this.pictureBox.TabIndex = 1;
|
||||||
this.pictureBox.TabStop = false;
|
this.pictureBox.TabStop = false;
|
||||||
//
|
//
|
||||||
// FormMapWithSetAirplanes
|
// FormGeneratorAirplane
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(1015, 554);
|
this.ClientSize = new System.Drawing.Size(1015, 554);
|
||||||
this.Controls.Add(this.pictureBox);
|
this.Controls.Add(this.pictureBox);
|
||||||
this.Controls.Add(this.groupBoxTools);
|
this.Controls.Add(this.groupBoxTools);
|
||||||
this.Name = "FormMapWithSetAirplanes";
|
this.Name = "FormGeneratorAirplane";
|
||||||
this.Text = "Карта с набором объектов";
|
this.Text = "Генератор самолетов";
|
||||||
this.groupBoxTools.ResumeLayout(false);
|
this.groupBoxTools.ResumeLayout(false);
|
||||||
this.groupBoxTools.PerformLayout();
|
this.groupBoxTools.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericSpeed)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericWeight)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownEngines)).EndInit();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
@ -199,14 +243,18 @@
|
|||||||
private GroupBox groupBoxTools;
|
private GroupBox groupBoxTools;
|
||||||
private PictureBox pictureBox;
|
private PictureBox pictureBox;
|
||||||
private ComboBox comboBoxSelectorMap;
|
private ComboBox comboBoxSelectorMap;
|
||||||
private Button buttonShowOnMap;
|
|
||||||
private Button buttonAddAirplane;
|
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonShowStorage;
|
private Button btnAddCountEngines;
|
||||||
private Button buttonRemoveAirplane;
|
private Button buttonAddTypeOfEntity;
|
||||||
private MaskedTextBox maskedTextBoxPosition;
|
private Label labelCountEngines;
|
||||||
|
private NumericUpDown numericUpDownEngines;
|
||||||
|
private Button btnGenerateAirplane;
|
||||||
|
private Label labelSpeed;
|
||||||
|
private NumericUpDown numericSpeed;
|
||||||
|
private Label labelWeight;
|
||||||
|
private NumericUpDown numericWeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
119
AirBomber/AirBomber/FormGeneratorAirplane.cs
Normal file
119
AirBomber/AirBomber/FormGeneratorAirplane.cs
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
public partial class FormGeneratorAirplane : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Объект от класса карты с набором объектов
|
||||||
|
/// </summary>
|
||||||
|
private GeneratorAirplane<EntityAirplane, IAirplaneEngines> _generatorAirplane;
|
||||||
|
private IDrawningObject? _airplane;
|
||||||
|
private AbstractMap? _map;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormGeneratorAirplane()
|
||||||
|
{
|
||||||
|
_generatorAirplane = new(100, 100);
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Выбор карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
switch (comboBoxSelectorMap.Text)
|
||||||
|
{
|
||||||
|
case "Простая карта":
|
||||||
|
_map = new SimpleMap();
|
||||||
|
break;
|
||||||
|
case "Карта со стенами":
|
||||||
|
_map = new WallMap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (_map != null)
|
||||||
|
{
|
||||||
|
pictureBox.Image = _map.CreateMap(pictureBox.Width, pictureBox.Height, _airplane);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <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 = _map?.MoveObject(dir) ?? pictureBox.Image;
|
||||||
|
}
|
||||||
|
|
||||||
|
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}",
|
||||||
|
"Успешно добавлены свойства");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnGenerateAirplane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var airplane = _generatorAirplane.Generate();
|
||||||
|
if (airplane == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось сгенерировать самолет. Добавьте хотя бы по одному количество двигателей и свойств для генерации"
|
||||||
|
, "Генерация самолета");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_airplane = airplane;
|
||||||
|
|
||||||
|
// Если есть карта отрисовываем объект на карте иначе на пустом фоне
|
||||||
|
if (_map != null)
|
||||||
|
{
|
||||||
|
pictureBox.Image = _map.CreateMap(pictureBox.Width, pictureBox.Height, _airplane);
|
||||||
|
}
|
||||||
|
else if (_airplane != null)
|
||||||
|
{
|
||||||
|
var rnd = new Random();
|
||||||
|
pictureBox.Image = new Bitmap(pictureBox.Width, pictureBox.Height);
|
||||||
|
var g = Graphics.FromImage(pictureBox.Image);
|
||||||
|
_airplane.SetObject(rnd.Next() % 256, rnd.Next() % 256, pictureBox.Image.Width, pictureBox.Image.Height);
|
||||||
|
_airplane.DrawningObject(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnAddCountEngines_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
IAirplaneEngines engines = new DrawningAirplaneEngines();
|
||||||
|
engines.CountEngines = (int)numericUpDownEngines.Value;
|
||||||
|
_generatorAirplane.AddTypeOfEngines(engines);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,153 +0,0 @@
|
|||||||
namespace AirBomber
|
|
||||||
{
|
|
||||||
public partial class FormMapWithSetAirplanes : Form
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Объект от класса карты с набором объектов
|
|
||||||
/// </summary>
|
|
||||||
private MapWithSetAirplanesGeneric<DrawningObject, AbstractMap> _mapAirplanesCollectionGeneric;
|
|
||||||
/// <summary>
|
|
||||||
/// Конструктор
|
|
||||||
/// </summary>
|
|
||||||
public FormMapWithSetAirplanes()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
/// <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 ButtonAddAirplane_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if(_mapAirplanesCollectionGeneric == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
FormAirBomber form = new();
|
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
DrawningObject airplane = new(form.SelectedAirplane);
|
|
||||||
if (form.SelectedAirplane == null || !(_mapAirplanesCollectionGeneric + airplane))
|
|
||||||
{
|
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("Объект добавлен");
|
|
||||||
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <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)
|
|
||||||
{
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Перемещение
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (_mapAirplanesCollectionGeneric == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//получаем имя кнопки
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -31,7 +31,7 @@ namespace AirBomber
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="type">тип</param>
|
/// <param name="type">тип</param>
|
||||||
/// <returns>Успешно ли проведена операция</returns>
|
/// <returns>Успешно ли проведена операция</returns>
|
||||||
public bool AddTypeOfEntity(T type)
|
public virtual bool AddTypeOfEntity(T type)
|
||||||
{
|
{
|
||||||
if (NumTypesOfEntity >= typesOfEntity.Length)
|
if (NumTypesOfEntity >= typesOfEntity.Length)
|
||||||
{
|
{
|
||||||
@ -45,7 +45,7 @@ namespace AirBomber
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="type">тип</param>
|
/// <param name="type">тип</param>
|
||||||
/// <returns>Успешно ли проведена операция</returns>
|
/// <returns>Успешно ли проведена операция</returns>
|
||||||
public bool AddTypeOfEngines(U type)
|
public virtual bool AddTypeOfEngines(U type)
|
||||||
{
|
{
|
||||||
if (NumTypesOfEngines >= typesOfEngines.Length)
|
if (NumTypesOfEngines >= typesOfEngines.Length)
|
||||||
{
|
{
|
||||||
|
@ -11,7 +11,7 @@ namespace AirBomber
|
|||||||
// 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 FormAirBomber());
|
Application.Run(new FormGeneratorAirplane());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user