Мелкие исправления.
This commit is contained in:
parent
2263aa7c83
commit
017b18a3db
@ -96,13 +96,11 @@ namespace AirplaneWithRadar
|
|||||||
int x = _random.Next(0, 10);
|
int x = _random.Next(0, 10);
|
||||||
int y = _random.Next(0, 10);
|
int y = _random.Next(0, 10);
|
||||||
_drawingObject.SetObject(x, y, _width, _height);
|
_drawingObject.SetObject(x, y, _width, _height);
|
||||||
// TODO проверка, что объект не "накладывается" на закрытые участки
|
|
||||||
if (!CheckBarriers(0, 0, 0, 0))
|
if (!CheckBarriers(0, 0, 0, 0))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
private Bitmap DrawMapWithObject()
|
private Bitmap DrawMapWithObject()
|
||||||
{
|
{
|
||||||
|
@ -26,7 +26,6 @@ namespace AirplaneWithRadar
|
|||||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||||
{
|
{
|
||||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, (i + 1) * (_size_x + 1), (j + 1) * (_size_y + 1));
|
g.FillRectangle(roadColor, i * _size_x, j * _size_y, (i + 1) * (_size_x + 1), (j + 1) * (_size_y + 1));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void GenerateMap()
|
protected override void GenerateMap()
|
||||||
@ -49,7 +48,6 @@ namespace AirplaneWithRadar
|
|||||||
int y = _random.Next(0, 80);
|
int y = _random.Next(0, 80);
|
||||||
int blockWidth = _random.Next(0, 19);
|
int blockWidth = _random.Next(0, 19);
|
||||||
int blockHeight = _random.Next(0, 19);
|
int blockHeight = _random.Next(0, 19);
|
||||||
|
|
||||||
bool isFree = true;
|
bool isFree = true;
|
||||||
for (int i = x; i < x + blockWidth; i++)
|
for (int i = x; i < x + blockWidth; i++)
|
||||||
{
|
{
|
||||||
@ -60,7 +58,6 @@ namespace AirplaneWithRadar
|
|||||||
isFree = false;
|
isFree = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isFree)
|
if (isFree)
|
||||||
|
@ -16,11 +16,11 @@ namespace AirplaneWithRadar
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityAirplane Airplane { get; protected set; }
|
public EntityAirplane Airplane { get; protected set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата отрисовки автомобиля
|
/// Левая координата отрисовки самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected float _startPosX;
|
protected float _startPosX;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната отрисовки автомобиля
|
/// Верхняя кооридната отрисовки самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected float _startPosY;
|
protected float _startPosY;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -32,18 +32,18 @@ namespace AirplaneWithRadar
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _pictureHeight = null;
|
private int? _pictureHeight = null;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина отрисовки автомобиля
|
/// Ширина отрисовки самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _airplaneWidth = 303;
|
private readonly int _airplaneWidth = 303;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота отрисовки автомобиля
|
/// Высота отрисовки самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _airplaneHeight = 107;
|
private readonly int _airplaneHeight = 107;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Инициализация свойств
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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 DrawingAirplane(int speed, float weight, Color bodyColor)
|
public DrawingAirplane(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
@ -53,10 +53,10 @@ namespace AirplaneWithRadar
|
|||||||
/// Инициализация свойств
|
/// Инициализация свойств
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">Вес автомобиля</param>
|
/// <param name="weight">Вес самолета</param>
|
||||||
/// <param name="bodyColor">Цвет кузова</param>
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
/// <param name="airplaneWidth">Ширина отрисовки автомобиля</param>
|
/// <param name="airplaneWidth">Ширина отрисовки самолета</param>
|
||||||
/// <param name="airplaneHeight">Высота отрисовки автомобиля</param>
|
/// <param name="airplaneHeight">Высота отрисовки самолета</param>
|
||||||
protected DrawingAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) :
|
protected DrawingAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) :
|
||||||
this(speed, weight, bodyColor)
|
this(speed, weight, bodyColor)
|
||||||
{
|
{
|
||||||
@ -64,7 +64,7 @@ namespace AirplaneWithRadar
|
|||||||
_airplaneHeight = airplaneHeight;
|
_airplaneHeight = airplaneHeight;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиции автомобиля
|
/// Установка позиции самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="x">Координата X</param>
|
/// <param name="x">Координата X</param>
|
||||||
/// <param name="y">Координата Y</param>
|
/// <param name="y">Координата Y</param>
|
||||||
@ -72,7 +72,6 @@ namespace AirplaneWithRadar
|
|||||||
/// <param name="height">Высота картинки</param>
|
/// <param name="height">Высота картинки</param>
|
||||||
public void SetPosition(int x, int y, int width, int height)
|
public void SetPosition(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
// TODO checks
|
|
||||||
if (x > 0 && x < width)
|
if (x > 0 && x < width)
|
||||||
{
|
{
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
@ -89,12 +88,6 @@ namespace AirplaneWithRadar
|
|||||||
{
|
{
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//_startPosX = x;
|
|
||||||
//_startPosY = y;
|
|
||||||
//_pictureWidth = width;
|
|
||||||
//_pictureHeight = height;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Изменение направления пермещения
|
/// Изменение направления пермещения
|
||||||
@ -108,28 +101,24 @@ namespace AirplaneWithRadar
|
|||||||
}
|
}
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
// вправо
|
|
||||||
case Direction.Right:
|
case Direction.Right:
|
||||||
if (_startPosX + _airplaneWidth + Airplane.Step < _pictureWidth)
|
if (_startPosX + _airplaneWidth + Airplane.Step < _pictureWidth)
|
||||||
{
|
{
|
||||||
_startPosX += Airplane.Step;
|
_startPosX += Airplane.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//влево
|
|
||||||
case Direction.Left:
|
case Direction.Left:
|
||||||
if (_startPosX - Airplane.Step > 0)
|
if (_startPosX - Airplane.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= Airplane.Step;
|
_startPosX -= Airplane.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//вверх
|
|
||||||
case Direction.Up:
|
case Direction.Up:
|
||||||
if (_startPosY - Airplane.Step > 0)
|
if (_startPosY - Airplane.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= Airplane.Step;
|
_startPosY -= Airplane.Step;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//вниз
|
|
||||||
case Direction.Down:
|
case Direction.Down:
|
||||||
if (_startPosY + _airplaneHeight + Airplane.Step < _pictureHeight)
|
if (_startPosY + _airplaneHeight + Airplane.Step < _pictureHeight)
|
||||||
{
|
{
|
||||||
@ -139,7 +128,7 @@ namespace AirplaneWithRadar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Отрисовка автомобиля
|
/// Отрисовка самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public virtual void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
@ -218,6 +207,5 @@ namespace AirplaneWithRadar
|
|||||||
{
|
{
|
||||||
return (_startPosX, _startPosX + _airplaneWidth, _startPosY, _startPosY + _airplaneHeight);
|
return (_startPosX, _startPosX + _airplaneWidth, _startPosY, _startPosY + _airplaneHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,16 +12,15 @@ namespace AirplaneWithRadar
|
|||||||
/// Инициализация свойств
|
/// Инициализация свойств
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">Вес автомобиля</param>
|
/// <param name="weight">Вес самолета</param>
|
||||||
/// <param name="bodyColor">Цвет кузова</param>
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
/// <param name="dopColor">Дополнительный цвет</param>
|
/// <param name="dopColor">Дополнительный цвет</param>
|
||||||
/// <param name="radar">Признак наличия обвеса</param>
|
/// <param name="radar">Признак наличия радара</param>
|
||||||
/// <param name="extraFuelTank">Признак наличия антикрыла</param>
|
/// <param name="extraFuelTank">Признак наличия дополнительных топливных баков</param>
|
||||||
public DrawingAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool extraFuelTank) : base(speed, weight, bodyColor, 303, 102)
|
public DrawingAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool extraFuelTank) : base(speed, weight, bodyColor, 303, 102)
|
||||||
{
|
{
|
||||||
Airplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, dopColor, radar, extraFuelTank);
|
Airplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, dopColor, radar, extraFuelTank);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawTransport(Graphics g)
|
public override void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (Airplane is not EntityAirplaneWithRadar airplaneWithRadar)
|
if (Airplane is not EntityAirplaneWithRadar airplaneWithRadar)
|
||||||
@ -30,7 +29,6 @@ namespace AirplaneWithRadar
|
|||||||
}
|
}
|
||||||
Pen pen = new(Color.Black, 5);
|
Pen pen = new(Color.Black, 5);
|
||||||
Brush dopBrush = new SolidBrush(airplaneWithRadar.DopColor);
|
Brush dopBrush = new SolidBrush(airplaneWithRadar.DopColor);
|
||||||
|
|
||||||
if (airplaneWithRadar.Radar)
|
if (airplaneWithRadar.Radar)
|
||||||
{
|
{
|
||||||
g.DrawLine(pen, _startPosX + 120, _startPosY + 30, _startPosX + 110, _startPosY + 60);
|
g.DrawLine(pen, _startPosX + 120, _startPosY + 30, _startPosX + 110, _startPosY + 60);
|
||||||
@ -43,15 +41,12 @@ namespace AirplaneWithRadar
|
|||||||
g.FillPolygon(dopBrush, radarPoints);
|
g.FillPolygon(dopBrush, radarPoints);
|
||||||
g.DrawEllipse(pen, _startPosX + 85, _startPosY + 15, 90, 20);
|
g.DrawEllipse(pen, _startPosX + 85, _startPosY + 15, 90, 20);
|
||||||
g.FillEllipse(dopBrush, _startPosX + 85, _startPosY + 15, 90, 20);
|
g.FillEllipse(dopBrush, _startPosX + 85, _startPosY + 15, 90, 20);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_startPosX += 10;
|
_startPosX += 10;
|
||||||
_startPosY += 5;
|
_startPosY += 5;
|
||||||
base.DrawTransport(g);
|
base.DrawTransport(g);
|
||||||
_startPosX -= 10;
|
_startPosX -= 10;
|
||||||
_startPosY -= 5;
|
_startPosY -= 5;
|
||||||
|
|
||||||
if (airplaneWithRadar.ExtraFuelTank)
|
if (airplaneWithRadar.ExtraFuelTank)
|
||||||
{
|
{
|
||||||
g.DrawLine(pen, _startPosX + 145, _startPosY + 98, _startPosX + 145, _startPosY + 108);
|
g.DrawLine(pen, _startPosX + 145, _startPosY + 98, _startPosX + 145, _startPosY + 108);
|
||||||
|
@ -30,6 +30,5 @@ namespace AirplaneWithRadar
|
|||||||
{
|
{
|
||||||
_airplane.DrawTransport(g);
|
_airplane.DrawTransport(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,11 @@ namespace AirplaneWithRadar
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Color BodyColor { get; private set; }
|
public Color BodyColor { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Шаг перемещения автомобиля
|
/// Шаг перемещения самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float Step => Speed * 100 / Weight;
|
public float Step => Speed * 100 / Weight;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация полей объекта-класса автомобиля
|
/// Инициализация полей объекта-класса самолета
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed"></param>
|
/// <param name="speed"></param>
|
||||||
/// <param name="weight"></param>
|
/// <param name="weight"></param>
|
||||||
@ -42,8 +42,5 @@ namespace AirplaneWithRadar
|
|||||||
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
|
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
|
||||||
BodyColor = bodyColor;
|
BodyColor = bodyColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,29 +13,27 @@ namespace AirplaneWithRadar
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Color DopColor { get; private set; }
|
public Color DopColor { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Признак наличия обвеса
|
/// Признак наличия радара
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Radar { get; private set; }
|
public bool Radar { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Признак наличия антикрыла
|
/// Признак наличия дополнительных топливных баков
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool ExtraFuelTank { get; private set; }
|
public bool ExtraFuelTank { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Инициализация свойств
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
/// <param name="speed">Скорость</param>
|
||||||
/// <param name="weight">Вес автомобиля</param>
|
/// <param name="weight">Вес самолета</param>
|
||||||
/// <param name="bodyColor">Цвет кузова</param>
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
/// <param name="dopColor">Дополнительный цвет</param>
|
/// <param name="dopColor">Дополнительный цвет</param>
|
||||||
/// <param name="radar">Признак наличия обвеса</param>
|
/// <param name="radar">Признак наличия радара</param>
|
||||||
/// <param name="extraFuelTank">Признак наличия антикрыла</param>
|
/// <param name="extraFuelTank">Признак наличия дополнительных топливных баков</param>
|
||||||
public EntityAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool extraFuelTank) : base(speed, weight, bodyColor)
|
public EntityAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool extraFuelTank) : base(speed, weight, bodyColor)
|
||||||
{
|
{
|
||||||
DopColor = dopColor;
|
DopColor = dopColor;
|
||||||
Radar = radar;
|
Radar = radar;
|
||||||
ExtraFuelTank = extraFuelTank;
|
ExtraFuelTank = extraFuelTank;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,6 @@
|
|||||||
this.pictureBoxAirplane.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
this.pictureBoxAirplane.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||||
this.pictureBoxAirplane.TabIndex = 1;
|
this.pictureBoxAirplane.TabIndex = 1;
|
||||||
this.pictureBoxAirplane.TabStop = false;
|
this.pictureBoxAirplane.TabStop = false;
|
||||||
this.pictureBoxAirplane.Click += new System.EventHandler(this.pictureBoxAirplane_Click);
|
|
||||||
//
|
//
|
||||||
// buttonCreate
|
// buttonCreate
|
||||||
//
|
//
|
||||||
|
@ -3,16 +3,14 @@ namespace AirplaneWithRadar
|
|||||||
public partial class FormAirplaneWithRadar : Form
|
public partial class FormAirplaneWithRadar : Form
|
||||||
{
|
{
|
||||||
private DrawingAirplane _airplane;
|
private DrawingAirplane _airplane;
|
||||||
|
|
||||||
public DrawingAirplane SelectedAirplane { get; private set; }
|
public DrawingAirplane SelectedAirplane { get; private set; }
|
||||||
|
|
||||||
public FormAirplaneWithRadar()
|
public FormAirplaneWithRadar()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
/// Ěĺňîä ďđîđčńîâęč ńŕěîëĺňŕ
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
@ -27,7 +25,6 @@ namespace AirplaneWithRadar
|
|||||||
private void SetData()
|
private void SetData()
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
|
|
||||||
_airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
_airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
||||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";
|
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";
|
||||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airplane.Airplane.Weight}";
|
toolStripStatusLabelWeight.Text = $"Âåñ: {_airplane.Airplane.Weight}";
|
||||||
@ -40,16 +37,20 @@ namespace AirplaneWithRadar
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
_airplane = new DrawingAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
_airplane = new DrawingAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
|
||||||
SetData();
|
SetData();
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
//ïîëó÷àåì èìÿ êíîïêè
|
|
||||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
@ -67,18 +68,6 @@ namespace AirplaneWithRadar
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void FormAirplaneWithRadar_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void pictureBoxAirplane_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
|
||||||
@ -88,22 +77,26 @@ namespace AirplaneWithRadar
|
|||||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
_airplane = new DrawingAirplaneWithRadar(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0,2)));
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||||
|
ColorDialog dialogDop = new();
|
||||||
|
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = dialogDop.Color;
|
||||||
|
}
|
||||||
|
_airplane = new DrawingAirplaneWithRadar(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0,2)));
|
||||||
SetData();
|
SetData();
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonSelectAirplane_Click(object sender, EventArgs e)
|
private void ButtonSelectAirplane_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SelectedAirplane = _airplane;
|
SelectedAirplane = _airplane;
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FormAirplaneWithRadar_Load_1(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,15 +1,4 @@
|
|||||||
using System;
|
namespace AirplaneWithRadar
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
using static System.Windows.Forms.DataFormats;
|
|
||||||
|
|
||||||
namespace AirplaneWithRadar
|
|
||||||
{
|
{
|
||||||
public partial class FormMapWithSetAirplanes : Form
|
public partial class FormMapWithSetAirplanes : Form
|
||||||
{
|
{
|
||||||
@ -142,7 +131,6 @@ namespace AirplaneWithRadar
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//получаем имя кнопки
|
|
||||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
Direction dir = Direction.None;
|
Direction dir = Direction.None;
|
||||||
switch (name)
|
switch (name)
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
using System;
|
namespace AirplaneWithRadar
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AirplaneWithRadar
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Интерфейс для работы с объектом, прорисовываемым на форме
|
/// Интерфейс для работы с объектом, прорисовываемым на форме
|
||||||
|
@ -32,7 +32,6 @@ namespace AirplaneWithRadar
|
|||||||
_map = new int[100, 100];
|
_map = new int[100, 100];
|
||||||
_size_x = (float)_width / _map.GetLength(0);
|
_size_x = (float)_width / _map.GetLength(0);
|
||||||
_size_y = (float)_height / _map.GetLength(1);
|
_size_y = (float)_height / _map.GetLength(1);
|
||||||
//int counter = 0;
|
|
||||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||||
@ -40,10 +39,7 @@ namespace AirplaneWithRadar
|
|||||||
_map[i, j] = _freeRoad;
|
_map[i, j] = _freeRoad;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int counter;
|
||||||
|
|
||||||
int counter = 0;
|
|
||||||
|
|
||||||
for (int j = 0; j < _map.GetLength(1); j++)
|
for (int j = 0; j < _map.GetLength(1); j++)
|
||||||
{
|
{
|
||||||
int startX = _random.Next(0, 80);
|
int startX = _random.Next(0, 80);
|
||||||
@ -59,7 +55,6 @@ namespace AirplaneWithRadar
|
|||||||
}
|
}
|
||||||
j += 3;
|
j += 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,27 +161,23 @@ namespace AirplaneWithRadar
|
|||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
private void DrawBackground(Graphics g)
|
private void DrawBackground(Graphics g)
|
||||||
{
|
{
|
||||||
Pen pen = new(Color.White, 3);
|
Pen pen = new(Color.White, 5);
|
||||||
g.FillRectangle(Brushes.Gray, 0, 0, _pictureWidth, _pictureHeight);
|
g.FillRectangle(Brushes.DimGray, 0, 0, _pictureWidth, _pictureHeight);
|
||||||
|
|
||||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
|
||||||
{
|
{
|
||||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth * 3/4, j * _placeSizeHeight);
|
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth * 4/5, j * _placeSizeHeight);
|
||||||
}
|
}
|
||||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Метод прорисовки объектов
|
/// Метод прорисовки объектов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
private void DrawAirplanes(Graphics g)
|
private void DrawAirplanes(Graphics g)
|
||||||
{
|
{
|
||||||
|
|
||||||
int numInRow = _pictureWidth / _placeSizeWidth;
|
int numInRow = _pictureWidth / _placeSizeWidth;
|
||||||
int maxLeft = (numInRow - 1) * _placeSizeWidth;
|
int maxLeft = (numInRow - 1) * _placeSizeWidth;
|
||||||
for (int i = 0; i < _setAirplanes.Count; i++)
|
for (int i = 0; i < _setAirplanes.Count; i++)
|
||||||
@ -191,6 +187,5 @@ namespace AirplaneWithRadar
|
|||||||
airplane?.DrawingObject(g);
|
airplane?.DrawingObject(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ namespace AirplaneWithRadar
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
|
||||||
// see https://aka.ms/applicationconfiguration.
|
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormMapWithSetAirplanes());
|
Application.Run(new FormMapWithSetAirplanes());
|
||||||
}
|
}
|
||||||
|
@ -32,47 +32,33 @@ namespace AirplaneWithRadar
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="airplane">Добавляемый автомобиль</param>
|
/// <param name="airplane">Добавляемый самолет</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T airplane)
|
public int Insert(T airplane)
|
||||||
{
|
{
|
||||||
// TODO вставка в начало набора
|
|
||||||
return Insert(airplane, 0);
|
return Insert(airplane, 0);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор на конкретную позицию
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="airplane">Добавляемый автомобиль</param>
|
/// <param name="airplane">Добавляемый самолет</param>
|
||||||
/// <param name="position">Позиция</param>
|
/// <param name="position">Позиция</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T airplane, int position)
|
public int Insert(T airplane, int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
int positionNullElement = position;
|
||||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то проверка, что после вставляемого элемента в массиве есть пустой элемент
|
while (Get(positionNullElement) != null)
|
||||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
{
|
||||||
// TODO вставка по позиции
|
positionNullElement++;
|
||||||
if (position >= _places.Length)
|
}
|
||||||
|
if (positionNullElement > Count || positionNullElement < 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (_places[position] != null)
|
while (positionNullElement != position)
|
||||||
{
|
{
|
||||||
int indexNull = -1;
|
_places[positionNullElement] = _places[positionNullElement - 1];
|
||||||
for (int i = position; i < _places.Length; i++)
|
positionNullElement--;
|
||||||
{
|
|
||||||
if (_places[i] == null)
|
|
||||||
{
|
|
||||||
indexNull = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (indexNull == -1) return -1;
|
|
||||||
for (int i = indexNull; i > position; i--)
|
|
||||||
{
|
|
||||||
T tmp = _places[i];
|
|
||||||
_places[i] = _places[i - 1];
|
|
||||||
_places[i - 1] = tmp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_places[position] = airplane;
|
_places[position] = airplane;
|
||||||
return position;
|
return position;
|
||||||
@ -84,15 +70,16 @@ namespace AirplaneWithRadar
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T Remove(int position)
|
public T Remove(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
if (position > Count || position < 0)
|
||||||
// TODO удаление объекта из массива, присовив элементу массива значение null
|
|
||||||
if (position >= _places.Length)
|
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
T removedObject = _places[position];
|
else
|
||||||
_places[position] = null;
|
{
|
||||||
return removedObject;
|
var removedObject = _places[position];
|
||||||
|
_places[position] = null;
|
||||||
|
return removedObject;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение объекта из набора по позиции
|
/// Получение объекта из набора по позиции
|
||||||
@ -101,12 +88,14 @@ namespace AirplaneWithRadar
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T Get(int position)
|
public T Get(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
if (position > Count || position < 0)
|
||||||
if (position >= _places.Length)
|
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return _places[position];
|
else
|
||||||
|
{
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user