Compare commits
No commits in common. "fc86d0a67c1f72eddaff9e55a04030e01b92945b" and "bae1ea9e280a6e32e06f8f32cafe4eb04d1a4ed6" have entirely different histories.
fc86d0a67c
...
bae1ea9e28
@ -1,11 +1,10 @@
|
||||
namespace ProjectAirBomber.Drawnings;
|
||||
namespace ProjectAirBomber;
|
||||
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
Unknow = -1,
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
@ -1,18 +1,14 @@
|
||||
using ProjectAirBomber.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace ProjectAirBomber;
|
||||
|
||||
namespace ProjectAirBomber.Drawnings;
|
||||
|
||||
public class DrawningBomber
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningAirBomber
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityBomber? EntityBomber { get; protected set; }
|
||||
public EntityAirBomber? EntityAirBomber { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
@ -27,17 +23,17 @@ public class DrawningBomber
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки бомбардировщика
|
||||
/// </summary>
|
||||
protected int? _startPosX;
|
||||
private int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки бомбардировщика
|
||||
/// </summary>
|
||||
protected int? _startPosY;
|
||||
private int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки бомбардировщика
|
||||
/// </summary>
|
||||
private readonly int _drawningAirBomberWidth = 190;
|
||||
private readonly int _drawningAirBomberWidth = 200;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки бомбардировщика
|
||||
@ -45,55 +41,23 @@ public class DrawningBomber
|
||||
private readonly int _drawningAirBomberHeight = 160;
|
||||
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int? GetPosX => _startPosX;
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int? GetPosY => _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawningAirBomberWidth;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawningAirBomberHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
public DrawningBomber()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <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 DrawningBomber(int speed, double weight, Color bodyColor) : this()
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool fuelTanks, bool bombs)
|
||||
{
|
||||
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;
|
||||
EntityAirBomber = new EntityAirBomber();
|
||||
EntityAirBomber.Init(speed, weight, bodyColor, additionalColor, fuelTanks, bombs);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -160,7 +124,7 @@ public class DrawningBomber
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityBomber == null || !_startPosX.HasValue ||
|
||||
if (EntityAirBomber == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
@ -173,30 +137,30 @@ public class DrawningBomber
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityBomber.Step > 0)
|
||||
if (_startPosX.Value - EntityAirBomber.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityBomber.Step;
|
||||
_startPosX -= (int)EntityAirBomber.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityBomber.Step > 0)
|
||||
if (_startPosY.Value - EntityAirBomber.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityBomber.Step;
|
||||
_startPosY -= (int)EntityAirBomber.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + EntityBomber.Step < _pictureWidth - _drawningAirBomberWidth)
|
||||
if (_startPosX.Value + EntityAirBomber.Step < _pictureWidth - _drawningAirBomberWidth)
|
||||
{
|
||||
_startPosX += (int)EntityBomber.Step;
|
||||
_startPosX += (int)EntityAirBomber.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntityBomber.Step < _pictureHeight - _drawningAirBomberHeight)
|
||||
if (_startPosY.Value + EntityAirBomber.Step < _pictureHeight - _drawningAirBomberHeight)
|
||||
{
|
||||
_startPosY += (int)EntityBomber.Step;
|
||||
_startPosY += (int)EntityAirBomber.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
@ -204,72 +168,102 @@ public class DrawningBomber
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBomber == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityAirBomber == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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 + 40, _startPosY.Value + 55, 150, 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 60, 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);
|
||||
g.FillRectangle(brGray, _startPosX.Value + 95, _startPosY.Value, 15, 160);
|
||||
g.FillRectangle(brGray, _startPosX.Value + 105, _startPosY.Value, 20, 160);
|
||||
|
||||
//правое крыло
|
||||
g.FillPolygon(brGray, new Point[]
|
||||
{
|
||||
new Point(_startPosX.Value + 95, _startPosY.Value),
|
||||
new Point(_startPosX.Value + 110, _startPosY.Value + 5),
|
||||
new Point(_startPosX.Value + 118, _startPosY.Value + 85)
|
||||
new Point(_startPosX.Value + 105, _startPosY.Value),
|
||||
new Point(_startPosX.Value + 125, _startPosY.Value + 10),
|
||||
new Point(_startPosX.Value + 135, _startPosY.Value + 90)
|
||||
});
|
||||
|
||||
////левое крыло
|
||||
g.FillPolygon(brGray, new Point[]
|
||||
{
|
||||
new Point(_startPosX.Value + 95, _startPosY.Value + 85),
|
||||
new Point(_startPosX.Value + 110, _startPosY.Value + 135),
|
||||
new Point(_startPosX.Value + 115, _startPosY.Value + 85)
|
||||
new Point(_startPosX.Value + 105, _startPosY.Value + 90),
|
||||
new Point(_startPosX.Value + 125, _startPosY.Value + 140),
|
||||
new Point(_startPosX.Value + 131, _startPosY.Value + 90)
|
||||
});
|
||||
|
||||
//задние крылья
|
||||
|
||||
g.FillRectangle(brGray, _startPosX.Value + 160, _startPosY.Value + 40, 30, 60);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 170, _startPosY.Value + 45, 30, 60);
|
||||
|
||||
g.FillPolygon(brGray, new Point[]
|
||||
g.FillPolygon(additionalBrush, new Point[]
|
||||
{
|
||||
new Point(_startPosX.Value + 160, _startPosY.Value + 40),
|
||||
new Point(_startPosX.Value + 190, _startPosY.Value + 55),
|
||||
new Point(_startPosX.Value + 190, _startPosY.Value + 5)
|
||||
new Point(_startPosX.Value + 170, _startPosY.Value + 45),
|
||||
new Point(_startPosX.Value + 200, _startPosY.Value + 60),
|
||||
new Point(_startPosX.Value + 200, _startPosY.Value + 10)
|
||||
});
|
||||
g.FillPolygon(brGray, new Point[]
|
||||
g.FillPolygon(additionalBrush, new Point[]
|
||||
{
|
||||
new Point(_startPosX.Value + 160, _startPosY.Value + 100),
|
||||
new Point(_startPosX.Value + 190, _startPosY.Value + 100),
|
||||
new Point(_startPosX.Value + 190, _startPosY.Value + 140)
|
||||
new Point(_startPosX.Value + 170, _startPosY.Value + 105),
|
||||
new Point(_startPosX.Value + 200, _startPosY.Value + 105),
|
||||
new Point(_startPosX.Value + 200, _startPosY.Value + 145)
|
||||
});
|
||||
|
||||
|
||||
|
||||
//фюзеляж
|
||||
Brush br = new SolidBrush(EntityBomber.BodyColor);
|
||||
g.FillRectangle(br, _startPosX.Value + 40, _startPosY.Value + 55, 150, 30);
|
||||
Brush br = new SolidBrush(EntityAirBomber.BodyColor);
|
||||
g.FillRectangle(br, _startPosX.Value + 50, _startPosY.Value + 60, 150, 30);
|
||||
|
||||
//передняя часть (треугольник)
|
||||
|
||||
g.FillPolygon(brBlack, new Point[]
|
||||
g.FillPolygon(additionalBrush, new Point[]
|
||||
{
|
||||
new Point(_startPosX.Value + 40, _startPosY.Value + 55),
|
||||
new Point(_startPosX.Value + 40, _startPosY.Value + 85),
|
||||
new Point(_startPosX.Value, _startPosY.Value + 65)
|
||||
new Point(_startPosX.Value + 50, _startPosY.Value + 60),
|
||||
new Point(_startPosX.Value + 50, _startPosY.Value + 90),
|
||||
new Point(_startPosX.Value, _startPosY.Value + 75)
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
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) : 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,40 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,12 +1,24 @@
|
||||
namespace ProjectAirBomber.Entities;
|
||||
namespace ProjectAirBomber;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Бомбардировщик"
|
||||
/// </summary>
|
||||
public class EntityAirBomber : EntityBomber
|
||||
public class EntityAirBomber
|
||||
{
|
||||
/// <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>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
@ -39,8 +51,11 @@ public class EntityAirBomber : EntityBomber
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="fuelTanks">Признак наличия дополнительных топливных баков</param>
|
||||
/// <param name="bombs">Признак наличия бомб</param>
|
||||
public EntityAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool fuelTanks, bool bombs): base(speed, weight, bodyColor)
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool fuelTanks, bool bombs)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
FuelTanks = fuelTanks;
|
||||
Bombs = bombs;
|
@ -1,15 +1,11 @@
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ProjectAirBomber
|
||||
namespace ProjectAirBomber
|
||||
{
|
||||
partial class FormAirBomber
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
@ -35,32 +31,29 @@ namespace ProjectAirBomber
|
||||
pictureBoxAirBomber = new PictureBox();
|
||||
buttonCreateAirBomber = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonCreateCar = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
buttonUp = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxElectroTrans
|
||||
// pictureBoxAirBomber
|
||||
//
|
||||
pictureBoxAirBomber.Dock = DockStyle.Fill;
|
||||
pictureBoxAirBomber.Location = new Point(0, 0);
|
||||
pictureBoxAirBomber.Name = "pictureBoxElectroTrans";
|
||||
pictureBoxAirBomber.Size = new Size(923, 597);
|
||||
pictureBoxAirBomber.Name = "pictureBoxAirBomber";
|
||||
pictureBoxAirBomber.Size = new Size(880, 510);
|
||||
pictureBoxAirBomber.TabIndex = 0;
|
||||
pictureBoxAirBomber.TabStop = false;
|
||||
//
|
||||
// buttonCreateElectroTrans
|
||||
// buttonCreateAirBomber
|
||||
//
|
||||
buttonCreateAirBomber.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateAirBomber.Location = new Point(12, 562);
|
||||
buttonCreateAirBomber.Location = new Point(12, 475);
|
||||
buttonCreateAirBomber.Name = "buttonCreateAirBomber";
|
||||
buttonCreateAirBomber.Size = new Size(223, 23);
|
||||
buttonCreateAirBomber.Size = new Size(75, 23);
|
||||
buttonCreateAirBomber.TabIndex = 1;
|
||||
buttonCreateAirBomber.Text = "Создать бомбардировщик";
|
||||
buttonCreateAirBomber.Text = "Создать";
|
||||
buttonCreateAirBomber.UseVisualStyleBackColor = true;
|
||||
buttonCreateAirBomber.Click += ButtonCreateAirBomber_Click;
|
||||
//
|
||||
@ -69,34 +62,22 @@ namespace ProjectAirBomber
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonLeft.Location = new Point(787, 550);
|
||||
buttonLeft.Location = new Point(750, 469);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(35, 35);
|
||||
buttonLeft.TabIndex = 2;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonUp.Location = new Point(828, 509);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(35, 35);
|
||||
buttonUp.TabIndex = 3;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDown.Location = new Point(828, 550);
|
||||
buttonDown.Location = new Point(786, 469);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(35, 35);
|
||||
buttonDown.TabIndex = 4;
|
||||
buttonDown.TabIndex = 3;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
@ -105,60 +86,38 @@ namespace ProjectAirBomber
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonRight.Location = new Point(869, 550);
|
||||
buttonRight.Location = new Point(822, 469);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(35, 35);
|
||||
buttonRight.TabIndex = 5;
|
||||
buttonRight.TabIndex = 4;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateCar
|
||||
// buttonUp
|
||||
//
|
||||
buttonCreateCar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateCar.Location = new Point(250, 562);
|
||||
buttonCreateCar.Name = "buttonCreateTrans";
|
||||
buttonCreateCar.Size = new Size(223, 23);
|
||||
buttonCreateCar.TabIndex = 6;
|
||||
buttonCreateCar.Text = "Создать военный самолет";
|
||||
buttonCreateCar.UseVisualStyleBackColor = true;
|
||||
buttonCreateCar.Click += ButtonCreateBomber_Click;
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonUp.Location = new Point(786, 433);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(35, 35);
|
||||
buttonUp.TabIndex = 5;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
|
||||
comboBoxStrategy.Location = new Point(790, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(121, 23);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStrategyStep
|
||||
//
|
||||
buttonStrategyStep.Location = new Point(836, 41);
|
||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||
buttonStrategyStep.Size = new Size(75, 23);
|
||||
buttonStrategyStep.TabIndex = 8;
|
||||
buttonStrategyStep.Text = "Шаг";
|
||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||
buttonStrategyStep.Click += ButtonStrategyStep_Click;
|
||||
//
|
||||
// FormElectroTrans
|
||||
// FormAirBomber
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(923, 597);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateCar);
|
||||
ClientSize = new Size(880, 510);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreateAirBomber);
|
||||
Controls.Add(pictureBoxAirBomber);
|
||||
Name = "FormElectroTrans";
|
||||
Text = "Электропоезд";
|
||||
Name = "FormAirBomber";
|
||||
Text = "Бомбардировщик";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
@ -168,11 +127,8 @@ namespace ProjectAirBomber
|
||||
private PictureBox pictureBoxAirBomber;
|
||||
private Button buttonCreateAirBomber;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonCreateCar;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
private Button buttonUp;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,87 +1,64 @@
|
||||
using ProjectAirBomber.Drawnings;
|
||||
using ProjectAirBomber.MovementStrategy;
|
||||
|
||||
namespace ProjectAirBomber;
|
||||
namespace ProjectAirBomber;
|
||||
|
||||
/// <summary>
|
||||
/// Форма работы с объектом "Бомбардировщик"
|
||||
/// </summary>
|
||||
public partial class FormAirBomber : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningBomber? _drawingBomber;
|
||||
private DrawningAirBomber? _drawningAirBomber;
|
||||
|
||||
/// <summary>
|
||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||
/// Конструктор формы
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
public FormAirBomber()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
||||
/// Метод прорисовки бомбардировщика
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingBomber == null)
|
||||
if (_drawningAirBomber == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bmp = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawingBomber.DrawTransport(gr);
|
||||
_drawningAirBomber.DrawTransport(gr);
|
||||
pictureBoxAirBomber.Image = bmp;
|
||||
}
|
||||
private void CreateObject(string type)
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateAirBomber_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningBomber):
|
||||
_drawingBomber = 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):
|
||||
_drawingBomber = 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)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
_drawingBomber.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||
_drawingBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_strategy = null;
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_drawningAirBomber = new DrawningAirBomber();
|
||||
_drawningAirBomber.Init(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)));
|
||||
_drawningAirBomber.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||
_drawningAirBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü ñïîðòèâíûé àâòîìîáèëü"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateAirBomber_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirBomber));
|
||||
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü àâòîìîáèëü"
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateBomber_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBomber));
|
||||
/// <summary>
|
||||
/// Ïåðåìåùåíèå îáúåêòà ïî ôîðìå (íàæàòèå êíîïîê íàâèãàöèè)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingBomber == null)
|
||||
if (_drawningAirBomber == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -91,16 +68,16 @@ public partial class FormAirBomber : Form
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawingBomber.MoveTransport(DirectionType.Up);
|
||||
result = _drawningAirBomber.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawingBomber.MoveTransport(DirectionType.Down);
|
||||
result = _drawningAirBomber.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawingBomber.MoveTransport(DirectionType.Left);
|
||||
result = _drawningAirBomber.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawingBomber.MoveTransport(DirectionType.Right);
|
||||
result = _drawningAirBomber.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -109,46 +86,4 @@ public partial class FormAirBomber : Form
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingBomber == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableTrans(_drawingBomber), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
|
||||
}
|
||||
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
|
||||
namespace ProjectAirBomber.MovementStrategy;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Класс-стратегия перемещения объекта
|
||||
/// </summary>
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObject? _moveableObject;
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||
/// <summary>
|
||||
/// Ширина поля
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
/// <summary>
|
||||
/// Высота поля
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
public StrategyStatus GetStatus() { return _state; }
|
||||
/// <summary>
|
||||
/// Установка данных
|
||||
/// </summary>
|
||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = StrategyStatus.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = StrategyStatus.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = StrategyStatus.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
||||
/// <summary>
|
||||
/// Перемещение вверх
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
||||
/// <summary>
|
||||
/// Перемещение вниз
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters? GetObjectParameters =>
|
||||
_moveableObject?.GetObjectPosition;
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
/// <summary>
|
||||
/// Достигнута ли цель
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
/// <summary>
|
||||
/// Попытка перемещения в требуемом направлении
|
||||
/// </summary>
|
||||
/// <param name="movementDirection">Направление</param>
|
||||
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||
private bool MoveTo(MovementDirection movementDirection)
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
|
||||
|
||||
namespace ProjectAirBomber.MovementStrategy;
|
||||
|
||||
public interface IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты объекта
|
||||
/// </summary>
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
/// <summary>
|
||||
/// Попытка переместить объект в указанном направлении
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - объект перемещен, false - перемещение невозможно</returns>
|
||||
bool TryMoveObject(MovementDirection direction);
|
||||
}
|
||||
|
@ -1,52 +0,0 @@
|
||||
using ProjectAirBomber.MovementStrategy;
|
||||
|
||||
namespace ProjectAirBomber.MovementStrategy;
|
||||
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth
|
||||
&& objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth &&
|
||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight
|
||||
&& objParams.ObjectMiddleVertical + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth - 5;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
int diffY = objParams.ObjectMiddleVertical - FieldHeight - 5;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
|
||||
namespace ProjectAirBomber.MovementStrategy;
|
||||
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2
|
||||
&& objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2
|
||||
&& objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
using ProjectAirBomber.Drawnings;
|
||||
|
||||
|
||||
namespace ProjectAirBomber.MovementStrategy;
|
||||
public class MoveableTrans : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект класса DrawningTrans или его наследника
|
||||
/// </summary>
|
||||
private readonly DrawningBomber? _bomber = null;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="bomber">Объект класса DrawningTrans</param>
|
||||
public MoveableTrans(DrawningBomber bomber)
|
||||
{
|
||||
_bomber = bomber;
|
||||
}
|
||||
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_bomber == null || _bomber.EntityBomber == null ||
|
||||
!_bomber.GetPosX.HasValue || !_bomber.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_bomber.GetPosX.Value,
|
||||
_bomber.GetPosY.Value, _bomber.GetWidth, _bomber.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_bomber?.EntityBomber?.Step ?? 0);
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if (_bomber == null || _bomber.EntityBomber == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _bomber.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
/// <summary>
|
||||
/// Конвертация из MovementDirection в DirectionType
|
||||
/// </summary>
|
||||
/// <param name="direction">MovementDirection</param>
|
||||
/// <returns>DirectionType</returns>
|
||||
private static DirectionType GetDirectionType(MovementDirection direction)
|
||||
{
|
||||
return direction switch
|
||||
{
|
||||
MovementDirection.Left => DirectionType.Left,
|
||||
MovementDirection.Right => DirectionType.Right,
|
||||
MovementDirection.Up => DirectionType.Up,
|
||||
MovementDirection.Down => DirectionType.Down,
|
||||
_ => DirectionType.Unknow,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
namespace ProjectAirBomber.MovementStrategy;
|
||||
|
||||
public enum MovementDirection
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
namespace ProjectAirBomber.MovementStrategy;
|
||||
|
||||
public class ObjectParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Координата X
|
||||
/// </summary>
|
||||
private readonly int _x;
|
||||
/// <summary>
|
||||
/// Координата Y
|
||||
/// </summary>
|
||||
private readonly int _y;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
private readonly int _width;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
private readonly int _height;
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
public int LeftBorder => _x;
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
public int TopBorder => _y;
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
public int RightBorder => _x + _width;
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
public int DownBorder => _y + _height;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина объекта</param>
|
||||
/// <param name="height">Высота объекта</param>
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
namespace ProjectAirBomber.MovementStrategy;
|
||||
|
||||
public enum StrategyStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Все готово к началу
|
||||
/// </summary>
|
||||
NotInit,
|
||||
/// <summary>
|
||||
/// Выполняется
|
||||
/// </summary>
|
||||
InProgress,
|
||||
/// <summary>
|
||||
/// Завершено
|
||||
/// </summary>
|
||||
Finish
|
||||
}
|
Loading…
Reference in New Issue
Block a user