Agliullov D. A. Lab Work 5 Advanced #6

Merged
eegov merged 5 commits from Lab5 into Lab4 2022-10-21 10:40:11 +04:00
3 changed files with 41 additions and 11 deletions
Showing only changes of commit a5f607c8c0 - Show all commits

View File

@ -26,6 +26,22 @@ namespace AirBomber
Airplane = new EntityAirBomber(speed, weight, bodyColor, dopColor, hasBombs, hasFuelTanks);
}
/// <summary>
/// Получения копии текущего объекта. Для перемены свойств изменить необязательные аргументы нужным значением
/// </summary>
/// <param name="speed">The speed.</param>
/// <param name="weight">The weight.</param>
/// <param name="bodyColor">Color of the body.</param>
/// <returns>Копию или Измененную копию текущего объекта</returns>
public DrawningAirBomber Copy(int? speed = null, float? weight = null, Color? bodyColor = null,
Color? dopColor = null, bool? hasBombs = null, bool? hasFuelTanks = null, IAirplaneEngines? typeAirplaneEngines = null)
{
var e = (EntityAirBomber)Airplane;
var res = new DrawningAirBomber(speed ?? e.Speed, weight ?? e.Weight, bodyColor ?? e.BodyColor, dopColor ?? e.DopColor, hasBombs ?? e.HasBombs, hasFuelTanks ?? e.HasFuelTanks);
res.DrawningEngines = typeAirplaneEngines ?? DrawningEngines;
return res;
}
public override void DrawTransport(Graphics g)
{
if (Airplane is not EntityAirBomber airBomber)

View File

@ -10,7 +10,7 @@
/// </summary>
public EntityAirplane Airplane { get; protected set; }
public IAirplaneEngines? DrawningEngines { get; private set; }
public IAirplaneEngines? DrawningEngines { get; protected set; }
/// <summary>
/// Левая координата отрисовки самолета
/// </summary>
@ -52,6 +52,21 @@
Airplane = entityAirplane;
DrawningEngines = typeAirplaneEngines;
}
/// <summary>
/// Получения копии текущего объекта. Для перемены свойств изменить необязательные аргументы нужным значением
/// </summary>
/// <param name="speed">The speed.</param>
/// <param name="weight">The weight.</param>
/// <param name="bodyColor">Color of the body.</param>
/// <returns>Копию или Измененную копию текущего объекта</returns>
public DrawningAirplane Copy(int? speed = null, float? weight = null, Color? bodyColor = null, IAirplaneEngines? typeAirplaneEngines = null)
{
var res = new DrawningAirplane(speed ?? Airplane.Speed, weight ?? Airplane.Weight, bodyColor ?? Airplane.BodyColor);
res.DrawningEngines = typeAirplaneEngines ?? DrawningEngines;
return res;
}
/// <summary>
/// Инициализация свойств
/// </summary>

View File

@ -1,4 +1,5 @@
using System.Xml.Linq;
using System.Drawing;
using System.Xml.Linq;
namespace AirBomber
{
@ -147,12 +148,11 @@ namespace AirBomber
var color = (Color)e.Data.GetData(typeof(Color));
if (_airplane is DrawningAirBomber)
{
var a = (EntityAirBomber)_airplane.Airplane;
_airplane = new DrawningAirBomber(a.Speed, a.Weight, color, a.DopColor, a.HasBombs, a.HasFuelTanks, _airplane.DrawningEngines);
_airplane = ((DrawningAirBomber)_airplane).Copy(bodyColor: color);
}
else if (_airplane is DrawningAirplane)
{
_airplane = new DrawningAirplane(_airplane.Airplane.Speed, _airplane.Airplane.Weight, color, _airplane.DrawningEngines);
_airplane = _airplane.Copy(bodyColor: color);
}
DrawAirplane();
}
@ -164,10 +164,10 @@ namespace AirBomber
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
var color = (Color)e.Data.GetData(typeof(Color));
if (_airplane is DrawningAirBomber)
var airplane = _airplane as DrawningAirBomber;
if (airplane != null)
{
var a = (EntityAirBomber)_airplane.Airplane;
_airplane = new DrawningAirBomber(a.Speed, a.Weight, a.BodyColor, color, a.HasBombs, a.HasFuelTanks, _airplane.DrawningEngines);
_airplane = airplane.Copy(dopColor: color);
}
DrawAirplane();
}
@ -214,12 +214,11 @@ namespace AirBomber
engines.CountEngines = _airplane.DrawningEngines.CountEngines;
if (_airplane is DrawningAirBomber)
{
var a = (EntityAirBomber)_airplane.Airplane;
_airplane = new DrawningAirBomber(a.Speed, a.Weight, a.BodyColor, a.DopColor, a.HasBombs, a.HasFuelTanks, engines);
_airplane = ((DrawningAirBomber)_airplane).Copy(typeAirplaneEngines: engines);
}
else if (_airplane is DrawningAirplane)
{
_airplane = new DrawningAirplane(_airplane.Airplane.Speed, _airplane.Airplane.Weight, _airplane.Airplane.BodyColor, engines);
_airplane = _airplane.Copy(typeAirplaneEngines: engines);
}
DrawAirplane();
}