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