diff --git a/AirplaneWithRadar/AirplaneWithRadar/AirplaneWithRadar.csproj b/AirplaneWithRadar/AirplaneWithRadar/AirplaneWithRadar.csproj
index 20cd17e..0a3bc55 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/AirplaneWithRadar.csproj
+++ b/AirplaneWithRadar/AirplaneWithRadar/AirplaneWithRadar.csproj
@@ -9,9 +9,8 @@
-
-
+
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/AirplanesGenericCollection.cs b/AirplaneWithRadar/AirplaneWithRadar/AirplanesGenericCollection.cs
index 10d01c4..5f6614c 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/AirplanesGenericCollection.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/AirplanesGenericCollection.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -7,47 +6,95 @@ using System.Threading.Tasks;
using AirplaneWithRadar.PaintObjects;
using AirplaneWithRadar.MovementStrategy;
-namespace AirplaneWithRadar.Generics;
-
-internal class AirplanesGenericCollection
- where T : PaintAirplane
- where U : IMoveableObject
+namespace AirplaneWithRadar.Generics
{
- private readonly int pictWidth;
- private readonly int pictHeight;
- private readonly int placeSizeWidth = 210;
- private readonly int placeSizeHeight = 90;
- private readonly SetGeneric collection;
-
- public AirplanesGenericCollection(int picWidth, int picHeight)
+ internal class AirplanesGenericCollection
+ where T : PaintAirplane
+ where U : IMoveableObject
{
- int width = picWidth / placeSizeWidth;
- int height = picHeight / placeSizeHeight;
- pictWidth = picWidth;
- pictHeight = picHeight;
- collection = new SetGeneric(width * height);
+ private readonly int pictWidth;
+ private readonly int pictHeight;
+ private readonly int placeSizeWidth = 200;
+ private readonly int placeSizeHeight = 70;
+ private readonly SetGeneric collection;
- }
-
- public static bool operator +(AirplanesGenericCollection collect, T?
-obj)
- {
- if (obj == null)
+ public AirplanesGenericCollection(int picWidth, int picHeight)
{
- return false;
+ int width = picWidth / placeSizeWidth;
+ int height = picHeight / placeSizeHeight;
+ pictWidth = picWidth;
+ pictHeight = picHeight;
+ collection = new SetGeneric(width * height);
+
}
- return collect?.collection.Insert(obj) ?? false;
- }
- public static T? operator -(AirplanesGenericCollection collect, int
- pos)
- {
- T? obj = collect.collection.Get(pos);
- if (obj != null)
+
+ public static int? operator +(AirplanesGenericCollection collect, T? obj)
{
- collect.collection.Remove(pos);
+ if (obj == null)
+ {
+ return -1;
+ }
+ return collect?.collection.Insert(obj);
+ }
+ public static bool operator -(AirplanesGenericCollection collect, int pos)
+ {
+ T? obj = collect.collection.Get(pos);
+ if (obj == null)
+ {
+ return false;
+ }
+ return collect.collection.Remove(pos);
+ }
+
+ public U? GetU(int pos)
+ {
+ return (U?)collection.Get(pos)?.GetMoveableObject;
+ }
+
+ public Bitmap ShowAirplanes()
+ {
+ Bitmap bmp = new(pictWidth, pictHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawBackground(gr);
+ DrawObjects(gr);
+ return bmp;
+ }
+
+ private void DrawBackground(Graphics g)
+ {
+ Pen pen = new(Color.Black, 3);
+ for (int i = 0; i < pictWidth / placeSizeWidth; i++)
+ {
+ for (int j = 0; j < pictHeight / placeSizeHeight + 1; ++j)
+ {
+ g.DrawLine(pen, i * placeSizeWidth, j * placeSizeHeight, i * placeSizeWidth + placeSizeWidth / 2, j * placeSizeHeight);
+ }
+ g.DrawLine(pen, i * placeSizeWidth, 0, i * placeSizeWidth, pictHeight / placeSizeHeight * placeSizeHeight);
+ }
+ }
+ private void DrawObjects(Graphics g)
+ {
+ int width = pictWidth / placeSizeWidth;
+ int height = pictHeight / placeSizeHeight;
+
+ int j = 3;
+ int k = 0;
+
+ for (int i = 0; i < collection.Count; i++)
+ {
+ PaintAirplane? airplane = collection.Get(i);
+ if (j < 0)
+ {
+ j += 4;
+ k++;
+ }
+ if (airplane != null)
+ {
+ airplane.SetPosition(placeSizeWidth * j, placeSizeHeight * k);
+ airplane.DrawTransport(g);
+ }
+ j--;
+ }
}
- return obj;
}
-
-
}
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.Designer.cs
new file mode 100644
index 0000000..2c0f837
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.Designer.cs
@@ -0,0 +1,124 @@
+namespace AirplaneWithRadar
+{
+ partial class FormAirplaneCollection
+ {
+ ///
+ /// 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()
+ {
+ groupBox1 = new GroupBox();
+ maskedTextBoxNumber = new TextBox();
+ ButtonRefreshCollection = new Button();
+ ButtonDeleteAirplane = new Button();
+ ButtonAddAirplane = new Button();
+ pictureBoxCollection = new PictureBox();
+ groupBox1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
+ SuspendLayout();
+ //
+ // groupBox1
+ //
+ groupBox1.Controls.Add(maskedTextBoxNumber);
+ groupBox1.Controls.Add(ButtonRefreshCollection);
+ groupBox1.Controls.Add(ButtonDeleteAirplane);
+ groupBox1.Controls.Add(ButtonAddAirplane);
+ groupBox1.Location = new Point(749, 9);
+ groupBox1.Name = "groupBox1";
+ groupBox1.Size = new Size(223, 440);
+ groupBox1.TabIndex = 0;
+ groupBox1.TabStop = false;
+ groupBox1.Text = "Инструменты";
+ //
+ // maskedTextBoxNumber
+ //
+ maskedTextBoxNumber.Location = new Point(39, 148);
+ maskedTextBoxNumber.Name = "maskedTextBoxNumber";
+ maskedTextBoxNumber.Size = new Size(161, 23);
+ maskedTextBoxNumber.TabIndex = 3;
+ //
+ // ButtonRefreshCollection
+ //
+ ButtonRefreshCollection.Location = new Point(20, 229);
+ ButtonRefreshCollection.Name = "ButtonRefreshCollection";
+ ButtonRefreshCollection.Size = new Size(194, 46);
+ ButtonRefreshCollection.TabIndex = 2;
+ ButtonRefreshCollection.Text = "Обновить коллекцию";
+ ButtonRefreshCollection.UseVisualStyleBackColor = true;
+ ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
+ //
+ // ButtonDeleteAirplane
+ //
+ ButtonDeleteAirplane.Location = new Point(20, 177);
+ ButtonDeleteAirplane.Name = "ButtonDeleteAirplane";
+ ButtonDeleteAirplane.Size = new Size(194, 46);
+ ButtonDeleteAirplane.TabIndex = 1;
+ ButtonDeleteAirplane.Text = "Удалить самолёт";
+ ButtonDeleteAirplane.UseVisualStyleBackColor = true;
+ ButtonDeleteAirplane.Click += ButtonDeleteAirplane_Click;
+ //
+ // ButtonAddAirplane
+ //
+ ButtonAddAirplane.Location = new Point(20, 22);
+ ButtonAddAirplane.Name = "ButtonAddAirplane";
+ ButtonAddAirplane.Size = new Size(194, 46);
+ ButtonAddAirplane.TabIndex = 0;
+ ButtonAddAirplane.Text = "Добавить самолёт";
+ ButtonAddAirplane.UseVisualStyleBackColor = true;
+ ButtonAddAirplane.Click += ButtonAddAirplane_Click;
+ //
+ // pictureBoxCollection
+ //
+ pictureBoxCollection.Dock = DockStyle.Fill;
+ pictureBoxCollection.Location = new Point(0, 0);
+ pictureBoxCollection.Name = "pictureBoxCollection";
+ pictureBoxCollection.Size = new Size(984, 461);
+ pictureBoxCollection.TabIndex = 1;
+ pictureBoxCollection.TabStop = false;
+ //
+ // FormAirplaneCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(984, 461);
+ Controls.Add(groupBox1);
+ Controls.Add(pictureBoxCollection);
+ Name = "FormAirplaneCollection";
+ Text = "FormAirplaneCollection";
+ groupBox1.ResumeLayout(false);
+ groupBox1.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBox1;
+ private Button ButtonRefreshCollection;
+ private Button ButtonDeleteAirplane;
+ private Button ButtonAddAirplane;
+ private PictureBox pictureBoxCollection;
+ private TextBox maskedTextBoxNumber;
+ }
+}
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs
new file mode 100644
index 0000000..e5b058a
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.cs
@@ -0,0 +1,69 @@
+using AirplaneWithRadar.Generics;
+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 AirplaneWithRadar.PaintObjects;
+using AirplaneWithRadar.MovementStrategy;
+
+
+namespace AirplaneWithRadar
+{
+ public partial class FormAirplaneCollection : Form
+ {
+ private readonly AirplanesGenericCollection airplanes;
+ public FormAirplaneCollection()
+ {
+ InitializeComponent();
+ airplanes = new AirplanesGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ }
+
+ private void ButtonAddAirplane_Click(object sender, EventArgs e)
+ {
+ PlaneVisual form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (airplanes + form.SelectedAirplane != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBoxCollection.Image = airplanes.ShowAirplanes();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+
+ }
+
+ private void ButtonDeleteAirplane_Click(object sender, EventArgs e)
+ {
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
+ if (airplanes - pos != false)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBoxCollection.Image = airplanes.ShowAirplanes();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+
+ }
+
+ private void ButtonRefreshCollection_Click(object sender, EventArgs e)
+ {
+ pictureBoxCollection.Image = airplanes.ShowAirplanes();
+
+ }
+ }
+}
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.resx b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneCollection.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/AirplaneWithRadar/AirplaneWithRadar/GenericClass.cs b/AirplaneWithRadar/AirplaneWithRadar/GenericClass.cs
new file mode 100644
index 0000000..b6660b9
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/GenericClass.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirplaneWithRadar
+{
+ internal class GenericClass
+ where T : AirplaneWithRadar.PaintObjects.PaintAirplaneWithRadar
+ {
+
+ }
+}
+
diff --git a/AirplaneWithRadar/AirplaneWithRadar/PaintAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/PaintAirplane.cs
index e2be915..e57be41 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/PaintAirplane.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/PaintAirplane.cs
@@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirplaneWithRadar.Entities;
+using AirplaneWithRadar.MovementStrategy;
namespace AirplaneWithRadar.PaintObjects
{
@@ -23,6 +24,8 @@ namespace AirplaneWithRadar.PaintObjects
public int GetWidth => planeWidth;
public int GetHeight => planeHeight;
+ public IMoveableObject GetMoveableObject => new PaintObjectAirplane(this);
+
public bool CanMove(Movement dir)
{
if (AirplaneEntity == null)
diff --git a/AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.Designer.cs
index 8309e97..0707816 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.Designer.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.Designer.cs
@@ -37,6 +37,7 @@
StrategyComboBox = new ComboBox();
StepButton = new Button();
CreateAirplaneButton = new Button();
+ buttonSelectAirplane = new Button();
((System.ComponentModel.ISupportInitialize)PlanesPictureBox).BeginInit();
SuspendLayout();
//
@@ -136,11 +137,22 @@
CreateAirplaneButton.UseVisualStyleBackColor = true;
CreateAirplaneButton.Click += CreateAirplaneButton_Click;
//
+ // buttonSelectAirplane
+ //
+ buttonSelectAirplane.Location = new Point(282, 391);
+ buttonSelectAirplane.Name = "buttonSelectAirplane";
+ buttonSelectAirplane.Size = new Size(120, 40);
+ buttonSelectAirplane.TabIndex = 9;
+ buttonSelectAirplane.Text = "Выбрать самолёт";
+ buttonSelectAirplane.UseVisualStyleBackColor = true;
+ buttonSelectAirplane.Click += buttonSelectAirplane_Click;
+ //
// PlaneVisual
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
+ Controls.Add(buttonSelectAirplane);
Controls.Add(CreateAirplaneButton);
Controls.Add(StepButton);
Controls.Add(StrategyComboBox);
@@ -167,5 +179,6 @@
private ComboBox StrategyComboBox;
private Button StepButton;
private Button CreateAirplaneButton;
+ private Button buttonSelectAirplane;
}
}
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.cs b/AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.cs
index e635d5f..f832066 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/PlaneVisual.cs
@@ -1,4 +1,5 @@
using System;
+using System.Drawing;
using AirplaneWithRadar.MovementStrategy;
using AirplaneWithRadar.PaintObjects;
@@ -8,7 +9,7 @@ namespace AirplaneWithRadar
{
private PaintAirplane? PaintPlanes;
private AbstractStrategy? abstractStrategy;
-
+ public PaintAirplane? SelectedAirplane { get; private set; }
private void Draw()
{
if (PaintPlanes == null)
@@ -23,7 +24,8 @@ namespace AirplaneWithRadar
public PlaneVisual()
{
InitializeComponent();
-
+ abstractStrategy = null;
+ SelectedAirplane = null;
}
private void buttonMove_Click(object sender, EventArgs e)
@@ -54,8 +56,22 @@ namespace AirplaneWithRadar
{
Random random = new Random();
- PaintPlanes = new PaintAirplaneWithRadar(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
- random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), true,
+
+ Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+
+ Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ dopColor = dialog.Color;
+ }
+
+ PaintPlanes = new PaintAirplaneWithRadar(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, true,
Convert.ToBoolean(random.Next(0, 2)), PlanesPictureBox.Width, PlanesPictureBox.Height);
PaintPlanes.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
@@ -64,7 +80,14 @@ namespace AirplaneWithRadar
private void CreateAirplaneButton_Click(object sender, EventArgs e)
{
Random random = new Random();
- PaintPlanes = new PaintAirplane(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+
+ Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+ PaintPlanes = new PaintAirplane(random.Next(100, 300), random.Next(1000, 3000), color,
PlanesPictureBox.Width, PlanesPictureBox.Height);
PaintPlanes.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
@@ -103,5 +126,12 @@ namespace AirplaneWithRadar
abstractStrategy = null;
}
}
+
+ private void buttonSelectAirplane_Click(object sender, EventArgs e)
+ {
+ SelectedAirplane = PaintPlanes;
+ DialogResult = DialogResult.OK;
+
+ }
}
}
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/Program.cs b/AirplaneWithRadar/AirplaneWithRadar/Program.cs
index bb8cbd8..ec2131f 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/Program.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/Program.cs
@@ -11,7 +11,7 @@ namespace AirplaneWithRadar
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new PlaneVisual());
+ Application.Run(new FormAirplaneCollection());
}
}
}
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/SetGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/SetGeneric.cs
index fa4cead..f7f03fb 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/SetGeneric.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/SetGeneric.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -10,44 +9,73 @@ internal class SetGeneric
where T : class
{
private readonly T?[] places;
- public int Count => places.Length;
+ public int Count => places.Length;
public SetGeneric(int count)
{
places = new T?[count];
}
- public bool Insert(T airplane)
+ public int Insert(T airplane)
{
- if (places[0] == null)
+ int emptyPosition = -1;
+ for (int i = 0; i < Count; i++)
{
- places[0] = airplane;
- }
- else
- {
- for (int i = Count - 1; i < 0; i--)
+ if (places[i] == null)
{
- places[i] = places[i - 1];
+ emptyPosition = i;
+ break;
}
- places[0] = airplane;
}
- return true;
+ if (emptyPosition < 0)
+ {
+ return -1;
+ }
+
+ for (int i = emptyPosition; i > 0; i--)
+ {
+ places[i] = places[i - 1];
+ }
+
+ places[0] = airplane;
+ return 0;
}
- public bool Insert(T airplane, int position)
+ public int Insert(T airplane, int position)
{
if (position > Count || position < 0)
{
- return false;
+ return -1;
}
- // TODO проверка, что элемент массива по этой позиции пустой, если нет, то
- // проверка, что после вставляемого элемента в массиве есть пустой элемент
- // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
- // TODO вставка по позиции
+ if (places[position] == null)
+ {
+ places[position] = airplane;
+ return position;
+ }
+
+ int emptyPosition = -1;
+ for (int i = position + 1; i < Count; i++)
+ {
+ if (places[i]==null)
+ {
+ emptyPosition = i;
+ break;
+ }
+ }
+ if (emptyPosition < 0)
+ {
+ return -1;
+ }
+
+ for (int i = emptyPosition; i > position; i--)
+ {
+ places[i] = places[i - 1];
+ }
+
places[position] = airplane;
- return true;
+ return position;
}
public bool Remove(int position)
{
- if (position > Count || position < 0)
+ if ((position >= Count && position < 0) || places[position] == null)
{
return false;
}
@@ -56,7 +84,7 @@ internal class SetGeneric
}
public T? Get(int position)
{
- if (position > Count || position < 0)
+ if (position >= Count && position < 0)
{
return null;
}