Добавление родителей и ввод конструкторов
This commit is contained in:
parent
bae1ea9e28
commit
f78bc58e13
@ -1,4 +1,4 @@
|
|||||||
namespace ProjectAirBomber;
|
namespace ProjectAirBomber.Drawnings;
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
namespace ProjectAirBomber.Drawnings;
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
|
||||||
/// </summary>
|
public class DrawningBomber
|
||||||
public class DrawningAirBomber
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityAirBomber? EntityAirBomber { get; private set; }
|
public EntityBomber? EntityBomber { get; protected set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
@ -23,43 +27,60 @@ public class DrawningAirBomber
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата прорисовки бомбардировщика
|
/// Левая координата прорисовки бомбардировщика
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosX;
|
protected int? _startPosX;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната прорисовки бомбардировщика
|
/// Верхняя кооридната прорисовки бомбардировщика
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosY;
|
protected int? _startPosY;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки бомбардировщика
|
/// Ширина прорисовки бомбардировщика
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningAirBomberWidth = 200;
|
private readonly int _drawningAirBomberWidth = 190;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота прорисовки бомбардировщика
|
/// Высота прорисовки бомбардировщика
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningAirBomberHeight = 160;
|
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;
|
_pictureWidth = null;
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
_startPosX = null;
|
_startPosX = null;
|
||||||
_startPosY = 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>
|
||||||
/// Установка границ поля
|
/// Установка границ поля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -124,7 +145,7 @@ public class DrawningAirBomber
|
|||||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||||
public bool MoveTransport(DirectionType direction)
|
public bool MoveTransport(DirectionType direction)
|
||||||
{
|
{
|
||||||
if (EntityAirBomber == null || !_startPosX.HasValue ||
|
if (EntityBomber == null || !_startPosX.HasValue ||
|
||||||
!_startPosY.HasValue)
|
!_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -137,30 +158,30 @@ public class DrawningAirBomber
|
|||||||
{
|
{
|
||||||
//влево
|
//влево
|
||||||
case DirectionType.Left:
|
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;
|
return true;
|
||||||
//вверх
|
//вверх
|
||||||
case DirectionType.Up:
|
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;
|
return true;
|
||||||
// вправо
|
// вправо
|
||||||
case DirectionType.Right:
|
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;
|
return true;
|
||||||
//вниз
|
//вниз
|
||||||
case DirectionType.Down:
|
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;
|
return true;
|
||||||
default:
|
default:
|
||||||
@ -172,98 +193,68 @@ public class DrawningAirBomber
|
|||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pen pen = new(Color.Black);
|
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);
|
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 55, 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)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//Крылья
|
//Крылья
|
||||||
Brush brGray = new SolidBrush(Color.Gray);
|
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[]
|
g.FillPolygon(brGray, new Point[]
|
||||||
{
|
{
|
||||||
new Point(_startPosX.Value + 105, _startPosY.Value),
|
new Point(_startPosX.Value + 95, _startPosY.Value),
|
||||||
new Point(_startPosX.Value + 125, _startPosY.Value + 10),
|
new Point(_startPosX.Value + 115, _startPosY.Value + 5),
|
||||||
new Point(_startPosX.Value + 135, _startPosY.Value + 90)
|
new Point(_startPosX.Value + 125, _startPosY.Value + 85)
|
||||||
});
|
});
|
||||||
|
|
||||||
////левое крыло
|
////левое крыло
|
||||||
g.FillPolygon(brGray, new Point[]
|
g.FillPolygon(brGray, new Point[]
|
||||||
{
|
{
|
||||||
new Point(_startPosX.Value + 105, _startPosY.Value + 90),
|
new Point(_startPosX.Value + 95, _startPosY.Value + 85),
|
||||||
new Point(_startPosX.Value + 125, _startPosY.Value + 140),
|
new Point(_startPosX.Value + 115, _startPosY.Value + 135),
|
||||||
new Point(_startPosX.Value + 131, _startPosY.Value + 90)
|
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 + 160, _startPosY.Value + 40),
|
||||||
new Point(_startPosX.Value + 200, _startPosY.Value + 60),
|
new Point(_startPosX.Value + 190, _startPosY.Value + 55),
|
||||||
new Point(_startPosX.Value + 200, _startPosY.Value + 10)
|
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 + 160, _startPosY.Value + 100),
|
||||||
new Point(_startPosX.Value + 200, _startPosY.Value + 105),
|
new Point(_startPosX.Value + 190, _startPosY.Value + 100),
|
||||||
new Point(_startPosX.Value + 200, _startPosY.Value + 145)
|
new Point(_startPosX.Value + 190, _startPosY.Value + 140)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//фюзеляж
|
//фюзеляж
|
||||||
Brush br = new SolidBrush(EntityAirBomber.BodyColor);
|
Brush br = new SolidBrush(EntityBomber.BodyColor);
|
||||||
g.FillRectangle(br, _startPosX.Value + 50, _startPosY.Value + 60, 150, 30);
|
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 + 40, _startPosY.Value + 55),
|
||||||
new Point(_startPosX.Value + 50, _startPosY.Value + 90),
|
new Point(_startPosX.Value + 40, _startPosY.Value + 85),
|
||||||
new Point(_startPosX.Value, _startPosY.Value + 75)
|
new Point(_startPosX.Value, _startPosY.Value + 65)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,24 +1,14 @@
|
|||||||
namespace ProjectAirBomber;
|
namespace ProjectAirBomber.Entities;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность "Бомбардировщик"
|
/// Класс-сущность "Бомбардировщик"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EntityAirBomber
|
public class EntityAirBomber : EntityBomber
|
||||||
{
|
{
|
||||||
/// <summary>
|
public EntityAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool fuelTanks, bool bombs) : base(speed, weight, bodyColor)
|
||||||
/// Скорость
|
{
|
||||||
/// </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>
|
||||||
/// Дополнительный цвет (для опциональных элементов)
|
/// Дополнительный цвет (для опциональных элементов)
|
||||||
@ -53,9 +43,6 @@ public class EntityAirBomber
|
|||||||
/// <param name="bombs">Признак наличия бомб</param>
|
/// <param name="bombs">Признак наличия бомб</param>
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool fuelTanks, bool bombs)
|
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool fuelTanks, bool bombs)
|
||||||
{
|
{
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
FuelTanks = fuelTanks;
|
FuelTanks = fuelTanks;
|
||||||
Bombs = bombs;
|
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();
|
buttonDown = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
|
buttonCreateBomber = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -51,9 +52,9 @@
|
|||||||
buttonCreateAirBomber.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreateAirBomber.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreateAirBomber.Location = new Point(12, 475);
|
buttonCreateAirBomber.Location = new Point(12, 475);
|
||||||
buttonCreateAirBomber.Name = "buttonCreateAirBomber";
|
buttonCreateAirBomber.Name = "buttonCreateAirBomber";
|
||||||
buttonCreateAirBomber.Size = new Size(75, 23);
|
buttonCreateAirBomber.Size = new Size(233, 23);
|
||||||
buttonCreateAirBomber.TabIndex = 1;
|
buttonCreateAirBomber.TabIndex = 1;
|
||||||
buttonCreateAirBomber.Text = "Создать";
|
buttonCreateAirBomber.Text = "Создать военный самолёт";
|
||||||
buttonCreateAirBomber.UseVisualStyleBackColor = true;
|
buttonCreateAirBomber.UseVisualStyleBackColor = true;
|
||||||
buttonCreateAirBomber.Click += ButtonCreateAirBomber_Click;
|
buttonCreateAirBomber.Click += ButtonCreateAirBomber_Click;
|
||||||
//
|
//
|
||||||
@ -105,11 +106,23 @@
|
|||||||
buttonUp.UseVisualStyleBackColor = true;
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
buttonUp.Click += ButtonMove_Click;
|
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
|
// FormAirBomber
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(880, 510);
|
ClientSize = new Size(880, 510);
|
||||||
|
Controls.Add(buttonCreateBomber);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
@ -130,5 +143,6 @@
|
|||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
|
private Button buttonCreateBomber;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,6 @@
|
|||||||
namespace ProjectAirBomber;
|
using ProjectAirBomber.Drawnings;
|
||||||
|
|
||||||
|
namespace ProjectAirBomber;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Форма работы с объектом "Бомбардировщик"
|
/// Форма работы с объектом "Бомбардировщик"
|
||||||
@ -8,7 +10,7 @@ public partial class FormAirBomber : Form
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Поле-объект для прорисовки объекта
|
/// Поле-объект для прорисовки объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private DrawningAirBomber? _drawningAirBomber;
|
private DrawningBomber? _drawningBomber;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор формы
|
/// Конструктор формы
|
||||||
@ -22,34 +24,58 @@ public partial class FormAirBomber : Form
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningAirBomber == null)
|
if (_drawningBomber == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap bmp = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
Bitmap bmp = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningAirBomber.DrawTransport(gr);
|
_drawningBomber.DrawTransport(gr);
|
||||||
pictureBoxAirBomber.Image = bmp;
|
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>
|
||||||
/// Обработка нажатия кнопки "Создать"
|
/// Обработка нажатия кнопки "Создать военный самолёт"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonCreateAirBomber_Click(object sender, EventArgs e)
|
private void ButtonCreateAirBomber_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirBomber));
|
||||||
{
|
|
||||||
Random random = new();
|
/// <summary>
|
||||||
_drawningAirBomber = new DrawningAirBomber();
|
/// Обработка нажатия кнопки "Создать самолёт"
|
||||||
_drawningAirBomber.Init(random.Next(100, 300), random.Next(1000, 3000),
|
/// </summary>
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
/// <param name="sender"></param>
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
/// <param name="e"></param>
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
|
||||||
_drawningAirBomber.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
private void buttonCreateBomber_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBomber));
|
||||||
_drawningAirBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
||||||
Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||||
@ -58,7 +84,7 @@ public partial class FormAirBomber : Form
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningAirBomber == null)
|
if (_drawningBomber == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -68,16 +94,16 @@ public partial class FormAirBomber : Form
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
result = _drawningAirBomber.MoveTransport(DirectionType.Up);
|
result = _drawningBomber.MoveTransport(DirectionType.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
result = _drawningAirBomber.MoveTransport(DirectionType.Down);
|
result = _drawningBomber.MoveTransport(DirectionType.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
result = _drawningAirBomber.MoveTransport(DirectionType.Left);
|
result = _drawningBomber.MoveTransport(DirectionType.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
result = _drawningAirBomber.MoveTransport(DirectionType.Right);
|
result = _drawningBomber.MoveTransport(DirectionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,4 +112,8 @@ public partial class FormAirBomber : Form
|
|||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user