Добавление родителей и ввод конструкторов
This commit is contained in:
parent
f870c99a0b
commit
4a92a4e41c
@ -1,5 +1,4 @@
|
||||
|
||||
namespace AntiAircraftGun;
|
||||
namespace AntiAircraftGun.Drawnings;
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
@ -1,56 +1,101 @@
|
||||
namespace AntiAircraftGun;
|
||||
/// <summary>
|
||||
/// Класс отвечающий за прорисовку и перемещение объекта - сущности
|
||||
/// </summary>
|
||||
public class DrawningAntiAircraftGun
|
||||
using AntiAircraftGun.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AntiAircraftGun.Drawnings;
|
||||
|
||||
public class DrawningAircraftGun
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс - сущность
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAntiAircraftGun? EntityAntiAircraftGun { get; set; }
|
||||
public EntityAircraftGun? EntityAircraftGun { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// Ширина
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// Высота
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки зенитной установки
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
protected int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя координата прорисовки зенитной установки
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки зенитной установки
|
||||
/// </summary>
|
||||
private readonly int _drawningGunWidth = 130;
|
||||
private readonly int _drawningGunWidth = 129;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки зенитной установки
|
||||
/// </summary>
|
||||
private readonly int _drawningGunHeight = 100;
|
||||
private readonly int _drawningGunHeight = 105;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса зенитной установки
|
||||
/// Координата Х объекта
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Наличие обвеса</param>
|
||||
/// <param name="tower">Наличие башни</param>
|
||||
/// <param name="radar">Наличие радара</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool tower, bool radar)
|
||||
public int? GetPosX => _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int? GetPosY => _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawningGunWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawningGunHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningAircraftGun()
|
||||
{
|
||||
EntityAntiAircraftGun = new EntityAntiAircraftGun();
|
||||
EntityAntiAircraftGun.Init(speed, weight, bodyColor, additionalColor, bodyKit, tower, radar);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningAircraftGun(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityAircraftGun = new EntityAircraftGun(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningGunWidth">Ширина прорисовки зенитной установки</param>
|
||||
/// <param name="drawningGunHeight">Высота прорисовки зенитной установки</param>
|
||||
protected DrawningAircraftGun(int drawningGunWidth, int drawningGunHeight) : this()
|
||||
{
|
||||
_drawningGunWidth = drawningGunWidth;
|
||||
_drawningGunHeight = drawningGunHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
@ -133,34 +178,34 @@ public class DrawningAntiAircraftGun
|
||||
/// <returns></returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityAntiAircraftGun == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityAircraftGun == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityAntiAircraftGun.Step > 0)
|
||||
if (_startPosX.Value - EntityAircraftGun.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityAntiAircraftGun.Step;
|
||||
_startPosX -= (int)EntityAircraftGun.Step;
|
||||
}
|
||||
return true;
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _drawningGunWidth + EntityAntiAircraftGun.Step < _pictureWidth)
|
||||
if (_startPosX.Value + _drawningGunWidth + EntityAircraftGun.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityAntiAircraftGun.Step;
|
||||
_startPosX += (int)EntityAircraftGun.Step;
|
||||
}
|
||||
return true;
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawningGunHeight + EntityAntiAircraftGun.Step < _pictureHeight)
|
||||
if (_startPosY.Value + _drawningGunHeight + EntityAircraftGun.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityAntiAircraftGun.Step;
|
||||
_startPosY += (int)EntityAircraftGun.Step;
|
||||
}
|
||||
return true;
|
||||
case DirectionType.Up: //вверх
|
||||
if (_startPosY - EntityAntiAircraftGun.Step > 0)
|
||||
if (_startPosY - EntityAircraftGun.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityAntiAircraftGun.Step;
|
||||
_startPosY -= (int)EntityAircraftGun.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
@ -171,22 +216,21 @@ public class DrawningAntiAircraftGun
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAntiAircraftGun == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityAircraftGun == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityAntiAircraftGun.AdditionalColor);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 75, 30, 30);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 75, 30, 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 75, 90, 30);
|
||||
|
||||
//границы ЦВЕТ
|
||||
Brush brDarkSlateGray = new SolidBrush(EntityAntiAircraftGun.BodyColor);
|
||||
Brush brDarkSlateGray = new SolidBrush(EntityAircraftGun.BodyColor);
|
||||
g.FillRectangle(brDarkSlateGray, _startPosX.Value + 35, _startPosY.Value + 40, 35, 30);
|
||||
g.FillEllipse(brDarkSlateGray, _startPosX.Value + 10, _startPosY.Value + 75, 30, 30);
|
||||
g.FillEllipse(brDarkSlateGray, _startPosX.Value + 100, _startPosY.Value + 75, 30, 30);
|
||||
@ -220,26 +264,8 @@ public class DrawningAntiAircraftGun
|
||||
|
||||
g.FillRectangle(brDarkSlateGray, _startPosX.Value + 10, _startPosY.Value + 65, 120, 13);
|
||||
|
||||
if (EntityAntiAircraftGun.Tower)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 50, 35, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 50, 35, 15);
|
||||
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 50, _startPosX.Value + 90, _startPosY.Value + 20);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 50, _startPosX.Value + 95, _startPosY.Value + 27);
|
||||
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 50, _startPosX.Value + 60, _startPosY.Value + 50);
|
||||
g.DrawLine(pen, _startPosX.Value + 90, _startPosY.Value + 20, _startPosX.Value + 95, _startPosY.Value + 27);
|
||||
g.DrawLine(pen, _startPosX.Value + 90, _startPosY.Value + 20, _startPosX.Value + 100, _startPosY.Value + 20);
|
||||
g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 20, _startPosX.Value + 95, _startPosY.Value + 27);
|
||||
|
||||
}
|
||||
|
||||
if (EntityAntiAircraftGun.Radar)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX.Value + 20, _startPosY.Value + 65, _startPosX.Value + 20, _startPosY.Value + 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 40, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 40, 20, 20);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
64
AntiAircraftGun/Drawnings/DrawningAntiAircraftGun.cs
Normal file
64
AntiAircraftGun/Drawnings/DrawningAntiAircraftGun.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using AntiAircraftGun.Entities;
|
||||
|
||||
namespace AntiAircraftGun.Drawnings;
|
||||
/// <summary>
|
||||
/// Класс отвечающий за прорисовку и перемещение объекта - сущности
|
||||
/// </summary>
|
||||
public class DrawningAntiAircraftGun : DrawningAircraftGun
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвесов</param>
|
||||
/// <param name="tower">Признак наличия башни</param>
|
||||
/// <param name="radar">Признак наличия радара</param>
|
||||
|
||||
public DrawningAntiAircraftGun(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool radar, bool tower) : base(129, 60)
|
||||
{
|
||||
EntityAircraftGun = new EntityAntiAircraftGun(speed, weight, bodyColor, radar, tower, bodyKit, additionalColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAircraftGun == null || EntityAircraftGun is not EntityAntiAircraftGun aircraftGun || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(aircraftGun.AdditionalColor);
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
|
||||
if (aircraftGun.Tower)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 50, 35, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 50, 35, 15);
|
||||
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 50, _startPosX.Value + 90, _startPosY.Value + 20);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 50, _startPosX.Value + 95, _startPosY.Value + 27);
|
||||
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 50, _startPosX.Value + 60, _startPosY.Value + 50);
|
||||
g.DrawLine(pen, _startPosX.Value + 90, _startPosY.Value + 20, _startPosX.Value + 95, _startPosY.Value + 27);
|
||||
g.DrawLine(pen, _startPosX.Value + 90, _startPosY.Value + 20, _startPosX.Value + 100, _startPosY.Value + 20);
|
||||
g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 20, _startPosX.Value + 95, _startPosY.Value + 27);
|
||||
|
||||
}
|
||||
|
||||
if (aircraftGun.Radar)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX.Value + 20, _startPosY.Value + 65, _startPosX.Value + 20, _startPosY.Value + 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 40, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 40, 20, 20);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
40
AntiAircraftGun/Entities/EntityAircraftGun.cs
Normal file
40
AntiAircraftGun/Entities/EntityAircraftGun.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AntiAircraftGun.Entities;
|
||||
|
||||
public class EntityAircraftGun
|
||||
{
|
||||
/// <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 * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
public EntityAircraftGun(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
@ -1,20 +1,9 @@
|
||||
namespace AntiAircraftGun;
|
||||
namespace AntiAircraftGun.Entities;
|
||||
/// <summary>
|
||||
/// Класс-сущность Зенитная установка
|
||||
/// </summary>
|
||||
public class EntityAntiAircraftGun
|
||||
{ /// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
public class EntityAntiAircraftGun : EntityAircraftGun
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополниетльный цвет
|
||||
/// </summary>
|
||||
@ -31,12 +20,9 @@ public class EntityAntiAircraftGun
|
||||
/// Наличие радара
|
||||
/// </summary>
|
||||
public bool Radar { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения гидросамолета
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса гидросамолета
|
||||
/// Инициализация полей объекта-класса зенитной установки
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
@ -45,14 +31,12 @@ public class EntityAntiAircraftGun
|
||||
/// <param name="bodyKit">Наличие обвеса</param>
|
||||
/// <param name="tower">Наличие башни</param>
|
||||
/// <param name="radar">Наличие радара</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool tower, bool radar)
|
||||
public EntityAntiAircraftGun(int speed, double weight, Color bodyColor, bool radar, bool tower, bool bodyKit, Color additionalColor) : base(speed, weight, bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Tower = tower;
|
||||
|
||||
Radar = radar;
|
||||
Tower = tower;
|
||||
BodyKit = bodyKit;
|
||||
AdditionalColor = additionalColor;
|
||||
}
|
||||
}
|
40
AntiAircraftGun/FormAntiAircraftGun.Designer.cs
generated
40
AntiAircraftGun/FormAntiAircraftGun.Designer.cs
generated
@ -29,11 +29,12 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxAntiAircraftGun = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonCreate = new Button();
|
||||
buttonCreatAircraftGun = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAntiAircraftGun).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -46,17 +47,6 @@
|
||||
pictureBoxAntiAircraftGun.TabIndex = 0;
|
||||
pictureBoxAntiAircraftGun.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 406);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(95, 32);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreate_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
@ -105,11 +95,34 @@
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 406);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(215, 32);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать зенитную установку";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreate_Click;
|
||||
//
|
||||
// buttonCreatAircraftGun
|
||||
//
|
||||
buttonCreatAircraftGun.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreatAircraftGun.Location = new Point(233, 406);
|
||||
buttonCreatAircraftGun.Name = "buttonCreatAircraftGun";
|
||||
buttonCreatAircraftGun.Size = new Size(215, 32);
|
||||
buttonCreatAircraftGun.TabIndex = 6;
|
||||
buttonCreatAircraftGun.Text = "Создать установку";
|
||||
buttonCreatAircraftGun.UseVisualStyleBackColor = true;
|
||||
buttonCreatAircraftGun.Click += buttonCreatAircraftGun_Click;
|
||||
//
|
||||
// FormAntiAircraftGun
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(buttonCreatAircraftGun);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
@ -125,10 +138,11 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxAntiAircraftGun;
|
||||
private Button buttonCreate;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private Button buttonCreate;
|
||||
private Button buttonCreatAircraftGun;
|
||||
}
|
||||
}
|
@ -1,11 +1,13 @@
|
||||
namespace AntiAircraftGun
|
||||
using AntiAircraftGun.Drawnings;
|
||||
|
||||
namespace AntiAircraftGun
|
||||
{
|
||||
public partial class FormAntiAircraftGun : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningAntiAircraftGun? _drawningAntiAircraftGun;
|
||||
private DrawningAircraftGun? _drawningAircraftGun;
|
||||
/// <summary>
|
||||
/// конструктор формы
|
||||
/// </summary>
|
||||
@ -18,32 +20,51 @@
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningAntiAircraftGun == null)
|
||||
if (_drawningAircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningAntiAircraftGun.DrawTransport(gr);
|
||||
_drawningAircraftGun.DrawTransport(gr);
|
||||
pictureBoxAntiAircraftGun.Image = bmp;
|
||||
}
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningAircraftGun):
|
||||
_drawningAircraftGun = new DrawningAircraftGun(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(DrawningAntiAircraftGun):
|
||||
_drawningAircraftGun = new DrawningAntiAircraftGun(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;
|
||||
}
|
||||
|
||||
_drawningAircraftGun.SetPictureSize(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
_drawningAircraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка кнопик Создать
|
||||
/// Обработка кнопик Создать Зенитную установку
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningAntiAircraftGun = new DrawningAntiAircraftGun();
|
||||
_drawningAntiAircraftGun.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 255),
|
||||
random.Next(0, 255), random.Next(0, 255)), Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
_drawningAntiAircraftGun.SetPictureSize(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
_drawningAntiAircraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
|
||||
Draw();
|
||||
}
|
||||
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAntiAircraftGun));
|
||||
/// <summary>
|
||||
/// Обработка кнопик Создать установку
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreatAircraftGun_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAircraftGun));
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме
|
||||
/// </summary>
|
||||
@ -51,7 +72,7 @@
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAntiAircraftGun == null)
|
||||
if (_drawningAircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -60,16 +81,16 @@
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningAntiAircraftGun.MoveTransport(DirectionType.Up);
|
||||
result = _drawningAircraftGun.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningAntiAircraftGun.MoveTransport(DirectionType.Down);
|
||||
result = _drawningAircraftGun.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningAntiAircraftGun.MoveTransport(DirectionType.Right);
|
||||
result = _drawningAircraftGun.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningAntiAircraftGun.MoveTransport(DirectionType.Left);
|
||||
result = _drawningAircraftGun.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
@ -77,5 +98,7 @@
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user