diff --git a/AirBomber/AirBomber/AbstractMap.cs b/AirBomber/AirBomber/AbstractMap.cs
new file mode 100644
index 0000000..78425d8
--- /dev/null
+++ b/AirBomber/AirBomber/AbstractMap.cs
@@ -0,0 +1,176 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirBomber
+{
+ internal abstract class AbstractMap
+ {
+ private IDrawningObject _drawningObject = null;
+ private Bitmap? _staticBitMap;
+ 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)
+ {
+ _staticBitMap = null;
+ _width = width;
+ _height = height;
+ _drawningObject = drawningObject;
+ GenerateMap();
+ while (!SetObjectOnMap())
+ {
+ GenerateMap();
+ }
+ return DrawMapWithObject();
+ }
+
+ /// Проверяет наличие непроходимых участков в заданной области
+ /// Заданная область
+ /// i-ый индекс первого барьера, который был найден в области
+ /// j-ый индекс первого барьера, который был найден в области
+ /// Есть ли барьеры
+ protected bool BarriersInArea(RectangleF area, ref int iBarrier, ref int jBarrier)
+ {
+ if (!(0 < area.Left && area.Right < _width && 0 < area.Top && area.Bottom < _height))
+ {
+ return true; // Если область попала за карту, считаем что она столкнулась с барьером
+ }
+ int rightArea = (int)Math.Ceiling(area.Right / _size_x);
+ int bottomArea = (int)Math.Ceiling(area.Bottom / _size_y);
+ for (int i = (int)(area.Left / _size_x); i < rightArea; i++)
+ {
+ for (int j = (int)(area.Top / _size_y); j < bottomArea; j++)
+ {
+ if (_map[i, j] == _barrier)
+ {
+ iBarrier = i;
+ jBarrier = j;
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ /// Проверяет наличие непроходимых участков в заданной области
+ /// Заданная область
+ /// Есть ли барьеры
+ protected bool BarriersInArea(RectangleF area)
+ {
+ int a = 0, b = 0;
+ return BarriersInArea(area, ref a, ref b);
+ }
+
+
+ public Bitmap MoveObject(Direction direction)
+ {
+ var rect = _drawningObject.GetCurrentPosition();
+ var step = _drawningObject.Step;
+ // Вычисляем области смещения объекта
+ RectangleF? area = null;
+ if (direction == Direction.Left)
+ area = new(rect.Left - step, rect.Top, step, rect.Height);
+ else if (direction == Direction.Right)
+ area = new(rect.Right, rect.Top, step, rect.Height);
+ else if (direction == Direction.Up)
+ area = new(rect.Left, rect.Top - step, rect.Width, step);
+ else if (direction == Direction.Down)
+ area = new(rect.Left, rect.Bottom, rect.Width, step);
+ if (area.HasValue && !BarriersInArea(area.Value))
+ {
+ _drawningObject.MoveObject(direction);
+ }
+ return DrawMapWithObject();
+ }
+ private bool SetObjectOnMap()
+ {
+ if (_drawningObject == null || _map == null)
+ {
+ return false;
+ }
+ int x = _random.Next(0, 10);
+ int y = _random.Next(0, 10);
+ _drawningObject.SetObject(x, y, _width, _height);
+
+ // Если натыкаемся на барьер помещаем левый верхний угол чуть ниже этого барьера
+ // если при этом выходим за карту, пермещаем правый нижный угол чуть выше этого барьера
+ // если объект выходит за карту, генирируем новые координаты рандомно
+ int currI = 0, currJ = 0;
+ var areaObject = _drawningObject.GetCurrentPosition();
+ int cntOut = 10000; // Количество итераций до выхода из цикла
+ while (BarriersInArea(areaObject, ref currI, ref currJ) && --cntOut >= 0)
+ {
+ if ((currJ + 1) * _size_y + areaObject.Height <= _height)
+ {
+ areaObject.Location = new PointF((currI + 1) * _size_x, (currJ + 1) * _size_y);
+ }
+ else if ((currI - 1) * _size_x - areaObject.Width >= 0)
+ {
+ areaObject = new((currI - 1) * _size_x - areaObject.Width, (currJ - 1) * _size_y - areaObject.Height, areaObject.Width, areaObject.Height);
+ }
+ else
+ {
+ areaObject.Location = new PointF(_random.Next(0, _width - (int)areaObject.Width),
+ _random.Next(0, _height - (int)areaObject.Height));
+ }
+ }
+ _drawningObject.SetObject((int)areaObject.X, (int)areaObject.Y, _width, _height);
+ return cntOut >= 0;
+ }
+ ///
+ /// Заполняет BitMap для отрисовки статичных объектов. Выполняется один раз при создании карты
+ ///
+ private void DrawMap()
+ {
+ if (_staticBitMap != null) return;
+ _staticBitMap = new(_width, _height);
+ Graphics gr = Graphics.FromImage(_staticBitMap);
+ 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);
+ }
+ }
+ }
+ }
+
+ private Bitmap DrawMapWithObject()
+ {
+ Bitmap bmp = new(_width, _height);
+ if (_drawningObject == null || _map == null)
+ {
+ return bmp;
+ }
+ Graphics gr = Graphics.FromImage(bmp);
+ if (_staticBitMap == null)
+ DrawMap();
+ if (_staticBitMap != null)
+ gr.DrawImage(_staticBitMap, 0, 0);
+ _drawningObject.DrawningObject(gr);
+ return bmp;
+ }
+
+ ///
+ /// Генерация карты. При перегрузки определить поля _map, _size_x, _size_y
+ ///
+ 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/AirBomber/AirBomber/Direction.cs b/AirBomber/AirBomber/Direction.cs
index 950a2d3..808d3d0 100644
--- a/AirBomber/AirBomber/Direction.cs
+++ b/AirBomber/AirBomber/Direction.cs
@@ -5,6 +5,7 @@
///
internal enum Direction
{
+ None = 0,
Up = 1,
Down = 2,
Left = 3,
diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs
new file mode 100644
index 0000000..2f5da52
--- /dev/null
+++ b/AirBomber/AirBomber/DrawningAirBomber.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirBomber
+{
+ internal class DrawningAirBomber : DrawningAirplane
+ {
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес самолета
+ /// Цвет обшивки
+ /// Дополнительный цвет
+ /// Признак наличия бомб
+ /// Признак наличия топливных баков
+ public DrawningAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool hasBombs, bool hasFuelTanks)
+ : base(speed, weight, bodyColor, 115, 155)
+ {
+ Airplane = new EntityAirBomber(speed, weight, bodyColor, dopColor, hasBombs, hasFuelTanks);
+ }
+
+ public override void DrawTransport(Graphics g)
+ {
+ if (Airplane is not EntityAirBomber airBomber)
+ {
+ return;
+ }
+
+ var x = _startPosX;
+ var y = _startPosY;
+ var w = _airplaneWidth;
+ var h = _airplaneHeight;
+ Brush brush = new SolidBrush(airBomber.DopColor);
+
+ if (airBomber.HasBombs) // Бомбы снизу рисуются сначала
+ {
+ DrawBomb(g, airBomber.DopColor, new RectangleF(x + w / 2 - 15, y + h / 2 - 19, 23, 10));
+ DrawBomb(g, airBomber.DopColor, new RectangleF(x + w / 2 - 15, y + h / 2 + 9, 23, 10));
+ }
+
+ base.DrawTransport(g);
+
+ if (airBomber.HasFuelTanks)
+ {
+ g.FillEllipse(brush, new RectangleF(x + w / 4, y + h / 2 - 6, w / 2.5f, 12));
+ }
+ }
+
+ private void DrawBomb(Graphics g, Color colorBomb, RectangleF r)
+ {
+ Pen pen = new(colorBomb);
+ pen.Width = r.Height / 3;
+ var widthTail = r.Width / 6;
+ g.FillEllipse(new SolidBrush(colorBomb), r.X, r.Y, r.Width - widthTail, r.Height); // Основание бомбы
+ // Хвост бомбы
+ var baseTail = new PointF(r.Right - widthTail, r.Y + r.Height / 2);
+ g.DrawLine(pen, baseTail, new PointF(r.Right, r.Top));
+ g.DrawLine(pen, baseTail, new PointF(r.Right, r.Bottom));
+ }
+ }
+}
diff --git a/AirBomber/AirBomber/DrawningAirplane.cs b/AirBomber/AirBomber/DrawningAirplane.cs
index 7fcb3d7..c9cf1dc 100644
--- a/AirBomber/AirBomber/DrawningAirplane.cs
+++ b/AirBomber/AirBomber/DrawningAirplane.cs
@@ -8,41 +8,55 @@
///
/// Класс-сущность
///
- public EntityAirplane Airplane { get; private set; }
+ public EntityAirplane Airplane { 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 _airplaneWidth = 110;
+ protected readonly int _airplaneWidth = 80;
///
/// Высота отрисовки самолета
///
- private readonly int _airplaneHeight = 140;
+ protected readonly int _airplaneHeight = 90;
///
/// Инициализация свойств
///
/// Скорость
/// Вес самолета
/// Цвет обшивки
- public void Init(int speed, float weight, Color bodyColor)
+ public DrawningAirplane(int speed, float weight, Color bodyColor)
{
- Airplane = new EntityAirplane();
- Airplane.Init(speed, weight, bodyColor);
+ Airplane = new EntityAirplane(speed, weight, bodyColor);
+ }
+
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес самолета
+ /// Цвет обшивки
+ /// Ширина отрисовки самолета
+ /// Высота отрисовки самолета
+ protected DrawningAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) :
+ this(speed, weight, bodyColor)
+ {
+ _airplaneWidth = airplaneWidth;
+ _airplaneHeight = airplaneHeight;
}
///
/// Установка позиции самолета
@@ -112,7 +126,7 @@
/// Отрисовка самолета
///
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
@@ -192,5 +206,14 @@
_startPosY = _pictureHeight.Value - _airplaneHeight;
}
}
+
+ ///
+ /// Получение текущей позиции объекта
+ ///
+ ///
+ public RectangleF GetCurrentPosition()
+ {
+ return new(_startPosX, _startPosY, _airplaneWidth, _airplaneHeight);
+ }
}
}
\ No newline at end of file
diff --git a/AirBomber/AirBomber/DrawningObject.cs b/AirBomber/AirBomber/DrawningObject.cs
new file mode 100644
index 0000000..d79a291
--- /dev/null
+++ b/AirBomber/AirBomber/DrawningObject.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirBomber
+{
+ internal class DrawningObject : IDrawningObject
+ {
+ private DrawningAirplane _airplane = null;
+
+ public DrawningObject(DrawningAirplane airplane)
+ {
+ _airplane = airplane;
+ }
+
+ public float Step => _airplane?.Airplane?.Step ?? 0;
+
+ public RectangleF GetCurrentPosition()
+ {
+ return _airplane.GetCurrentPosition();
+ }
+
+ public void MoveObject(Direction direction)
+ {
+ _airplane?.MoveTransport(direction);
+ }
+
+ public void SetObject(int x, int y, int width, int height)
+ {
+ _airplane.SetPosition(x, y, width, height);
+ }
+
+ void IDrawningObject.DrawningObject(Graphics g)
+ {
+ _airplane.DrawTransport(g);
+ }
+ }
+}
diff --git a/AirBomber/AirBomber/EntityAirBomber.cs b/AirBomber/AirBomber/EntityAirBomber.cs
new file mode 100644
index 0000000..6d5b03f
--- /dev/null
+++ b/AirBomber/AirBomber/EntityAirBomber.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirBomber
+{
+ internal class EntityAirBomber : EntityAirplane
+ {
+ ///
+ /// Дополнительный цвет
+ ///
+ public Color DopColor { get; private set; }
+ ///
+ /// Признак наличия бомб
+ ///
+ public bool HasBombs { get; private set; }
+ ///
+ /// Признак наличия топливных баков
+ ///
+ public bool HasFuelTanks { get; private set; }
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес самолета
+ /// Цвет обшивки самолета
+ /// Дополнительный цвет
+ /// Признак наличия бомб
+ /// Признак наличия топливных баков
+ public EntityAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool hasBombs, bool hasFuelTanks) :
+ base(speed, weight, bodyColor)
+ {
+ DopColor = dopColor;
+ HasBombs = hasBombs;
+ HasFuelTanks = hasFuelTanks;
+ }
+ }
+}
diff --git a/AirBomber/AirBomber/EntityAirplane.cs b/AirBomber/AirBomber/EntityAirplane.cs
index bd6810f..2869683 100644
--- a/AirBomber/AirBomber/EntityAirplane.cs
+++ b/AirBomber/AirBomber/EntityAirplane.cs
@@ -28,7 +28,7 @@
///
///
///
- public void Init(int speed, float weight, Color bodyColor)
+ public EntityAirplane(int speed, float weight, Color bodyColor)
{
Random rnd = new();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
diff --git a/AirBomber/AirBomber/FormAirBomber.Designer.cs b/AirBomber/AirBomber/FormAirBomber.Designer.cs
index 910628c..013e662 100644
--- a/AirBomber/AirBomber/FormAirBomber.Designer.cs
+++ b/AirBomber/AirBomber/FormAirBomber.Designer.cs
@@ -28,7 +28,7 @@
///
private void InitializeComponent()
{
- this.pictureBoxCar = new System.Windows.Forms.PictureBox();
+ this.pictureBoxAirplane = 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();
@@ -38,20 +38,21 @@
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).BeginInit();
+ this.buttonCreateModif = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
//
- // pictureBoxCar
+ // pictureBoxAirplane
//
- this.pictureBoxCar.Dock = System.Windows.Forms.DockStyle.Fill;
- this.pictureBoxCar.Location = new System.Drawing.Point(0, 0);
- this.pictureBoxCar.Name = "pictureBoxCar";
- this.pictureBoxCar.Size = new System.Drawing.Size(800, 428);
- this.pictureBoxCar.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
- this.pictureBoxCar.TabIndex = 0;
- this.pictureBoxCar.TabStop = false;
- this.pictureBoxCar.Resize += new System.EventHandler(this.PictureBoxCar_Resize);
+ this.pictureBoxAirplane.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBoxAirplane.Location = new System.Drawing.Point(0, 0);
+ this.pictureBoxAirplane.Name = "pictureBoxAirplane";
+ this.pictureBoxAirplane.Size = new System.Drawing.Size(800, 428);
+ this.pictureBoxAirplane.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
+ this.pictureBoxAirplane.TabIndex = 0;
+ this.pictureBoxAirplane.TabStop = false;
+ this.pictureBoxAirplane.Resize += new System.EventHandler(this.PictureBoxAirplane_Resize);
//
// statusStrip
//
@@ -141,21 +142,33 @@
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(93, 390);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(108, 23);
+ this.buttonCreateModif.TabIndex = 8;
+ this.buttonCreateModif.Text = "Модификация";
+ this.buttonCreateModif.UseVisualStyleBackColor = true;
+ this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
+ //
// FormAirBomber
//
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);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonCreate);
- this.Controls.Add(this.pictureBoxCar);
+ this.Controls.Add(this.pictureBoxAirplane);
this.Controls.Add(this.statusStrip);
this.Name = "FormAirBomber";
this.Text = "Самолет";
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).EndInit();
this.statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout();
this.ResumeLayout(false);
@@ -165,7 +178,7 @@
#endregion
- private PictureBox pictureBoxCar;
+ private PictureBox pictureBoxAirplane;
private StatusStrip statusStrip;
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
@@ -175,5 +188,6 @@
private Button buttonLeft;
private Button buttonRight;
private Button buttonDown;
+ private Button buttonCreateModif;
}
}
\ No newline at end of file
diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs
index ecc8bd0..8eaaa46 100644
--- a/AirBomber/AirBomber/FormAirBomber.cs
+++ b/AirBomber/AirBomber/FormAirBomber.cs
@@ -9,14 +9,25 @@ namespace AirBomber
InitializeComponent();
}
///
- ///
+ ///
///
private void Draw()
{
- Bitmap bmp = new(pictureBoxCar.Width, pictureBoxCar.Height);
+ Bitmap bmp = new(pictureBoxAirplane.Width, pictureBoxAirplane.Height);
Graphics gr = Graphics.FromImage(bmp);
_airplane?.DrawTransport(gr);
- pictureBoxCar.Image = bmp;
+ pictureBoxAirplane.Image = bmp;
+ }
+ ///
+ ///
+ ///
+ private void SetData()
+ {
+ Random rnd = new();
+ _airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
+ toolStripStatusLabelSpeed.Text = $": {_airplane.Airplane.Speed}";
+ toolStripStatusLabelWeight.Text = $": {_airplane.Airplane.Weight}";
+ toolStripStatusLabelBodyColor.Text = $": {_airplane.Airplane.BodyColor.Name}";
}
///
/// ""
@@ -26,12 +37,8 @@ namespace AirBomber
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
- _airplane = new DrawningAirplane();
- _airplane.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
- _airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height);
- toolStripStatusLabelSpeed.Text = $": {_airplane.Airplane.Speed}";
- toolStripStatusLabelWeight.Text = $": {_airplane.Airplane.Weight}";
- toolStripStatusLabelBodyColor.Text = $": {_airplane.Airplane.BodyColor.Name}";
+ _airplane = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ SetData();
Draw();
}
///
@@ -65,9 +72,24 @@ namespace AirBomber
///
///
///
- private void PictureBoxCar_Resize(object sender, EventArgs e)
+ private void PictureBoxAirplane_Resize(object sender, EventArgs e)
{
- _airplane?.ChangeBorders(pictureBoxCar.Width, pictureBoxCar.Height);
+ _airplane?.ChangeBorders(pictureBoxAirplane.Width, pictureBoxAirplane.Height);
+ Draw();
+ }
+ ///
+ /// ""
+ ///
+ ///
+ ///
+ private void buttonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ _airplane = new DrawningAirBomber(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();
}
}
diff --git a/AirBomber/AirBomber/FormMap.Designer.cs b/AirBomber/AirBomber/FormMap.Designer.cs
new file mode 100644
index 0000000..6781998
--- /dev/null
+++ b/AirBomber/AirBomber/FormMap.Designer.cs
@@ -0,0 +1,208 @@
+namespace AirBomber
+{
+ 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.pictureBoxAirplane = 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.pictureBoxAirplane)).BeginInit();
+ this.statusStrip.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // pictureBoxAirplane
+ //
+ this.pictureBoxAirplane.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBoxAirplane.Location = new System.Drawing.Point(0, 0);
+ this.pictureBoxAirplane.Name = "pictureBoxAirplane";
+ this.pictureBoxAirplane.Size = new System.Drawing.Size(800, 428);
+ this.pictureBoxAirplane.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
+ this.pictureBoxAirplane.TabIndex = 0;
+ this.pictureBoxAirplane.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::AirBomber.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::AirBomber.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::AirBomber.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::AirBomber.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.pictureBoxAirplane);
+ this.Controls.Add(this.statusStrip);
+ this.Name = "FormMap";
+ this.Text = "Карта";
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).EndInit();
+ this.statusStrip.ResumeLayout(false);
+ this.statusStrip.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private PictureBox pictureBoxAirplane;
+ 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/AirBomber/AirBomber/FormMap.cs b/AirBomber/AirBomber/FormMap.cs
new file mode 100644
index 0000000..8bd4c48
--- /dev/null
+++ b/AirBomber/AirBomber/FormMap.cs
@@ -0,0 +1,96 @@
+using AirBomber;
+
+namespace AirBomber
+{
+ public partial class FormMap : Form
+ {
+ private AbstractMap _abstractMap;
+
+ public FormMap()
+ {
+ InitializeComponent();
+ _abstractMap = new SimpleMap();
+ }
+ ///
+ /// Заполнение информации по объекту
+ ///
+ ///
+ private void SetData(DrawningAirplane airplane)
+ {
+ toolStripStatusLabelSpeed.Text = $"Скорость: {airplane.Airplane.Speed}";
+ toolStripStatusLabelWeight.Text = $"Вес: {airplane.Airplane.Weight}";
+ toolStripStatusLabelBodyColor.Text = $"Цвет: {airplane.Airplane.BodyColor.Name}";
+ pictureBoxAirplane.Image = _abstractMap.CreateMap(pictureBoxAirplane.Width, pictureBoxAirplane.Height,
+ new DrawningObject(airplane));
+ }
+ ///
+ /// Обработка нажатия кнопки "Создать"
+ ///
+ ///
+ ///
+ private void ButtonCreate_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ var airplane = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ SetData(airplane);
+ }
+ ///
+ /// Изменение размеров формы
+ ///
+ ///
+ ///
+ 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;
+ }
+ pictureBoxAirplane.Image = _abstractMap?.MoveObject(dir);
+ }
+ ///
+ /// Обработка нажатия кнопки "Модификация"
+ ///
+ ///
+ ///
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ var airplane = new DrawningAirBomber(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(airplane);
+ }
+ ///
+ /// Смена карты
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorMap.Text)
+ {
+ case "Простая карта":
+ _abstractMap = new SimpleMap();
+ break;
+ case "Карта со стенами":
+ _abstractMap = new WallMap();
+ break;
+ }
+ }
+ }
+}
diff --git a/AirBomber/AirBomber/FormMap.resx b/AirBomber/AirBomber/FormMap.resx
new file mode 100644
index 0000000..2c0949d
--- /dev/null
+++ b/AirBomber/AirBomber/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/AirBomber/AirBomber/IDrawningObject.cs b/AirBomber/AirBomber/IDrawningObject.cs
new file mode 100644
index 0000000..6077012
--- /dev/null
+++ b/AirBomber/AirBomber/IDrawningObject.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirBomber
+{
+ ///
+ /// Интерфейс для работы с объектом, прорисовываемым на форме
+ ///
+ 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();
+ }
+}
diff --git a/AirBomber/AirBomber/Program.cs b/AirBomber/AirBomber/Program.cs
index 76b85fe..e462fb5 100644
--- a/AirBomber/AirBomber/Program.cs
+++ b/AirBomber/AirBomber/Program.cs
@@ -11,7 +11,7 @@ namespace AirBomber
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormAirBomber());
+ Application.Run(new FormMap());
}
}
}
\ No newline at end of file
diff --git a/AirBomber/AirBomber/SimpleMap.cs b/AirBomber/AirBomber/SimpleMap.cs
new file mode 100644
index 0000000..63bb878
--- /dev/null
+++ b/AirBomber/AirBomber/SimpleMap.cs
@@ -0,0 +1,50 @@
+namespace AirBomber
+{
+ ///
+ /// Простая реализация абсрактного класса 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, i * (_size_x + 1), j * (_size_y + 1));
+ }
+ 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 < 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/AirBomber/AirBomber/WallMap.cs b/AirBomber/AirBomber/WallMap.cs
new file mode 100644
index 0000000..8cb7989
--- /dev/null
+++ b/AirBomber/AirBomber/WallMap.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirBomber
+{
+ internal class WallMap : AbstractMap
+ {
+ ///
+ /// Цвет участка закрытого
+ ///
+ private readonly Brush barrierColor = new SolidBrush(Color.Brown);
+ ///
+ /// Цвет участка открытого
+ ///
+ private readonly Brush roadColor = new SolidBrush(Color.LightPink);
+ protected override void DrawBarrierPart(Graphics g, int i, int j)
+ {
+ g.FillPolygon(barrierColor, new PointF[]
+ {
+ new PointF(i * _size_x, j * _size_y),
+ new PointF((i + 1) * _size_x, j * _size_y),
+ new PointF((i + 1) * _size_x - _size_x / 4, (j + 1) * _size_y - _size_y / 2),
+ new PointF((i + 1) * _size_x, (j + 1) * _size_y),
+ new PointF(i * _size_x, (j + 1) * _size_y),
+ new PointF(i * _size_x + _size_x / 4, (j + 1) * _size_y - _size_y / 2),
+ });
+ }
+
+ protected override void DrawRoadPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(roadColor, i * _size_x, j * _size_y, (i + 1) * _size_x, (j + 1) * _size_y);
+ }
+
+ protected override void GenerateMap()
+ {
+ _map = new int[120, 120];
+ var minSize = Math.Min(_map.GetLength(0), _map.GetLength(1));
+ _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)
+ {
+ _map[i, j] = _freeRoad;
+ }
+ }
+ for (var i = 0; i < 10; i++)
+ {
+ var lengthWall = _random.Next(3, minSize / 2);
+ var incX = _random.Next(0, 2);
+ var incY = 1 - incX;
+ var left = _random.Next(0, _map.GetLength(0) - lengthWall);
+ var top = _random.Next(0, _map.GetLength(1) - lengthWall);
+ for (var j = 0; j < lengthWall; j++)
+ {
+ _map[left + incX * j, top + incY * j] = _barrier;
+ }
+ }
+
+ }
+ }
+}