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