Добавление родителей и ввод конструкторов
This commit is contained in:
parent
bae1ea9e28
commit
f78bc58e13
@ -1,4 +1,4 @@
|
||||
namespace ProjectAirBomber;
|
||||
namespace ProjectAirBomber.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
@ -0,0 +1,75 @@
|
||||
using ProjectAirBomber.Entities;
|
||||
|
||||
namespace ProjectAirBomber.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningAirBomber : DrawningBomber
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="fuelTanks">Признак наличия дополнительных топливных баков</param>
|
||||
/// <param name="bombs">Признак наличия бомб</param>
|
||||
|
||||
|
||||
|
||||
|
||||
//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;
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningAirBomber
|
||||
namespace ProjectAirBomber.Drawnings;
|
||||
|
||||
public class DrawningBomber
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAirBomber? EntityAirBomber { get; private set; }
|
||||
public EntityBomber? EntityBomber { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
@ -23,43 +27,60 @@ public class DrawningAirBomber
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки бомбардировщика
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
protected int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки бомбардировщика
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки бомбардировщика
|
||||
/// </summary>
|
||||
private readonly int _drawningAirBomberWidth = 200;
|
||||
private readonly int _drawningAirBomberWidth = 190;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки бомбардировщика
|
||||
/// </summary>
|
||||
private readonly int _drawningAirBomberHeight = 160;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="fuelTanks">Признак наличия дополнительных топливных баков</param>
|
||||
/// <param name="bombs">Признак наличия бомб</param>
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool fuelTanks, bool bombs)
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
public DrawningBomber()
|
||||
{
|
||||
EntityAirBomber = new EntityAirBomber();
|
||||
EntityAirBomber.Init(speed, weight, bodyColor, additionalColor, fuelTanks, bombs);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
|
||||
public DrawningBomber(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityBomber = new EntityBomber(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningAirBomberWidth">Ширина прорисовки бомбардировщика</param>
|
||||
/// <param name="drawningAirBomberHeight">Высота прорисовки бомбардировщика</param>
|
||||
|
||||
protected DrawningBomber(int drawningAirBomberWidth, int drawningAirBomberHeight) : this()
|
||||
{
|
||||
_drawningAirBomberWidth = drawningAirBomberWidth;
|
||||
_drawningAirBomberHeight = drawningAirBomberHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
@ -124,7 +145,7 @@ public class DrawningAirBomber
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
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
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
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)
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,24 +1,14 @@
|
||||
namespace ProjectAirBomber;
|
||||
namespace ProjectAirBomber.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Бомбардировщик"
|
||||
/// </summary>
|
||||
public class EntityAirBomber
|
||||
public class EntityAirBomber : EntityBomber
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
public EntityAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool fuelTanks, bool bombs) : base(speed, weight, bodyColor)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
@ -53,9 +43,6 @@ public class EntityAirBomber
|
||||
/// <param name="bombs">Признак наличия бомб</param>
|
||||
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;
|
40
ProjectAirBomber/ProjectAirBomber/Entities/EntityBomber.cs
Normal file
40
ProjectAirBomber/ProjectAirBomber/Entities/EntityBomber.cs
Normal file
@ -0,0 +1,40 @@
|
||||
namespace ProjectAirBomber.Entities;
|
||||
/// <summary>
|
||||
/// Класс-сущность "Бомбардировщик"
|
||||
/// </summary>
|
||||
public class EntityBomber
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения бомбардировщика
|
||||
/// </summary>
|
||||
public double Step => Speed * 200 / Weight;
|
||||
/// <summary>
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес бомбардировщика</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
///
|
||||
/// TO DO?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
public EntityBomber(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
namespace ProjectAirBomber;
|
||||
using ProjectAirBomber.Drawnings;
|
||||
|
||||
namespace ProjectAirBomber;
|
||||
|
||||
/// <summary>
|
||||
/// Форма работы с объектом "Бомбардировщик"
|
||||
@ -8,7 +10,7 @@ public partial class FormAirBomber : Form
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningAirBomber? _drawningAirBomber;
|
||||
private DrawningBomber? _drawningBomber;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
@ -22,34 +24,58 @@ public partial class FormAirBomber : Form
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// Обработка нажатия кнопки "Создать военный самолёт"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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));
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать самолёт"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
private void buttonCreateBomber_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBomber));
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
@ -58,7 +84,7 @@ public partial class FormAirBomber : Form
|
||||
/// <param name="e"></param>
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user