Изменены типы возвращаемых значений, добавлена отрисовка базы
This commit is contained in:
parent
1868d30d50
commit
a4072a3348
@ -56,7 +56,7 @@ namespace ArmoredCar
|
||||
/// <param name="map"></param>
|
||||
/// <param name="car"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(MapWithSetArmoredCarsGeneric<T, U> map, T car)
|
||||
public static int operator +(MapWithSetArmoredCarsGeneric<T, U> map, T car)
|
||||
{
|
||||
return map._setCars.Insert(car);
|
||||
}
|
||||
@ -66,7 +66,7 @@ namespace ArmoredCar
|
||||
/// <param name="map"></param>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(MapWithSetArmoredCarsGeneric<T, U> map, int
|
||||
public static T operator -(MapWithSetArmoredCarsGeneric<T, U> map, int
|
||||
position)
|
||||
{
|
||||
return map._setCars.Remove(position);
|
||||
@ -108,7 +108,7 @@ namespace ArmoredCar
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
@ -149,12 +149,22 @@ namespace ArmoredCar
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
Brush brushRoad = new SolidBrush(Color.Gray);
|
||||
Brush brushBox = new SolidBrush(Color.SandyBrown);
|
||||
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.FillRectangle(brushRoad, i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth, _placeSizeHeight);
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
|
||||
int boxSize = _placeSizeWidth / 7;
|
||||
g.FillRectangle(brushBox, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight + _placeSizeHeight / 5, boxSize, boxSize);
|
||||
g.DrawRectangle(pen, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight + _placeSizeHeight / 5, boxSize, boxSize);
|
||||
g.FillRectangle(brushBox, i * _placeSizeWidth + _placeSizeWidth / 2 - boxSize / 2, j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
|
||||
g.DrawRectangle(pen, i * _placeSizeWidth + _placeSizeWidth / 2 - boxSize / 2, j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
|
||||
g.FillRectangle(brushBox, i * _placeSizeWidth + _placeSizeWidth / 2 + boxSize / 2, j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
|
||||
g.DrawRectangle(pen, i * _placeSizeWidth + _placeSizeWidth / 2 + boxSize / 2, j * _placeSizeHeight + _placeSizeHeight / 5 + boxSize, boxSize, boxSize);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
|
||||
(_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
@ -169,9 +179,11 @@ namespace ArmoredCar
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
|
||||
for (int i = 0; i < _setCars.Count; i++)
|
||||
{
|
||||
_setCars.Get(i)?.SetObject(i % width * _placeSizeWidth + 10, i / width * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
_setCars.Get(i)?.DrawningObject(g);
|
||||
{
|
||||
if (_setCars.Get(i) != null) {
|
||||
_setCars.Get(i)?.SetObject(i % width * _placeSizeWidth + 5, i / width * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
_setCars.Get(i)?.DrawningObject(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace ArmoredCar
|
||||
/// </summary>
|
||||
/// <param name="armoredCar">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T armoredCar)
|
||||
public int Insert(T armoredCar)
|
||||
{
|
||||
return Insert(armoredCar, 0);
|
||||
}
|
||||
@ -40,10 +40,10 @@ namespace ArmoredCar
|
||||
/// <param name="armoredCar">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T armoredCar, int position)
|
||||
public int Insert(T armoredCar, int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
return false;
|
||||
return -1;
|
||||
|
||||
if (!(_places[position] == null))
|
||||
{
|
||||
@ -57,7 +57,7 @@ namespace ArmoredCar
|
||||
}
|
||||
}
|
||||
if (index_empty == -1)
|
||||
return false;
|
||||
return -1;
|
||||
else
|
||||
{
|
||||
for (int i = index_empty; i > position; i--)
|
||||
@ -67,20 +67,20 @@ namespace ArmoredCar
|
||||
}
|
||||
}
|
||||
_places[position] = armoredCar;
|
||||
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)
|
||||
return false;
|
||||
|
||||
return null;
|
||||
T armoredCar = _places[position];
|
||||
_places[position] = null;
|
||||
return true;
|
||||
return armoredCar;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
|
Loading…
Reference in New Issue
Block a user