Переход на конструкторы
This commit is contained in:
parent
97b7cd4d5e
commit
b190f9518e
@ -14,15 +14,15 @@ namespace AirBomber
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityJet Jet { get; private set; }
|
public EntityJet Jet { get; protected set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата отрисовки самолета
|
/// Левая координата отрисовки самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _startPosX;
|
protected float _startPosX;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната отрисовки самолета
|
/// Верхняя кооридната отрисовки самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _startPosY;
|
protected float _startPosY;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -45,10 +45,16 @@ namespace AirBomber
|
|||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">Вес самолета</param>
|
/// <param name="weight">Вес самолета</param>
|
||||||
/// <param name="bodyColor">Цвет самолета</param>
|
/// <param name="bodyColor">Цвет самолета</param>
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
public DrawningJet(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Jet = new EntityJet();
|
Jet = new EntityJet(speed, weight, bodyColor);
|
||||||
Jet.Init(speed, weight, bodyColor);
|
}
|
||||||
|
|
||||||
|
protected DrawningJet(int speed, float weight, Color bodyColor, int jetWidth, int jetHeight) :
|
||||||
|
this(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
_jetWidth = jetWidth;
|
||||||
|
_jetHeight = jetHeight;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиции самолета
|
/// Установка позиции самолета
|
||||||
@ -58,7 +64,7 @@ namespace AirBomber
|
|||||||
/// <param name="width">Ширина картинки</param>
|
/// <param name="width">Ширина картинки</param>
|
||||||
/// <param name="height">Высота картинки</param>
|
/// <param name="height">Высота картинки</param>
|
||||||
|
|
||||||
public void SetPosition(int x, int y, int width, int height)
|
public virtual void SetPosition(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
if (x < 0 || y < 0 || width < x + _jetWidth || height < y + _jetHeight)
|
if (x < 0 || y < 0 || width < x + _jetWidth || height < y + _jetHeight)
|
||||||
{
|
{
|
||||||
@ -122,7 +128,7 @@ namespace AirBomber
|
|||||||
/// Отрисовка самолета
|
/// Отрисовка самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (_startPosX < 0 || _startPosY < 0
|
if (_startPosX < 0 || _startPosY < 0
|
||||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||||
@ -202,5 +208,12 @@ namespace AirBomber
|
|||||||
_startPosY = _pictureHeight.Value - _jetHeight;
|
_startPosY = _pictureHeight.Value - _jetHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение текущей позиции
|
||||||
|
/// </summary>
|
||||||
|
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||||
|
{
|
||||||
|
return (_startPosX, _startPosY, _startPosX + _jetWidth, _startPosY + _jetHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ namespace AirBomber
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
///
|
///
|
||||||
|
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
public EntityJet(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||||
|
@ -57,8 +57,7 @@ namespace AirBomber
|
|||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
private void buttonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
_jet = new DrawningJet();
|
_jet = new DrawningJet(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||||
_jet.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
|
||||||
_jet.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height);
|
_jet.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height);
|
||||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_jet.Jet.Speed}";
|
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_jet.Jet.Speed}";
|
||||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_jet.Jet.Weight}";
|
toolStripStatusLabelWeight.Text = $"Âåñ: {_jet.Jet.Weight}";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user