Правки
This commit is contained in:
parent
11d60d4076
commit
458092c11c
@ -25,12 +25,16 @@ public abstract class AbstractCompany
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureHeight;
|
||||
|
||||
protected static int amountOfObjects = 0;
|
||||
/// <summary>
|
||||
/// Коллекция бомбардировщиков
|
||||
/// </summary>
|
||||
protected ICollectionGenericObjects<DrawningBaseStormtrooper>? _collection = null;
|
||||
|
||||
public static int getAmountOfObjects() {
|
||||
return amountOfObjects;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Вычисление максимального количества элементов, который можно разместить в окне
|
||||
/// </summary>
|
||||
@ -56,9 +60,9 @@ public abstract class AbstractCompany
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="stormtrooper">Добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(AbstractCompany company, DrawningBaseStormtrooper stormtrooper)
|
||||
public static int operator +(AbstractCompany company, DrawningBaseStormtrooper stormtrooper)
|
||||
{
|
||||
return company._collection?.Insert(stormtrooper) ?? false;
|
||||
return company._collection.Insert(stormtrooper);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -67,9 +71,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 DrawningBaseStormtrooper operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection?.Remove(position) ?? false;
|
||||
return company._collection.Remove(position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -91,14 +95,12 @@ public abstract class AbstractCompany
|
||||
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
||||
Graphics graphics = Graphics.FromImage(bitmap);
|
||||
DrawBackgound(graphics);
|
||||
|
||||
SetObjectsPosition();
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||
{
|
||||
DrawningBaseStormtrooper? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,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 +30,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>
|
||||
/// Получение объекта по позиции
|
||||
|
@ -1,4 +1,4 @@
|
||||
|
||||
using ProjectStormtrooper.Drawnings;
|
||||
namespace ProjectStormtrooper.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
@ -32,7 +32,6 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
@ -48,7 +47,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public bool Insert(T obj)
|
||||
public int Insert(T obj)
|
||||
{
|
||||
// TODO вставка в свободное место набора
|
||||
int index = 0;
|
||||
@ -56,25 +55,25 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
{
|
||||
if (_collection[index] == null) {
|
||||
_collection[index] = obj;
|
||||
return true;
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// ищется свободное место после этой позиции и идет вставка туда
|
||||
// если нет после, ищем до
|
||||
// TODO вставка
|
||||
if (position >= _collection.Length || position < 0) return false;
|
||||
if (position >= _collection.Length || position < 0) return -1;
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return true;
|
||||
return position;
|
||||
}
|
||||
int index = position + 1;
|
||||
while (index < _collection.Length)
|
||||
@ -82,7 +81,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return true;
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
@ -92,19 +91,20 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return true;
|
||||
return index;
|
||||
}
|
||||
index--;
|
||||
}
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
public T? Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||
if (position >= _collection.Length || position < 0) return false;
|
||||
if (position >= _collection.Length || position < 0) return null;
|
||||
T temp = _collection[position];
|
||||
_collection[position] = null;
|
||||
return true;
|
||||
return temp;
|
||||
}
|
||||
}
|
@ -14,8 +14,6 @@ public class StormtrooperSharingService : AbstractCompany
|
||||
public StormtrooperSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningBaseStormtrooper> collection) : base(picWidth, picHeight, collection)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
protected override void DrawBackgound(Graphics g)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
@ -35,23 +33,20 @@ public class StormtrooperSharingService : AbstractCompany
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
int curWidth = 0;
|
||||
int curWidth = width-1;
|
||||
int curHeight = 0;
|
||||
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||
{
|
||||
if (_collection.Get(i) != null)
|
||||
{
|
||||
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 20, curHeight * _placeSizeHeight + 4);
|
||||
_collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 15, curHeight * _placeSizeHeight + 3);
|
||||
}
|
||||
|
||||
if (curWidth < width-1)
|
||||
curWidth++;
|
||||
if (curWidth >0)
|
||||
curWidth--;
|
||||
else
|
||||
{
|
||||
curWidth = 0;
|
||||
curWidth = width -1;
|
||||
curHeight++;
|
||||
}
|
||||
if (curHeight > height)
|
||||
@ -59,6 +54,5 @@ public class StormtrooperSharingService : AbstractCompany
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -86,6 +86,7 @@ namespace ProjectStormtrooper
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
@ -65,7 +65,8 @@ public partial class FormStormtrooperCollection : Form
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if (_company + drawningBaseStormtrooper)
|
||||
int tempSize = StormtrooperSharingService.getAmountOfObjects();
|
||||
if (_company + drawningBaseStormtrooper != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
@ -119,7 +120,8 @@ public partial class FormStormtrooperCollection : Form
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_company - pos)
|
||||
int tempSize = StormtrooperSharingService.getAmountOfObjects();
|
||||
if (_company-pos!=null)
|
||||
{
|
||||
MessageBox.Show("Объект удалён");
|
||||
pictureBox.Image = _company.Show();
|
||||
|
Loading…
x
Reference in New Issue
Block a user