This commit is contained in:
Baryshev Dmitry 2024-03-27 22:01:46 +04:00
parent c4c450563c
commit cbbd0d4eb2
3 changed files with 44 additions and 18 deletions

View File

@ -12,11 +12,11 @@ public abstract class AbstractCompany
/// <summary>
/// Размер места (ширина)
/// </summary>
protected readonly int _placeSizeWidth = 210;
protected readonly int _placeSizeWidth = 310;
/// <summary>
/// Размер места (высота)
/// </summary>
protected readonly int _placeSizeHeight = 80;
protected readonly int _placeSizeHeight = 125;
/// <summary>
/// Ширина окна
/// </summary>
@ -55,7 +55,7 @@ public abstract class AbstractCompany
/// <returns></returns>
public static int operator +(AbstractCompany company, DrawningTruck truck)
{
return company._collection?.Insert(truck)??-1;
return company._collection.Insert(truck);
}
/// <summary>
@ -66,7 +66,7 @@ public abstract class AbstractCompany
/// <returns></returns>
public static DrawningTruck? operator -(AbstractCompany company, int position)
{
return company._collection?.Remove(position);
return company._collection?.Remove(position-1);
}
/// <summary>
@ -88,6 +88,7 @@ public abstract class AbstractCompany
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
Graphics graphics = Graphics.FromImage(bitmap);
DrawBackground(graphics);
SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{

View File

@ -16,7 +16,7 @@ public class Autopark : AbstractCompany
protected override void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 2);
Pen widerPen = new(Color.Black, 5);
Pen Pen2 = new(Color.Black, 3);
for (int i = 0; i < _pictureHeight / _placeSizeHeight; i++)
{
@ -28,10 +28,9 @@ public class Autopark : AbstractCompany
int x = _placeSizeWidth;
x *= j;
g.DrawLine(widerPen, x, y, x + _placeSizeWidth / 2, y);
g.DrawLine(widerPen, x, y + _placeSizeHeight - 10, x + _placeSizeWidth / 2, y + _placeSizeHeight - 10);
g.DrawLine(pen, x, y, x, y + _placeSizeHeight - 10);
g.DrawLine(pen, x + _placeSizeWidth / 2, y, x + _placeSizeWidth / 2, y + _placeSizeHeight - 10);
g.DrawLine(Pen2, x+10, y, x + _placeSizeWidth / 2, y);
g.DrawLine(Pen2, x+10, y + _placeSizeHeight - 10, x + _placeSizeWidth / 2, y + _placeSizeHeight - 10);
g.DrawLine(pen, x + 10, y, x+10, y + _placeSizeHeight - 10);
}
}
}
@ -45,8 +44,8 @@ public class Autopark : AbstractCompany
{
if (_collection?.Get(i) != null)
{
int x = 5 + _placeSizeWidth * n;
int y = (10 + _placeSizeHeight * (_pictureHeight / _placeSizeHeight - 1)) - _placeSizeHeight * m;
int x = 20 + _placeSizeWidth * n;
int y = 10 + _placeSizeHeight * m;
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection?.Get(i)?.SetPosition(x, y);
@ -61,4 +60,31 @@ public class Autopark : AbstractCompany
}
}
}
//protected override void SetObjectsPosition()
//{
// int nowWidth = 0;
// int nowHeight = 0;
// for (int i = 0; i < (_collection?.Count ?? 0); i++)
// {
// if (nowHeight > _pictureHeight / _placeSizeHeight)
// {
// return;
// }
// if (_collection?.Get(i) != null)
// {
// _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
// _collection?.Get(i)?.SetPosition(_placeSizeWidth * nowWidth + 30, nowHeight * _placeSizeHeight * 2 + 20);
// }
// if (nowWidth < _pictureWidth / _placeSizeWidth - 1) nowWidth++;
// else
// {
// nowWidth = 0;
// nowHeight++;
// }
// }
//}
}

View File

@ -1,4 +1,4 @@
using System;
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
@ -31,20 +31,19 @@ public class MassiveGenericObjects<T> : ICollectionGenericObject<T>
public T? Get(int position)
{
// TODO проверка позиции
if (position >= 0 && position < Count)
if (position < 0 || position > Count)
{
return _collection[position];
return null;
}
return null;
return _collection[position];
}
public int Insert(T obj)
{
// TODO вставка в свободное место набора
for (int i = 0; i < _collection.Length; i++)
for (int i = 0; i < Count; i++)
{
if (_collection[i] != null)
if (_collection[i] == null)
{
_collection[i] = obj;
return i;