Bogdanov D.S. LabWork03 #3
1
Ship/Ship/FormMapWithSetShips.Designer.cs
generated
1
Ship/Ship/FormMapWithSetShips.Designer.cs
generated
@ -170,6 +170,7 @@
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(169, 23);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
|
@ -163,10 +163,17 @@ namespace Ship
|
||||
/// <param name="g"></param>
|
||||
private void DrawCars(Graphics g)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
for (int i = 0; i < _setShips.Count; i++)
|
||||
{
|
||||
// TODO установка позиции
|
||||
_setShips.Get(i)?.DrawningObject(g);
|
||||
var artillery = _setShips.Get(i);
|
||||
if (artillery != null)
|
||||
{
|
||||
artillery.SetObject((i % width) * _placeSizeWidth + 10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
artillery.DrawningObject(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,27 +28,52 @@ namespace Ship
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="car">Добавляемый автомобиль</param>
|
||||
/// <param name="ship">Добавляемый корабль</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T car)
|
||||
public bool Insert(T ship)
|
||||
{
|
||||
// TODO вставка в начало набора
|
||||
return true;
|
||||
return Insert(ship, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="car">Добавляемый автомобиль</param>
|
||||
/// <param name="ship">Добавляемый корабль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T car, int position)
|
||||
public bool Insert(T ship, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
// TODO вставка по позиции
|
||||
_places[position] = car;
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = ship;
|
||||
return true;
|
||||
}
|
||||
|
||||
int firstNull = -1;
|
||||
|
||||
for (int i = position + 1; i < Count; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
firstNull = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (firstNull == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = firstNull; i > position; i--)
|
||||
{
|
||||
(_places[i], _places[i - 1]) = (_places[i - 1], _places[i]);
|
||||
}
|
||||
_places[position] = ship;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
@ -58,8 +83,11 @@ namespace Ship
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присовив элементу массива значение null
|
||||
if (position < 0 || position >= Count || _places[position] == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
@ -69,7 +97,10 @@ namespace Ship
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user