PIbd-14_Calimullin_A.R._Lab03_Simple #3

Closed
Bloody_Arthur wants to merge 3 commits from Lab03 into Lab02
8 changed files with 146 additions and 144 deletions
Showing only changes of commit a1f80b6ca7 - Show all commits

View File

@ -15,7 +15,7 @@ public abstract class AbstractCompany
/// <summary>
/// Размер места (высота)
/// </summary>
protected readonly int _placeSizeHeight = 100;
protected readonly int _placeSizeHeight = 86;
/// <summary>
/// Ширина окна
@ -57,9 +57,9 @@ public abstract class AbstractCompany
/// <param name="company">Компания</param>
/// <param name="aircraft">Добавляемый объект</param>
/// <returns></returns>
public static bool operator +(AbstractCompany company, DrawningAirCraft aircraft)
public static int operator +(AbstractCompany company, DrawningAirCraft aircraft)
{
return company._collection?.Insert(aircraft) ?? false;
return company._collection.Insert(aircraft);
}
/// <summary>
@ -68,9 +68,9 @@ public abstract class AbstractCompany
/// <param name="company">Компания</param>
/// <param name="position">Номер удаляемого объекта</param>
/// <returns></returns>
public static bool operator -(AbstractCompany company, int position)
public static DrawningAirCraft? operator -(AbstractCompany company, int position)
{
return company._collection?.Remove(position) ?? false;
return company._collection?.Remove(position);
}
/// <summary>

View File

@ -0,0 +1,62 @@
using ProjectAirFighter.Drawnings;
namespace ProjectAirFighter.CollectionGenericObjects;
/// <summary>
/// Реализация абстрактной компании - СимбирФлот
/// </summary>
public class AirCraftAngar : AbstractCompany
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="collection"></param>
public AirCraftAngar(int picWidth, int picHeight, ICollectionGenericObjects<DrawningAirCraft> collection) : base(picWidth, picHeight, collection)
{
}
/// <summary>
/// Отрисовка хранилища
/// </summary>
/// <param name="g">Графика</param>
int pamat_i = 0;
protected override void DrawBackgound(Graphics g)
{
Pen pen = new(Color.Black, 4);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
pamat_i = i;
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
{
g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * j));
g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new(_placeSizeWidth * i, _placeSizeHeight * (j + 1)));
}
g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * (_pictureHeight / _placeSizeHeight)), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * (_pictureHeight / _placeSizeHeight)));
}
}
/// <summary>
/// Установка объекта в Ангар
/// </summary>
protected override void SetObjectsPosition()
{
int currentIndex = -1;
for (int j = 0 ; j < _pictureHeight / _placeSizeHeight; j++)
{
for (int i = pamat_i; i >= 0; i--)
{
currentIndex++;
if (_collection?.Get(currentIndex) == null) continue;
_collection.Get(currentIndex)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection.Get(currentIndex)?.SetPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5);
}
}
}
}

View File

@ -1,84 +0,0 @@
using ProjectAirFighter.Drawnings;
namespace ProjectAirFighter.CollectionGenericObjects;
/// <summary>
/// Реализация абстрактной компании - СимбирФлот
/// </summary>
public class AirCraftSharingService : AbstractCompany
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="collection"></param>
public AirCraftSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningAirCraft> collection) : base(picWidth, picHeight, collection)
{
}
private int doroga = 40;
/// <summary>
/// Отрисовка хранилища
/// </summary>
/// <param name="g">Графика</param>
protected override void DrawBackgound(Graphics g)
{
Pen pen = new Pen(Color.Black);
int X_max = (_pictureWidth / _placeSizeWidth);
int Y_max = (_pictureHeight / _placeSizeHeight);
for (int i = 0; i < X_max; i++)
{
for (int j = 0; j < Y_max; j++)
{
Point[] angars_1 = new Point[] {
new Point { X = i * doroga + i * _placeSizeWidth, Y = j * _placeSizeHeight},
new Point { X = _placeSizeWidth + i * doroga + i * _placeSizeWidth, Y = j * _placeSizeHeight}
};
g.DrawPolygon(pen, angars_1);
Point[] angars_2 = new Point[] {
new Point { X = i * doroga + i * _placeSizeWidth, Y = j * _placeSizeHeight},
new Point { X = i * doroga + i * _placeSizeWidth, Y = _placeSizeHeight + j * _placeSizeHeight}
};
g.DrawPolygon(pen, angars_2);
Point[] angars_3 = new Point[] {
new Point { X = i * doroga + i * _placeSizeWidth, Y = _placeSizeHeight + j * _placeSizeHeight},
new Point { X = _placeSizeWidth + i * doroga + i * _placeSizeWidth, Y = _placeSizeHeight + j * _placeSizeHeight}
};
g.DrawPolygon(pen, angars_3);
}
}
}
/// <summary>
/// Установка объекта в хранилища
/// </summary>
protected override void SetObjectsPosition()
{
int X_max = (_pictureWidth / _placeSizeWidth);
int Y_max = (_pictureHeight / _placeSizeHeight);
int granicaX = 10;
int granicaY = 10;
int num_ang = 0;
for (int j = 0; j < Y_max; j++)
{
for (int i = 0; i < X_max; i++)
{
if (_collection?.Get(num_ang) == null)
{
num_ang++;
continue;
}
_collection.Get(num_ang)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection.Get(num_ang)?.SetPosition(granicaX + i * _placeSizeWidth + i * doroga, granicaY + j * _placeSizeHeight);
num_ang++;
}
}
}
}

View File

@ -1,5 +1,9 @@
namespace ProjectAirFighter.CollectionGenericObjects;
/// <summary>
/// Интерфейс описания действий для набора хранимых объектов
/// </summary>
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
/// <summary>
/// Интерфейс описания действий для набора хранимых объектов
/// </summary>
@ -22,7 +26,7 @@ public interface ICollectionGenericObjects<T>
/// </summary>
/// <param name="obj">Добавляемый объект</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
bool Insert(T obj);
int Insert(T obj);
/// <summary>
/// Добавление объекта в коллекцию на конкретную позицию
@ -30,14 +34,14 @@ public interface ICollectionGenericObjects<T>
/// <param name="obj">Добавляемый объект</param>
/// <param name="position">Позиция</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
bool Insert(T obj, int position);
int Insert(T obj, int position);
/// <summary>
/// Удаление объекта из коллекции с конкретной позиции
/// </summary>
/// <param name="position">Позиция</param>
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
bool Remove(int position);
T? Remove(int position);
/// <summary>
/// Получение объекта по позиции
@ -46,3 +50,4 @@ public interface ICollectionGenericObjects<T>
/// <returns>Объект</returns>
T? Get(int position);
}

View File

@ -43,55 +43,74 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
public T? Get(int position)
{
if (position < 0 || position >= _collection.Length)
if (position >= 0 && position < Count)
{
return _collection[position];
}
return null;
}
public int Insert(T obj)
{
return Insert(obj, 0);
}
public int Insert(T obj, int position)
{
if (position < 0 || position >= Count)
{
return -1;
}
if (_collection[position] != null)
{
bool pushed = false;
for (int index = position + 1; index < Count; index++)
{
if (_collection[index] == null)
{
position = index;
pushed = true;
break;
}
}
if (!pushed)
{
for (int index = position - 1; index >= 0; index--)
{
if (_collection[index] == null)
{
position = index;
pushed = true;
break;
}
}
}
if (!pushed)
{
return position;
}
}
_collection[position] = obj;
return position;
}
public T? Remove(int position)
{
if (position < 0 || position >= Count)
{
return null;
}
return _collection[position];
}
public bool Insert(T obj)
{
for (int i = 0; i < _collection.Length; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
}
}
return false;
}
public bool Insert(T obj, int position)
{
for (int i = position; i < Count; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return false;
}
}
for (int i = position - 1; i >= 0; --i)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
}
}
return false;
}
public bool Remove(int position)
{
if (position < 0 || position >= _collection.Length)
{
return false;
}
if (_collection[position] == null) return null;
T? temp = _collection[position];
_collection[position] = null;
return true;
return temp;
}
}

View File

@ -16,7 +16,7 @@ public class DrawningAirFighter : DrawningAirCraft
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="pgo">Признак наличия ПГО</param>
/// <param name="rockets">Признак наличия ракет</param>
public DrawningAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, bool pgo, bool rockets) : base(76, 80)
public DrawningAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, bool pgo, bool rockets) : base(66, 74)
{
EntityAirCraft = new EntityAirFighter(speed, weight, bodyColor, additionalColor, pgo, rockets);
}

View File

@ -118,7 +118,7 @@
buttonAddAirCraft.Name = "buttonAddAirCraft";
buttonAddAirCraft.Size = new Size(186, 49);
buttonAddAirCraft.TabIndex = 1;
buttonAddAirCraft.Text = "Добавление самолёта";
buttonAddAirCraft.Text = "Добавление военного самолёта";
buttonAddAirCraft.UseVisualStyleBackColor = true;
buttonAddAirCraft.Click += ButtonAddAirCraft_Click;
//
@ -127,7 +127,7 @@
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Items.AddRange(new object[] { "Ангар" });
comboBoxSelectorCompany.Location = new Point(17, 26);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(186, 28);

View File

@ -30,8 +30,8 @@ public partial class FormAirCraftCollection : Form
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new AirCraftSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningAirCraft>());
case "Ангар":
_company = new AirCraftAngar(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningAirCraft>());
break;
}
}
@ -79,14 +79,14 @@ public partial class FormAirCraftCollection : Form
return;
}
if (_company + drawningAirCraft)
if (_company + drawningAirCraft != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось добавить объект");
_ = MessageBox.Show(drawningAirCraft.ToString());
}
}
@ -125,7 +125,7 @@ public partial class FormAirCraftCollection : Form
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_company - pos)
if (_company - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _company.Show();