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>
/// Размер места (ширина) /// Размер места (ширина)
/// </summary> /// </summary>
protected readonly int _placeSizeWidth = 210; protected readonly int _placeSizeWidth = 310;
/// <summary> /// <summary>
/// Размер места (высота) /// Размер места (высота)
/// </summary> /// </summary>
protected readonly int _placeSizeHeight = 80; protected readonly int _placeSizeHeight = 125;
/// <summary> /// <summary>
/// Ширина окна /// Ширина окна
/// </summary> /// </summary>
@ -55,7 +55,7 @@ public abstract class AbstractCompany
/// <returns></returns> /// <returns></returns>
public static int operator +(AbstractCompany company, DrawningTruck truck) public static int operator +(AbstractCompany company, DrawningTruck truck)
{ {
return company._collection?.Insert(truck)??-1; return company._collection.Insert(truck);
} }
/// <summary> /// <summary>
@ -66,7 +66,7 @@ public abstract class AbstractCompany
/// <returns></returns> /// <returns></returns>
public static DrawningTruck? operator -(AbstractCompany company, int position) public static DrawningTruck? operator -(AbstractCompany company, int position)
{ {
return company._collection?.Remove(position); return company._collection?.Remove(position-1);
} }
/// <summary> /// <summary>
@ -88,6 +88,7 @@ public abstract class AbstractCompany
Bitmap bitmap = new(_pictureWidth, _pictureHeight); Bitmap bitmap = new(_pictureWidth, _pictureHeight);
Graphics graphics = Graphics.FromImage(bitmap); Graphics graphics = Graphics.FromImage(bitmap);
DrawBackground(graphics); DrawBackground(graphics);
SetObjectsPosition(); SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i) 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) protected override void DrawBackground(Graphics g)
{ {
Pen pen = new(Color.Black, 2); 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++) for (int i = 0; i < _pictureHeight / _placeSizeHeight; i++)
{ {
@ -28,10 +28,9 @@ public class Autopark : AbstractCompany
int x = _placeSizeWidth; int x = _placeSizeWidth;
x *= j; x *= j;
g.DrawLine(widerPen, x, y, x + _placeSizeWidth / 2, y); g.DrawLine(Pen2, x+10, y, x + _placeSizeWidth / 2, y);
g.DrawLine(widerPen, x, y + _placeSizeHeight - 10, x + _placeSizeWidth / 2, y + _placeSizeHeight - 10); g.DrawLine(Pen2, x+10, y + _placeSizeHeight - 10, x + _placeSizeWidth / 2, y + _placeSizeHeight - 10);
g.DrawLine(pen, x, y, x, y + _placeSizeHeight - 10); g.DrawLine(pen, x + 10, y, x+10, y + _placeSizeHeight - 10);
g.DrawLine(pen, x + _placeSizeWidth / 2, y, x + _placeSizeWidth / 2, y + _placeSizeHeight - 10);
} }
} }
} }
@ -45,8 +44,8 @@ public class Autopark : AbstractCompany
{ {
if (_collection?.Get(i) != null) if (_collection?.Get(i) != null)
{ {
int x = 5 + _placeSizeWidth * n; int x = 20 + _placeSizeWidth * n;
int y = (10 + _placeSizeHeight * (_pictureHeight / _placeSizeHeight - 1)) - _placeSizeHeight * m; int y = 10 + _placeSizeHeight * m;
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection?.Get(i)?.SetPosition(x, y); _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.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection.Metadata.Ecma335; using System.Reflection.Metadata.Ecma335;
@ -31,20 +31,19 @@ public class MassiveGenericObjects<T> : ICollectionGenericObject<T>
public T? Get(int position) public T? Get(int position)
{ {
// TODO проверка позиции // TODO проверка позиции
if (position >= 0 && position < Count) if (position < 0 || position > Count)
{ {
return _collection[position]; return null;
} }
return _collection[position];
return null;
} }
public int Insert(T obj) public int Insert(T obj)
{ {
// TODO вставка в свободное место набора // 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; _collection[i] = obj;
return i; return i;