pre final work

This commit is contained in:
NikGapon 2022-11-07 21:37:24 +04:00
parent 9074f7f01c
commit b72751ca0d
4 changed files with 70 additions and 53 deletions

View File

@ -120,6 +120,7 @@
this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "карта";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click);
//
// buttonStorage
//
@ -129,6 +130,7 @@
this.buttonStorage.TabIndex = 4;
this.buttonStorage.Text = "Хранилище";
this.buttonStorage.UseVisualStyleBackColor = true;
this.buttonStorage.Click += new System.EventHandler(this.buttonStorage_Click);
//
// buttonRemoveAirplane
//
@ -138,6 +140,7 @@
this.buttonRemoveAirplane.TabIndex = 3;
this.buttonRemoveAirplane.Text = "Удалить";
this.buttonRemoveAirplane.UseVisualStyleBackColor = true;
this.buttonRemoveAirplane.Click += new System.EventHandler(this.buttonRemoveAirplane_Click);
//
// maskedTextBoxPosition
//
@ -160,12 +163,12 @@
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 22);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Первая карта",
"Вторая карта",
"Третья карта"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 22);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(182, 23);
this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);

View File

@ -14,8 +14,7 @@ namespace Airbus
public partial class FormMapWithSetAirplane : Form
{
private AbstractMap _abstractMap;
private MapWithSetAirplaneGeneric<DrawningObjectAirplane, AbstractMap>
_mapCarsCollectionGeneric;
private MapWithSetAirplaneGeneric<DrawningObjectAirplane, AbstractMap> _mapAirplanesCollectionGeneric;
/// <summary>
/// Конструктор
/// </summary>
@ -46,13 +45,13 @@ namespace Airbus
}
if (map != null)
{
_mapCarsCollectionGeneric = new
_mapAirplanesCollectionGeneric = new
MapWithSetAirplaneGeneric<DrawningObjectAirplane, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapCarsCollectionGeneric = null;
_mapAirplanesCollectionGeneric = null;
}
}
/// <summary>
@ -62,7 +61,7 @@ namespace Airbus
/// <param name="e"></param>
private void buttonAddAirplane_Click(object sender, EventArgs e)
{
if (_mapCarsCollectionGeneric == null)
if (_mapAirplanesCollectionGeneric == null)
{
return;
}
@ -70,10 +69,10 @@ namespace Airbus
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectAirplane airplane = new(form.SelectedAirplane);
if (_mapCarsCollectionGeneric + airplane)
if (_mapAirplanesCollectionGeneric + airplane)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapCarsCollectionGeneric.ShowSet();
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
}
else
{
@ -86,7 +85,7 @@ namespace Airbus
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveCar_Click(object sender, EventArgs e)
private void buttonRemoveAirplane_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
@ -98,10 +97,10 @@ namespace Airbus
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapCarsCollectionGeneric - pos)
if (_mapAirplanesCollectionGeneric - pos)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapCarsCollectionGeneric.ShowSet();
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
}
else
{
@ -113,26 +112,27 @@ namespace Airbus
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e)
private void buttonStorage_Click(object sender, EventArgs e)
{
if (_mapCarsCollectionGeneric == null)
if (_mapAirplanesCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapCarsCollectionGeneric.ShowSet();
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
}
/// <summary>
/// Вывод карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
private void buttonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapCarsCollectionGeneric == null)
if (_mapAirplanesCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapCarsCollectionGeneric.ShowOnMap();
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowOnMap();
}
/// <summary>
/// Перемещение
@ -141,7 +141,7 @@ namespace Airbus
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapCarsCollectionGeneric == null)
if (_mapAirplanesCollectionGeneric == null)
{
return;
}
@ -163,7 +163,7 @@ namespace Airbus
dir = Direction.Right;
break;
}
pictureBox.Image = _mapCarsCollectionGeneric.MoveObject(dir);
pictureBox.Image = _mapAirplanesCollectionGeneric.MoveObject(dir);
}
}

View File

@ -21,11 +21,11 @@ namespace Airbus
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 210;
private readonly int _placeSizeWidth = 250;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 90;
private readonly int _placeSizeHeight = 70;
/// <summary>
/// Набор объектов
/// </summary>
@ -55,9 +55,9 @@ namespace Airbus
/// <param name="map"></param>
/// <param name="car"></param>
/// <returns></returns>
public static bool operator +(MapWithSetAirplaneGeneric<T, U> map, T car)
public static bool operator +(MapWithSetAirplaneGeneric<T, U> map, T airplane)
{
return map._setAirplane.Insert(car);
return map._setAirplane.Insert(airplane);
}
/// <summary>
/// Перегрузка оператора вычитания
@ -79,7 +79,7 @@ namespace Airbus
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawCars(gr);
DrawAirplanes(gr);
return bmp;
}
/// <summary>
@ -91,10 +91,10 @@ namespace Airbus
Shaking();
for (int i = 0; i < _setAirplane.Count; i++)
{
var car = _setAirplane.Get(i);
if (car != null)
var airplane = _setAirplane.Get(i);
if (airplane != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, car);
return _map.CreateMap(_pictureWidth, _pictureHeight, airplane);
}
}
return new(_pictureWidth, _pictureHeight);
@ -124,10 +124,10 @@ namespace Airbus
{
for (; j > i; j--)
{
var car = _setAirplane.Get(j);
if (car != null)
var airplane = _setAirplane.Get(j);
if (airplane != null)
{
_setAirplane.Insert(car, i);
_setAirplane.Insert(airplane, i);
_setAirplane.Remove(j);
break;
}
@ -161,11 +161,13 @@ namespace Airbus
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawCars(Graphics g)
private void DrawAirplanes(Graphics g)
{
int countInLine = _pictureWidth / _placeSizeWidth;
int maxLeft = (countInLine - 1) * _placeSizeWidth;
for (int i = 0; i < _setAirplane.Count; i++)
{
// TODO установка позиции
_setAirplane.Get(i)?.SetObject(maxLeft - i % countInLine * _placeSizeWidth, i / countInLine * _placeSizeHeight + 3, _pictureWidth, _pictureHeight);
_setAirplane.Get(i)?.DrawningObject(g);
}
}

View File

@ -15,27 +15,41 @@ namespace Airbus
{
_places = new T[count];
}
public bool Insert(T airplane)
{
return Insert(airplane, 0);
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="car">Добавляемый автомобиль</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T car, int position)
private bool CanInsert(int position)
{
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой,
//если нет, то
// проверка, что после вставляемого элемента в
//массиве есть пустой элемент
// сдвиг всех объектов, находящихся справа от
//позиции до первого пустого элемента
// TODO вставка по позиции
_places[position] = car;
for (int i = position; i < _places.Length; i++)
if (_places[i] == null)
return true;
return false;
}
public bool Insert(T airplane)
{
return Insert(airplane, 0);
}
public bool Insert(T airplane, int position)
{
if (position < 0 || position > _places.Length) return false;
if (_places[position] != null && CanInsert(position))
{
for (int i = _places.Length - 1; i > position; --i)
{
if (_places[i] == null)
{
_places[i] = _places[i - 1];
_places[i - 1] = null;
}
}
}
_places[position] = airplane;
return true;
}
/// <summary>
@ -45,9 +59,7 @@ namespace Airbus
/// <returns></returns>
public bool Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из массива, присовив элементу массива
//значение null
_places[position] = null;
return true;
}
/// <summary>
@ -57,7 +69,7 @@ namespace Airbus
/// <returns></returns>
public T Get(int position)
{
// TODO проверка позиции
if (position < 0 || position > _places.Length) return null;
return _places[position];
}
}