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];
}
}