PIbd-21 Potapov N.S. LabWork03 #3
@ -37,7 +37,7 @@ namespace ProjectStormtrooper
|
||||
FormStormtrooper form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_planes + form.SelectedPlane)
|
||||
if (_planes + form.SelectedPlane > -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _planes.ShowPlanes();
|
||||
|
@ -46,7 +46,7 @@
|
||||
pictureBoxStormtrooper.Dock = DockStyle.Fill;
|
||||
pictureBoxStormtrooper.Location = new Point(0, 0);
|
||||
pictureBoxStormtrooper.Name = "pictureBoxStormtrooper";
|
||||
pictureBoxStormtrooper.Size = new Size(882, 453);
|
||||
pictureBoxStormtrooper.Size = new Size(1043, 546);
|
||||
pictureBoxStormtrooper.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxStormtrooper.TabIndex = 0;
|
||||
pictureBoxStormtrooper.TabStop = false;
|
||||
@ -54,7 +54,7 @@
|
||||
// buttonCreateStormtrooper
|
||||
//
|
||||
buttonCreateStormtrooper.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateStormtrooper.Location = new Point(12, 412);
|
||||
buttonCreateStormtrooper.Location = new Point(12, 505);
|
||||
buttonCreateStormtrooper.Name = "buttonCreateStormtrooper";
|
||||
buttonCreateStormtrooper.Size = new Size(201, 29);
|
||||
buttonCreateStormtrooper.TabIndex = 1;
|
||||
@ -67,7 +67,7 @@
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = Properties.Resources.arrowUP;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(804, 375);
|
||||
buttonUp.Location = new Point(965, 468);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(30, 30);
|
||||
buttonUp.TabIndex = 2;
|
||||
@ -79,7 +79,7 @@
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = Properties.Resources.arrowDOWN;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(804, 411);
|
||||
buttonDown.Location = new Point(965, 504);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(30, 30);
|
||||
buttonDown.TabIndex = 3;
|
||||
@ -91,7 +91,7 @@
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.arrowLEFT;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Location = new Point(768, 411);
|
||||
buttonLeft.Location = new Point(929, 504);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(30, 30);
|
||||
buttonLeft.TabIndex = 4;
|
||||
@ -103,7 +103,7 @@
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = Properties.Resources.arrowRIGHT;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Location = new Point(840, 411);
|
||||
buttonRight.Location = new Point(1001, 504);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(30, 30);
|
||||
buttonRight.TabIndex = 5;
|
||||
@ -113,7 +113,7 @@
|
||||
// buttonCreatePlane
|
||||
//
|
||||
buttonCreatePlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreatePlane.Location = new Point(219, 412);
|
||||
buttonCreatePlane.Location = new Point(219, 505);
|
||||
buttonCreatePlane.Name = "buttonCreatePlane";
|
||||
buttonCreatePlane.Size = new Size(201, 29);
|
||||
buttonCreatePlane.TabIndex = 6;
|
||||
@ -123,17 +123,19 @@
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToRightBottom" });
|
||||
comboBoxStrategy.Location = new Point(719, 12);
|
||||
comboBoxStrategy.Location = new Point(880, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(151, 28);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
buttonStep.Location = new Point(776, 46);
|
||||
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonStep.Location = new Point(937, 46);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(94, 29);
|
||||
buttonStep.TabIndex = 8;
|
||||
@ -143,7 +145,7 @@
|
||||
//
|
||||
// buttonSelectPlane
|
||||
//
|
||||
buttonSelectPlane.Location = new Point(537, 412);
|
||||
buttonSelectPlane.Location = new Point(426, 505);
|
||||
buttonSelectPlane.Name = "buttonSelectPlane";
|
||||
buttonSelectPlane.Size = new Size(137, 29);
|
||||
buttonSelectPlane.TabIndex = 9;
|
||||
@ -155,7 +157,7 @@
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(882, 453);
|
||||
ClientSize = new Size(1043, 546);
|
||||
Controls.Add(buttonSelectPlane);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
|
@ -26,11 +26,11 @@ namespace ProjectStormtrooper
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 110;
|
||||
private readonly int _placeSizeWidth = 160;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 110;
|
||||
private readonly int _placeSizeHeight = 120;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
@ -42,11 +42,11 @@ namespace ProjectStormtrooper
|
||||
/// <param name="picHeight"></param>
|
||||
public PlanesGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
int horizontalObjectsCount = picWidth / _placeSizeWidth;
|
||||
int verticalObjectsCount = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
_collection = new SetGeneric<T>(horizontalObjectsCount * verticalObjectsCount);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
@ -54,13 +54,13 @@ namespace ProjectStormtrooper
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(PlanesGenericCollection<T, U> collect, T? obj)
|
||||
public static int operator +(PlanesGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
return collect?._collection.Insert(obj) ?? false;
|
||||
return collect?._collection.Insert(obj) ?? -1;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
@ -70,12 +70,7 @@ namespace ProjectStormtrooper
|
||||
/// <returns></returns>
|
||||
public static T? operator -(PlanesGenericCollection<T, U> collect, int pos)
|
||||
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return obj;
|
||||
return collect._collection.Remove(pos);
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
@ -104,18 +99,34 @@ namespace ProjectStormtrooper
|
||||
/// <param name="g"></param>
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
// TODO отрисовка фона
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
// Линия разметки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int placesColumnCount = _pictureHeight / _placeSizeHeight;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
// TODO получение объекта
|
||||
// TODO установка позиции
|
||||
// TODO прорисовка объекта
|
||||
// получение объекта
|
||||
var obj = _collection.Get(i);
|
||||
// установка позиции
|
||||
obj?.SetPosition(
|
||||
(int)(i / placesColumnCount * _placeSizeWidth + (_placeSizeWidth - obj?.GetWidth) / 2),
|
||||
(int)(i % placesColumnCount * _placeSizeHeight + (_placeSizeHeight - obj?.GetHeight) / 2)
|
||||
);
|
||||
// прорисовка объекта
|
||||
obj?.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ namespace ProjectStormtrooper
|
||||
/// </summary>
|
||||
/// <param name="plane"></param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T plane)
|
||||
public int Insert(T plane)
|
||||
{
|
||||
return Insert(plane, 0);
|
||||
}
|
||||
@ -42,12 +42,12 @@ namespace ProjectStormtrooper
|
||||
/// <param name="plane"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T plane, int position)
|
||||
public int Insert(T plane, int position)
|
||||
{
|
||||
// Проверка позиции
|
||||
if (position < 0 || position > Count - 1)
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
// Проверка, что элемент массива по этой позиции пустой
|
||||
if (_places[position] != null)
|
||||
@ -65,40 +65,36 @@ namespace ProjectStormtrooper
|
||||
// Если пустого элемента нет, то выходим
|
||||
if (nullIndex < 0)
|
||||
{
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
// Сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
int i = nullIndex - 1;
|
||||
while (i >= position)
|
||||
int j = nullIndex - 1;
|
||||
while (j >= position)
|
||||
{
|
||||
_places[i + 1] = _places[i];
|
||||
i--;
|
||||
_places[j + 1] = _places[j];
|
||||
j--;
|
||||
}
|
||||
}
|
||||
// Вставка по позиции
|
||||
_places[position] = plane;
|
||||
return true;
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
public T? Remove(int position)
|
||||
{
|
||||
// Проверка позиции
|
||||
if (position < 0 || position > Count - 1)
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Нельзя удалить пустой элемент
|
||||
if (_places[position] == null)
|
||||
{
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
// Удаление объекта из массива, присвоив элементу массива значение null
|
||||
T? plane = _places[position];
|
||||
_places[position] = null;
|
||||
return true;
|
||||
return plane;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
@ -108,7 +104,7 @@ namespace ProjectStormtrooper
|
||||
public T? Get(int position)
|
||||
{
|
||||
// Проверка позиции
|
||||
if (position < 0 || position > Count - 1)
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user
Требовалось поменять тип возвращаемого значения