From 63bd9b5701bce9ec934245dd1c7c16361a27063e Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Sun, 9 Oct 2022 00:24:24 +0400 Subject: [PATCH 1/6] generic classes --- .../ProjectPlane/MapWithSetPlanesGeneric.cs | 170 ++++++++++++++++++ ProjectPlane/ProjectPlane/SetPlanesGeneric.cs | 12 ++ 2 files changed, 182 insertions(+) create mode 100644 ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs create mode 100644 ProjectPlane/ProjectPlane/SetPlanesGeneric.cs diff --git a/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs b/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs new file mode 100644 index 0000000..ce2e36d --- /dev/null +++ b/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs @@ -0,0 +1,170 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectPlane +{ + internal class MapWithSetPlanesGeneric + where T : class, IDrawingObject + where U : AbstractMap + { + /// + /// Ширина окна отрисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна отрисовки + /// + private readonly int _pictureHeight; + /// + /// Размер занимаемого объектом места (ширина) + /// + private readonly int _placeSizeWidth = 210; + /// + /// Размер занимаемого объектом места (высота) + /// + private readonly int _placeSizeHeight = 90; + /// + /// Набор объектов + /// + private readonly SetPlanesGeneric _setPlanes; + /// + /// Карта + /// + private readonly U _map; + /// + /// Конструктор + /// + /// + /// + /// + public MapWithSetPlanesGeneric(int picWidth, int picHeight, U map) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _setPlanes = new SetPlanesGeneric(width * height); + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _map = map; + } + /// + /// Перегрузка оператора сложения + /// + /// + /// + /// + public static bool operator +(MapWithSetPlanesGeneric map, T car) + { + return map._setPlanes.Insert(car); + } + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static bool operator -(MapWithSetPlanesGeneric map, int position) + { + return map._setPlanes.Remove(position); + } + /// + /// Вывод всего набора объектов + /// + /// + public Bitmap ShowSet() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawPlanes(gr); + return bmp; + } + /// + /// Просмотр объекта на карте + /// + /// + public Bitmap ShowOnMap() + { + Shaking(); + for (int i = 0; i < _setPlanes.Count; i++) + { + var car = _setPlanes.Get(i); + if (car != null) + { + return _map.CreateMap(_pictureWidth, _pictureHeight, car); + } + } + 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 = _setPlanes.Count - 1; + for (int i = 0; i < _setPlanes.Count; i++) + { + if (_setPlanes.Get(i) == null) + { + for (; j > i; j--) + { + var car = _setPlanes.Get(j); + if (car != null) + { + _setPlanes.Insert(car, i); + _setPlanes.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 DrawPlanes(Graphics g) + { + for (int i = 0; i < _setPlanes.Count; i++) + { + // TODO установка позиции + _setPlanes.Get(i)?.DrawingObject(g); + } + } + } +} diff --git a/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs b/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs new file mode 100644 index 0000000..cf3336f --- /dev/null +++ b/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectPlane +{ + internal class SetPlanesGeneric + { + } +} From 69701d2656ef52e423c8ee0d78b4bf254f36b6f5 Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Sun, 9 Oct 2022 00:40:01 +0400 Subject: [PATCH 2/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectPlane/ProjectPlane/Direction.cs | 2 +- ProjectPlane/ProjectPlane/DrawningPlane.cs | 2 +- ProjectPlane/ProjectPlane/EntityPlane.cs | 2 +- .../FormMapWithSetPlanes.Designer.cs | 39 ++++++ .../ProjectPlane/FormMapWithSetPlanes.cs | 20 +++ .../ProjectPlane/FormMapWithSetPlanes.resx | 120 ++++++++++++++++++ .../ProjectPlane/FormPlane.Designer.cs | 13 ++ ProjectPlane/ProjectPlane/FormPlane.cs | 9 +- .../ProjectPlane/MapWithSetPlanesGeneric.cs | 18 +-- ProjectPlane/ProjectPlane/SetPlanesGeneric.cs | 67 +++++++++- 10 files changed, 276 insertions(+), 16 deletions(-) create mode 100644 ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs create mode 100644 ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs create mode 100644 ProjectPlane/ProjectPlane/FormMapWithSetPlanes.resx diff --git a/ProjectPlane/ProjectPlane/Direction.cs b/ProjectPlane/ProjectPlane/Direction.cs index 45ee136..1b673f8 100644 --- a/ProjectPlane/ProjectPlane/Direction.cs +++ b/ProjectPlane/ProjectPlane/Direction.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ProjectPlane { - internal enum Direction + public enum Direction { None = 0, Up = 1, diff --git a/ProjectPlane/ProjectPlane/DrawningPlane.cs b/ProjectPlane/ProjectPlane/DrawningPlane.cs index 61d0386..28ee1ae 100644 --- a/ProjectPlane/ProjectPlane/DrawningPlane.cs +++ b/ProjectPlane/ProjectPlane/DrawningPlane.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ProjectPlane { - internal class DrawingPlane + public class DrawingPlane { /// diff --git a/ProjectPlane/ProjectPlane/EntityPlane.cs b/ProjectPlane/ProjectPlane/EntityPlane.cs index 856c101..29bc7db 100644 --- a/ProjectPlane/ProjectPlane/EntityPlane.cs +++ b/ProjectPlane/ProjectPlane/EntityPlane.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ProjectPlane { - internal class EntityPlane + public class EntityPlane { /// diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs new file mode 100644 index 0000000..b787796 --- /dev/null +++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs @@ -0,0 +1,39 @@ +namespace ProjectPlane +{ + partial class FormMapWithSetPlanes + { + /// + /// 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.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "Form1"; + } + + #endregion + } +} \ No newline at end of file diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs new file mode 100644 index 0000000..d50f5bc --- /dev/null +++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectPlane +{ + public partial class FormMapWithSetPlanes : Form + { + public FormMapWithSetPlanes() + { + InitializeComponent(); + } + } +} diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.resx b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/ProjectPlane/ProjectPlane/FormPlane.Designer.cs b/ProjectPlane/ProjectPlane/FormPlane.Designer.cs index 06e5038..cc37f70 100644 --- a/ProjectPlane/ProjectPlane/FormPlane.Designer.cs +++ b/ProjectPlane/ProjectPlane/FormPlane.Designer.cs @@ -42,6 +42,7 @@ this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); this.buttonCreateModif = new System.Windows.Forms.Button(); + this.buttonSelectPlane = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlane)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -148,11 +149,22 @@ this.buttonCreateModif.UseVisualStyleBackColor = false; this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click); // + // buttonSelectPlane + // + this.buttonSelectPlane.Location = new System.Drawing.Point(541, 388); + this.buttonSelectPlane.Name = "buttonSelectPlane"; + this.buttonSelectPlane.Size = new System.Drawing.Size(75, 23); + this.buttonSelectPlane.TabIndex = 11; + this.buttonSelectPlane.Text = "Select"; + this.buttonSelectPlane.UseVisualStyleBackColor = true; + this.buttonSelectPlane.Click += new System.EventHandler(this.buttonSelectPlane_Click); + // // FormPlane // 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.buttonSelectPlane); this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonCreate); this.Controls.Add(this.buttonLeft); @@ -185,5 +197,6 @@ private ToolStripStatusLabel toolStripStatusLabelWeight; private ToolStripStatusLabel toolStripStatusLabelBodyColor; private Button buttonCreateModif; + private Button buttonSelectPlane; } } \ No newline at end of file diff --git a/ProjectPlane/ProjectPlane/FormPlane.cs b/ProjectPlane/ProjectPlane/FormPlane.cs index 35aa65e..76af002 100644 --- a/ProjectPlane/ProjectPlane/FormPlane.cs +++ b/ProjectPlane/ProjectPlane/FormPlane.cs @@ -4,6 +4,7 @@ { private DrawingPlane _plane; + public DrawingPlane SelectedPlane { get; private set; } public FormPlane() { @@ -62,7 +63,7 @@ SetData(); Draw(); } - private void PictureBoxCar_Resize(object sender, EventArgs e) + private void PictureBoxplane_Resize(object sender, EventArgs e) { _plane?.ChangeBorders(pictureBoxPlane.Width, pictureBoxPlane.Height); Draw(); @@ -83,6 +84,10 @@ Draw(); } - + private void buttonSelectPlane_Click(object sender, EventArgs e) + { + SelectedPlane = _plane; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs b/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs index ce2e36d..336fe74 100644 --- a/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs +++ b/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs @@ -53,11 +53,11 @@ namespace ProjectPlane /// Перегрузка оператора сложения /// /// - /// + /// /// - public static bool operator +(MapWithSetPlanesGeneric map, T car) + public static bool operator +(MapWithSetPlanesGeneric map, T plane) { - return map._setPlanes.Insert(car); + return map._setPlanes.Insert(plane); } /// /// Перегрузка оператора вычитания @@ -90,10 +90,10 @@ namespace ProjectPlane Shaking(); for (int i = 0; i < _setPlanes.Count; i++) { - var car = _setPlanes.Get(i); - if (car != null) + var plane = _setPlanes.Get(i); + if (plane != null) { - return _map.CreateMap(_pictureWidth, _pictureHeight, car); + return _map.CreateMap(_pictureWidth, _pictureHeight, plane); } } return new(_pictureWidth, _pictureHeight); @@ -123,10 +123,10 @@ namespace ProjectPlane { for (; j > i; j--) { - var car = _setPlanes.Get(j); - if (car != null) + var plane = _setPlanes.Get(j); + if (plane != null) { - _setPlanes.Insert(car, i); + _setPlanes.Insert(plane, i); _setPlanes.Remove(j); break; } diff --git a/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs b/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs index cf3336f..568cca4 100644 --- a/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs +++ b/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs @@ -6,7 +6,70 @@ using System.Threading.Tasks; namespace ProjectPlane { - internal class SetPlanesGeneric + internal class SetPlanesGeneric where T : class { - } + /// + /// Массив объектов, которые храним + /// + private readonly T[] _places; + /// + /// Количество объектов в массиве + /// + public int Count => _places.Length; + /// + /// Конструктор + /// + /// + public SetPlanesGeneric(int count) + { + _places = new T[count]; + } + /// + /// Добавление объекта в набор + /// + /// Добавляемый самолет + /// + public bool Insert(T plane) + { + // TODO вставка в начало набора + return true; + } + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемый самолет + /// Позиция + /// + public bool Insert(T plane, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // проверка, что после вставляемого элемента в массиве есть пустой элемент + // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента + // TODO вставка по позиции + _places[position] = plane; + return true; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присовив элементу массива значение null + return true; + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T Get(int position) + { + // TODO проверка позиции + return _places[position]; + } + } } From 8b95a84ef0ab2a6b4d4278574501d06c389873cb Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Sun, 9 Oct 2022 16:39:27 +0400 Subject: [PATCH 3/6] changes forms --- ProjectPlane/ProjectPlane/FormMap.Designer.cs | 206 ------------------ ProjectPlane/ProjectPlane/FormMap.cs | 97 --------- ProjectPlane/ProjectPlane/FormMap.resx | 63 ------ .../FormMapWithSetPlanes.Designer.cs | 176 ++++++++++++++- .../ProjectPlane/FormMapWithSetPlanes.cs | 141 ++++++++++++ .../ProjectPlane/FormMapWithSetPlanes.resx | 62 +----- ProjectPlane/ProjectPlane/Program.cs | 2 +- 7 files changed, 316 insertions(+), 431 deletions(-) delete mode 100644 ProjectPlane/ProjectPlane/FormMap.Designer.cs delete mode 100644 ProjectPlane/ProjectPlane/FormMap.cs delete mode 100644 ProjectPlane/ProjectPlane/FormMap.resx diff --git a/ProjectPlane/ProjectPlane/FormMap.Designer.cs b/ProjectPlane/ProjectPlane/FormMap.Designer.cs deleted file mode 100644 index c368940..0000000 --- a/ProjectPlane/ProjectPlane/FormMap.Designer.cs +++ /dev/null @@ -1,206 +0,0 @@ -namespace ProjectPlane -{ - partial class FormMap - { - /// - /// 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); - } - - private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) - { - - } - #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.buttonUp = new System.Windows.Forms.Button(); - this.buttonRight = new System.Windows.Forms.Button(); - this.buttonDown = new System.Windows.Forms.Button(); - this.buttonLeft = new System.Windows.Forms.Button(); - this.buttonCreate = new System.Windows.Forms.Button(); - this.pictureBoxPlane = new System.Windows.Forms.PictureBox(); - this.statusStrip1 = 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.buttonCreateModif = new System.Windows.Forms.Button(); - this.comboMapSelector = new System.Windows.Forms.ComboBox(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlane)).BeginInit(); - this.statusStrip1.SuspendLayout(); - this.SuspendLayout(); - // - // buttonUp - // - this.buttonUp.BackgroundImage = global::ProjectPlane.Properties.Resources.up; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(686, 323); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(48, 47); - this.buttonUp.TabIndex = 8; - this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonRight - // - this.buttonRight.BackgroundImage = global::ProjectPlane.Properties.Resources.right; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(740, 372); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(48, 47); - this.buttonRight.TabIndex = 7; - this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonDown - // - this.buttonDown.BackgroundImage = global::ProjectPlane.Properties.Resources.down; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(686, 372); - this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(48, 47); - this.buttonDown.TabIndex = 6; - this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonLeft - // - this.buttonLeft.BackgroundImage = global::ProjectPlane.Properties.Resources.left; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(632, 372); - this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(48, 47); - this.buttonLeft.TabIndex = 5; - this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonCreate - // - this.buttonCreate.BackColor = System.Drawing.SystemColors.ControlLightLight; - this.buttonCreate.Location = new System.Drawing.Point(12, 376); - this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(120, 47); - this.buttonCreate.TabIndex = 4; - this.buttonCreate.Text = "New Plane"; - this.buttonCreate.UseVisualStyleBackColor = false; - this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); - // - // pictureBoxPlane - // - this.pictureBoxPlane.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBoxPlane.Location = new System.Drawing.Point(0, 0); - this.pictureBoxPlane.Name = "pictureBoxPlane"; - this.pictureBoxPlane.Size = new System.Drawing.Size(800, 450); - this.pictureBoxPlane.TabIndex = 5; - this.pictureBoxPlane.TabStop = false; - - // - // statusStrip1 - // - this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripStatusLabelSpeed, - this.toolStripStatusLabelWeight, - this.toolStripStatusLabelBodyColor}); - this.statusStrip1.Location = new System.Drawing.Point(0, 428); - this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Size = new System.Drawing.Size(800, 22); - this.statusStrip1.TabIndex = 9; - this.statusStrip1.Text = "statusStrip1"; - this.statusStrip1.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.statusStrip1_ItemClicked); - // - // toolStripStatusLabelSpeed - // - this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; - this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(39, 17); - this.toolStripStatusLabelSpeed.Text = "Speed"; - // - // toolStripStatusLabelWeight - // - this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; - this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(45, 17); - this.toolStripStatusLabelWeight.Text = "Weight"; - // - // toolStripStatusLabelBodyColor - // - this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; - this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17); - this.toolStripStatusLabelBodyColor.Text = "Color"; - // - // buttonCreateModif - // - this.buttonCreateModif.BackColor = System.Drawing.SystemColors.ControlLight; - this.buttonCreateModif.Location = new System.Drawing.Point(138, 376); - this.buttonCreateModif.Name = "buttonCreateModif"; - this.buttonCreateModif.Size = new System.Drawing.Size(115, 47); - this.buttonCreateModif.TabIndex = 10; - this.buttonCreateModif.Text = "Modificate"; - this.buttonCreateModif.UseVisualStyleBackColor = false; - this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click); - // - // comboMapSelector - // - this.comboMapSelector.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboMapSelector.FormattingEnabled = true; - this.comboMapSelector.Items.AddRange(new object[] { - "Simple Map", - "Sky Map"}); - this.comboMapSelector.Location = new System.Drawing.Point(12, 12); - this.comboMapSelector.Name = "comboMapSelector"; - this.comboMapSelector.Size = new System.Drawing.Size(121, 23); - this.comboMapSelector.TabIndex = 11; - this.comboMapSelector.SelectedIndexChanged += new System.EventHandler(this.comboMapSelector_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.comboMapSelector); - this.Controls.Add(this.buttonCreateModif); - this.Controls.Add(this.buttonCreate); - this.Controls.Add(this.buttonLeft); - this.Controls.Add(this.buttonDown); - this.Controls.Add(this.buttonRight); - this.Controls.Add(this.buttonUp); - this.Controls.Add(this.statusStrip1); - this.Controls.Add(this.pictureBoxPlane); - this.Name = "FormMap"; - this.Text = "FormMap"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlane)).EndInit(); - this.statusStrip1.ResumeLayout(false); - this.statusStrip1.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - private Button buttonUp; - private Button buttonRight; - private Button buttonDown; - private Button buttonLeft; - private Button buttonCreate; - private PictureBox pictureBoxPlane; - private StatusStrip statusStrip1; - private ToolStripStatusLabel toolStripStatusLabelSpeed; - private ToolStripStatusLabel toolStripStatusLabelWeight; - private ToolStripStatusLabel toolStripStatusLabelBodyColor; - private Button buttonCreateModif; - private ComboBox comboMapSelector; - } -} \ No newline at end of file diff --git a/ProjectPlane/ProjectPlane/FormMap.cs b/ProjectPlane/ProjectPlane/FormMap.cs deleted file mode 100644 index 4ba845e..0000000 --- a/ProjectPlane/ProjectPlane/FormMap.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace ProjectPlane -{ - public partial class FormMap : Form - { - private AbstractMap _abstractMap; - public FormMap() - { - InitializeComponent(); - _abstractMap = new SimpleMap(); - } - - private void comboMapSelector_SelectedIndexChanged(object sender, EventArgs e) - { - switch (comboMapSelector.SelectedIndex) - { - case 0: - _abstractMap = new SimpleMap(); - break; - case 1: - _abstractMap = new SkyMap(); - break; - } - } - /// - private void SetData(DrawingPlane plane) - { - toolStripStatusLabelSpeed.Text = $"Speed: {plane.Plane.Speed}"; - toolStripStatusLabelWeight.Text = $"Weight: {plane.Plane.Weight}"; - toolStripStatusLabelBodyColor.Text = $"Color: {plane.Plane.BodyColor.Name}"; - pictureBoxPlane.Image = _abstractMap.CreateMap(pictureBoxPlane.Width, pictureBoxPlane.Height, - new DrawingObject(plane)); - } - - /// - /// "Обработка нажатия на кнопки движения" - /// - /// - /// - 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; - } - pictureBoxPlane.Image = _abstractMap?.MoveObject(dir); - } - private void buttonCreate_Click(object sender, EventArgs e) - { - Random rnd = new(); - var plane = new DrawingPlane(rnd.Next(300, 400), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - SetData(plane); - - } - - /// - /// Обработка нажатия кнопки "Модификация" - /// - /// - /// - private void buttonCreateModif_Click(object sender, EventArgs e) - { - Random rnd = new(); - var _plane = new DrawingWarPlane(rnd.Next(300, 400), 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)), Convert.ToBoolean(rnd.Next(0, 2))); - SetData(_plane); - } - - - } -} - diff --git a/ProjectPlane/ProjectPlane/FormMap.resx b/ProjectPlane/ProjectPlane/FormMap.resx deleted file mode 100644 index 5cb320f..0000000 --- a/ProjectPlane/ProjectPlane/FormMap.resx +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 - - - 17, 17 - - \ No newline at end of file diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs index b787796..f6e0526 100644 --- a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs +++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs @@ -26,14 +26,184 @@ /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// + private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.groupBoxTools = new System.Windows.Forms.GroupBox(); + this.buttonUp = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.buttonRemovePlane = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonAddPlane = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.SuspendLayout(); + // + // groupBoxTools + // + this.groupBoxTools.Controls.Add(this.buttonRight); + this.groupBoxTools.Controls.Add(this.buttonDown); + this.groupBoxTools.Controls.Add(this.buttonLeft); + this.groupBoxTools.Controls.Add(this.buttonUp); + this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); + this.groupBoxTools.Controls.Add(this.buttonRemovePlane); + this.groupBoxTools.Controls.Add(this.buttonShowStorage); + this.groupBoxTools.Controls.Add(this.buttonShowOnMap); + this.groupBoxTools.Controls.Add(this.buttonAddPlane); + this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap); + 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, 554); + this.groupBoxTools.TabIndex = 0; + this.groupBoxTools.TabStop = false; + this.groupBoxTools.Text = "Tools"; + // + // buttonUp + // + this.buttonUp.BackgroundImage = global::ProjectPlane.Properties.Resources.up; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(81, 445); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(48, 47); + this.buttonUp.TabIndex = 6; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 166); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23); + this.maskedTextBoxPosition.TabIndex = 2; + this.maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonRemovePlane + // + this.buttonRemovePlane.Location = new System.Drawing.Point(17, 195); + this.buttonRemovePlane.Name = "buttonRemovePlane"; + this.buttonRemovePlane.Size = new System.Drawing.Size(175, 35); + this.buttonRemovePlane.TabIndex = 3; + this.buttonRemovePlane.Text = "Remove plane"; + this.buttonRemovePlane.UseVisualStyleBackColor = true; + this.buttonRemovePlane.Click += new System.EventHandler(this.ButtonRemovePlane_Click); + // + // buttonShowStorage + // + this.buttonShowStorage.Location = new System.Drawing.Point(17, 287); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(175, 35); + this.buttonShowStorage.TabIndex = 4; + this.buttonShowStorage.Text = "Check storage"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // 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 = "Show map"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + // + // buttonAddPlane + // + this.buttonAddPlane.Location = new System.Drawing.Point(17, 106); + this.buttonAddPlane.Name = "buttonAddPlane"; + this.buttonAddPlane.Size = new System.Drawing.Size(175, 35); + this.buttonAddPlane.TabIndex = 1; + this.buttonAddPlane.Text = "Add plane"; + this.buttonAddPlane.UseVisualStyleBackColor = true; + this.buttonAddPlane.Click += new System.EventHandler(this.ButtonAddPlane_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Simple map"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 32); + 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); + // + // 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, 554); + this.pictureBox.TabIndex = 1; + this.pictureBox.TabStop = false; + // + // buttonLeft + // + this.buttonLeft.BackgroundImage = global::ProjectPlane.Properties.Resources.left; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(27, 495); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(48, 47); + this.buttonLeft.TabIndex = 7; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonDown + // + this.buttonDown.BackgroundImage = global::ProjectPlane.Properties.Resources.down; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(81, 495); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(48, 47); + this.buttonDown.TabIndex = 8; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonRight + // + this.buttonRight.BackgroundImage = global::ProjectPlane.Properties.Resources.right; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(135, 495); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(48, 47); + this.buttonRight.TabIndex = 9; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // FormMapWithSetPlanes + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; + this.ClientSize = new System.Drawing.Size(1015, 554); + this.Controls.Add(this.pictureBox); + this.Controls.Add(this.groupBoxTools); + this.Name = "FormMapWithSetPlanes"; + this.Text = "Map with object sets"; + this.groupBoxTools.ResumeLayout(false); + this.groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.ResumeLayout(false); + } #endregion + + private GroupBox groupBoxTools; + private PictureBox pictureBox; + private ComboBox comboBoxSelectorMap; + private Button buttonShowOnMap; + private Button buttonAddPlane; + private Button buttonShowStorage; + private Button buttonRemovePlane; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonUp; + private Button buttonRight; + private Button buttonDown; + private Button buttonLeft; } } \ No newline at end of file diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs index d50f5bc..02f0784 100644 --- a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs +++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs @@ -12,9 +12,150 @@ namespace ProjectPlane { public partial class FormMapWithSetPlanes : Form { + /// + /// Объект от класса карты с набором объектов + /// + private MapWithSetPlanesGeneric _mapPlanesCollectionGeneric; + /// + /// Конструктор + /// public FormMapWithSetPlanes() { InitializeComponent(); } + + /// + /// "Обработка нажатия на кнопки движения" + /// + /// + /// + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + switch (comboBoxSelectorMap.Text) + { + case "Simple map": + map = new SimpleMap(); + break; + } + if (map != null) + { + _mapPlanesCollectionGeneric = new MapWithSetPlanesGeneric( + pictureBox.Width, pictureBox.Height, map); + } + else + { + _mapPlanesCollectionGeneric = null; + } + } + /// + /// Добавление объекта + /// + /// + /// + private void ButtonAddPlane_Click(object sender, EventArgs e) + { + if (_mapPlanesCollectionGeneric == null) + { + return; + } + FormPlane form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + DrawingObject Plane = new(form.SelectedPlane); + if (_mapPlanesCollectionGeneric + Plane) + { + MessageBox.Show("Object added"); + pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Error with object adding"); + } + } + } + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemovePlane_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) + { + return; + } + if (MessageBox.Show("Remove object?", "Removing", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_mapPlanesCollectionGeneric - pos) + { + MessageBox.Show("Object removed"); + pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Error with object removing"); + } + } + /// + /// Вывод набора + /// + /// + /// + private void ButtonShowStorage_Click(object sender, EventArgs e) + { + if (_mapPlanesCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); + } + /// + /// Вывод карты + /// + /// + /// + private void ButtonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapPlanesCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapPlanesCollectionGeneric.ShowOnMap(); + } + /// + /// Перемещение + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_mapPlanesCollectionGeneric == 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 = _mapPlanesCollectionGeneric.MoveObject(dir); + } } } diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.resx b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.resx index 1af7de1..f298a7b 100644 --- a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.resx +++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.resx @@ -1,64 +1,4 @@ - - - + diff --git a/ProjectPlane/ProjectPlane/Program.cs b/ProjectPlane/ProjectPlane/Program.cs index bce2d5a..3fa0fe7 100644 --- a/ProjectPlane/ProjectPlane/Program.cs +++ b/ProjectPlane/ProjectPlane/Program.cs @@ -9,7 +9,7 @@ namespace ProjectPlane static void Main() { ApplicationConfiguration.Initialize(); - Application.Run(new FormMap()); + Application.Run(new FormMapWithSetPlanes()); } } } \ No newline at end of file From 6306f4c3b3bf62dfed94bbd476d3b00c3db2d66f Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Tue, 11 Oct 2022 11:45:41 +0400 Subject: [PATCH 4/6] =?UTF-8?q?=D0=B5=D1=89=D0=B5=20=D0=BD=D0=B5=D0=BC?= =?UTF-8?q?=D0=BD=D0=BE=D0=B6=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectPlane/ProjectPlane/AirfieldMap.cs | 60 ++++++++++++++++ .../FormMapWithSetPlanes.Designer.cs | 70 ++++++++++--------- .../ProjectPlane/FormMapWithSetPlanes.cs | 11 ++- ProjectPlane/ProjectPlane/FormPlane.cs | 25 +++++-- .../ProjectPlane/MapWithSetPlanesGeneric.cs | 25 +++++-- ProjectPlane/ProjectPlane/SetPlanesGeneric.cs | 58 +++++++++++---- 6 files changed, 188 insertions(+), 61 deletions(-) create mode 100644 ProjectPlane/ProjectPlane/AirfieldMap.cs diff --git a/ProjectPlane/ProjectPlane/AirfieldMap.cs b/ProjectPlane/ProjectPlane/AirfieldMap.cs new file mode 100644 index 0000000..2eeb115 --- /dev/null +++ b/ProjectPlane/ProjectPlane/AirfieldMap.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectPlane +{ + internal class AirfieldMap : AbstractMap + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.Black); + private readonly Brush lineColor = new SolidBrush(Color.Yellow); + /// + /// Цвет участка открытого + /// + private readonly Brush roadColor = new SolidBrush(Color.Gray); + + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + Point[] Triangle = new Point[3]; + Triangle[0].X = i * (int)_size_x; Triangle[0].Y = j * (int)_size_y; + Triangle[1].X = i * (int)_size_x + 8; Triangle[1].Y = j * (int)_size_y - 5; + Triangle[2].X = i * (int)_size_x + 8; Triangle[2].Y = j * (int)_size_y + 5; + g.FillPolygon(barrierColor, Triangle); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + + } + protected override void GenerateMap() + { + _map = new int[100, 100]; + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + int counter = 0; + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + + while (counter < 30) + { + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + counter++; + } + } + } + } +} diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs index f6e0526..527147e 100644 --- a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs +++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs @@ -30,6 +30,9 @@ private void InitializeComponent() { this.groupBoxTools = new System.Windows.Forms.GroupBox(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.buttonRemovePlane = new System.Windows.Forms.Button(); @@ -38,9 +41,6 @@ this.buttonAddPlane = new System.Windows.Forms.Button(); this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.pictureBox = new System.Windows.Forms.PictureBox(); - this.buttonLeft = new System.Windows.Forms.Button(); - this.buttonDown = new System.Windows.Forms.Button(); - this.buttonRight = new System.Windows.Forms.Button(); this.groupBoxTools.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.SuspendLayout(); @@ -65,6 +65,36 @@ this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Tools"; // + // buttonRight + // + this.buttonRight.BackgroundImage = global::ProjectPlane.Properties.Resources.right; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(135, 495); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(48, 47); + this.buttonRight.TabIndex = 9; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonDown + // + this.buttonDown.BackgroundImage = global::ProjectPlane.Properties.Resources.down; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(81, 495); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(48, 47); + this.buttonDown.TabIndex = 8; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonLeft + // + this.buttonLeft.BackgroundImage = global::ProjectPlane.Properties.Resources.left; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(27, 495); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(48, 47); + this.buttonLeft.TabIndex = 7; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // // buttonUp // this.buttonUp.BackgroundImage = global::ProjectPlane.Properties.Resources.up; @@ -129,7 +159,9 @@ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Simple map"}); + "Simple map", + "Sky map", + "Airfield map"}); this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 32); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23); @@ -145,36 +177,6 @@ this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // - // buttonLeft - // - this.buttonLeft.BackgroundImage = global::ProjectPlane.Properties.Resources.left; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(27, 495); - this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(48, 47); - this.buttonLeft.TabIndex = 7; - this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonDown - // - this.buttonDown.BackgroundImage = global::ProjectPlane.Properties.Resources.down; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(81, 495); - this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(48, 47); - this.buttonDown.TabIndex = 8; - this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonRight - // - this.buttonRight.BackgroundImage = global::ProjectPlane.Properties.Resources.right; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(135, 495); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(48, 47); - this.buttonRight.TabIndex = 9; - this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); - // // FormMapWithSetPlanes // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs index 02f0784..46feda5 100644 --- a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs +++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs @@ -37,7 +37,14 @@ namespace ProjectPlane case "Simple map": map = new SimpleMap(); break; + case "Sky map": + map = new SkyMap(); + break; + case "Airfield map": + map = new AirfieldMap(); + break; } + if (map != null) { _mapPlanesCollectionGeneric = new MapWithSetPlanesGeneric( @@ -63,7 +70,7 @@ namespace ProjectPlane if (form.ShowDialog() == DialogResult.OK) { DrawingObject Plane = new(form.SelectedPlane); - if (_mapPlanesCollectionGeneric + Plane) + if (_mapPlanesCollectionGeneric + Plane != -1) { MessageBox.Show("Object added"); pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); @@ -90,7 +97,7 @@ namespace ProjectPlane return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapPlanesCollectionGeneric - pos) + if (_mapPlanesCollectionGeneric - pos is not null) { MessageBox.Show("Object removed"); pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); diff --git a/ProjectPlane/ProjectPlane/FormPlane.cs b/ProjectPlane/ProjectPlane/FormPlane.cs index 76af002..bdb998f 100644 --- a/ProjectPlane/ProjectPlane/FormPlane.cs +++ b/ProjectPlane/ProjectPlane/FormPlane.cs @@ -58,8 +58,13 @@ private void buttonCreate_Click(object sender, EventArgs e) { Random rand = new Random(); - _plane = new DrawingPlane(rand.Next(200, 500), rand.Next(2000, 3000), - Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256))); + Color color = Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + _plane = new DrawingPlane(rand.Next(200, 500), rand.Next(2000, 3000), color); SetData(); Draw(); } @@ -76,9 +81,19 @@ private void buttonCreateModif_Click(object sender, EventArgs e) { Random rnd = new(); - _plane = new DrawingWarPlane(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)), + 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; + } + Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialogDop = new(); + if (dialogDop.ShowDialog() == DialogResult.OK) + { + dopColor = dialogDop.Color; + } + _plane = new DrawingWarPlane(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); SetData(); Draw(); diff --git a/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs b/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs index 336fe74..122d40d 100644 --- a/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs +++ b/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs @@ -55,7 +55,7 @@ namespace ProjectPlane /// /// /// - public static bool operator +(MapWithSetPlanesGeneric map, T plane) + public static int operator +(MapWithSetPlanesGeneric map, T plane) { return map._setPlanes.Insert(plane); } @@ -65,7 +65,7 @@ namespace ProjectPlane /// /// /// - public static bool operator -(MapWithSetPlanesGeneric map, int position) + public static T operator -(MapWithSetPlanesGeneric map, int position) { return map._setPlanes.Remove(position); } @@ -145,11 +145,16 @@ namespace ProjectPlane private void DrawBackground(Graphics g) { Pen pen = new(Color.Black, 3); + Pen pen2 = new(Color.Yellow, 8); + Brush grBrush = new SolidBrush(Color.Gray); 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, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight); + g.FillRectangle(grBrush, i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth, _placeSizeHeight); + g.DrawLine(pen2, i * _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight / 2, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight / 2); + } g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); } @@ -160,11 +165,21 @@ namespace ProjectPlane /// private void DrawPlanes(Graphics g) { + int width = _pictureWidth / _placeSizeWidth; + + int curWidth = 0; + int curHeight = 0; for (int i = 0; i < _setPlanes.Count; i++) { - // TODO установка позиции + _setPlanes.Get(i)?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 15, _pictureWidth, _pictureHeight); _setPlanes.Get(i)?.DrawingObject(g); } + if (curWidth < width) curWidth++; + else + { + curWidth = 0; + curHeight++; + } } } } diff --git a/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs b/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs index 568cca4..288a49c 100644 --- a/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs +++ b/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs @@ -29,10 +29,9 @@ namespace ProjectPlane /// /// Добавляемый самолет /// - public bool Insert(T plane) + public int Insert(T plane) { - // TODO вставка в начало набора - return true; + return Insert(plane, 0); } /// /// Добавление объекта в набор на конкретную позицию @@ -40,26 +39,52 @@ namespace ProjectPlane /// Добавляемый самолет /// Позиция /// - public bool Insert(T plane, int position) + public int Insert(T plane, int position) { - // TODO проверка позиции - // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // проверка, что после вставляемого элемента в массиве есть пустой элемент - // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента - // TODO вставка по позиции + bool isNull = false; + int nullElem = 0; + if (position < 0 || position >= Count) + { + return -1; + } + if (_places[position] == null) + { + _places[position] = plane; + return position; + } + for (int i = position + 1; i < Count; i ++) + { + if (_places[i] == null) + { + isNull = true; + nullElem = i; + break; + } + } + if (!isNull) + { + return -1; + } + for (int i = nullElem; i > position; i--) + { + _places[i] = _places[i - 1]; + } _places[position] = plane; - return true; + return position; } /// /// Удаление объекта из набора с конкретной позиции /// /// /// - public bool Remove(int position) + public T Remove(int position) { - // TODO проверка позиции - // TODO удаление объекта из массива, присовив элементу массива значение null - return true; + if (position < 0 || position >= Count) + { + return null; + } + _places[position] = null; + return _places[position]; } /// /// Получение объекта из набора по позиции @@ -68,7 +93,10 @@ namespace ProjectPlane /// public T Get(int position) { - // TODO проверка позиции + if (position < 0 || position >= Count) + { + return null; + } return _places[position]; } } From 4114801ea949317977509a117f1f79d7f1ddd9ce Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Tue, 11 Oct 2022 16:45:46 +0400 Subject: [PATCH 5/6] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB(?= =?UTF-8?q?=D0=B0)=20=D0=BD=D0=B0=20'ProjectPlane/ProjectPlane/MapWithSetP?= =?UTF-8?q?lanesGeneric.cs'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectPlane/MapWithSetPlanesGeneric.cs | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs b/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs index 122d40d..ddcf57b 100644 --- a/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs +++ b/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs @@ -69,6 +69,7 @@ namespace ProjectPlane { return map._setPlanes.Remove(position); } + /// /// Вывод всего набора объектов /// @@ -165,21 +166,26 @@ namespace ProjectPlane /// private void DrawPlanes(Graphics g) { - int width = _pictureWidth / _placeSizeWidth; + int width = _pictureWidth / _placeSizeWidth - 1; + int height = _pictureHeight / _placeSizeHeight - 1; - int curWidth = 0; - int curHeight = 0; for (int i = 0; i < _setPlanes.Count; i++) { - _setPlanes.Get(i)?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 15, _pictureWidth, _pictureHeight); + _setPlanes.Get(i)?.SetObject((width) * _placeSizeWidth + 10, (height) * _placeSizeHeight + 15, _pictureWidth, _pictureHeight); _setPlanes.Get(i)?.DrawingObject(g); + + if (width <= 0) + { + width = _pictureWidth / _placeSizeWidth - 1; + height--; + } + else + { + width--; + + } } - if (curWidth < width) curWidth++; - else - { - curWidth = 0; - curHeight++; - } + } } } From 01370364b68777aeae5719b9d2e66a9d52e8e44c Mon Sep 17 00:00:00 2001 From: devil_1nc Date: Wed, 12 Oct 2022 21:41:07 +0400 Subject: [PATCH 6/6] =?UTF-8?q?=D0=9D=D1=83=20=D0=B2=D1=81=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=80=D0=B0=20=D0=BF=D1=83=D0=BB=D0=BB=20=D1=80=D0=B5?= =?UTF-8?q?=D0=BA=D0=B2=D0=B5=D1=81=D1=82=20=D0=B4=D0=B5=D0=BB=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D1=85=D0=B8=D1=85=D0=B8=D1=85=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectPlane/ProjectPlane/AirfieldMap.cs | 60 ------------------- .../FormMapWithSetPlanes.Designer.cs | 3 +- .../ProjectPlane/FormMapWithSetPlanes.cs | 3 - ProjectPlane/ProjectPlane/SetPlanesGeneric.cs | 3 +- 4 files changed, 3 insertions(+), 66 deletions(-) delete mode 100644 ProjectPlane/ProjectPlane/AirfieldMap.cs diff --git a/ProjectPlane/ProjectPlane/AirfieldMap.cs b/ProjectPlane/ProjectPlane/AirfieldMap.cs deleted file mode 100644 index 2eeb115..0000000 --- a/ProjectPlane/ProjectPlane/AirfieldMap.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectPlane -{ - internal class AirfieldMap : AbstractMap - { - /// - /// Цвет участка закрытого - /// - private readonly Brush barrierColor = new SolidBrush(Color.Black); - private readonly Brush lineColor = new SolidBrush(Color.Yellow); - /// - /// Цвет участка открытого - /// - private readonly Brush roadColor = new SolidBrush(Color.Gray); - - protected override void DrawBarrierPart(Graphics g, int i, int j) - { - Point[] Triangle = new Point[3]; - Triangle[0].X = i * (int)_size_x; Triangle[0].Y = j * (int)_size_y; - Triangle[1].X = i * (int)_size_x + 8; Triangle[1].Y = j * (int)_size_y - 5; - Triangle[2].X = i * (int)_size_x + 8; Triangle[2].Y = j * (int)_size_y + 5; - g.FillPolygon(barrierColor, Triangle); - } - protected override void DrawRoadPart(Graphics g, int i, int j) - { - g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); - - } - protected override void GenerateMap() - { - _map = new int[100, 100]; - _size_x = (float)_width / _map.GetLength(0); - _size_y = (float)_height / _map.GetLength(1); - int counter = 0; - for (int i = 0; i < _map.GetLength(0); ++i) - { - for (int j = 0; j < _map.GetLength(1); ++j) - { - _map[i, j] = _freeRoad; - } - } - - while (counter < 30) - { - int x = _random.Next(0, 100); - int y = _random.Next(0, 100); - if (_map[x, y] == _freeRoad) - { - _map[x, y] = _barrier; - counter++; - } - } - } - } -} diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs index 527147e..a5413d9 100644 --- a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs +++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs @@ -160,8 +160,7 @@ this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.Items.AddRange(new object[] { "Simple map", - "Sky map", - "Airfield map"}); + "Sky map"}); this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 32); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23); diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs index 46feda5..5436a47 100644 --- a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs +++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs @@ -40,9 +40,6 @@ namespace ProjectPlane case "Sky map": map = new SkyMap(); break; - case "Airfield map": - map = new AirfieldMap(); - break; } if (map != null) diff --git a/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs b/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs index 288a49c..e84b88a 100644 --- a/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs +++ b/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs @@ -83,8 +83,9 @@ namespace ProjectPlane { return null; } + T temp = _places[position]; _places[position] = null; - return _places[position]; + return temp; } /// /// Получение объекта из набора по позиции