Bogdanov D.S. LabWork03 #3
@ -63,7 +63,7 @@ namespace Ship
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawingObject car = new(form.SelectedShip);
|
||||
if (_mapShipsCollectionGeneric + car)
|
||||
if (_mapShipsCollectionGeneric + car != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapShipsCollectionGeneric.ShowSet();
|
||||
@ -91,7 +91,7 @@ namespace Ship
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapShipsCollectionGeneric - pos)
|
||||
if (_mapShipsCollectionGeneric - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapShipsCollectionGeneric.ShowSet();
|
||||
|
@ -55,7 +55,7 @@ namespace Ship
|
||||
/// <param name="map"></param>
|
||||
/// <param name="car"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(MapWithSetShipsGeneric<T, U> map, T car)
|
||||
public static int operator +(MapWithSetShipsGeneric<T, U> map, T car)
|
||||
{
|
||||
return map._setShips.Insert(car);
|
||||
}
|
||||
@ -65,7 +65,7 @@ namespace Ship
|
||||
/// <param name="map"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(MapWithSetShipsGeneric<T, U> map, int
|
||||
public static T operator -(MapWithSetShipsGeneric<T, U> map, int
|
||||
position)
|
||||
{
|
||||
return map._setShips.Remove(position);
|
||||
@ -146,15 +146,22 @@ namespace Ship
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
Brush seaBrush = new SolidBrush(Color.Blue);
|
||||
Pen thickPen = new Pen(Color.Black, 8);
|
||||
Pen thinPen = new Pen(Color.Black, 4);
|
||||
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, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
g.FillRectangle(seaBrush, i * _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 - 5, _placeSizeWidth / 2, _placeSizeHeight / 3);
|
||||
g.DrawLine(thickPen, i * _placeSizeWidth, j * _placeSizeHeight - 45, i * _placeSizeWidth + _placeSizeWidth / 2 - 50, j * _placeSizeHeight - 45);
|
||||
g.DrawLine(thinPen, i * _placeSizeWidth + 10, j * _placeSizeHeight - 45, i * _placeSizeWidth + 10, j * _placeSizeHeight - 60);
|
||||
g.DrawLine(thinPen, i * _placeSizeWidth + 20, j * _placeSizeHeight - 45, i * _placeSizeWidth + 20, j * _placeSizeHeight - 60);
|
||||
g.DrawLine(thinPen, i * _placeSizeWidth + 30, j * _placeSizeHeight - 45, i * _placeSizeWidth + 30, j * _placeSizeHeight - 60);
|
||||
g.DrawLine(thinPen, i * _placeSizeWidth + 40, j * _placeSizeHeight - 45, i * _placeSizeWidth + 40, j * _placeSizeHeight - 60);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
|
||||
(_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@ -171,7 +178,7 @@ namespace Ship
|
||||
var artillery = _setShips.Get(i);
|
||||
if (artillery != null)
|
||||
{
|
||||
artillery.SetObject((i % width) * _placeSizeWidth + 10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
artillery.SetObject((width - i % width - 1) * _placeSizeWidth + 10, (i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
artillery.DrawningObject(g);
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace Ship
|
||||
/// </summary>
|
||||
/// <param name="ship">Добавляемый корабль</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T ship)
|
||||
public int Insert(T ship)
|
||||
{
|
||||
return Insert(ship, 0);
|
||||
}
|
||||
@ -40,17 +40,17 @@ namespace Ship
|
||||
/// <param name="ship">Добавляемый корабль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T ship, int position)
|
||||
public int Insert(T ship, int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = ship;
|
||||
return true;
|
||||
return position;
|
||||
}
|
||||
|
||||
int firstNull = -1;
|
||||
@ -66,7 +66,7 @@ namespace Ship
|
||||
|
||||
if (firstNull == -1)
|
||||
{
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = firstNull; i > position; i--)
|
||||
@ -74,21 +74,22 @@ namespace Ship
|
||||
(_places[i], _places[i - 1]) = (_places[i - 1], _places[i]);
|
||||
}
|
||||
_places[position] = ship;
|
||||
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 || _places[position] == null)
|
||||
{
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
_places[position] = null;
|
||||
return true;
|
||||
var result = _places[position];
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
|
Loading…
x
Reference in New Issue
Block a user