Compare commits
6 Commits
master
...
LabWork3Ad
Author | SHA1 | Date | |
---|---|---|---|
2e574e6b57 | |||
44c31f0029 | |||
da30b3db9f | |||
9abc6120dc | |||
307b802e23 | |||
d3ef8ea0e2 |
121
AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs
Normal file
121
AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs
Normal file
@ -0,0 +1,121 @@
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
internal abstract class AbstractMap
|
||||
{
|
||||
private IDrawningObject _drawningObject = null;
|
||||
protected int[,] _map = null;
|
||||
protected int _width;
|
||||
protected int _height;
|
||||
protected float _size_x;
|
||||
protected float _size_y;
|
||||
protected readonly Random _random = new();
|
||||
protected readonly int _freeRoad = 0;
|
||||
protected readonly int _barrier = 1;
|
||||
public Bitmap CreateMap(int width, int height, IDrawningObject drawningObject)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
_drawningObject = drawningObject;
|
||||
GenerateMap();
|
||||
while (!SetObjectOnMap())
|
||||
{
|
||||
GenerateMap();
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
private bool HasCollisionBarrier(float x, float y, float right, float bottom)
|
||||
{
|
||||
if (x < 0 || y < 0 || right > _width || bottom > _height)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (float i = x / _size_x; i < right / _size_x; i++)
|
||||
{
|
||||
for (float j = y / _size_y; j < bottom / _size_y; j++)
|
||||
{
|
||||
if (_map[(int)i, (int)j] == _barrier)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
(float left, float top, float right, float bottom) = _drawningObject.GetCurrentPosition();
|
||||
float width = right - left, height = bottom - top;
|
||||
if (direction == Direction.Up)
|
||||
{
|
||||
top -= _drawningObject.Step;
|
||||
}
|
||||
if (direction == Direction.Down)
|
||||
{
|
||||
top += _drawningObject.Step;
|
||||
}
|
||||
if (direction == Direction.Left)
|
||||
{
|
||||
left -= _drawningObject.Step;
|
||||
}
|
||||
if (direction == Direction.Right)
|
||||
{
|
||||
left += _drawningObject.Step;
|
||||
}
|
||||
if (!HasCollisionBarrier(left, top, left + width, top + height))
|
||||
{
|
||||
_drawningObject.MoveObject(direction);
|
||||
}
|
||||
return DrawMapWithObject();
|
||||
}
|
||||
|
||||
private bool SetObjectOnMap()
|
||||
{
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
(float left, float top, float right, float bottom) = _drawningObject.GetCurrentPosition();
|
||||
|
||||
return !HasCollisionBarrier(x, y, right, bottom);
|
||||
}
|
||||
private Bitmap DrawMapWithObject()
|
||||
{
|
||||
Bitmap bmp = new(_width, _height);
|
||||
if (_drawningObject == null || _map == null)
|
||||
{
|
||||
return bmp;
|
||||
}
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
if (_map[i, j] == _freeRoad)
|
||||
{
|
||||
DrawRoadPart(gr, i, j);
|
||||
}
|
||||
else if (_map[i, j] == _barrier)
|
||||
{
|
||||
DrawBarrierPart(gr, i, j);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
_drawningObject.DrawningObject(gr);
|
||||
return bmp;
|
||||
}
|
||||
protected abstract void GenerateMap();
|
||||
protected abstract void DrawRoadPart(Graphics g, int i, int j);
|
||||
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
|
||||
}
|
||||
}
|
@ -4,8 +4,9 @@ namespace AirplaneWithRadar
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
internal enum Direction
|
||||
public enum Direction
|
||||
{
|
||||
None = 0,
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
|
@ -4,50 +4,70 @@ namespace AirplaneWithRadar
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
internal class DrawningAirplane
|
||||
public class DrawningAirplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAirplane Airplane { private set; get; }
|
||||
public DrawningAirplanePortholes DrawningPortholes { get; private set; }
|
||||
public EntityAirplane Airplane { protected set; get; }
|
||||
public IAirplanePortholes DrawningPortholes { get; private set; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки самолёта
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки самолёта
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private int? _pictureWidth = null;
|
||||
protected int? _pictureWidth = null;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private int? _pictureHeight = null;
|
||||
protected int? _pictureHeight = null;
|
||||
/// <summary>
|
||||
/// Ширина отрисовки
|
||||
/// </summary>
|
||||
private readonly int _airplaneWidth = 100;
|
||||
protected readonly int _airplaneWidth = 100;
|
||||
/// <summary>
|
||||
/// Высота отрисовки самолёта
|
||||
/// </summary>
|
||||
private readonly int _airplaneHeight = 20;
|
||||
protected readonly int _airplaneHeight = 20;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет</param>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Цвет обшивки</param>
|
||||
/// <param name="typeAirplanePortholes">Какие будут иллюминаторы самолета</param>
|
||||
public DrawningAirplane(int speed, float weight, Color bodyColor, IAirplanePortholes typeAirplanePortholes)
|
||||
{
|
||||
Airplane = new EntityAirplane();
|
||||
Airplane.Init(speed, weight, bodyColor);
|
||||
DrawningPortholes = new();
|
||||
DrawningPortholes.CountPortholes = 10;
|
||||
Airplane = new EntityAirplane(speed, weight, bodyColor);
|
||||
DrawningPortholes = typeAirplanePortholes;
|
||||
}
|
||||
public DrawningAirplane(EntityAirplane entityAirplane, IAirplanePortholes typeAirplanePortholes)
|
||||
{
|
||||
Airplane = entityAirplane;
|
||||
DrawningPortholes = typeAirplanePortholes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолёта</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="airplaneWidth">Ширина отрисовки самолёта</param>
|
||||
/// <param name="airplaneHeight">Высота отрисовки самолёта</param>
|
||||
protected DrawningAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight, IAirplanePortholes typeAirplanePortholes) :
|
||||
this(speed, weight, bodyColor, typeAirplanePortholes)
|
||||
{
|
||||
_airplaneWidth = airplaneWidth;
|
||||
_airplaneHeight = airplaneHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
@ -114,7 +134,7 @@ namespace AirplaneWithRadar
|
||||
/// Отрисовка самолёта
|
||||
/// </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)
|
||||
@ -183,6 +203,17 @@ namespace AirplaneWithRadar
|
||||
_startPosY = _pictureHeight.Value - _airplaneHeight;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение текущей позиции объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public (float Left, float Top, float Right, float Bottom)
|
||||
GetCurrentPosition()
|
||||
{
|
||||
return (_startPosX, _startPosY, _startPosX + _airplaneWidth, _startPosY +
|
||||
_airplaneHeight);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
internal class DrawningAirplanePortholes
|
||||
internal class DrawningAirplanePortholes : IAirplanePortholes
|
||||
{
|
||||
private CountPortholes _countPortholes;
|
||||
|
||||
@ -33,7 +33,7 @@ namespace AirplaneWithRadar
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawPorthole(Graphics g, int _startPosX, int _startPosY)
|
||||
protected virtual void DrawPorthole(Graphics g, int _startPosX, int _startPosY)
|
||||
{
|
||||
Pen pen = new(Color.Black);
|
||||
g.DrawRectangle(pen, _startPosX, _startPosY, 2, 2);
|
||||
|
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
internal class DrawningAirplaneWithRadar : DrawningAirplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="radar">Признак наличия радара</param>
|
||||
/// <param name="fuelTanks">Признак наличия дополнительных топливных баков</param>
|
||||
public DrawningAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool fuelTanks, IAirplanePortholes typeAirplanePortholes) :
|
||||
base(speed, weight, bodyColor, 100, 20, typeAirplanePortholes)
|
||||
{
|
||||
Airplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, dopColor, radar, fuelTanks);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Airplane is not EntityAirplaneWithRadar airplaneWithRadar)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(airplaneWithRadar.DopColor);
|
||||
if (airplaneWithRadar.Radar)
|
||||
{
|
||||
g.FillEllipse(dopBrush, _startPosX + 30, _startPosY, 20, 5);
|
||||
g.DrawLine(pen, _startPosX + 33, _startPosY + 4, _startPosX + 33, _startPosY + 7);
|
||||
g.DrawLine(pen, _startPosX + 47, _startPosY + 4, _startPosX + 47, _startPosY + 7);
|
||||
}
|
||||
base.DrawTransport(g);
|
||||
if (airplaneWithRadar.FuelTanks)
|
||||
{
|
||||
g.FillEllipse(dopBrush, _startPosX + 25, _startPosY + 15, 30, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
internal class DrawningDeltaPortholes : DrawningAirplanePortholes
|
||||
{
|
||||
protected override void DrawPorthole(Graphics g, int _startPosX, int _startPosY)
|
||||
{
|
||||
Pen pen = new (Color.Black);
|
||||
PointF[] point = new PointF[3];
|
||||
point[0] = new PointF(_startPosX, _startPosY);
|
||||
point[1] = new PointF(_startPosX-2, _startPosY+2);
|
||||
point[2] = new PointF(_startPosX + 2, _startPosY + 2);
|
||||
g.DrawPolygon(pen, point);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
internal class DrawningObjectAirplane : IDrawningObject
|
||||
{
|
||||
private DrawningAirplane _airplane = null;
|
||||
public DrawningObjectAirplane(DrawningAirplane airplane)
|
||||
{
|
||||
_airplane = airplane;
|
||||
}
|
||||
public float Step => _airplane?.Airplane?.Step ?? 0;
|
||||
public (float Left, float Top, float Right, float Bottom)
|
||||
GetCurrentPosition()
|
||||
{
|
||||
return _airplane?.GetCurrentPosition() ?? default;
|
||||
}
|
||||
public void MoveObject(Direction direction)
|
||||
{
|
||||
_airplane?.MoveTransport(direction);
|
||||
}
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_airplane.SetPosition(x, y, width, height);
|
||||
}
|
||||
public void DrawningObject(Graphics g)
|
||||
{
|
||||
_airplane.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
internal class DrawningRhombusPortholes : DrawningAirplanePortholes
|
||||
{
|
||||
protected override void DrawPorthole(Graphics g, int _startPosX, int _startPosY)
|
||||
{
|
||||
Pen pen = new(Color.Black);
|
||||
PointF[] point = new PointF[4];
|
||||
point[0] = new PointF(_startPosX, _startPosY);
|
||||
point[1] = new PointF(_startPosX - 2, _startPosY + 2);
|
||||
point[2] = new PointF(_startPosX, _startPosY + 4);
|
||||
point[3] = new PointF(_startPosX + 2, _startPosY + 2);
|
||||
g.DrawPolygon(pen, point);
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ namespace AirplaneWithRadar
|
||||
/// <summary>
|
||||
/// Класс-сущность "Самолёт"
|
||||
/// </summary>
|
||||
internal class EntityAirplane
|
||||
public class EntityAirplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
@ -29,7 +29,7 @@ namespace AirplaneWithRadar
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <returns></returns>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public EntityAirplane(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new();
|
||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||
|
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
internal class EntityAirplaneWithRadar : EntityAirplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color DopColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия радара
|
||||
/// </summary>
|
||||
public bool Radar { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия дополнительного топливного бака
|
||||
/// </summary>
|
||||
public bool FuelTanks { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолёта</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="radar">Признак наличия радара</param>
|
||||
/// <param name="fuelTanks">Признак наличия дополнительных топливных баков</param>
|
||||
public EntityAirplaneWithRadar(int speed, float weight, Color bodyColor, Color
|
||||
dopColor, bool radar, bool fuelTanks) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
Radar = radar;
|
||||
FuelTanks = fuelTanks;
|
||||
}
|
||||
}
|
||||
}
|
@ -40,6 +40,9 @@
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.labelPortholes = new System.Windows.Forms.Label();
|
||||
this.comboBoxPortholes = new System.Windows.Forms.ComboBox();
|
||||
this.comboBoxTypePortholes = new System.Windows.Forms.ComboBox();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
this.buttonSelectAirplane = new System.Windows.Forms.Button();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -94,7 +97,7 @@
|
||||
this.buttonCreate.TabIndex = 2;
|
||||
this.buttonCreate.Text = "Создать";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
@ -166,11 +169,48 @@
|
||||
this.comboBoxPortholes.TabIndex = 8;
|
||||
this.comboBoxPortholes.Text = "10";
|
||||
//
|
||||
// comboBoxTypePortholes
|
||||
//
|
||||
this.comboBoxTypePortholes.FormattingEnabled = true;
|
||||
this.comboBoxTypePortholes.Items.AddRange(new object[] {
|
||||
"Квадратные",
|
||||
"Треугольные",
|
||||
"Ромбовидные"});
|
||||
this.comboBoxTypePortholes.Location = new System.Drawing.Point(12, 338);
|
||||
this.comboBoxTypePortholes.Name = "comboBoxTypePortholes";
|
||||
this.comboBoxTypePortholes.Size = new System.Drawing.Size(121, 23);
|
||||
this.comboBoxTypePortholes.TabIndex = 9;
|
||||
this.comboBoxTypePortholes.Text = "Квадратные";
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(93, 395);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(115, 23);
|
||||
this.buttonCreateModif.TabIndex = 10;
|
||||
this.buttonCreateModif.Text = "Модификация";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||
//
|
||||
// buttonSelectAirplane
|
||||
//
|
||||
this.buttonSelectAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonSelectAirplane.Location = new System.Drawing.Point(572, 402);
|
||||
this.buttonSelectAirplane.Name = "buttonSelectAirplane";
|
||||
this.buttonSelectAirplane.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonSelectAirplane.TabIndex = 11;
|
||||
this.buttonSelectAirplane.Text = "Выбрать";
|
||||
this.buttonSelectAirplane.UseVisualStyleBackColor = true;
|
||||
this.buttonSelectAirplane.Click += new System.EventHandler(this.ButtonSelectAirplane_Click);
|
||||
//
|
||||
// FormAirplane
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.buttonSelectAirplane);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.comboBoxTypePortholes);
|
||||
this.Controls.Add(this.comboBoxPortholes);
|
||||
this.Controls.Add(this.labelPortholes);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
@ -204,5 +244,8 @@
|
||||
private Button buttonRight;
|
||||
private Label labelPortholes;
|
||||
private ComboBox comboBoxPortholes;
|
||||
private ComboBox comboBoxTypePortholes;
|
||||
private Button buttonCreateModif;
|
||||
private Button buttonSelectAirplane;
|
||||
}
|
||||
}
|
@ -4,6 +4,11 @@ namespace AirplaneWithRadar
|
||||
{
|
||||
private DrawningAirplane _airplane;
|
||||
|
||||
/// <summary>
|
||||
/// Âûáðàííûé ñàìîëåò
|
||||
/// </summary>
|
||||
public DrawningAirplane SelectedAirplane { get; private set; }
|
||||
|
||||
public FormAirplane()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -20,6 +25,18 @@ namespace AirplaneWithRadar
|
||||
_airplane?.DrawTransport(gr);
|
||||
pictureBoxAirplane.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ìåòîä óñòàíîâêè äàííûõ
|
||||
/// </summary>
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
_airplane.SetPosition(rnd.Next(20, 100), rnd.Next(20, 100), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airplane.Airplane.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airplane.Airplane.BodyColor.Name}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
@ -27,11 +44,20 @@ namespace AirplaneWithRadar
|
||||
/// <param name="e"></param>
|
||||
///
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
IAirplanePortholes typeAirplanePortholes = new DrawningAirplanePortholes();
|
||||
switch (comboBoxTypePortholes.Text)
|
||||
{
|
||||
case "Òðåóãîëüíûå":
|
||||
typeAirplanePortholes = new DrawningDeltaPortholes();
|
||||
break;
|
||||
case "Ðîìáîâèäíûå":
|
||||
typeAirplanePortholes = new DrawningRhombusPortholes();
|
||||
break;
|
||||
}
|
||||
Random rnd = new();
|
||||
_airplane = new DrawningAirplane();
|
||||
_airplane.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_airplane = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), typeAirplanePortholes);
|
||||
_airplane.DrawningPortholes.CountPortholes = Convert.ToInt32(comboBoxPortholes.Text);
|
||||
_airplane.SetPosition(rnd.Next(20, 100), rnd.Next(20, 100), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";
|
||||
@ -76,5 +102,35 @@ namespace AirplaneWithRadar
|
||||
_airplane?.ChangeBorders(pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
IAirplanePortholes typeAirplanePortholes = new DrawningAirplanePortholes();
|
||||
switch (comboBoxTypePortholes.Text)
|
||||
{
|
||||
case "Òðåóãîëüíûå":
|
||||
typeAirplanePortholes = new DrawningDeltaPortholes();
|
||||
break;
|
||||
case "Ðîìáîâèäíûå":
|
||||
typeAirplanePortholes = new DrawningRhombusPortholes();
|
||||
break;
|
||||
}
|
||||
Random rnd = new();
|
||||
_airplane = new DrawningAirplaneWithRadar(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
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)),
|
||||
typeAirplanePortholes);
|
||||
_airplane.DrawningPortholes.CountPortholes = Convert.ToInt32(comboBoxPortholes.Text);
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonSelectAirplane_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedAirplane = _airplane;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
379
AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs
generated
Normal file
379
AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs
generated
Normal file
@ -0,0 +1,379 @@
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
partial class FormMapWithSetAirplanes
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonRemoveAirplane = new System.Windows.Forms.Button();
|
||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||
this.buttonAddAirplane = new System.Windows.Forms.Button();
|
||||
this.groupBoxGenerate = new System.Windows.Forms.GroupBox();
|
||||
this.comboTypePortholes = new System.Windows.Forms.ComboBox();
|
||||
this.comboBoxPortholes = new System.Windows.Forms.ComboBox();
|
||||
this.comboTypePotholes = new System.Windows.Forms.ComboBox();
|
||||
this.buttonAddTypeOfPhortholes = new System.Windows.Forms.Button();
|
||||
this.labelSpeed = new System.Windows.Forms.Label();
|
||||
this.numericSpeed = new System.Windows.Forms.NumericUpDown();
|
||||
this.buttonAddTypeOfEntity = new System.Windows.Forms.Button();
|
||||
this.labelWeight = new System.Windows.Forms.Label();
|
||||
this.numericWeight = new System.Windows.Forms.NumericUpDown();
|
||||
this.labelCountPortholes = new System.Windows.Forms.Label();
|
||||
this.buttonGenerateAirplane = new System.Windows.Forms.Button();
|
||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
||||
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.groupBoxGenerate.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericSpeed)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericWeight)).BeginInit();
|
||||
this.groupBoxTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(35, 331);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
|
||||
this.maskedTextBoxPosition.TabIndex = 29;
|
||||
this.maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonRemoveAirplane
|
||||
//
|
||||
this.buttonRemoveAirplane.Location = new System.Drawing.Point(35, 360);
|
||||
this.buttonRemoveAirplane.Name = "buttonRemoveAirplane";
|
||||
this.buttonRemoveAirplane.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonRemoveAirplane.TabIndex = 30;
|
||||
this.buttonRemoveAirplane.Text = "Удалить самолет";
|
||||
this.buttonRemoveAirplane.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveAirplane.Click += new System.EventHandler(this.ButtonRemoveAirplane_Click);
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(35, 401);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonShowStorage.TabIndex = 31;
|
||||
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(35, 438);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonShowOnMap.TabIndex = 32;
|
||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
|
||||
//
|
||||
// buttonAddAirplane
|
||||
//
|
||||
this.buttonAddAirplane.Location = new System.Drawing.Point(35, 287);
|
||||
this.buttonAddAirplane.Name = "buttonAddAirplane";
|
||||
this.buttonAddAirplane.Size = new System.Drawing.Size(175, 35);
|
||||
this.buttonAddAirplane.TabIndex = 28;
|
||||
this.buttonAddAirplane.Text = "Добавить самолет вручную";
|
||||
this.buttonAddAirplane.UseVisualStyleBackColor = true;
|
||||
this.buttonAddAirplane.Click += new System.EventHandler(this.ButtonAddAirplane_Click);
|
||||
//
|
||||
// groupBoxGenerate
|
||||
//
|
||||
this.groupBoxGenerate.Controls.Add(this.comboTypePortholes);
|
||||
this.groupBoxGenerate.Controls.Add(this.comboBoxPortholes);
|
||||
this.groupBoxGenerate.Controls.Add(this.comboTypePotholes);
|
||||
this.groupBoxGenerate.Controls.Add(this.buttonAddTypeOfPhortholes);
|
||||
this.groupBoxGenerate.Controls.Add(this.labelSpeed);
|
||||
this.groupBoxGenerate.Controls.Add(this.numericSpeed);
|
||||
this.groupBoxGenerate.Controls.Add(this.buttonAddTypeOfEntity);
|
||||
this.groupBoxGenerate.Controls.Add(this.labelWeight);
|
||||
this.groupBoxGenerate.Controls.Add(this.numericWeight);
|
||||
this.groupBoxGenerate.Controls.Add(this.labelCountPortholes);
|
||||
this.groupBoxGenerate.Controls.Add(this.buttonGenerateAirplane);
|
||||
this.groupBoxGenerate.Location = new System.Drawing.Point(16, 15);
|
||||
this.groupBoxGenerate.Name = "groupBoxGenerate";
|
||||
this.groupBoxGenerate.Size = new System.Drawing.Size(200, 266);
|
||||
this.groupBoxGenerate.TabIndex = 27;
|
||||
this.groupBoxGenerate.TabStop = false;
|
||||
this.groupBoxGenerate.Text = "Генерация";
|
||||
//
|
||||
// comboTypePortholes
|
||||
//
|
||||
this.comboTypePortholes.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.comboTypePortholes.FormattingEnabled = true;
|
||||
this.comboTypePortholes.Items.AddRange(new object[] {
|
||||
"Квадратные",
|
||||
"Треугольные",
|
||||
"Ромбовидные"});
|
||||
this.comboTypePortholes.Location = new System.Drawing.Point(17, 122);
|
||||
this.comboTypePortholes.Name = "comboTypePortholes";
|
||||
this.comboTypePortholes.Size = new System.Drawing.Size(175, 23);
|
||||
this.comboTypePortholes.TabIndex = 21;
|
||||
//
|
||||
// comboBoxPortholes
|
||||
//
|
||||
this.comboBoxPortholes.FormattingEnabled = true;
|
||||
this.comboBoxPortholes.Items.AddRange(new object[] {
|
||||
"10",
|
||||
"20",
|
||||
"30"});
|
||||
this.comboBoxPortholes.Location = new System.Drawing.Point(150, 148);
|
||||
this.comboBoxPortholes.Name = "comboBoxPortholes";
|
||||
this.comboBoxPortholes.Size = new System.Drawing.Size(44, 23);
|
||||
this.comboBoxPortholes.TabIndex = 20;
|
||||
this.comboBoxPortholes.Text = "10";
|
||||
//
|
||||
// comboTypePotholes
|
||||
//
|
||||
this.comboTypePotholes.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.comboTypePotholes.FormattingEnabled = true;
|
||||
this.comboTypePotholes.Items.AddRange(new object[] {
|
||||
"Закругленный",
|
||||
"Квадратный",
|
||||
"Стрелка"});
|
||||
this.comboTypePotholes.Location = new System.Drawing.Point(19, 282);
|
||||
this.comboTypePotholes.Name = "comboTypePotholes";
|
||||
this.comboTypePotholes.Size = new System.Drawing.Size(175, 23);
|
||||
this.comboTypePotholes.TabIndex = 9;
|
||||
//
|
||||
// buttonAddTypeOfPhortholes
|
||||
//
|
||||
this.buttonAddTypeOfPhortholes.Location = new System.Drawing.Point(17, 175);
|
||||
this.buttonAddTypeOfPhortholes.Name = "buttonAddTypeOfPhortholes";
|
||||
this.buttonAddTypeOfPhortholes.Size = new System.Drawing.Size(175, 56);
|
||||
this.buttonAddTypeOfPhortholes.TabIndex = 12;
|
||||
this.buttonAddTypeOfPhortholes.Text = "Добавить тип иллюминатора и их кол-во";
|
||||
this.buttonAddTypeOfPhortholes.UseVisualStyleBackColor = true;
|
||||
this.buttonAddTypeOfPhortholes.Click += new System.EventHandler(this.ButtonAddTypeOfPortholes_Click);
|
||||
//
|
||||
// labelSpeed
|
||||
//
|
||||
this.labelSpeed.AutoSize = true;
|
||||
this.labelSpeed.Location = new System.Drawing.Point(17, 19);
|
||||
this.labelSpeed.Name = "labelSpeed";
|
||||
this.labelSpeed.Size = new System.Drawing.Size(117, 15);
|
||||
this.labelSpeed.TabIndex = 19;
|
||||
this.labelSpeed.Text = "Скорость самолета:";
|
||||
//
|
||||
// numericSpeed
|
||||
//
|
||||
this.numericSpeed.Location = new System.Drawing.Point(136, 17);
|
||||
this.numericSpeed.Name = "numericSpeed";
|
||||
this.numericSpeed.Size = new System.Drawing.Size(56, 23);
|
||||
this.numericSpeed.TabIndex = 18;
|
||||
//
|
||||
// buttonAddTypeOfEntity
|
||||
//
|
||||
this.buttonAddTypeOfEntity.Location = new System.Drawing.Point(17, 71);
|
||||
this.buttonAddTypeOfEntity.Name = "buttonAddTypeOfEntity";
|
||||
this.buttonAddTypeOfEntity.Size = new System.Drawing.Size(175, 39);
|
||||
this.buttonAddTypeOfEntity.TabIndex = 11;
|
||||
this.buttonAddTypeOfEntity.Text = "Добавить свойства для генерации";
|
||||
this.buttonAddTypeOfEntity.UseVisualStyleBackColor = true;
|
||||
this.buttonAddTypeOfEntity.Click += new System.EventHandler(this.ButtonAddTypeOfEntity_Click);
|
||||
//
|
||||
// labelWeight
|
||||
//
|
||||
this.labelWeight.AutoSize = true;
|
||||
this.labelWeight.Location = new System.Drawing.Point(17, 44);
|
||||
this.labelWeight.Name = "labelWeight";
|
||||
this.labelWeight.Size = new System.Drawing.Size(100, 15);
|
||||
this.labelWeight.TabIndex = 17;
|
||||
this.labelWeight.Text = "Масса самолета:";
|
||||
//
|
||||
// numericWeight
|
||||
//
|
||||
this.numericWeight.Location = new System.Drawing.Point(136, 42);
|
||||
this.numericWeight.Name = "numericWeight";
|
||||
this.numericWeight.Size = new System.Drawing.Size(56, 23);
|
||||
this.numericWeight.TabIndex = 16;
|
||||
//
|
||||
// labelCountPortholes
|
||||
//
|
||||
this.labelCountPortholes.AutoSize = true;
|
||||
this.labelCountPortholes.Location = new System.Drawing.Point(6, 151);
|
||||
this.labelCountPortholes.Name = "labelCountPortholes";
|
||||
this.labelCountPortholes.Size = new System.Drawing.Size(144, 15);
|
||||
this.labelCountPortholes.TabIndex = 14;
|
||||
this.labelCountPortholes.Text = "Кол-во иллюминаторов:";
|
||||
//
|
||||
// buttonGenerateAirplane
|
||||
//
|
||||
this.buttonGenerateAirplane.Location = new System.Drawing.Point(19, 237);
|
||||
this.buttonGenerateAirplane.Name = "buttonGenerateAirplane";
|
||||
this.buttonGenerateAirplane.Size = new System.Drawing.Size(175, 23);
|
||||
this.buttonGenerateAirplane.TabIndex = 15;
|
||||
this.buttonGenerateAirplane.Text = "Сгенерировать самолет";
|
||||
this.buttonGenerateAirplane.UseVisualStyleBackColor = true;
|
||||
this.buttonGenerateAirplane.Click += new System.EventHandler(this.ButtonGenerateAirplane_Click);
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта",
|
||||
"Моя карта"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(35, 479);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
|
||||
this.comboBoxSelectorMap.TabIndex = 26;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
this.groupBoxTools.Controls.Add(this.buttonRight);
|
||||
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
||||
this.groupBoxTools.Controls.Add(this.buttonDown);
|
||||
this.groupBoxTools.Controls.Add(this.buttonUp);
|
||||
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRemoveAirplane);
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
||||
this.groupBoxTools.Controls.Add(this.buttonAddAirplane);
|
||||
this.groupBoxTools.Controls.Add(this.groupBoxGenerate);
|
||||
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(894, 0);
|
||||
this.groupBoxTools.Name = "groupBoxTools";
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(225, 598);
|
||||
this.groupBoxTools.TabIndex = 33;
|
||||
this.groupBoxTools.TabStop = false;
|
||||
this.groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(139, 555);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 36;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(67, 555);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 35;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(103, 555);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 34;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(103, 519);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 33;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(894, 598);
|
||||
this.pictureBox.TabIndex = 34;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// FormMapWithSetAirplanes
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1119, 598);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Name = "FormMapWithSetAirplanes";
|
||||
this.Text = "FormMapWithSetAirplanes";
|
||||
this.groupBoxGenerate.ResumeLayout(false);
|
||||
this.groupBoxGenerate.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericSpeed)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericWeight)).EndInit();
|
||||
this.groupBoxTools.ResumeLayout(false);
|
||||
this.groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private Button buttonRemoveAirplane;
|
||||
private Button buttonShowStorage;
|
||||
private Button buttonShowOnMap;
|
||||
private Button buttonAddAirplane;
|
||||
private GroupBox groupBoxGenerate;
|
||||
private ComboBox comboTypePortholes;
|
||||
private Button buttonAddTypeOfPhortholes;
|
||||
private Label labelSpeed;
|
||||
private NumericUpDown numericSpeed;
|
||||
private Button buttonAddTypeOfEntity;
|
||||
private Label labelWeight;
|
||||
private NumericUpDown numericWeight;
|
||||
private Label labelCountPortholes;
|
||||
private Button buttonGenerateAirplane;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
private GroupBox groupBoxTools;
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonUp;
|
||||
private PictureBox pictureBox;
|
||||
private ComboBox comboBoxPortholes;
|
||||
private ComboBox comboTypePotholes;
|
||||
}
|
||||
}
|
222
AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs
Normal file
222
AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs
Normal file
@ -0,0 +1,222 @@
|
||||
using AirplaneWithRadar;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
public partial class FormMapWithSetAirplanes : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Объект от класса карты с набором объектов
|
||||
/// </summary>
|
||||
private MapWithSetAirplanesGeneric<DrawningObjectAirplane, AbstractMap> _mapAirplanesCollectionGeneric;
|
||||
private GeneratorAirplane<EntityAirplane, IAirplanePortholes> _generatorAirplane;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormMapWithSetAirplanes()
|
||||
{
|
||||
_generatorAirplane = new(100, 100);
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление самолета на карту
|
||||
/// </summary>
|
||||
/// <param name="airplane">самолет.</param>
|
||||
private void AddAirplaneInMap(DrawningObjectAirplane airplane)
|
||||
{
|
||||
if (airplane == null || (_mapAirplanesCollectionGeneric + airplane) == -1)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
AbstractMap map = null;
|
||||
switch (comboBoxSelectorMap.Text)
|
||||
{
|
||||
case "Простая карта":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Моя карта":
|
||||
map = new MyMap();
|
||||
break;
|
||||
}
|
||||
if (map != null)
|
||||
{
|
||||
_mapAirplanesCollectionGeneric = new MapWithSetAirplanesGeneric<DrawningObjectAirplane, AbstractMap>(pictureBox.Width, pictureBox.Height, map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapAirplanesCollectionGeneric = null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
//получаем имя кнопки
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
Direction dir = Direction.None;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
dir = Direction.Up;
|
||||
break;
|
||||
case "buttonDown":
|
||||
dir = Direction.Down;
|
||||
break;
|
||||
case "buttonLeft":
|
||||
dir = Direction.Left;
|
||||
break;
|
||||
case "buttonRight":
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapAirplanesCollectionGeneric?.MoveObject(dir) ?? pictureBox.Image;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавления сущности в генератор
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddTypeOfEntity_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
Color colorBody = Color.FromArgb(rnd.Next() % 256, rnd.Next() % 256, rnd.Next() % 256);
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
colorBody = dialog.Color;
|
||||
}
|
||||
var entity = new EntityAirplane((int)numericSpeed.Value, (int)numericWeight.Value, colorBody);
|
||||
_generatorAirplane.AddTypeOfEntity(entity);
|
||||
MessageBox.Show($"Добавлены свойства самолета:\n" +
|
||||
$"Вес: {entity.Weight}\n" +
|
||||
$"Скорость: {entity.Speed}\n" +
|
||||
$"Цвет: {colorBody.Name}",
|
||||
"Успешно добавлены свойства");
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавления типа иллюминаторов и их колличетсва в генератор
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddTypeOfPortholes_Click(object sender, EventArgs e)
|
||||
{
|
||||
IAirplanePortholes typeAirplanePortholes = new DrawningAirplanePortholes();
|
||||
switch (comboTypePortholes.Text)
|
||||
{
|
||||
case "Треугольные":
|
||||
typeAirplanePortholes = new DrawningDeltaPortholes();
|
||||
break;
|
||||
case "Ромбовидные":
|
||||
typeAirplanePortholes = new DrawningRhombusPortholes();
|
||||
break;
|
||||
}
|
||||
typeAirplanePortholes.CountPortholes = Convert.ToInt32(comboBoxPortholes.Text);
|
||||
_generatorAirplane.AddTypeOfPortholes(typeAirplanePortholes);
|
||||
}
|
||||
/// <summary>
|
||||
/// Генерация самолета
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonGenerateAirplane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapAirplanesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var airplane = _generatorAirplane.Generate();
|
||||
if (airplane == null)
|
||||
{
|
||||
MessageBox.Show("Не удалось сгенерировать самолет. Добавьте свойства для генерации"
|
||||
, "Генерация самолета");
|
||||
return;
|
||||
}
|
||||
AddAirplaneInMap(airplane);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddAirplane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapAirplanesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormAirplane form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK && form.SelectedAirplane != null)
|
||||
{
|
||||
AddAirplaneInMap(new(form.SelectedAirplane));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveAirplane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapAirplanesCollectionGeneric - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapAirplanesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapAirplanesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowOnMap();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
73
AirplaneWithRadar/AirplaneWithRadar/GeneratorAirplane.cs
Normal file
73
AirplaneWithRadar/AirplaneWithRadar/GeneratorAirplane.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using AirplaneWithRadar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, который генирирует самолет из разнообразного количества сущностей и типа иллюминаторов
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Класс Сущность самолет</typeparam>
|
||||
/// <typeparam name="U">Класс иллюминатора самолета</typeparam>
|
||||
internal class GeneratorAirplane<T, U>
|
||||
where T : EntityAirplane
|
||||
where U : class, IAirplanePortholes
|
||||
{
|
||||
private readonly T[] typesOfEntity;
|
||||
private readonly U[] typesOfPortholes;
|
||||
|
||||
public int NumTypesOfEntity { get; private set; }
|
||||
public int NumTypesOfPortholes { get; private set; }
|
||||
|
||||
public GeneratorAirplane(int countTypesOfEntity, int countTypesOfPortholes)
|
||||
{
|
||||
typesOfEntity = new T[countTypesOfEntity];
|
||||
typesOfPortholes = new U[countTypesOfPortholes];
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавляет возможный тип сущности при генерации самолета
|
||||
/// </summary>
|
||||
/// <param name="type">тип</param>
|
||||
/// <returns>Успешно ли проведена операция</returns>
|
||||
public virtual bool AddTypeOfEntity(T type)
|
||||
{
|
||||
if (NumTypesOfEntity >= typesOfEntity.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
typesOfEntity[NumTypesOfEntity++] = type;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавляет возможный тип иллюминатора при генерации самолета
|
||||
/// </summary>
|
||||
/// <param name="type">тип</param>
|
||||
/// <returns>Успешно ли проведена операция</returns>
|
||||
public virtual bool AddTypeOfPortholes(U type)
|
||||
{
|
||||
if (NumTypesOfPortholes >= typesOfPortholes.Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
typesOfPortholes[NumTypesOfPortholes++] = type;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Генерирует объект отрисовки
|
||||
/// </summary>
|
||||
/// <returns>Возвращает объект отрисовки, либо null, если не были добавлены типы для выборки</returns>
|
||||
public DrawningObjectAirplane? Generate()
|
||||
{
|
||||
if (NumTypesOfPortholes == 0 || NumTypesOfEntity == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var rnd = new Random();
|
||||
var airplane = new DrawningAirplane(typesOfEntity[rnd.Next() % NumTypesOfEntity], typesOfPortholes[rnd.Next() % NumTypesOfPortholes]);
|
||||
return new DrawningObjectAirplane(airplane);
|
||||
}
|
||||
}
|
||||
}
|
14
AirplaneWithRadar/AirplaneWithRadar/IAirplanePortholes.cs
Normal file
14
AirplaneWithRadar/AirplaneWithRadar/IAirplanePortholes.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
public interface IAirplanePortholes
|
||||
{
|
||||
int CountPortholes { set; }
|
||||
public void DrawPortholes(Graphics g, int _startPosX, int _startPosY, int _airplaneWidth);
|
||||
}
|
||||
}
|
40
AirplaneWithRadar/AirplaneWithRadar/IDrawningObject.cs
Normal file
40
AirplaneWithRadar/AirplaneWithRadar/IDrawningObject.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
internal interface IDrawningObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Шаг перемещения объекта
|
||||
/// </summary>
|
||||
public float Step { get; }
|
||||
/// <summary>
|
||||
/// Установка позиции объекта
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина полотна</param>
|
||||
/// <param name="height">Высота полотна</param>
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
/// <summary>
|
||||
/// Изменение направления пермещения объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
void MoveObject(Direction direction);
|
||||
/// <summary>
|
||||
/// Отрисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
void DrawningObject(Graphics g);
|
||||
/// <summary>
|
||||
/// Получение текущей позиции объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
(float Left, float Top, float Right, float Bottom)
|
||||
GetCurrentPosition();
|
||||
}
|
||||
}
|
@ -0,0 +1,178 @@
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
/// <summary>
|
||||
/// Карта с набром объектов под нее
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
internal class MapWithSetAirplanesGeneric<T, U>
|
||||
where T : class, IDrawningObject
|
||||
where U : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 210;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetAirplanesGeneric<T> _setAirplanes;
|
||||
/// <summary>
|
||||
/// Карта
|
||||
/// </summary>
|
||||
private readonly U _map;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
/// <param name="map"></param>
|
||||
public MapWithSetAirplanesGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setAirplanes = new SetAirplanesGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="airplane"></param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(MapWithSetAirplanesGeneric<T, U> map, T airplane)
|
||||
{
|
||||
return map._setAirplanes.Insert(airplane);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public static T operator -(MapWithSetAirplanesGeneric<T, U> map, int position)
|
||||
{
|
||||
return map._setAirplanes.Remove(position);
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowSet()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawAirplanes(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Просмотр объекта на карте
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setAirplanes.Count; i++)
|
||||
{
|
||||
var airplane = _setAirplanes.Get(i);
|
||||
if (airplane != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, airplane);
|
||||
}
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение объекта по крате
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
/// <summary>
|
||||
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
|
||||
/// </summary>
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setAirplanes.Count - 1;
|
||||
for (int i = 0; i < _setAirplanes.Count; i++)
|
||||
{
|
||||
if (_setAirplanes.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var airplane = _setAirplanes.Get(j);
|
||||
if (airplane != null)
|
||||
{
|
||||
_setAirplanes.Insert(airplane, i);
|
||||
_setAirplanes.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void DrawHangar(Graphics g, int x, int y, int width, int height)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
g.DrawLine(pen, x, y, x + width, y);
|
||||
g.DrawLine(pen, x, y, x, y + height);
|
||||
g.DrawLine(pen, x, y + height, x + width, y + height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
DrawHangar(g, i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth * 3 / 4, _placeSizeHeight - 55);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawAirplanes(Graphics g)
|
||||
{
|
||||
int countInLine = _pictureWidth / _placeSizeWidth;
|
||||
int maxLeft = (countInLine - 1) * _placeSizeWidth;
|
||||
for (int i = 0; i < _setAirplanes.Count; i++)
|
||||
{
|
||||
var airplane = _setAirplanes.Get(i);
|
||||
airplane?.SetObject(maxLeft - i % countInLine * _placeSizeWidth + 5, i / countInLine * _placeSizeHeight + 15, _pictureWidth, _pictureHeight);
|
||||
airplane?.DrawningObject(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
54
AirplaneWithRadar/AirplaneWithRadar/MyMap.cs
Normal file
54
AirplaneWithRadar/AirplaneWithRadar/MyMap.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
internal class MyMap : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Brown);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.BlueViolet);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 20)
|
||||
{
|
||||
int x = _random.Next(0, _map.GetLength(0));
|
||||
int y = _random.Next(0, _map.GetLength(1));
|
||||
int len = _random.Next(3, 10);
|
||||
for (int i = x; i < _map.GetLength(0) && i < len + x; i++)
|
||||
{
|
||||
|
||||
_map[i, y] = _barrier;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace AirplaneWithRadar
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormAirplane());
|
||||
Application.Run(new FormMapWithSetAirplanes());
|
||||
}
|
||||
}
|
||||
}
|
87
AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs
Normal file
87
AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs
Normal file
@ -0,0 +1,87 @@
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetAirplanesGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T[] _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetAirplanesGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="airplane">Добавляемый самолёт</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T airplane)
|
||||
{
|
||||
return Insert(airplane, 0);
|
||||
}
|
||||
private bool isCorrectPosition(int position)
|
||||
{
|
||||
return 0 <= position && position < Count;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="airplane">Добавляемый самолет</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T airplane, int position)
|
||||
{
|
||||
int positionNullElement = position;
|
||||
while (Get(positionNullElement) != null)
|
||||
{
|
||||
positionNullElement++;
|
||||
}
|
||||
if (!isCorrectPosition(positionNullElement))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
while (positionNullElement != position) // Смещение вправо
|
||||
{
|
||||
_places[positionNullElement] = _places[positionNullElement - 1];
|
||||
positionNullElement--;
|
||||
}
|
||||
_places[position] = airplane;
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (!isCorrectPosition(position)) return null;
|
||||
var result = _places[position];
|
||||
_places[position] = null;
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
{
|
||||
if (isCorrectPosition(position)) { return _places[position]; }
|
||||
else { return null; }
|
||||
}
|
||||
}
|
||||
}
|
52
AirplaneWithRadar/AirplaneWithRadar/SimpleMap.cs
Normal file
52
AirplaneWithRadar/AirplaneWithRadar/SimpleMap.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
internal class SimpleMap : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Black);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void GenerateMap()
|
||||
{
|
||||
_map = new int[100, 100];
|
||||
_size_x = (float)_width / _map.GetLength(0);
|
||||
_size_y = (float)_height / _map.GetLength(1);
|
||||
int counter = 0;
|
||||
for (int i = 0; i < _map.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < _map.GetLength(1); ++j)
|
||||
{
|
||||
_map[i, j] = _freeRoad;
|
||||
}
|
||||
}
|
||||
while (counter < 50)
|
||||
{
|
||||
int x = _random.Next(0, 100);
|
||||
int y = _random.Next(0, 100);
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user