diff --git a/ProjectAirBomber/ProjectAirBomber/DirectionType.cs b/ProjectAirBomber/ProjectAirBomber/Drawnings/DirectionType.cs similarity index 90% rename from ProjectAirBomber/ProjectAirBomber/DirectionType.cs rename to ProjectAirBomber/ProjectAirBomber/Drawnings/DirectionType.cs index bd234d3..83700a7 100644 --- a/ProjectAirBomber/ProjectAirBomber/DirectionType.cs +++ b/ProjectAirBomber/ProjectAirBomber/Drawnings/DirectionType.cs @@ -1,4 +1,4 @@ -namespace ProjectAirBomber; +namespace ProjectAirBomber.Drawnings; /// /// Направление перемещения diff --git a/ProjectAirBomber/ProjectAirBomber/Drawnings/DrawningAirBomber.cs b/ProjectAirBomber/ProjectAirBomber/Drawnings/DrawningAirBomber.cs new file mode 100644 index 0000000..f9fc76c --- /dev/null +++ b/ProjectAirBomber/ProjectAirBomber/Drawnings/DrawningAirBomber.cs @@ -0,0 +1,75 @@ +using ProjectAirBomber.Entities; + +namespace ProjectAirBomber.Drawnings; + +/// +/// Класс, отвечающий за прорисовку и перемещение объекта-сущности +/// +public class DrawningAirBomber : DrawningBomber +{ + + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия дополнительных топливных баков + /// Признак наличия бомб + + + + + //TO DO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + public DrawningAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool fuelTanks, bool bombs, bool v) : base(200, 160) + { + EntityBomber = new EntityAirBomber(speed, weight, bodyColor, additionalColor, fuelTanks, bombs); + } + + + + public override void DrawTransport(Graphics g) + { + if (EntityBomber == null || EntityBomber is not EntityAirBomber airBomber || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(airBomber.AdditionalColor); + + // топливные баки + if (airBomber.FuelTanks) + { + g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 20, 20, 20); + g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 110, 20, 20); + } + + // бомбы + if (airBomber.Bombs) + { + g.FillPolygon(additionalBrush, new Point[] + { + new Point(_startPosX.Value + 110, _startPosY.Value + 42), + new Point(_startPosX.Value + 110, _startPosY.Value + 60), + new Point(_startPosX.Value + 80, _startPosY.Value + 50) + }); + + g.FillPolygon(additionalBrush, new Point[] + { + new Point(_startPosX.Value + 110, _startPosY.Value + 90), + new Point(_startPosX.Value + 110, _startPosY.Value + 108), + new Point(_startPosX.Value + 80, _startPosY.Value + 100) + }); + } + + _startPosX += 10; + _startPosY += 5; + base.DrawTransport(g); + _startPosX -= 10; + _startPosY -= 5; + + + } +} \ No newline at end of file diff --git a/ProjectAirBomber/ProjectAirBomber/DrawningAirBomber.cs b/ProjectAirBomber/ProjectAirBomber/Drawnings/DrawningBomber.cs similarity index 53% rename from ProjectAirBomber/ProjectAirBomber/DrawningAirBomber.cs rename to ProjectAirBomber/ProjectAirBomber/Drawnings/DrawningBomber.cs index 2aaf914..b7ea6ce 100644 --- a/ProjectAirBomber/ProjectAirBomber/DrawningAirBomber.cs +++ b/ProjectAirBomber/ProjectAirBomber/Drawnings/DrawningBomber.cs @@ -1,14 +1,18 @@ -namespace ProjectAirBomber; +using ProjectAirBomber.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; -/// -/// Класс, отвечающий за прорисовку и перемещение объекта-сущности -/// -public class DrawningAirBomber +namespace ProjectAirBomber.Drawnings; + +public class DrawningBomber { /// /// Класс-сущность /// - public EntityAirBomber? EntityAirBomber { get; private set; } + public EntityBomber? EntityBomber { get; protected set; } /// /// Ширина окна @@ -23,43 +27,60 @@ public class DrawningAirBomber /// /// Левая координата прорисовки бомбардировщика /// - private int? _startPosX; + protected int? _startPosX; /// /// Верхняя кооридната прорисовки бомбардировщика /// - private int? _startPosY; + protected int? _startPosY; /// /// Ширина прорисовки бомбардировщика /// - private readonly int _drawningAirBomberWidth = 200; + private readonly int _drawningAirBomberWidth = 190; /// /// Высота прорисовки бомбардировщика /// private readonly int _drawningAirBomberHeight = 160; - /// - /// Инициализация свойств - /// - /// Скорость - /// Вес - /// Основной цвет - /// Дополнительный цвет - /// Признак наличия дополнительных топливных баков - /// Признак наличия бомб - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool fuelTanks, bool bombs) + + /// + /// Пустой конструктор + /// + public DrawningBomber() { - EntityAirBomber = new EntityAirBomber(); - EntityAirBomber.Init(speed, weight, bodyColor, additionalColor, fuelTanks, bombs); _pictureWidth = null; _pictureHeight = null; _startPosX = null; _startPosY = null; } + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + + public DrawningBomber(int speed, double weight, Color bodyColor) : this() + { + EntityBomber = new EntityBomber(speed, weight, bodyColor); + } + + /// + /// Конструктор для наследников + /// + /// Ширина прорисовки бомбардировщика + /// Высота прорисовки бомбардировщика + + protected DrawningBomber(int drawningAirBomberWidth, int drawningAirBomberHeight) : this() + { + _drawningAirBomberWidth = drawningAirBomberWidth; + _drawningAirBomberHeight = drawningAirBomberHeight; + } + /// /// Установка границ поля /// @@ -124,7 +145,7 @@ public class DrawningAirBomber /// true - перемещене выполнено, false - перемещение невозможно public bool MoveTransport(DirectionType direction) { - if (EntityAirBomber == null || !_startPosX.HasValue || + if (EntityBomber == null || !_startPosX.HasValue || !_startPosY.HasValue) { return false; @@ -137,30 +158,30 @@ public class DrawningAirBomber { //влево case DirectionType.Left: - if (_startPosX.Value - EntityAirBomber.Step > 0) + if (_startPosX.Value - EntityBomber.Step > 0) { - _startPosX -= (int)EntityAirBomber.Step; + _startPosX -= (int)EntityBomber.Step; } return true; //вверх case DirectionType.Up: - if (_startPosY.Value - EntityAirBomber.Step > 0) + if (_startPosY.Value - EntityBomber.Step > 0) { - _startPosY -= (int)EntityAirBomber.Step; + _startPosY -= (int)EntityBomber.Step; } return true; // вправо case DirectionType.Right: - if (_startPosX.Value + EntityAirBomber.Step < _pictureWidth - _drawningAirBomberWidth) + if (_startPosX.Value + EntityBomber.Step < _pictureWidth - _drawningAirBomberWidth) { - _startPosX += (int)EntityAirBomber.Step; + _startPosX += (int)EntityBomber.Step; } return true; //вниз case DirectionType.Down: - if (_startPosY.Value + EntityAirBomber.Step < _pictureHeight - _drawningAirBomberHeight) + if (_startPosY.Value + EntityBomber.Step < _pictureHeight - _drawningAirBomberHeight) { - _startPosY += (int)EntityAirBomber.Step; + _startPosY += (int)EntityBomber.Step; } return true; default: @@ -172,98 +193,68 @@ public class DrawningAirBomber /// Прорисовка объекта /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { - if (EntityAirBomber == null || !_startPosX.HasValue || !_startPosY.HasValue) + if (EntityBomber == null || !_startPosX.HasValue || !_startPosY.HasValue) { return; } Pen pen = new(Color.Black); - Brush additionalBrush = new SolidBrush(EntityAirBomber.AdditionalColor); - - // Топливные баки - if (EntityAirBomber.FuelTanks) - { - g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 20, 20, 20); - g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 110, 20, 20); - - } + Brush brBlack = new SolidBrush(Color.Black); //границы бомбардировщика - g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 60, 150, 30); - - //бомбы - if (EntityAirBomber.Bombs) - { - g.FillPolygon(additionalBrush, new Point[] - { - new Point(_startPosX.Value + 110, _startPosY.Value + 42), - new Point(_startPosX.Value + 110, _startPosY.Value + 60), - new Point(_startPosX.Value + 80, _startPosY.Value + 50) - }); - - g.FillPolygon(additionalBrush, new Point[] - { - new Point(_startPosX.Value + 110, _startPosY.Value + 90), - new Point(_startPosX.Value + 110, _startPosY.Value + 108), - new Point(_startPosX.Value + 80, _startPosY.Value + 100) - }); - } + g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 55, 150, 30); //Крылья Brush brGray = new SolidBrush(Color.Gray); - g.FillRectangle(brGray, _startPosX.Value + 105, _startPosY.Value, 20, 160); + g.FillRectangle(brGray, _startPosX.Value + 95, _startPosY.Value, 15, 160); //правое крыло g.FillPolygon(brGray, new Point[] { - new Point(_startPosX.Value + 105, _startPosY.Value), - new Point(_startPosX.Value + 125, _startPosY.Value + 10), - new Point(_startPosX.Value + 135, _startPosY.Value + 90) + new Point(_startPosX.Value + 95, _startPosY.Value), + new Point(_startPosX.Value + 115, _startPosY.Value + 5), + new Point(_startPosX.Value + 125, _startPosY.Value + 85) }); ////левое крыло g.FillPolygon(brGray, new Point[] { - new Point(_startPosX.Value + 105, _startPosY.Value + 90), - new Point(_startPosX.Value + 125, _startPosY.Value + 140), - new Point(_startPosX.Value + 131, _startPosY.Value + 90) + new Point(_startPosX.Value + 95, _startPosY.Value + 85), + new Point(_startPosX.Value + 115, _startPosY.Value + 135), + new Point(_startPosX.Value + 121, _startPosY.Value + 85) }); //задние крылья - g.FillRectangle(additionalBrush, _startPosX.Value + 170, _startPosY.Value + 45, 30, 60); + g.FillRectangle(brGray, _startPosX.Value + 160, _startPosY.Value + 40, 30, 60); - g.FillPolygon(additionalBrush, new Point[] + g.FillPolygon(brGray, new Point[] { - new Point(_startPosX.Value + 170, _startPosY.Value + 45), - new Point(_startPosX.Value + 200, _startPosY.Value + 60), - new Point(_startPosX.Value + 200, _startPosY.Value + 10) + new Point(_startPosX.Value + 160, _startPosY.Value + 40), + new Point(_startPosX.Value + 190, _startPosY.Value + 55), + new Point(_startPosX.Value + 190, _startPosY.Value + 5) }); - g.FillPolygon(additionalBrush, new Point[] + g.FillPolygon(brGray, new Point[] { - new Point(_startPosX.Value + 170, _startPosY.Value + 105), - new Point(_startPosX.Value + 200, _startPosY.Value + 105), - new Point(_startPosX.Value + 200, _startPosY.Value + 145) + new Point(_startPosX.Value + 160, _startPosY.Value + 100), + new Point(_startPosX.Value + 190, _startPosY.Value + 100), + new Point(_startPosX.Value + 190, _startPosY.Value + 140) }); - //фюзеляж - Brush br = new SolidBrush(EntityAirBomber.BodyColor); - g.FillRectangle(br, _startPosX.Value + 50, _startPosY.Value + 60, 150, 30); + Brush br = new SolidBrush(EntityBomber.BodyColor); + g.FillRectangle(br, _startPosX.Value + 40, _startPosY.Value + 55, 150, 30); //передняя часть (треугольник) - g.FillPolygon(additionalBrush, new Point[] + g.FillPolygon(brBlack, new Point[] { - new Point(_startPosX.Value + 50, _startPosY.Value + 60), - new Point(_startPosX.Value + 50, _startPosY.Value + 90), - new Point(_startPosX.Value, _startPosY.Value + 75) + new Point(_startPosX.Value + 40, _startPosY.Value + 55), + new Point(_startPosX.Value + 40, _startPosY.Value + 85), + new Point(_startPosX.Value, _startPosY.Value + 65) }); - - - } -} \ No newline at end of file +} diff --git a/ProjectAirBomber/ProjectAirBomber/EntityAirBomber.cs b/ProjectAirBomber/ProjectAirBomber/Entities/EntityAirBomber.cs similarity index 78% rename from ProjectAirBomber/ProjectAirBomber/EntityAirBomber.cs rename to ProjectAirBomber/ProjectAirBomber/Entities/EntityAirBomber.cs index 8a832f5..be5688d 100644 --- a/ProjectAirBomber/ProjectAirBomber/EntityAirBomber.cs +++ b/ProjectAirBomber/ProjectAirBomber/Entities/EntityAirBomber.cs @@ -1,24 +1,14 @@ -namespace ProjectAirBomber; +namespace ProjectAirBomber.Entities; /// /// Класс-сущность "Бомбардировщик" /// -public class EntityAirBomber +public class EntityAirBomber : EntityBomber { - /// - /// Скорость - /// - public int Speed { get; private set; } + public EntityAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool fuelTanks, bool bombs) : base(speed, weight, bodyColor) + { + } - /// - /// Вес - /// - public double Weight { get; private set; } - - /// - /// Основной цвет - /// - public Color BodyColor { get; private set; } /// /// Дополнительный цвет (для опциональных элементов) @@ -53,9 +43,6 @@ public class EntityAirBomber /// Признак наличия бомб public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool fuelTanks, bool bombs) { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; AdditionalColor = additionalColor; FuelTanks = fuelTanks; Bombs = bombs; diff --git a/ProjectAirBomber/ProjectAirBomber/Entities/EntityBomber.cs b/ProjectAirBomber/ProjectAirBomber/Entities/EntityBomber.cs new file mode 100644 index 0000000..7d24cca --- /dev/null +++ b/ProjectAirBomber/ProjectAirBomber/Entities/EntityBomber.cs @@ -0,0 +1,40 @@ +namespace ProjectAirBomber.Entities; +/// +/// Класс-сущность "Бомбардировщик" +/// +public class EntityBomber +{ + /// + /// Скорость + /// + public int Speed { get; private set; } + + /// + /// Вес + /// + public double Weight { get; private set; } + + /// + /// Основной цвет + /// + public Color BodyColor { get; private set; } + + /// + /// Шаг перемещения бомбардировщика + /// + public double Step => Speed * 200 / Weight; + /// + /// Конструктор сущности + /// + /// Скорость + /// Вес бомбардировщика + /// Основной цвет + /// + /// TO DO?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + public EntityBomber(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } +} diff --git a/ProjectAirBomber/ProjectAirBomber/FormAirBomber.Designer.cs b/ProjectAirBomber/ProjectAirBomber/FormAirBomber.Designer.cs index 0b2736f..014ef18 100644 --- a/ProjectAirBomber/ProjectAirBomber/FormAirBomber.Designer.cs +++ b/ProjectAirBomber/ProjectAirBomber/FormAirBomber.Designer.cs @@ -34,6 +34,7 @@ buttonDown = new Button(); buttonRight = new Button(); buttonUp = new Button(); + buttonCreateBomber = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit(); SuspendLayout(); // @@ -51,9 +52,9 @@ buttonCreateAirBomber.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreateAirBomber.Location = new Point(12, 475); buttonCreateAirBomber.Name = "buttonCreateAirBomber"; - buttonCreateAirBomber.Size = new Size(75, 23); + buttonCreateAirBomber.Size = new Size(233, 23); buttonCreateAirBomber.TabIndex = 1; - buttonCreateAirBomber.Text = "Создать"; + buttonCreateAirBomber.Text = "Создать военный самолёт"; buttonCreateAirBomber.UseVisualStyleBackColor = true; buttonCreateAirBomber.Click += ButtonCreateAirBomber_Click; // @@ -105,11 +106,23 @@ buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += ButtonMove_Click; // + // buttonCreateBomber + // + buttonCreateBomber.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateBomber.Location = new Point(261, 475); + buttonCreateBomber.Name = "buttonCreateBomber"; + buttonCreateBomber.Size = new Size(233, 23); + buttonCreateBomber.TabIndex = 6; + buttonCreateBomber.Text = "Создать самолёт"; + buttonCreateBomber.UseVisualStyleBackColor = true; + buttonCreateBomber.Click += buttonCreateBomber_Click; + // // FormAirBomber // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(880, 510); + Controls.Add(buttonCreateBomber); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonDown); @@ -130,5 +143,6 @@ private Button buttonDown; private Button buttonRight; private Button buttonUp; + private Button buttonCreateBomber; } } \ No newline at end of file diff --git a/ProjectAirBomber/ProjectAirBomber/FormAirBomber.cs b/ProjectAirBomber/ProjectAirBomber/FormAirBomber.cs index b537378..4bc61dd 100644 --- a/ProjectAirBomber/ProjectAirBomber/FormAirBomber.cs +++ b/ProjectAirBomber/ProjectAirBomber/FormAirBomber.cs @@ -1,4 +1,6 @@ -namespace ProjectAirBomber; +using ProjectAirBomber.Drawnings; + +namespace ProjectAirBomber; /// /// Форма работы с объектом "Бомбардировщик" @@ -8,7 +10,7 @@ public partial class FormAirBomber : Form /// /// Поле-объект для прорисовки объекта /// - private DrawningAirBomber? _drawningAirBomber; + private DrawningBomber? _drawningBomber; /// /// Конструктор формы @@ -22,34 +24,58 @@ public partial class FormAirBomber : Form /// private void Draw() { - if (_drawningAirBomber == null) + if (_drawningBomber == null) { return; } Bitmap bmp = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); Graphics gr = Graphics.FromImage(bmp); - _drawningAirBomber.DrawTransport(gr); + _drawningBomber.DrawTransport(gr); pictureBoxAirBomber.Image = bmp; } + private void CreateObject(string type) + { + Random random = new(); + switch (type) + { + case nameof(DrawningBomber): + _drawningBomber = new DrawningBomber(random.Next(100, 300), random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); + break; + case nameof(DrawningAirBomber): + _drawningBomber = new DrawningAirBomber(random.Next(100, 300), random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + } + + _drawningBomber.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); + _drawningBomber.SetPosition(random.Next(10, 100), random.Next(10, 100)); + + + Draw(); + } + + /// - /// Обработка нажатия кнопки "Создать" + /// Обработка нажатия кнопки "Создать военный самолёт" /// /// /// - private void ButtonCreateAirBomber_Click(object sender, EventArgs e) - { - Random random = new(); - _drawningAirBomber = new DrawningAirBomber(); - _drawningAirBomber.Init(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - _drawningAirBomber.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); - _drawningAirBomber.SetPosition(random.Next(10, 100), random.Next(10, 100)); - Draw(); - } + private void ButtonCreateAirBomber_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirBomber)); + + /// + /// Обработка нажатия кнопки "Создать самолёт" + /// + /// + /// + + private void buttonCreateBomber_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBomber)); /// /// Перемещение объекта по форме (нажатие кнопок навигации) @@ -58,7 +84,7 @@ public partial class FormAirBomber : Form /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawningAirBomber == null) + if (_drawningBomber == null) { return; } @@ -68,16 +94,16 @@ public partial class FormAirBomber : Form switch (name) { case "buttonUp": - result = _drawningAirBomber.MoveTransport(DirectionType.Up); + result = _drawningBomber.MoveTransport(DirectionType.Up); break; case "buttonDown": - result = _drawningAirBomber.MoveTransport(DirectionType.Down); + result = _drawningBomber.MoveTransport(DirectionType.Down); break; case "buttonLeft": - result = _drawningAirBomber.MoveTransport(DirectionType.Left); + result = _drawningBomber.MoveTransport(DirectionType.Left); break; case "buttonRight": - result = _drawningAirBomber.MoveTransport(DirectionType.Right); + result = _drawningBomber.MoveTransport(DirectionType.Right); break; } @@ -86,4 +112,8 @@ public partial class FormAirBomber : Form Draw(); } } + + + + } \ No newline at end of file