Antonova D.V. Lab2 #2

Closed
AntonovaDaria wants to merge 3 commits from Lab2 into Lab1
3 changed files with 23 additions and 11 deletions
Showing only changes of commit b190f9518e - Show all commits

View File

@ -14,15 +14,15 @@ namespace AirBomber
/// <summary>
/// Класс-сущность
/// </summary>
public EntityJet Jet { get; private set; }
public EntityJet Jet { get; protected set; }
/// <summary>
/// Левая координата отрисовки самолета
/// </summary>
private float _startPosX;
protected float _startPosX;
/// <summary>
/// Верхняя кооридната отрисовки самолета
/// </summary>
private float _startPosY;
protected float _startPosY;
/// <summary>
/// Ширина окна отрисовки
/// </summary>
@ -45,10 +45,16 @@ namespace AirBomber
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес самолета</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.Init(speed, weight, bodyColor);
Jet = new EntityJet(speed, weight, bodyColor);
}
protected DrawningJet(int speed, float weight, Color bodyColor, int jetWidth, int jetHeight) :
this(speed, weight, bodyColor)
{
_jetWidth = jetWidth;
_jetHeight = jetHeight;
}
/// <summary>
/// Установка позиции самолета
@ -58,7 +64,7 @@ namespace AirBomber
/// <param name="width">Ширина картинки</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)
{
@ -122,7 +128,7 @@ namespace AirBomber
/// Отрисовка самолета
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
@ -202,5 +208,12 @@ namespace AirBomber
_startPosY = _pictureHeight.Value - _jetHeight;
}
}
/// <summary>
/// Получение текущей позиции
/// </summary>
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosY, _startPosX + _jetWidth, _startPosY + _jetHeight);
}
}
}

View File

@ -35,7 +35,7 @@ namespace AirBomber
/// <returns></returns>
///
public void Init(int speed, float weight, Color bodyColor)
public EntityJet(int speed, float weight, Color bodyColor)
{
Random rnd = new Random();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;

View File

@ -57,8 +57,7 @@ namespace AirBomber
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new Random();
_jet = new DrawningJet();
_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 = 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.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_jet.Jet.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_jet.Jet.Weight}";