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