diff --git a/AirFighter/AirFighter/Direction.cs b/AirFighter/AirFighter/Direction.cs
index 6ce5485..1ec8a60 100644
--- a/AirFighter/AirFighter/Direction.cs
+++ b/AirFighter/AirFighter/Direction.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AirFighter
{
- internal enum Direction
+ public enum Direction
{
None,
Up,
diff --git a/AirFighter/AirFighter/DrawingAirFighter.cs b/AirFighter/AirFighter/DrawingAirFighter.cs
index 5580c95..d78274d 100644
--- a/AirFighter/AirFighter/DrawingAirFighter.cs
+++ b/AirFighter/AirFighter/DrawingAirFighter.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AirFighter
{
- internal class DrawingAirFighter
+ public class DrawingAirFighter
{
public EntityAirFighter AirFighter { get; protected set; }
@@ -91,6 +91,7 @@ namespace AirFighter
{
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
{
+ MessageBox.Show("test");
return;
}
diff --git a/AirFighter/AirFighter/EntityAirFighter.cs b/AirFighter/AirFighter/EntityAirFighter.cs
index 6a2e3e9..28792d1 100644
--- a/AirFighter/AirFighter/EntityAirFighter.cs
+++ b/AirFighter/AirFighter/EntityAirFighter.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AirFighter
{
- internal class EntityAirFighter
+ public class EntityAirFighter
{
public int Speed { get; private set; }
public float Weight { get; private set; }
diff --git a/AirFighter/AirFighter/FormAirFighter.Designer.cs b/AirFighter/AirFighter/FormAirFighter.Designer.cs
index 8bf5034..220b567 100644
--- a/AirFighter/AirFighter/FormAirFighter.Designer.cs
+++ b/AirFighter/AirFighter/FormAirFighter.Designer.cs
@@ -39,6 +39,7 @@
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.button1 = new System.Windows.Forms.Button();
+ this.buttonSelect = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
@@ -159,11 +160,23 @@
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.CreateModernButton_Click);
//
+ // buttonSelect
+ //
+ this.buttonSelect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonSelect.Location = new System.Drawing.Point(558, 389);
+ this.buttonSelect.Name = "buttonSelect";
+ this.buttonSelect.Size = new System.Drawing.Size(115, 29);
+ this.buttonSelect.TabIndex = 8;
+ this.buttonSelect.Text = "выбрать";
+ this.buttonSelect.UseVisualStyleBackColor = true;
+ this.buttonSelect.Click += new System.EventHandler(this.ButtonSelect_Click);
+ //
// FormAirFighter
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.buttonSelect);
this.Controls.Add(this.button1);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.RightButton);
@@ -195,5 +208,6 @@
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button button1;
+ private Button buttonSelect;
}
}
\ No newline at end of file
diff --git a/AirFighter/AirFighter/FormAirFighter.cs b/AirFighter/AirFighter/FormAirFighter.cs
index c5b8019..94c4189 100644
--- a/AirFighter/AirFighter/FormAirFighter.cs
+++ b/AirFighter/AirFighter/FormAirFighter.cs
@@ -4,6 +4,8 @@ namespace AirFighter
{
private DrawingAirFighter _airFighter;
+ public DrawingAirFighter SelectedAirFighter { get; private set; }
+
public FormAirFighter()
{
InitializeComponent();
@@ -19,9 +21,14 @@ namespace AirFighter
private void CreateButton_Click(object sender, EventArgs e)
{
Random rnd = new();
-
- _airFighter = new DrawingAirFighter(rnd.Next(100, 300), rnd.Next(1000, 2000),
- 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;
+ }
+ _airFighter = new DrawingAirFighter(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
_airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBox.Width, pictureBox.Height);
@@ -32,12 +39,21 @@ namespace AirFighter
private void CreateModernButton_Click(object sender, EventArgs e)
{
Random rnd = new();
-
- _airFighter = new DrawingModernAirFighter(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)),
- Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0,2)));
-
+ 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;
+ }
+ _airFighter = new DrawingModernAirFighter(rnd.Next(100, 300), rnd.Next(1000, 2000),
+ color, dopColor,
+ Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0,2)));
_airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBox.Width, pictureBox.Height);
@@ -77,6 +93,11 @@ namespace AirFighter
Draw();
}
+ private void ButtonSelect_Click(object sender, EventArgs e)
+ {
+ SelectedAirFighter = _airFighter;
+ DialogResult = DialogResult.OK;
+ }
public void Draw()
{
diff --git a/AirFighter/AirFighter/FormMapWithSetCars.Designer.cs b/AirFighter/AirFighter/FormMapWithSetCars.Designer.cs
new file mode 100644
index 0000000..78e9692
--- /dev/null
+++ b/AirFighter/AirFighter/FormMapWithSetCars.Designer.cs
@@ -0,0 +1,219 @@
+namespace AirFighter
+{
+ partial class FormMapWithSetCars
+ {
+ ///
+ /// 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.tools = new System.Windows.Forms.GroupBox();
+ this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
+ this.buttonRemove = new System.Windows.Forms.Button();
+ this.ButtonShowOnMap = new System.Windows.Forms.Button();
+ this.ButtonShowStorage = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
+ this.pictureBox = new System.Windows.Forms.PictureBox();
+ this.RightButton = new System.Windows.Forms.Button();
+ this.LeftButton = new System.Windows.Forms.Button();
+ this.UpButton = new System.Windows.Forms.Button();
+ this.DownButton = new System.Windows.Forms.Button();
+ this.tools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
+ this.SuspendLayout();
+ //
+ // tools
+ //
+ this.tools.Controls.Add(this.RightButton);
+ this.tools.Controls.Add(this.LeftButton);
+ this.tools.Controls.Add(this.UpButton);
+ this.tools.Controls.Add(this.DownButton);
+ this.tools.Controls.Add(this.maskedTextBoxPosition);
+ this.tools.Controls.Add(this.buttonRemove);
+ this.tools.Controls.Add(this.ButtonShowOnMap);
+ this.tools.Controls.Add(this.ButtonShowStorage);
+ this.tools.Controls.Add(this.buttonAdd);
+ this.tools.Controls.Add(this.comboBoxSelectorMap);
+ this.tools.Dock = System.Windows.Forms.DockStyle.Right;
+ this.tools.Location = new System.Drawing.Point(550, 0);
+ this.tools.Name = "tools";
+ this.tools.Size = new System.Drawing.Size(250, 450);
+ this.tools.TabIndex = 0;
+ this.tools.TabStop = false;
+ this.tools.Text = "Инструменты";
+ //
+ // maskedTextBoxPosition
+ //
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(3, 145);
+ this.maskedTextBoxPosition.Mask = "00";
+ this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ this.maskedTextBoxPosition.Size = new System.Drawing.Size(235, 27);
+ this.maskedTextBoxPosition.TabIndex = 5;
+ //
+ // buttonRemove
+ //
+ this.buttonRemove.Location = new System.Drawing.Point(3, 178);
+ this.buttonRemove.Name = "buttonRemove";
+ this.buttonRemove.Size = new System.Drawing.Size(235, 29);
+ this.buttonRemove.TabIndex = 4;
+ this.buttonRemove.Text = "Удалить";
+ this.buttonRemove.UseVisualStyleBackColor = true;
+ this.buttonRemove.Click += new System.EventHandler(this.ButtonRemoveCar_Click);
+ //
+ // ButtonShowOnMap
+ //
+ this.ButtonShowOnMap.Location = new System.Drawing.Point(3, 313);
+ this.ButtonShowOnMap.Name = "ButtonShowOnMap";
+ this.ButtonShowOnMap.Size = new System.Drawing.Size(235, 29);
+ this.ButtonShowOnMap.TabIndex = 3;
+ this.ButtonShowOnMap.Text = "Посмотреть карту";
+ this.ButtonShowOnMap.UseVisualStyleBackColor = true;
+ this.ButtonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
+ //
+ // ButtonShowStorage
+ //
+ this.ButtonShowStorage.Location = new System.Drawing.Point(3, 244);
+ this.ButtonShowStorage.Name = "ButtonShowStorage";
+ this.ButtonShowStorage.Size = new System.Drawing.Size(235, 29);
+ this.ButtonShowStorage.TabIndex = 2;
+ this.ButtonShowStorage.Text = "Посмотреть хранилище";
+ this.ButtonShowStorage.UseVisualStyleBackColor = true;
+ this.ButtonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(3, 91);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(235, 29);
+ this.buttonAdd.TabIndex = 1;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAddCar_Click);
+ //
+ // comboBoxSelectorMap
+ //
+ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.comboBoxSelectorMap.FormattingEnabled = true;
+ this.comboBoxSelectorMap.Items.AddRange(new object[] {
+ "Простая карта"});
+ this.comboBoxSelectorMap.Location = new System.Drawing.Point(3, 23);
+ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(235, 28);
+ 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(550, 450);
+ this.pictureBox.TabIndex = 1;
+ this.pictureBox.TabStop = false;
+ //
+ // RightButton
+ //
+ this.RightButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.RightButton.BackgroundImage = global::AirFighter.Properties.Resources.right;
+ this.RightButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.RightButton.Location = new System.Drawing.Point(148, 408);
+ this.RightButton.Name = "RightButton";
+ this.RightButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
+ this.RightButton.Size = new System.Drawing.Size(30, 30);
+ this.RightButton.TabIndex = 9;
+ this.RightButton.UseVisualStyleBackColor = true;
+ this.RightButton.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // LeftButton
+ //
+ this.LeftButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.LeftButton.BackgroundImage = global::AirFighter.Properties.Resources.left;
+ this.LeftButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.LeftButton.Location = new System.Drawing.Point(76, 408);
+ this.LeftButton.Name = "LeftButton";
+ this.LeftButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
+ this.LeftButton.Size = new System.Drawing.Size(30, 30);
+ this.LeftButton.TabIndex = 8;
+ this.LeftButton.UseVisualStyleBackColor = true;
+ this.LeftButton.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // UpButton
+ //
+ this.UpButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.UpButton.BackgroundImage = global::AirFighter.Properties.Resources.up;
+ this.UpButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.UpButton.Location = new System.Drawing.Point(112, 373);
+ this.UpButton.Name = "UpButton";
+ this.UpButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
+ this.UpButton.Size = new System.Drawing.Size(30, 30);
+ this.UpButton.TabIndex = 7;
+ this.UpButton.UseVisualStyleBackColor = true;
+ this.UpButton.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // DownButton
+ //
+ this.DownButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.DownButton.BackgroundImage = global::AirFighter.Properties.Resources.down;
+ this.DownButton.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.DownButton.Location = new System.Drawing.Point(112, 408);
+ this.DownButton.Name = "DownButton";
+ this.DownButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
+ this.DownButton.Size = new System.Drawing.Size(30, 30);
+ this.DownButton.TabIndex = 6;
+ this.DownButton.UseVisualStyleBackColor = true;
+ this.DownButton.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // FormMapWithSetCars
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.pictureBox);
+ this.Controls.Add(this.tools);
+ this.Name = "FormMapWithSetCars";
+ this.Text = "FormMapWithSetCars";
+ this.tools.ResumeLayout(false);
+ this.tools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private GroupBox tools;
+ private MaskedTextBox maskedTextBoxPosition;
+ private Button buttonRemove;
+ private Button ButtonShowOnMap;
+ private Button ButtonShowStorage;
+ private Button buttonAdd;
+ private ComboBox comboBoxSelectorMap;
+ private PictureBox pictureBox;
+ private Button RightButton;
+ private Button LeftButton;
+ private Button UpButton;
+ private Button DownButton;
+ }
+}
\ No newline at end of file
diff --git a/AirFighter/AirFighter/FormMapWithSetCars.cs b/AirFighter/AirFighter/FormMapWithSetCars.cs
new file mode 100644
index 0000000..134986f
--- /dev/null
+++ b/AirFighter/AirFighter/FormMapWithSetCars.cs
@@ -0,0 +1,159 @@
+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 AirFighter
+{
+ public partial class FormMapWithSetCars : Form
+ {
+ private MapWithSetCarsGeneric _mapCarsCollectionGeneric;
+ ///
+ /// Конструктор
+ ///
+ public FormMapWithSetCars()
+ {
+ InitializeComponent();
+ }
+ ///
+ /// Выбор карты
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ AbstractMap map = null;
+ switch (comboBoxSelectorMap.Text)
+ {
+ case "Простая карта":
+ map = new SimpleMap();
+ break;
+ }
+ if (map != null)
+ {
+ _mapCarsCollectionGeneric = new
+ MapWithSetCarsGeneric(
+ pictureBox.Width, pictureBox.Height, map);
+ }
+ else
+ {
+ _mapCarsCollectionGeneric = null;
+ }
+ }
+ ///
+ /// Добавление объекта
+ ///
+ ///
+ ///
+ private void ButtonAddCar_Click(object sender, EventArgs e)
+ {
+ if (_mapCarsCollectionGeneric == null)
+ {
+ return;
+ }
+ FormAirFighter form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ DrawingObjectAirFighter car = new(form.SelectedAirFighter);
+ if (_mapCarsCollectionGeneric + car != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _mapCarsCollectionGeneric.ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+ }
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void ButtonRemoveCar_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
+ {
+ return;
+ }
+ if (MessageBox.Show("Удалить объект?", "Удаление",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
+ if (_mapCarsCollectionGeneric - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _mapCarsCollectionGeneric.ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+ ///
+ /// Вывод набора
+ ///
+ ///
+ ///
+ private void ButtonShowStorage_Click(object sender, EventArgs e)
+ {
+ if (_mapCarsCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapCarsCollectionGeneric.ShowSet();
+ }
+ ///
+ /// Вывод карты
+ ///
+ ///
+ ///
+ private void ButtonShowOnMap_Click(object sender, EventArgs e)
+ {
+ if (_mapCarsCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapCarsCollectionGeneric.ShowOnMap();
+ }
+ ///
+ /// Перемещение
+ ///
+ ///
+ ///
+ private void ButtonMove_Click(object sender, EventArgs e)
+ {
+ if (_mapCarsCollectionGeneric == null)
+ {
+ return;
+ }
+ //получаем имя кнопки
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ Direction dir = Direction.None;
+ switch (name)
+ {
+ case "UpButton":
+ dir = Direction.Up;
+ break;
+ case "DownButton":
+ dir = Direction.Down;
+ break;
+ case "LeftButton":
+ dir = Direction.Left;
+ break;
+ case "RightButton":
+ dir = Direction.Right;
+ break;
+ }
+ pictureBox.Image = _mapCarsCollectionGeneric.MoveObject(dir);
+ }
+ }
+}
diff --git a/AirFighter/AirFighter/FormMapWithSetCars.resx b/AirFighter/AirFighter/FormMapWithSetCars.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/AirFighter/AirFighter/FormMapWithSetCars.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/AirFighter/AirFighter/MapWithSetCarsGeneric.cs b/AirFighter/AirFighter/MapWithSetCarsGeneric.cs
new file mode 100644
index 0000000..6999f07
--- /dev/null
+++ b/AirFighter/AirFighter/MapWithSetCarsGeneric.cs
@@ -0,0 +1,194 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirFighter
+{
+ internal class MapWithSetCarsGeneric
+ where T : class, IDrawingObject
+ where U : AbstractMap
+ {
+ ///
+ /// Ширина окна отрисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна отрисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Размер занимаемого объектом места (ширина)
+ ///
+ private readonly int _placeSizeWidth = 210;
+ ///
+ /// Размер занимаемого объектом места (высота)
+ ///
+ private readonly int _placeSizeHeight = 170;
+ ///
+ /// Набор объектов
+ ///
+ private readonly SetCarsGeneric _setCars;
+ ///
+ /// Карта
+ ///
+ private readonly U _map;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public MapWithSetCarsGeneric(int picWidth, int picHeight, U map)
+ {
+ int width = picWidth / _placeSizeWidth;
+ int height = picHeight / _placeSizeHeight;
+ _setCars = new SetCarsGeneric(width * height);
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _map = map;
+ }
+ ///
+ /// Перегрузка оператора сложения
+ ///
+ ///
+ ///
+ ///
+ public static int operator +(MapWithSetCarsGeneric map, T car)
+ {
+ return map._setCars.Insert(car);
+ }
+ ///
+ /// Перегрузка оператора вычитания
+ ///
+ ///
+ ///
+ ///
+ public static T operator -(MapWithSetCarsGeneric map, int
+ position)
+ {
+ return map._setCars.Remove(position);
+ }
+ ///
+ /// Вывод всего набора объектов
+ ///
+ ///
+ public Bitmap ShowSet()
+ {
+ Bitmap bmp = new(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawBackground(gr);
+ DrawCars(gr);
+ return bmp;
+ }
+ ///
+ /// Просмотр объекта на карте
+ ///
+ ///
+ public Bitmap ShowOnMap()
+ {
+ Shaking();
+ for (int i = 0; i < _setCars.Count; i++)
+ {
+ var car = _setCars.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 = _setCars.Count - 1;
+ for (int i = 0; i < _setCars.Count; i++)
+ {
+ if (_setCars.Get(i) == null)
+ {
+ for (; j > i; j--)
+ {
+ var car = _setCars.Get(j);
+ if (car != null)
+ {
+ _setCars.Insert(car, i);
+ _setCars.Remove(j);
+ break;
+ }
+ }
+ if (j <= i)
+ {
+ return;
+ }
+ }
+ }
+ }
+ ///
+ /// Метод отрисовки фона
+ ///
+ ///
+ private void DrawBackground(Graphics g)
+ {
+ Pen pen = new(Color.Black, 3);
+ Brush brownBrush = new SolidBrush(Color.FromArgb(255, 211, 136, 84));
+ Brush greyBrush = new SolidBrush(Color.FromArgb(255, 160, 160, 160));
+
+ Point[] angar =
+ {
+ new(0, _pictureHeight ),
+ new(0, _pictureHeight / 4 ),
+ new(_pictureWidth / 2 , 9),
+ new(_pictureWidth, _pictureHeight / 4 ),
+ new(_pictureWidth, _pictureHeight ),
+ };
+
+ g.FillPolygon(brownBrush, angar);
+ g.FillRectangle(greyBrush, _pictureWidth / 6, (_pictureHeight * 5) / 12, (_pictureWidth * 2) / 3, (_pictureHeight * 7) / 12);
+
+ 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 DrawCars(Graphics g)
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+
+ for (int i = 0; i < _setCars.Count; i++)
+ {
+ int x = i % width;
+ int y = i / width;
+
+ _setCars.Get(i)?.SetObject(x * _placeSizeWidth, y * _placeSizeHeight, _pictureWidth, _pictureHeight);
+ _setCars.Get(i)?.DrawningObject(g);
+ }
+ }
+ }
+}
diff --git a/AirFighter/AirFighter/Program.cs b/AirFighter/AirFighter/Program.cs
index b613151..a1208bc 100644
--- a/AirFighter/AirFighter/Program.cs
+++ b/AirFighter/AirFighter/Program.cs
@@ -11,7 +11,7 @@ namespace AirFighter
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormMap());
+ Application.Run(new FormMapWithSetCars());
}
}
}
\ No newline at end of file
diff --git a/AirFighter/AirFighter/SetCarsGeneric.cs b/AirFighter/AirFighter/SetCarsGeneric.cs
new file mode 100644
index 0000000..7031a28
--- /dev/null
+++ b/AirFighter/AirFighter/SetCarsGeneric.cs
@@ -0,0 +1,84 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirFighter
+{
+ internal class SetCarsGeneric
+ where T : class
+ {
+ ///
+ /// Массив объектов, которые храним
+ ///
+ private readonly T[] _places;
+ ///
+ /// Количество объектов в массиве
+ ///
+ public int Count => _places.Length;
+ ///
+ /// Конструктор
+ ///
+ ///
+ public SetCarsGeneric(int count)
+ {
+ _places = new T[count];
+ }
+ public int Insert(T car)
+ {
+ // TODO вставка в начало набора
+ for(int i = 0; i < _places.Length; i++)
+ {
+ if (_places[i] == null)
+ {
+ _places[i] = car;
+ return i;
+ }
+ }
+ return -1;
+ }
+ public int Insert(T car, int position)
+ {
+ // TODO проверка позиции
+ // TODO проверка, что элемент массива по этой позиции пустой, если нет, то
+ // проверка, что после вставляемого элемента в массиве есть пустой элемент
+ // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
+ // TODO вставка по позиции
+
+ int index = position;
+
+ while (_places[index] != null && index < _places.Length) index++;
+
+ if (index == _places.Length) return -1;
+ for (int i = index; i > position; --i) _places[i] = _places[i - 1];
+
+ _places[position] = car;
+ return position;
+ }
+ ///
+ /// Удаление объекта из набора с конкретной позиции
+ ///
+ ///
+ ///
+ public T Remove(int position)
+ {
+ // TODO проверка позиции
+ // TODO удаление объекта из массива, присовив элементу массива значение null
+ T res = _places[position];
+ _places[position] = null;
+ return res;
+ }
+ ///
+ /// Получение объекта из набора по позиции
+ ///
+ ///
+ ///
+ public T Get(int position)
+ {
+ // TODO проверка позиции
+ return _places[position];
+ }
+ }
+
+}