diff --git a/WarPlanes/WarPlanes/AbstractMap.cs b/WarPlanes/WarPlanes/AbstractMap.cs
new file mode 100644
index 0000000..90f92b0
--- /dev/null
+++ b/WarPlanes/WarPlanes/AbstractMap.cs
@@ -0,0 +1,107 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirFighter
+{
+ internal abstract class AbstractMap
+ {
+ private IDrawningObject _drawningObject = null;
+ protected int[,] _map = null;
+ protected int _width;
+ protected int _height;
+ protected float _size_x;
+ protected float _size_y;
+ protected readonly Random _random = new();
+ protected readonly int _freeRoad = 0;
+ protected readonly int _barrier = 1;
+
+ public Bitmap CreateMap(int width, int height, IDrawningObject drawningObject)
+ {
+ _width = width;
+ _height = height;
+ _drawningObject = drawningObject;
+ GenerateMap();
+ while (!SetObjectOnMap())
+ {
+ GenerateMap();
+ }
+ return DrawMapWithObject();
+ }
+ public Bitmap MoveObject(Direction direction)
+ {
+ RectangleF rectObject = _drawningObject.GetCurrentPosition();
+
+ if (direction == Direction.Up) rectObject.Y -= _drawningObject.Step;
+ else if (direction == Direction.Down) rectObject.Y += _drawningObject.Step;
+ else if (direction == Direction.Left) rectObject.X -= _drawningObject.Step;
+ else if (direction == Direction.Right) rectObject.X += _drawningObject.Step;
+
+ if(rectObject.X < 0 || rectObject.Right >= _width || rectObject.Y < 0 || rectObject.Bottom >= _height)
+ {
+ return DrawMapWithObject();
+ }
+ if (isCollision(rectObject))
+ {
+ _drawningObject.MoveObject(direction);
+ }
+ return DrawMapWithObject();
+ }
+ private bool isCollision (RectangleF rectObject)
+ {
+ for (int i = (int) Math.Clamp((rectObject.Left / _size_x),0, _width); i < MathF.Ceiling(rectObject.Right / _size_x); i++)
+ {
+ for (int j = (int)Math.Clamp((rectObject.Top / _size_y),0,_height); j < MathF.Ceiling(rectObject.Bottom / _size_y); j++)
+ {
+ if (_map[i, j] == _barrier)
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ private bool SetObjectOnMap()
+ {
+ if (_drawningObject == null || _map == null)
+ {
+ return false;
+ }
+ int x = _random.Next(0, 100);
+ int y = _random.Next(0, 100);
+ _drawningObject.SetObject(x, y, _width, _height);
+ return isCollision(_drawningObject.GetCurrentPosition());
+ }
+ private Bitmap DrawMapWithObject()
+ {
+ Bitmap bmp = new(_width, _height);
+ if (_drawningObject == null || _map == null)
+ {
+ return bmp;
+ }
+ Graphics gr = Graphics.FromImage(bmp);
+ for (int i = 0; i < _map.GetLength(0); ++i)
+ {
+ for (int j = 0; j < _map.GetLength(1); ++j)
+ {
+ if (_map[i, j] == _freeRoad)
+ {
+ DrawRoadPart(gr, i, j);
+ }
+ else if (_map[i, j] == _barrier)
+ {
+ DrawBarrierPart(gr, i, j);
+ }
+ }
+ }
+ _drawningObject.DrawningObject(gr);
+ return bmp;
+ }
+
+ protected abstract void GenerateMap();
+ protected abstract void DrawRoadPart(Graphics g, int i, int j);
+ protected abstract void DrawBarrierPart(Graphics g, int i, int j);
+ }
+}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/Direction.cs b/WarPlanes/WarPlanes/Direction.cs
index 1b5db87..b0777d9 100644
--- a/WarPlanes/WarPlanes/Direction.cs
+++ b/WarPlanes/WarPlanes/Direction.cs
@@ -5,6 +5,7 @@
///
internal enum Direction
{
+ None = 0,
Up = 1,
Down = 2,
Left = 3,
diff --git a/WarPlanes/WarPlanes/DrawningFighter.cs b/WarPlanes/WarPlanes/DrawningFighter.cs
new file mode 100644
index 0000000..4974d15
--- /dev/null
+++ b/WarPlanes/WarPlanes/DrawningFighter.cs
@@ -0,0 +1,73 @@
+namespace AirFighter
+{
+ internal class DrawningFighter : DrawningWarPlane
+ {
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес самолёта
+ /// Цвет самолёта
+ /// Дополнительный цвет
+ /// Признак наличия ракет
+ /// Признак наличия дополнительных крыльев
+ public DrawningFighter(int speed, float weight, Color bodyColor, Color dopColor, bool rocket, bool wing) :
+ base(speed, weight, bodyColor, 110, 60)
+ {
+ WarPlane = new EntityFighter(speed, weight, bodyColor, dopColor, rocket, wing);
+ }
+ public override void DrawTransport(Graphics g)
+ {
+ if (WarPlane is not EntityFighter Fighter)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush dopBrush = new SolidBrush(Fighter.DopColor);
+
+ if (Fighter.Rocket)
+ {
+ _startPosX -= 10;
+ _startPosY -= 5;
+ PointF[] point = new PointF[3];
+ //нижняя ракета
+ point[0] = new PointF(_startPosX + _warplaneWidth / 2, _startPosY + _warplaneHeight);
+ point[1] = new PointF(_startPosX + _warplaneWidth / 2, _startPosY + _warplaneHeight + _warplaneHeight / 15);
+ point[2] = new PointF(_startPosX + _warplaneWidth / 2 - 5, _startPosY + _warplaneHeight + _warplaneHeight / 30);
+ g.FillPolygon(dopBrush, point);
+ point[0] = new PointF(_startPosX + _warplaneWidth*3 / 4-2 , _startPosY + _warplaneHeight -4);
+ point[1] = new PointF(_startPosX + _warplaneWidth*3 / 4-2, _startPosY + _warplaneHeight + _warplaneHeight / 15 + 4);
+ point[2] = new PointF(_startPosX + _warplaneWidth * 3 / 4 - 8, _startPosY + _warplaneHeight + _warplaneHeight / 30);
+ g.FillPolygon(dopBrush, point);
+ g.FillRectangle(dopBrush, _startPosX + _warplaneWidth / 2, _startPosY + _warplaneHeight, _warplaneWidth/4, _warplaneHeight/15);
+
+ //верхняя ракета
+ point[0] = new PointF(_startPosX + _warplaneWidth / 2, _startPosY + _warplaneHeight / 15 + 1);
+ point[1] = new PointF(_startPosX + _warplaneWidth / 2, _startPosY + _warplaneHeight / 7.5F + 1);
+ point[2] = new PointF(_startPosX + _warplaneWidth / 2 - 5, _startPosY + _warplaneHeight / 11.25F +1);
+ g.FillPolygon(dopBrush, point);
+ point[0] = new PointF(_startPosX + _warplaneWidth * 3 / 4 - 2, _startPosY + _warplaneHeight / 15 -3);
+ point[1] = new PointF(_startPosX + _warplaneWidth * 3 / 4 - 2, _startPosY + _warplaneHeight / 7.5F + 5);
+ point[2] = new PointF(_startPosX + _warplaneWidth * 3 / 4 - 8, _startPosY + _warplaneHeight / 11.25F + 1 + _warplaneHeight / 30);
+ g.FillPolygon(dopBrush, point);
+ g.FillRectangle(dopBrush, _startPosX + _warplaneWidth / 2, _startPosY+ _warplaneHeight / 15+1, _warplaneWidth / 4, _warplaneHeight / 15);
+ _startPosX += 10;
+ _startPosY += 5;
+ }
+
+ base.DrawTransport(g);
+ if (Fighter.Wing)
+ {
+ //Задние Крьлья
+ PointF[] point = new PointF[5];
+ point[0] = new PointF(_startPosX + _warplaneWidth / 3, _startPosY + _warplaneHeight / 4);
+ point[1] = new PointF(_startPosX + _warplaneWidth / 3 + 5, _startPosY + _warplaneHeight / 4 );
+ point[2] = new PointF(_startPosX + _warplaneWidth / 3 + 10, _startPosY + _warplaneHeight / 2);
+ point[3] = new PointF(_startPosX + _warplaneWidth / 3 + 5, _startPosY + _warplaneHeight - _warplaneHeight / 4);
+ point[4] = new PointF(_startPosX + _warplaneWidth / 3, _startPosY + _warplaneHeight - _warplaneHeight / 4);
+ g.FillPolygon(dopBrush, point);
+ }
+ }
+ }
+}
diff --git a/WarPlanes/WarPlanes/DrawningObjectWarPlane.cs b/WarPlanes/WarPlanes/DrawningObjectWarPlane.cs
new file mode 100644
index 0000000..c8e2c7d
--- /dev/null
+++ b/WarPlanes/WarPlanes/DrawningObjectWarPlane.cs
@@ -0,0 +1,34 @@
+namespace AirFighter
+{
+ internal class DrawningObjectWarPlane : IDrawningObject
+ {
+ private DrawningWarPlane _warplane = null;
+
+ public DrawningObjectWarPlane(DrawningWarPlane warplane)
+ {
+ _warplane = warplane;
+ }
+
+ public float Step => _warplane?.WarPlane?.Step ?? 0;
+
+ public RectangleF GetCurrentPosition()
+ {
+ return _warplane?.GetCurrentPosition() ?? default;
+ }
+
+ public void MoveObject(Direction direction)
+ {
+ _warplane?.MoveTransport(direction);
+ }
+
+ public void SetObject(int x, int y, int width, int height)
+ {
+ _warplane.SetPosition(x, y, width, height);
+ }
+
+ void IDrawningObject.DrawningObject(Graphics g)
+ {
+ _warplane.DrawTransport(g);
+ }
+ }
+}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/DrawningWarPlane.cs b/WarPlanes/WarPlanes/DrawningWarPlane.cs
index c02d51a..3017cca 100644
--- a/WarPlanes/WarPlanes/DrawningWarPlane.cs
+++ b/WarPlanes/WarPlanes/DrawningWarPlane.cs
@@ -8,41 +8,54 @@
///
/// Класс-сущность
///
- public EntityWarPlane WarPlane { get; private set; }
+ public EntityWarPlane WarPlane { get; protected set; }
///
/// Левая координата отрисовки Военного самолёта
///
- private float _startPosX;
+ protected float _startPosX;
///
/// Верхняя кооридната отрисовки Военного самолёта
///
- private float _startPosY;
+ protected float _startPosY;
///
/// Ширина окна отрисовки
///
- private int? _pictureWidth = null;
+ protected int? _pictureWidth = null;
///
/// Высота окна отрисовки
///
- private int? _pictureHeight = null;
+ protected int? _pictureHeight = null;
///
/// Ширина отрисовки Военного самолёта
///
- private readonly int _warplaneWidth = 80;
+ protected readonly int _warplaneWidth = 80;
///
/// Высота отрисовки Военного самолёта
///
- private readonly int _warplaneHeight = 50;
+ protected readonly int _warplaneHeight = 50;
///
/// Инициализация свойств
///
/// Скорость
/// Вес Военного самолёта
/// Цвет Военного самолёта
- public void Init(int speed, float weight, Color bodyColor)
+ public DrawningWarPlane(int speed, float weight, Color bodyColor)
{
- WarPlane = new EntityWarPlane();
- WarPlane.Init(speed, weight, bodyColor);
+ WarPlane = new EntityWarPlane(speed, weight, bodyColor);
+ }
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес самолёта
+ /// Цвет кузова
+ /// Ширина отрисовки самолёта
+ /// Высота отрисовки самолёта
+ protected DrawningWarPlane(int speed, float weight, Color bodyColor, int warplaneWidth, int warplaneHeight) :
+ this(speed, weight, bodyColor)
+ {
+ _warplaneWidth = warplaneWidth;
+ _warplaneHeight = warplaneHeight;
}
///
/// Установка позиции Военного самолёта
@@ -110,7 +123,7 @@
/// Отрисовка самолёта
///
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
@@ -175,5 +188,13 @@
_startPosY = _pictureHeight.Value - _warplaneHeight;
}
}
+ ///
+ /// Получение текущей позиции объекта
+ ///
+ ///
+ public RectangleF GetCurrentPosition()
+ {
+ return new RectangleF(_startPosX, _startPosY, _warplaneWidth, _warplaneHeight);
+ }
}
}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/EntityFighter.cs b/WarPlanes/WarPlanes/EntityFighter.cs
new file mode 100644
index 0000000..c77b46b
--- /dev/null
+++ b/WarPlanes/WarPlanes/EntityFighter.cs
@@ -0,0 +1,37 @@
+namespace AirFighter
+{
+ ///
+ /// Класс-сущность "Истрибитель"
+ ///
+ internal class EntityFighter : EntityWarPlane
+ {
+ ///
+ /// Дополнительный цвет
+ ///
+ public Color DopColor { get; private set; }
+ ///
+ /// Признак наличия рокет
+ ///
+ public bool Rocket { get; private set; }
+ ///
+ /// Признак дополнительных крыльев
+ ///
+ public bool Wing { get; private set; }
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес самолёта
+ /// Цвет самолёта
+ /// Дополнительный цвет
+ /// Признак наличия ракет
+ /// Признак наличия дополнительных крыльев
+ public EntityFighter(int speed, float weight, Color bodyColor, Color dopColor, bool rocket, bool wing) :
+ base(speed, weight, bodyColor)
+ {
+ DopColor = dopColor;
+ Rocket = rocket;
+ Wing = wing;
+ }
+ }
+}
diff --git a/WarPlanes/WarPlanes/EntityWarPlane.cs b/WarPlanes/WarPlanes/EntityWarPlane.cs
index 2dbd039..f9823b0 100644
--- a/WarPlanes/WarPlanes/EntityWarPlane.cs
+++ b/WarPlanes/WarPlanes/EntityWarPlane.cs
@@ -28,7 +28,7 @@
///
///
///
- public void Init(int speed, float weight, Color bodyColor)
+ public EntityWarPlane(int speed, float weight, Color bodyColor)
{
Random rnd = new();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
diff --git a/WarPlanes/WarPlanes/FormMap.Designer.cs b/WarPlanes/WarPlanes/FormMap.Designer.cs
new file mode 100644
index 0000000..a2c54c1
--- /dev/null
+++ b/WarPlanes/WarPlanes/FormMap.Designer.cs
@@ -0,0 +1,207 @@
+namespace AirFighter
+{
+ 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);
+ }
+
+ #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.pictureBoxWarPlane = new System.Windows.Forms.PictureBox();
+ this.statusStrip = 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.buttonCreate = new System.Windows.Forms.Button();
+ this.buttonUp = new System.Windows.Forms.Button();
+ this.buttonLeft = new System.Windows.Forms.Button();
+ this.buttonRight = new System.Windows.Forms.Button();
+ this.buttonDown = new System.Windows.Forms.Button();
+ this.buttonCreateModif = new System.Windows.Forms.Button();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarPlane)).BeginInit();
+ this.statusStrip.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // pictureBoxWarPlane
+ //
+ this.pictureBoxWarPlane.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBoxWarPlane.Location = new System.Drawing.Point(0, 0);
+ this.pictureBoxWarPlane.Name = "pictureBoxWarPlane";
+ this.pictureBoxWarPlane.Size = new System.Drawing.Size(800, 428);
+ this.pictureBoxWarPlane.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
+ this.pictureBoxWarPlane.TabIndex = 0;
+ this.pictureBoxWarPlane.TabStop = false;
+ //
+ // statusStrip
+ //
+ this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripStatusLabelSpeed,
+ this.toolStripStatusLabelWeight,
+ this.toolStripStatusLabelBodyColor});
+ this.statusStrip.Location = new System.Drawing.Point(0, 428);
+ this.statusStrip.Name = "statusStrip";
+ this.statusStrip.Size = new System.Drawing.Size(800, 22);
+ this.statusStrip.TabIndex = 1;
+ //
+ // toolStripStatusLabelSpeed
+ //
+ this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
+ this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 17);
+ this.toolStripStatusLabelSpeed.Text = "Скорость:";
+ //
+ // toolStripStatusLabelWeight
+ //
+ this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
+ this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(29, 17);
+ this.toolStripStatusLabelWeight.Text = "Вес:";
+ //
+ // toolStripStatusLabelBodyColor
+ //
+ this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
+ this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
+ this.toolStripStatusLabelBodyColor.Text = "Цвет:";
+ //
+ // buttonCreate
+ //
+ this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonCreate.Location = new System.Drawing.Point(12, 390);
+ this.buttonCreate.Name = "buttonCreate";
+ this.buttonCreate.Size = new System.Drawing.Size(75, 23);
+ this.buttonCreate.TabIndex = 2;
+ this.buttonCreate.Text = "Создать";
+ this.buttonCreate.UseVisualStyleBackColor = true;
+ this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
+ //
+ // buttonUp
+ //
+ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.arrowUp;
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonUp.Location = new System.Drawing.Point(722, 350);
+ this.buttonUp.Name = "buttonUp";
+ this.buttonUp.Size = new System.Drawing.Size(30, 30);
+ this.buttonUp.TabIndex = 3;
+ this.buttonUp.UseVisualStyleBackColor = true;
+ this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonLeft
+ //
+ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonLeft.BackgroundImage = global::AirFighter.Properties.Resources.arrowLeft;
+ this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonLeft.Location = new System.Drawing.Point(686, 386);
+ this.buttonLeft.Name = "buttonLeft";
+ this.buttonLeft.Size = new System.Drawing.Size(30, 30);
+ this.buttonLeft.TabIndex = 4;
+ this.buttonLeft.UseVisualStyleBackColor = true;
+ this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonRight
+ //
+ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRight.BackgroundImage = global::AirFighter.Properties.Resources.arrowRight;
+ this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonRight.Location = new System.Drawing.Point(758, 386);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(30, 30);
+ this.buttonRight.TabIndex = 5;
+ this.buttonRight.UseVisualStyleBackColor = true;
+ this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonDown
+ //
+ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.arrowDown;
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonDown.Location = new System.Drawing.Point(722, 386);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(30, 30);
+ this.buttonDown.TabIndex = 6;
+ this.buttonDown.UseVisualStyleBackColor = true;
+ this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonCreateModif
+ //
+ this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonCreateModif.Location = new System.Drawing.Point(104, 390);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(110, 23);
+ this.buttonCreateModif.TabIndex = 7;
+ this.buttonCreateModif.Text = "Модификация";
+ this.buttonCreateModif.UseVisualStyleBackColor = true;
+ this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_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(12, 12);
+ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23);
+ this.comboBoxSelectorMap.TabIndex = 8;
+ this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_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.comboBoxSelectorMap);
+ this.Controls.Add(this.buttonCreateModif);
+ this.Controls.Add(this.buttonDown);
+ this.Controls.Add(this.buttonRight);
+ this.Controls.Add(this.buttonLeft);
+ this.Controls.Add(this.buttonUp);
+ this.Controls.Add(this.buttonCreate);
+ this.Controls.Add(this.pictureBoxWarPlane);
+ this.Controls.Add(this.statusStrip);
+ this.Name = "FormMap";
+ this.Text = "Карта";
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarPlane)).EndInit();
+ this.statusStrip.ResumeLayout(false);
+ this.statusStrip.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private PictureBox pictureBoxWarPlane;
+ private StatusStrip statusStrip;
+ private ToolStripStatusLabel toolStripStatusLabelSpeed;
+ private ToolStripStatusLabel toolStripStatusLabelWeight;
+ private ToolStripStatusLabel toolStripStatusLabelBodyColor;
+ private Button buttonCreate;
+ private Button buttonUp;
+ private Button buttonLeft;
+ private Button buttonRight;
+ private Button buttonDown;
+ private Button buttonCreateModif;
+ private ComboBox comboBoxSelectorMap;
+ }
+}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/FormMap.cs b/WarPlanes/WarPlanes/FormMap.cs
new file mode 100644
index 0000000..758f8b6
--- /dev/null
+++ b/WarPlanes/WarPlanes/FormMap.cs
@@ -0,0 +1,93 @@
+namespace AirFighter
+{
+ public partial class FormMap : Form
+ {
+ private AbstractMap _abstractMap;
+
+ public FormMap()
+ {
+ InitializeComponent();
+ _abstractMap = new SimpleMap();
+ }
+ ///
+ /// Заполнение информации по объекту
+ ///
+ ///
+ private void SetData(DrawningWarPlane warplane)
+ {
+ toolStripStatusLabelSpeed.Text = $"Скорость: {warplane.WarPlane.Speed}";
+ toolStripStatusLabelWeight.Text = $"Вес: {warplane.WarPlane.Weight}";
+ toolStripStatusLabelBodyColor.Text = $"Цвет: {warplane.WarPlane.BodyColor.Name}";
+ pictureBoxWarPlane.Image = _abstractMap.CreateMap(pictureBoxWarPlane.Width, pictureBoxWarPlane.Height, new DrawningObjectWarPlane(warplane));
+ }
+ ///
+ /// Обработка нажатия кнопки "Создать"
+ ///
+ ///
+ ///
+ private void ButtonCreate_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ var warplane = new DrawningWarPlane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ SetData(warplane);
+ }
+ ///
+ /// Изменение размеров формы
+ ///
+ ///
+ ///
+ 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;
+ }
+ pictureBoxWarPlane.Image = _abstractMap?.MoveObject(dir);
+ }
+ ///
+ /// Обработка нажатия кнопки "Модификация"
+ ///
+ ///
+ ///
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ var fighter = new DrawningFighter(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)));
+ SetData(fighter);
+ }
+ ///
+ /// Смена карты
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorMap.Text)
+ {
+ case "Простая карта":
+ _abstractMap = new SimpleMap();
+ break;
+ case "Закрытая карта":
+ _abstractMap = new CloseMap();
+ break;
+ }
+ }
+ }
+}
diff --git a/WarPlanes/WarPlanes/FormMap.resx b/WarPlanes/WarPlanes/FormMap.resx
new file mode 100644
index 0000000..2c0949d
--- /dev/null
+++ b/WarPlanes/WarPlanes/FormMap.resx
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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/WarPlanes/WarPlanes/FormWarPlane.Designer.cs b/WarPlanes/WarPlanes/FormWarPlane.Designer.cs
index 8393f09..1d258b2 100644
--- a/WarPlanes/WarPlanes/FormWarPlane.Designer.cs
+++ b/WarPlanes/WarPlanes/FormWarPlane.Designer.cs
@@ -38,6 +38,7 @@
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();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarPlane)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
@@ -141,11 +142,22 @@
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
this.toolStripStatusLabelBodyColor.Text = "Цвет:";
//
+ // buttonCreateModif
+ //
+ this.buttonCreateModif.Location = new System.Drawing.Point(104, 390);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(110, 23);
+ this.buttonCreateModif.TabIndex = 14;
+ this.buttonCreateModif.Text = "Модификация";
+ this.buttonCreateModif.UseVisualStyleBackColor = true;
+ this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
+ //
// FormWarPlane
//
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.buttonCreateModif);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
@@ -175,5 +187,6 @@
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
+ private Button buttonCreateModif;
}
}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/FormWarPlane.cs b/WarPlanes/WarPlanes/FormWarPlane.cs
index 5cfa58b..cdfd56f 100644
--- a/WarPlanes/WarPlanes/FormWarPlane.cs
+++ b/WarPlanes/WarPlanes/FormWarPlane.cs
@@ -19,6 +19,17 @@ namespace AirFighter
pictureBoxWarPlane.Image = bmp;
}
///
+ ///
+ ///
+ private void SetData()
+ {
+ Random rnd = new();
+ _warplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxWarPlane.Width, pictureBoxWarPlane.Height);
+ toolStripStatusLabelSpeed.Text = $": {_warplane.WarPlane.Speed}";
+ toolStripStatusLabelWeight.Text = $": {_warplane.WarPlane.Weight}";
+ toolStripStatusLabelBodyColor.Text = $": {_warplane.WarPlane.BodyColor.Name}";
+ }
+ ///
/// ""
///
///
@@ -26,12 +37,8 @@ namespace AirFighter
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
- _warplane = new DrawningWarPlane();
- _warplane.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
- _warplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxWarPlane.Width, pictureBoxWarPlane.Height);
- toolStripStatusLabelSpeed.Text = $": {_warplane.WarPlane.Speed}";
- toolStripStatusLabelWeight.Text = $": {_warplane.WarPlane.Weight}";
- toolStripStatusLabelBodyColor.Text = $": {_warplane.WarPlane.BodyColor.Name}";
+ _warplane = new DrawningWarPlane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ SetData();
Draw();
}
///
@@ -70,5 +77,20 @@ namespace AirFighter
_warplane?.ChangeBorders(pictureBoxWarPlane.Width, pictureBoxWarPlane.Height);
Draw();
}
+ ///
+ /// ""
+ ///
+ ///
+ ///
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ _warplane = new DrawningFighter(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)));
+ SetData();
+ Draw();
+ }
}
}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/IDrawningObject.cs b/WarPlanes/WarPlanes/IDrawningObject.cs
new file mode 100644
index 0000000..3d6457c
--- /dev/null
+++ b/WarPlanes/WarPlanes/IDrawningObject.cs
@@ -0,0 +1,34 @@
+namespace AirFighter
+{
+ internal interface IDrawningObject
+ {
+ ///
+ /// Шаг перемещения объекта
+ ///
+ public float Step { get; }
+ ///
+ /// Установка позиции объекта
+ ///
+ /// Координата X
+ /// Координата Y
+ /// Ширина полотна
+ /// Высота полотна
+ void SetObject(int x, int y, int width, int height);
+ ///
+ /// Изменение направления пермещения объекта
+ ///
+ /// Направление
+ ///
+ void MoveObject(Direction direction);
+ ///
+ /// Отрисовка объекта
+ ///
+ ///
+ void DrawningObject(Graphics g);
+ ///
+ /// Получение текущей позиции объекта
+ ///
+ ///
+ RectangleF GetCurrentPosition();
+ }
+}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/Program.cs b/WarPlanes/WarPlanes/Program.cs
index 8c689ac..b613151 100644
--- a/WarPlanes/WarPlanes/Program.cs
+++ b/WarPlanes/WarPlanes/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 FormWarPlane());
+ Application.Run(new FormMap());
}
}
}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/SimpleMap.cs b/WarPlanes/WarPlanes/SimpleMap.cs
new file mode 100644
index 0000000..7529e0c
--- /dev/null
+++ b/WarPlanes/WarPlanes/SimpleMap.cs
@@ -0,0 +1,50 @@
+namespace AirFighter
+{
+ ///
+ /// Простая реализация абсрактного класса AbstractMap
+ ///
+ internal class SimpleMap : AbstractMap
+ {
+ ///
+ /// Цвет участка закрытого
+ ///
+ private readonly Brush barrierColor = new SolidBrush(Color.Black);
+ ///
+ /// Цвет участка открытого
+ ///
+ private readonly Brush roadColor = new SolidBrush(Color.Gray);
+
+ protected override void DrawBarrierPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
+ }
+ protected override void DrawRoadPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
+ }
+ 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 < 50)
+ {
+ int x = _random.Next(0, 100);
+ int y = _random.Next(0, 100);
+ if (_map[x, y] == _freeRoad)
+ {
+ _map[x, y] = _barrier;
+ counter++;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/СloseMap.cs b/WarPlanes/WarPlanes/СloseMap.cs
new file mode 100644
index 0000000..83e09b2
--- /dev/null
+++ b/WarPlanes/WarPlanes/СloseMap.cs
@@ -0,0 +1,43 @@
+namespace AirFighter
+{
+ ///
+ /// Простая реализация абсрактного класса AbstractMap
+ ///
+ internal class CloseMap : AbstractMap
+ {
+ ///
+ /// Цвет участка закрытого
+ ///
+ private readonly Brush barrierColor = new SolidBrush(Color.Red);
+ ///
+ /// Цвет участка открытого
+ ///
+ private readonly Brush roadColor = new SolidBrush(Color.WhiteSmoke);
+
+ protected override void DrawBarrierPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
+ }
+ protected override void DrawRoadPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
+ }
+ protected override void GenerateMap()
+ {
+ _map = new int[100, 100];
+ _size_x = (float)_width / _map.GetLength(0);
+ _size_y = (float)_height / _map.GetLength(1);
+ for (int i = 0; i < _map.GetLength(0); ++i)
+ {
+ for (int j = 0; j < _map.GetLength(1); ++j)
+ {
+ if (i == 0 || j == 0 || i == _map.GetLength(0) - 1 || j == _map.GetLength(1) - 1)
+ _map[i, j] = _barrier;
+ else
+ _map[i, j] = _freeRoad;
+ }
+ }
+
+ }
+ }
+}
\ No newline at end of file