From 5172ab0e40a13b92878cb5f8be4882145b1907bf Mon Sep 17 00:00:00 2001 From: ker73rus Date: Tue, 1 Nov 2022 18:05:19 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D0=BA=D0=BE=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D1=8B=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Stormtrooper/Stormtrooper/Direction.cs | 2 +- .../Stormtrooper/DrawningMilitaryAirplane.cs | 2 +- .../Stormtrooper/EntityMilitaryAirplane.cs | 2 +- .../FormMapWithSetAirplane.Designer.cs | 214 ++++++++++++++++++ .../Stormtrooper/FormMapWithSetAirplane.cs | 156 +++++++++++++ .../Stormtrooper/FormMapWithSetAirplane.resx | 60 +++++ .../Stormtrooper/MainForm.Designer.cs | 13 ++ Stormtrooper/Stormtrooper/MainForm.cs | 7 + .../Stormtrooper/MapWithSetAirplaneGeneric.cs | 172 ++++++++++++++ Stormtrooper/Stormtrooper/Program.cs | 2 +- .../Stormtrooper/SetAirplaneGeneric.cs | 77 +++++++ 11 files changed, 703 insertions(+), 4 deletions(-) create mode 100644 Stormtrooper/Stormtrooper/FormMapWithSetAirplane.Designer.cs create mode 100644 Stormtrooper/Stormtrooper/FormMapWithSetAirplane.cs create mode 100644 Stormtrooper/Stormtrooper/FormMapWithSetAirplane.resx create mode 100644 Stormtrooper/Stormtrooper/MapWithSetAirplaneGeneric.cs create mode 100644 Stormtrooper/Stormtrooper/SetAirplaneGeneric.cs diff --git a/Stormtrooper/Stormtrooper/Direction.cs b/Stormtrooper/Stormtrooper/Direction.cs index f4826fe..f4b14f8 100644 --- a/Stormtrooper/Stormtrooper/Direction.cs +++ b/Stormtrooper/Stormtrooper/Direction.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Stormtrooper { - internal enum Direction + public enum Direction { None, diff --git a/Stormtrooper/Stormtrooper/DrawningMilitaryAirplane.cs b/Stormtrooper/Stormtrooper/DrawningMilitaryAirplane.cs index a59af2b..6e65760 100644 --- a/Stormtrooper/Stormtrooper/DrawningMilitaryAirplane.cs +++ b/Stormtrooper/Stormtrooper/DrawningMilitaryAirplane.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Stormtrooper { - internal class DrawningMilitaryAirplane + public class DrawningMilitaryAirplane { /// /// Класс-сущность diff --git a/Stormtrooper/Stormtrooper/EntityMilitaryAirplane.cs b/Stormtrooper/Stormtrooper/EntityMilitaryAirplane.cs index d7aa97e..6bb340d 100644 --- a/Stormtrooper/Stormtrooper/EntityMilitaryAirplane.cs +++ b/Stormtrooper/Stormtrooper/EntityMilitaryAirplane.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Stormtrooper { - internal class EntityMilitaryAirplane + public class EntityMilitaryAirplane { public int Speed { get; private set; } public int Weight { get; private set; } diff --git a/Stormtrooper/Stormtrooper/FormMapWithSetAirplane.Designer.cs b/Stormtrooper/Stormtrooper/FormMapWithSetAirplane.Designer.cs new file mode 100644 index 0000000..a7582cb --- /dev/null +++ b/Stormtrooper/Stormtrooper/FormMapWithSetAirplane.Designer.cs @@ -0,0 +1,214 @@ +namespace Stormtrooper +{ + partial class FormMapWithSetAirplane + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.groupBoxTools = new System.Windows.Forms.GroupBox(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.buttonRemove = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.comboBoxMapSelector = new System.Windows.Forms.ComboBox(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.SuspendLayout(); + // + // groupBoxTools + // + this.groupBoxTools.Controls.Add(this.buttonRight); + this.groupBoxTools.Controls.Add(this.buttonLeft); + this.groupBoxTools.Controls.Add(this.buttonDown); + this.groupBoxTools.Controls.Add(this.buttonUp); + this.groupBoxTools.Controls.Add(this.buttonShowOnMap); + this.groupBoxTools.Controls.Add(this.buttonShowStorage); + this.groupBoxTools.Controls.Add(this.buttonRemove); + this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); + this.groupBoxTools.Controls.Add(this.buttonCreate); + this.groupBoxTools.Controls.Add(this.comboBoxMapSelector); + this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; + this.groupBoxTools.Location = new System.Drawing.Point(600, 0); + this.groupBoxTools.Name = "groupBoxTools"; + this.groupBoxTools.Size = new System.Drawing.Size(200, 450); + this.groupBoxTools.TabIndex = 0; + this.groupBoxTools.TabStop = false; + this.groupBoxTools.Text = "Инструменты"; + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.Location = new System.Drawing.Point(119, 402); + this.buttonRight.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(35, 35); + this.buttonRight.TabIndex = 18; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.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.Location = new System.Drawing.Point(35, 402); + this.buttonLeft.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(35, 35); + this.buttonLeft.TabIndex = 17; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.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.Location = new System.Drawing.Point(77, 403); + this.buttonDown.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(35, 35); + this.buttonDown.TabIndex = 16; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.Location = new System.Drawing.Point(77, 361); + this.buttonUp.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(35, 35); + this.buttonUp.TabIndex = 15; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonShowOnMap + // + this.buttonShowOnMap.Location = new System.Drawing.Point(8, 323); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(174, 23); + this.buttonShowOnMap.TabIndex = 14; + this.buttonShowOnMap.Text = "Посмотреть карту"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + // + // buttonShowStorage + // + this.buttonShowStorage.Location = new System.Drawing.Point(8, 275); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(174, 23); + this.buttonShowStorage.TabIndex = 13; + this.buttonShowStorage.Text = "Посмотреть хранилище"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // buttonRemove + // + this.buttonRemove.Location = new System.Drawing.Point(7, 172); + this.buttonRemove.Name = "buttonRemove"; + this.buttonRemove.Size = new System.Drawing.Size(174, 23); + this.buttonRemove.TabIndex = 12; + this.buttonRemove.Text = "Удалить"; + this.buttonRemove.UseVisualStyleBackColor = true; + this.buttonRemove.Click += new System.EventHandler(this.ButtonRemove_Click); + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(7, 122); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23); + this.maskedTextBoxPosition.TabIndex = 11; + this.maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonCreate + // + this.buttonCreate.Location = new System.Drawing.Point(6, 74); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(175, 23); + this.buttonCreate.TabIndex = 10; + this.buttonCreate.Text = "Добавить"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // comboBoxMapSelector + // + this.comboBoxMapSelector.BackColor = System.Drawing.SystemColors.Window; + this.comboBoxMapSelector.FormattingEnabled = true; + this.comboBoxMapSelector.Items.AddRange(new object[] { + "Простая карта", + "Опасная карта", + "Облачная карта"}); + this.comboBoxMapSelector.Location = new System.Drawing.Point(6, 22); + this.comboBoxMapSelector.Name = "comboBoxMapSelector"; + this.comboBoxMapSelector.Size = new System.Drawing.Size(175, 23); + this.comboBoxMapSelector.TabIndex = 9; + this.comboBoxMapSelector.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); + // + // 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(600, 450); + this.pictureBox.TabIndex = 1; + this.pictureBox.TabStop = false; + // + // FormMapWithSetAirplane + // + 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.pictureBox); + this.Controls.Add(this.groupBoxTools); + this.Name = "FormMapWithSetAirplane"; + this.Text = "FormMapWithSetAirplane"; + this.groupBoxTools.ResumeLayout(false); + this.groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxTools; + private PictureBox pictureBox; + private Button buttonShowOnMap; + private Button buttonShowStorage; + private Button buttonRemove; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonCreate; + private ComboBox comboBoxMapSelector; + private Button buttonRight; + private Button buttonLeft; + private Button buttonDown; + private Button buttonUp; + } +} \ No newline at end of file diff --git a/Stormtrooper/Stormtrooper/FormMapWithSetAirplane.cs b/Stormtrooper/Stormtrooper/FormMapWithSetAirplane.cs new file mode 100644 index 0000000..2af4f62 --- /dev/null +++ b/Stormtrooper/Stormtrooper/FormMapWithSetAirplane.cs @@ -0,0 +1,156 @@ +using Cars; +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; +using static System.Windows.Forms.DataFormats; + +namespace Stormtrooper +{ + public partial class FormMapWithSetAirplane : Form + { + private MapWithSetAirplaneGeneric _mapAirsCollectionGeneric; + public FormMapWithSetAirplane() + { + InitializeComponent(); + } + /// + /// Выбор карты + /// + /// + /// + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + switch (comboBoxMapSelector.Text) + { + case "Простая карта": + map = new SimpleMap(); + break; + } + if (map != null) + { + _mapAirsCollectionGeneric = new MapWithSetAirplaneGeneric( + pictureBox.Width, pictureBox.Height, map); + } + else + { + _mapAirsCollectionGeneric = null; + } + } + /// + /// Добавление объекта + /// + /// + /// + private void ButtonAdd_Click(object sender, EventArgs e) + { + if (_mapAirsCollectionGeneric == null) + { + return; + } + MainForm form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + DrawningObject airplane = new(form.SelectedAirplane); + if (_mapAirsCollectionGeneric + airplane) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapAirsCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemove_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 (_mapAirsCollectionGeneric - pos) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _mapAirsCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Вывод набора + /// + /// + /// + private void ButtonShowStorage_Click(object sender, EventArgs e) + { + if (_mapAirsCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapAirsCollectionGeneric.ShowSet(); + } + /// + /// Вывод карты + /// + /// + /// + private void ButtonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapAirsCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapAirsCollectionGeneric.ShowOnMap(); + } + /// + /// Перемещение + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_mapAirsCollectionGeneric == 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 = _mapAirsCollectionGeneric.MoveObject(dir); + } + } +} diff --git a/Stormtrooper/Stormtrooper/FormMapWithSetAirplane.resx b/Stormtrooper/Stormtrooper/FormMapWithSetAirplane.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Stormtrooper/Stormtrooper/FormMapWithSetAirplane.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Stormtrooper/Stormtrooper/MainForm.Designer.cs b/Stormtrooper/Stormtrooper/MainForm.Designer.cs index e8d1930..c3d39fc 100644 --- a/Stormtrooper/Stormtrooper/MainForm.Designer.cs +++ b/Stormtrooper/Stormtrooper/MainForm.Designer.cs @@ -40,6 +40,7 @@ namespace Stormtrooper this.buttonLeft = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonCreateMod = new System.Windows.Forms.Button(); + this.button_Add = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit(); this.toolStripStatus.SuspendLayout(); this.SuspendLayout(); @@ -157,11 +158,22 @@ namespace Stormtrooper this.buttonCreateMod.UseVisualStyleBackColor = true; this.buttonCreateMod.Click += new System.EventHandler(this.buttonCreateMod_Click); // + // button_Add + // + this.button_Add.Location = new System.Drawing.Point(573, 600); + this.button_Add.Name = "button_Add"; + this.button_Add.Size = new System.Drawing.Size(75, 23); + this.button_Add.TabIndex = 8; + this.button_Add.Text = "Добавить"; + this.button_Add.UseVisualStyleBackColor = true; + this.button_Add.Click += new System.EventHandler(this.button_Add_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1343, 703); + this.Controls.Add(this.button_Add); this.Controls.Add(this.buttonCreateMod); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonLeft); @@ -194,6 +206,7 @@ namespace Stormtrooper private System.Windows.Forms.Button buttonLeft; private System.Windows.Forms.Button buttonRight; private Button buttonCreateMod; + private Button button_Add; } } diff --git a/Stormtrooper/Stormtrooper/MainForm.cs b/Stormtrooper/Stormtrooper/MainForm.cs index ee5ad95..9b1ad61 100644 --- a/Stormtrooper/Stormtrooper/MainForm.cs +++ b/Stormtrooper/Stormtrooper/MainForm.cs @@ -13,6 +13,7 @@ namespace Stormtrooper public partial class MainForm : Form { DrawningMilitaryAirplane _airplane; + public DrawningMilitaryAirplane SelectedAirplane { get; private set; } public MainForm() { InitializeComponent(); @@ -80,5 +81,11 @@ namespace Stormtrooper SetData(); Draw(); } + + private void button_Add_Click(object sender, EventArgs e) + { + SelectedAirplane = _airplane; + DialogResult = DialogResult.OK; + } } } diff --git a/Stormtrooper/Stormtrooper/MapWithSetAirplaneGeneric.cs b/Stormtrooper/Stormtrooper/MapWithSetAirplaneGeneric.cs new file mode 100644 index 0000000..18d580b --- /dev/null +++ b/Stormtrooper/Stormtrooper/MapWithSetAirplaneGeneric.cs @@ -0,0 +1,172 @@ +using Cars; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stormtrooper +{ + internal class MapWithSetAirplaneGeneric + where T : class, IDrawningObject + where U : AbstractMap + { + /// + /// Ширина окна отрисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна отрисовки + /// + private readonly int _pictureHeight; + /// + /// Размер занимаемого объектом места (ширина) + /// + private readonly int _placeSizeWidth = 210; + /// + /// Размер занимаемого объектом места (высота) + /// + private readonly int _placeSizeHeight = 90; + /// + /// Набор объектов + /// + private readonly SetAirplaneGeneric _setAirs; + /// + /// Карта + /// + private readonly U _map; + /// + /// Конструктор + /// + /// + /// + /// + public MapWithSetAirplaneGeneric(int picWidth, int picHeight, U map) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _setAirs = new SetAirplaneGeneric(width * height); + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _map = map; + } + /// + /// Перегрузка оператора сложения + /// + /// + /// + /// + public static bool operator +(MapWithSetAirplaneGeneric map, T car) + { + return map._setAirs.Insert(car); + } + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static bool operator -(MapWithSetAirplaneGeneric map, int position) + { + return map._setAirs.Remove(position); + } + /// + /// Вывод всего набора объектов + /// + /// + public Bitmap ShowSet() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawAirs(gr); + return bmp; + } + /// + /// Просмотр объекта на карте + /// + /// + public Bitmap ShowOnMap() + { + Shaking(); + for (int i = 0; i < _setAirs.Count; i++) + { + var air = _setAirs.Get(i); + if (air != null) + { + return _map.CreateMap(_pictureWidth, _pictureHeight, air); + } + } + return new(_pictureWidth, _pictureHeight); + } + /// + /// Перемещение объекта по крате + /// + /// + /// + public Bitmap MoveObject(Direction direction) + { + + if (_map != null) + { + return _map.MoveObject(direction); + } + return new(_pictureWidth, _pictureHeight); + } + /// + /// "Взбалтываем" набор, чтобы все элементы оказались в начале + /// + private void Shaking() + { + int j = _setAirs.Count - 1; + for (int i = 0; i < _setAirs.Count; i++) + { + if (_setAirs.Get(i) == null) + { + for (; j > i; j--) + { + var air = _setAirs.Get(j); + if (air != null) + { + _setAirs.Insert(air, i); + _setAirs.Remove(j); + break; + } + } + if (j <= i) + { + return; + } + } + } + } + /// + /// Метод отрисовки фона + /// + /// + 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) + {//линия рамзетки места + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); + } + } + /// + /// Метод прорисовки объектов + /// + /// + private void DrawAirs(Graphics g) + { + for (int i = 0; i < _setAirs.Count; i++) + { + // TODO установка позиции + _setAirs.Get(i)?.DrawningObject(g); + } + } + } +} diff --git a/Stormtrooper/Stormtrooper/Program.cs b/Stormtrooper/Stormtrooper/Program.cs index 63f467d..65b5334 100644 --- a/Stormtrooper/Stormtrooper/Program.cs +++ b/Stormtrooper/Stormtrooper/Program.cs @@ -16,7 +16,7 @@ namespace Stormtrooper { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new FormMap()); + Application.Run(new FormMapWithSetAirplane()); } } } diff --git a/Stormtrooper/Stormtrooper/SetAirplaneGeneric.cs b/Stormtrooper/Stormtrooper/SetAirplaneGeneric.cs new file mode 100644 index 0000000..dedf2a0 --- /dev/null +++ b/Stormtrooper/Stormtrooper/SetAirplaneGeneric.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stormtrooper +{ + internal class SetAirplaneGeneric + where T : class + { + /// + /// Массив объектов, которые храним + /// + private readonly T[] _places; + /// + /// Количество объектов в массиве + /// + public int Count => _places.Length; + /// + /// Конструктор + /// + /// + public SetAirplaneGeneric(int count) + { + _places = new T[count]; + } + /// + /// Добавление объекта в набор + /// + /// Добавляемый самолёт + /// + public bool Insert(T airplane) + { + _places[0] = airplane; + // TODO вставка в начало набора + return true; + } + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемый самолёт + /// Позиция + /// + public bool Insert(T airplane, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // проверка, что после вставляемого элемента в массиве есть пустой элемент + // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента + // TODO вставка по позиции + _places[position] = airplane; + return true; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присовив элементу массива значение null + return true; + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T Get(int position) + { + // TODO проверка позиции + return _places[position]; + } + } +}