Исправлены ошибки в отображении и отрисовке депо локомотивов.

This commit is contained in:
Danil Malin 2022-10-09 14:20:50 +04:00
parent c269ff167a
commit 33701833e9
2 changed files with 17 additions and 25 deletions

View File

@ -25,7 +25,7 @@ namespace WarmlyLocomotive
/// <summary> /// <summary>
/// Размер занимаемого объектом места (высота) /// Размер занимаемого объектом места (высота)
/// </summary> /// </summary>
private readonly int _placeSizeHeight = 120 /*105*/; private readonly int _placeSizeHeight = 120;
/// <summary> /// <summary>
/// Набор объектов /// Набор объектов
/// </summary> /// </summary>
@ -149,19 +149,20 @@ namespace WarmlyLocomotive
Brush brushLightGray = new SolidBrush(Color.LightGray); Brush brushLightGray = new SolidBrush(Color.LightGray);
Brush brushBrown = new SolidBrush(Color.Brown); Brush brushBrown = new SolidBrush(Color.Brown);
g.FillRectangle(brushLightGray, 0, 0, _pictureWidth, _pictureHeight); g.FillRectangle(brushLightGray, 0, 0, _pictureWidth, _pictureHeight);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) int placesInRow = _pictureWidth / (_placeSizeWidth + 30);
for (int i = 0; i < placesInRow; i++)
{ {
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{//линия рамзетки места {//линия рамзетки места
if (j != 0) if (j != 0)
{ {
int x = i * (_placeSizeWidth + 30); int xForRail = i * (_placeSizeWidth + 30);
g.DrawLine(penTwo, x, j * _placeSizeHeight, x + _placeSizeWidth - 20, j * _placeSizeHeight); g.DrawLine(penTwo, xForRail, j * _placeSizeHeight, xForRail + _placeSizeWidth - 20, j * _placeSizeHeight);
g.DrawLine(penTwo, x, j * _placeSizeHeight - 20, x + _placeSizeWidth - 20, j * _placeSizeHeight - 20); g.DrawLine(penTwo, xForRail, j * _placeSizeHeight - 20, xForRail + _placeSizeWidth - 20, j * _placeSizeHeight - 20);
for (int k = 0; k < (_placeSizeWidth - 20) / 15; ++k) for (int k = 0; k < (_placeSizeWidth - 20) / 15; ++k)
{ {
g.FillRectangle(brushBrown, x, j * _placeSizeHeight - 20, 5, 20); g.FillRectangle(brushBrown, xForRail, j * _placeSizeHeight - 20, 5, 20);
x += 15; xForRail += 15;
} }
} }
g.DrawLine(pen, i * (_placeSizeWidth + 30), j * _placeSizeHeight + 10, i * (_placeSizeWidth + 30) + _placeSizeWidth / 2, j * _placeSizeHeight + 10); g.DrawLine(pen, i * (_placeSizeWidth + 30), j * _placeSizeHeight + 10, i * (_placeSizeWidth + 30) + _placeSizeWidth / 2, j * _placeSizeHeight + 10);
@ -175,23 +176,23 @@ namespace WarmlyLocomotive
/// <param name="g"></param> /// <param name="g"></param>
private void DrawLocomotives(Graphics g) private void DrawLocomotives(Graphics g)
{ {
int x = 2; int xForLocomotive = 2;
int y = 10; int yForLocomotive = 10;
int countInRow = 0; int countInRow = 0;
for (int i = 0; i < _setLocomotives.Count; i++) for (int i = 0; i < _setLocomotives.Count; i++)
{ {
if (countInRow >= _pictureWidth / _placeSizeWidth) if (countInRow >= _pictureWidth / (_placeSizeWidth + 30))
{ {
x = 2; xForLocomotive = 2;
y += _placeSizeHeight; yForLocomotive += _placeSizeHeight;
countInRow = 0; countInRow = 0;
} }
if (_setLocomotives.Get(i) != null) if (_setLocomotives.Get(i) != null)
{ {
var locomotive = _setLocomotives.Get(i); T locomotive = _setLocomotives.Get(i);
locomotive.SetObject(x, y, _pictureWidth, _pictureHeight); locomotive.SetObject(xForLocomotive, yForLocomotive, _pictureWidth, _pictureHeight);
locomotive.DrawningObject(g); locomotive.DrawningObject(g);
x += _placeSizeWidth + 30; xForLocomotive += _placeSizeWidth + 30;
countInRow++; countInRow++;
} }
} }

View File

@ -32,7 +32,6 @@ namespace WarmlyLocomotive
/// <returns></returns> /// <returns></returns>
public int Insert(T locomotive) public int Insert(T locomotive)
{ {
// TODO вставка в начало набора
bool hasEmptySpace = false; bool hasEmptySpace = false;
int indexOfEmptyPlace = 0; int indexOfEmptyPlace = 0;
for (int i = 0; i < Count; ++i) for (int i = 0; i < Count; ++i)
@ -61,16 +60,11 @@ namespace WarmlyLocomotive
/// <summary> /// <summary>
/// Добавление объекта в набор на конкретную позицию /// Добавление объекта в набор на конкретную позицию
/// </summary> /// </summary>
/// <param name="car">Добавляемый локомотив</param> /// <param name="locomotive">Добавляемый локомотив</param>
/// <param name="position">Позиция</param> /// <param name="position">Позиция</param>
/// <returns></returns> /// <returns></returns>
public int Insert(T locomotive, int position) public int Insert(T locomotive, int position)
{ {
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// проверка, что после вставляемого элемента в массиве есть пустой элемент
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
// TODO вставка по позиции
if (position < 0 || position >= Count) if (position < 0 || position >= Count)
{ {
return -1; return -1;
@ -115,8 +109,6 @@ namespace WarmlyLocomotive
/// <returns></returns> /// <returns></returns>
public T Remove(int position) public T Remove(int position)
{ {
// TODO проверка позиции
// TODO удаление объекта из массива, присовив элементу массива значение null
if (position < 0 || position >= Count) if (position < 0 || position >= Count)
{ {
return null; return null;
@ -132,7 +124,6 @@ namespace WarmlyLocomotive
/// <returns></returns> /// <returns></returns>
public T Get(int position) public T Get(int position)
{ {
// TODO проверка позиции
if (position < 0 || position >= Count) if (position < 0 || position >= Count)
{ {
return null; return null;