Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
db179df769 | |||
436fb15353 | |||
a8cca87e52 | |||
3e9bd95023 | |||
7ccc06490e |
134
ProjectExcavator/ProjectExcavator/AbstractStrategy.cs
Normal file
134
ProjectExcavator/ProjectExcavator/AbstractStrategy.cs
Normal file
@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-стратегия перемещения объекта
|
||||
/// </summary>
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObject? _moveableObject;
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
private Status _state = Status.NotInit;
|
||||
/// <summary>
|
||||
/// Ширина поля
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
/// <summary>
|
||||
/// Высота поля
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
public Status GetStatus() { return _state; }
|
||||
/// <summary>
|
||||
/// Установка данных
|
||||
/// </summary>
|
||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
public void SetData(IMoveableObject moveableObject, int width, int
|
||||
height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = Status.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||
/// <summary>
|
||||
/// Перемещение вверх
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||
/// <summary>
|
||||
/// Перемещение вниз
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveDown() => MoveTo(DirectionType.Down);
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters? GetObjectParameters =>
|
||||
_moveableObject?.GetObjectPosition;
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
/// <summary>
|
||||
/// Достигнута ли цель
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
/// <summary>
|
||||
/// Попытка перемещения в требуемом направлении
|
||||
/// </summary>
|
||||
/// <param name="directionType">Направление</param>
|
||||
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||
private bool MoveTo(DirectionType directionType)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
31
ProjectExcavator/ProjectExcavator/Directions.cs
Normal file
31
ProjectExcavator/ProjectExcavator/Directions.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
||||
}
|
105
ProjectExcavator/ProjectExcavator/DrawKatkiCircle.cs
Normal file
105
ProjectExcavator/ProjectExcavator/DrawKatkiCircle.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using ProjectExcavator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
public class DrawKatkiCircle : IDrawingKatki
|
||||
{
|
||||
private KatkiNumber KatNum;
|
||||
public int Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
return Properties;
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case 1:
|
||||
KatNum = KatkiNumber.Four;
|
||||
break;
|
||||
case 2:
|
||||
KatNum = KatkiNumber.Five;
|
||||
break;
|
||||
case 3:
|
||||
KatNum = KatkiNumber.Six;
|
||||
break;
|
||||
default:
|
||||
KatNum = KatkiNumber.Four;
|
||||
MessageBox.Show("Было введено некорректное количество катков, поэтому было отрисовано стандартное количество катков");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public int GetShape()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public int GetAmount()
|
||||
{
|
||||
int x = 0;
|
||||
if (KatNum == KatkiNumber.Four)
|
||||
x = 1;
|
||||
if (KatNum == KatkiNumber.Five)
|
||||
x = 2;
|
||||
if (KatNum == KatkiNumber.Six)
|
||||
x = 3;
|
||||
return x;
|
||||
}
|
||||
public void Draw(int _startPosX, int _startPosY, Color katkiColor, Graphics g)
|
||||
{
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Brush KatkiColor = new SolidBrush(katkiColor);
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
if (KatNum == KatkiNumber.Four)
|
||||
{
|
||||
g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 30, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 60, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 85, _startPosY + 58, 15, 15);
|
||||
|
||||
g.FillEllipse(KatkiColor, _startPosX + 8, _startPosY + 61, 8, 8);
|
||||
g.FillEllipse(KatkiColor, _startPosX + 33, _startPosY + 61, 8, 8);
|
||||
g.FillEllipse(KatkiColor, _startPosX + 63, _startPosY + 61, 8, 8);
|
||||
g.FillEllipse(KatkiColor, _startPosX + 88, _startPosY + 61, 8, 8);
|
||||
|
||||
}
|
||||
if (KatNum == KatkiNumber.Five)
|
||||
{
|
||||
g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 25, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 45, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 85, _startPosY + 58, 15, 15);
|
||||
|
||||
g.FillEllipse(KatkiColor, _startPosX + 8, _startPosY + 61, 8, 8);
|
||||
g.FillEllipse(KatkiColor, _startPosX + 28, _startPosY + 61, 8, 8);
|
||||
g.FillEllipse(KatkiColor, _startPosX + 48, _startPosY + 61, 8, 8);
|
||||
g.FillEllipse(KatkiColor, _startPosX + 68, _startPosY + 61, 8, 8);
|
||||
g.FillEllipse(KatkiColor, _startPosX + 88, _startPosY + 61, 8, 8);
|
||||
}
|
||||
if (KatNum == KatkiNumber.Six)
|
||||
{
|
||||
g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 20, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 35, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 50, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 80, _startPosY + 58, 15, 15);
|
||||
|
||||
g.FillEllipse(KatkiColor, _startPosX + 8, _startPosY + 61, 8, 8);
|
||||
g.FillEllipse(KatkiColor, _startPosX + 23, _startPosY + 61, 8, 8);
|
||||
g.FillEllipse(KatkiColor, _startPosX + 38, _startPosY + 61, 8, 8);
|
||||
g.FillEllipse(KatkiColor, _startPosX + 53, _startPosY + 61, 8, 8);
|
||||
g.FillEllipse(KatkiColor, _startPosX + 68, _startPosY + 61, 8, 8);
|
||||
g.FillEllipse(KatkiColor, _startPosX + 83, _startPosY + 61, 8, 8);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
104
ProjectExcavator/ProjectExcavator/DrawKatkiSquare.cs
Normal file
104
ProjectExcavator/ProjectExcavator/DrawKatkiSquare.cs
Normal file
@ -0,0 +1,104 @@
|
||||
using ProjectExcavator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
public class DrawKatkiSquare : IDrawingKatki
|
||||
{
|
||||
private KatkiNumber KatNum;
|
||||
public int Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
return Properties;
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case 1:
|
||||
KatNum = KatkiNumber.Four;
|
||||
break;
|
||||
case 2:
|
||||
KatNum = KatkiNumber.Five;
|
||||
break;
|
||||
case 3:
|
||||
KatNum = KatkiNumber.Six;
|
||||
break;
|
||||
default:
|
||||
KatNum = KatkiNumber.Four;
|
||||
MessageBox.Show("Было введено некорректное количество катков, поэтому было отрисовано стандартное количество катков");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public int GetShape()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
public int GetAmount()
|
||||
{
|
||||
int x = 0;
|
||||
if (KatNum == KatkiNumber.Four)
|
||||
x = 1;
|
||||
if (KatNum == KatkiNumber.Five)
|
||||
x = 2;
|
||||
if (KatNum == KatkiNumber.Six)
|
||||
x = 3;
|
||||
return x;
|
||||
}
|
||||
public void Draw(int _startPosX, int _startPosY, Color katkiColor, Graphics g)
|
||||
{
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Brush KatkiColor = new SolidBrush(katkiColor);
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
if (KatNum == KatkiNumber.Four)
|
||||
{
|
||||
g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 30, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 60, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 85, _startPosY + 58, 15, 15);
|
||||
g.FillRectangle(KatkiColor, _startPosX + 9, _startPosY + 62, 7, 7);
|
||||
g.FillRectangle(KatkiColor, _startPosX + 34, _startPosY + 62, 7, 7);
|
||||
g.FillRectangle(KatkiColor, _startPosX + 64, _startPosY + 62, 7, 7);
|
||||
g.FillRectangle(KatkiColor, _startPosX + 89, _startPosY + 62, 7, 7);
|
||||
|
||||
|
||||
}
|
||||
if (KatNum == KatkiNumber.Five)
|
||||
{
|
||||
g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 25, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 45, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 85, _startPosY + 58, 15, 15);
|
||||
g.FillRectangle(KatkiColor, _startPosX + 9, _startPosY + 62, 7, 7);
|
||||
g.FillRectangle(KatkiColor, _startPosX + 29, _startPosY + 62, 7, 7);
|
||||
g.FillRectangle(KatkiColor, _startPosX + 49, _startPosY + 62, 7, 7);
|
||||
g.FillRectangle(KatkiColor, _startPosX + 69, _startPosY + 62, 7, 7);
|
||||
g.FillRectangle(KatkiColor, _startPosX + 89, _startPosY + 62, 7, 7);
|
||||
|
||||
}
|
||||
if (KatNum == KatkiNumber.Six)
|
||||
{
|
||||
g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 20, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 35, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 50, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 80, _startPosY + 58, 15, 15);
|
||||
g.FillRectangle(KatkiColor, _startPosX + 9, _startPosY + 62, 7, 7);
|
||||
g.FillRectangle(KatkiColor, _startPosX + 24, _startPosY + 62, 7, 7);
|
||||
g.FillRectangle(KatkiColor, _startPosX + 39, _startPosY + 62, 7, 7);
|
||||
g.FillRectangle(KatkiColor, _startPosX + 54, _startPosY + 62, 7, 7);
|
||||
g.FillRectangle(KatkiColor, _startPosX + 69, _startPosY + 62, 7, 7);
|
||||
g.FillRectangle(KatkiColor, _startPosX + 84, _startPosY + 62, 7, 7);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
163
ProjectExcavator/ProjectExcavator/DrawKatkiTriangle.cs
Normal file
163
ProjectExcavator/ProjectExcavator/DrawKatkiTriangle.cs
Normal file
@ -0,0 +1,163 @@
|
||||
using ProjectExcavator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
public class DrawKatkiTriangle : IDrawingKatki
|
||||
{
|
||||
private KatkiNumber KatNum;
|
||||
public int Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
return Properties;
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case 1:
|
||||
KatNum = KatkiNumber.Four;
|
||||
break;
|
||||
case 2:
|
||||
KatNum = KatkiNumber.Five;
|
||||
break;
|
||||
case 3:
|
||||
KatNum = KatkiNumber.Six;
|
||||
break;
|
||||
default:
|
||||
KatNum = KatkiNumber.Four;
|
||||
MessageBox.Show("Было введено некорректное количество катков, поэтому было отрисовано стандартное количество катков");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public int GetShape()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
public int GetAmount()
|
||||
{
|
||||
int x = 0;
|
||||
if (KatNum == KatkiNumber.Four)
|
||||
x = 1;
|
||||
if (KatNum == KatkiNumber.Five)
|
||||
x = 2;
|
||||
if (KatNum == KatkiNumber.Six)
|
||||
x = 3;
|
||||
return x;
|
||||
}
|
||||
public void Draw(int _startPosX, int _startPosY, Color katkiColor, Graphics g)
|
||||
{
|
||||
Pen pen = new Pen(Color.Black);
|
||||
Brush KatkiColor = new SolidBrush(katkiColor);
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
if (KatNum == KatkiNumber.Four)
|
||||
{
|
||||
g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 30, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 60, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 85, _startPosY + 58, 15, 15);
|
||||
|
||||
Point point1 = new Point(_startPosX + 12, _startPosY + 60);
|
||||
Point point2 = new Point(_startPosX + 17, _startPosY + 70);
|
||||
Point point3 = new Point(_startPosX + 7, _startPosY + 70);
|
||||
Point[] trianglePoints1 = { point1, point2, point3 };
|
||||
g.FillPolygon(KatkiColor, trianglePoints1);
|
||||
Point point4 = new Point(_startPosX + 37, _startPosY + 60);
|
||||
Point point5 = new Point(_startPosX + 42, _startPosY + 70);
|
||||
Point point6 = new Point(_startPosX + 32, _startPosY + 70);
|
||||
Point[] trianglePoints2 = { point4, point5, point6 };
|
||||
g.FillPolygon(KatkiColor, trianglePoints2);
|
||||
Point point7 = new Point(_startPosX + 67, _startPosY + 60);
|
||||
Point point8 = new Point(_startPosX + 72, _startPosY + 70);
|
||||
Point point9 = new Point(_startPosX + 62, _startPosY + 70);
|
||||
Point[] trianglePoints3 = { point7, point8, point9 };
|
||||
g.FillPolygon(KatkiColor, trianglePoints3);
|
||||
Point point10 = new Point(_startPosX + 92, _startPosY + 60);
|
||||
Point point11 = new Point(_startPosX + 97, _startPosY + 70);
|
||||
Point point12 = new Point(_startPosX + 87, _startPosY + 70);
|
||||
Point[] trianglePoints4 = { point10, point11, point12 };
|
||||
g.FillPolygon(KatkiColor, trianglePoints4);
|
||||
}
|
||||
if (KatNum == KatkiNumber.Five)
|
||||
{
|
||||
g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 25, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 45, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 85, _startPosY + 58, 15, 15);
|
||||
|
||||
Point point1 = new Point(_startPosX + 12, _startPosY + 60);
|
||||
Point point2 = new Point(_startPosX + 17, _startPosY + 70);
|
||||
Point point3 = new Point(_startPosX + 7, _startPosY + 70);
|
||||
Point[] trianglePoints1 = { point1, point2, point3 };
|
||||
g.FillPolygon(KatkiColor, trianglePoints1);
|
||||
Point point4 = new Point(_startPosX + 32, _startPosY + 60);
|
||||
Point point5 = new Point(_startPosX + 37, _startPosY + 70);
|
||||
Point point6 = new Point(_startPosX + 27, _startPosY + 70);
|
||||
Point[] trianglePoints2 = { point4, point5, point6 };
|
||||
g.FillPolygon(KatkiColor, trianglePoints2);
|
||||
Point point7 = new Point(_startPosX + 52, _startPosY + 60);
|
||||
Point point8 = new Point(_startPosX + 57, _startPosY + 70);
|
||||
Point point9 = new Point(_startPosX + 47, _startPosY + 70);
|
||||
Point[] trianglePoints3 = { point7, point8, point9 };
|
||||
g.FillPolygon(KatkiColor, trianglePoints3);
|
||||
Point point10 = new Point(_startPosX + 72, _startPosY + 60);
|
||||
Point point11 = new Point(_startPosX + 77, _startPosY + 70);
|
||||
Point point12 = new Point(_startPosX + 67, _startPosY + 70);
|
||||
Point[] trianglePoints4 = { point10, point11, point12 };
|
||||
g.FillPolygon(KatkiColor, trianglePoints4);
|
||||
Point point13 = new Point(_startPosX + 92, _startPosY + 60);
|
||||
Point point14 = new Point(_startPosX + 97, _startPosY + 70);
|
||||
Point point15 = new Point(_startPosX + 87, _startPosY + 70);
|
||||
Point[] trianglePoints5 = { point13, point14, point15 };
|
||||
g.FillPolygon(KatkiColor, trianglePoints5);
|
||||
}
|
||||
if (KatNum == KatkiNumber.Six)
|
||||
{
|
||||
g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 20, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 35, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 50, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(brBlack, _startPosX + 80, _startPosY + 58, 15, 15);
|
||||
|
||||
Point point1 = new Point(_startPosX + 12, _startPosY + 60);
|
||||
Point point2 = new Point(_startPosX + 17, _startPosY + 70);
|
||||
Point point3 = new Point(_startPosX + 7, _startPosY + 70);
|
||||
Point[] trianglePoints1 = { point1, point2, point3 };
|
||||
g.FillPolygon(KatkiColor, trianglePoints1);
|
||||
Point point4 = new Point(_startPosX + 27, _startPosY + 60);
|
||||
Point point5 = new Point(_startPosX + 32, _startPosY + 70);
|
||||
Point point6 = new Point(_startPosX + 22, _startPosY + 70);
|
||||
Point[] trianglePoints2 = { point4, point5, point6 };
|
||||
g.FillPolygon(KatkiColor, trianglePoints2);
|
||||
Point point7 = new Point(_startPosX + 42, _startPosY + 60);
|
||||
Point point8 = new Point(_startPosX + 47, _startPosY + 70);
|
||||
Point point9 = new Point(_startPosX + 37, _startPosY + 70);
|
||||
Point[] trianglePoints3 = { point7, point8, point9 };
|
||||
g.FillPolygon(KatkiColor, trianglePoints3);
|
||||
Point point10 = new Point(_startPosX + 57, _startPosY + 60);
|
||||
Point point11 = new Point(_startPosX + 62, _startPosY + 70);
|
||||
Point point12 = new Point(_startPosX + 52, _startPosY + 70);
|
||||
Point[] trianglePoints4 = { point10, point11, point12 };
|
||||
g.FillPolygon(KatkiColor, trianglePoints4);
|
||||
Point point13 = new Point(_startPosX + 72, _startPosY + 60);
|
||||
Point point14 = new Point(_startPosX + 77, _startPosY + 70);
|
||||
Point point15 = new Point(_startPosX + 67, _startPosY + 70);
|
||||
Point[] trianglePoints5 = { point13, point14, point15 };
|
||||
g.FillPolygon(KatkiColor, trianglePoints5);
|
||||
Point point16 = new Point(_startPosX + 87, _startPosY + 60);
|
||||
Point point17 = new Point(_startPosX + 92, _startPosY + 70);
|
||||
Point point18 = new Point(_startPosX + 82, _startPosY + 70);
|
||||
Point[] trianglePoints6 = { point16, point17, point18 };
|
||||
g.FillPolygon(KatkiColor, trianglePoints6);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
245
ProjectExcavator/ProjectExcavator/DrawingExcavator.cs
Normal file
245
ProjectExcavator/ProjectExcavator/DrawingExcavator.cs
Normal file
@ -0,0 +1,245 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectExcavator.Entities;
|
||||
using ProjectExcavator.MovementStrategy;
|
||||
using ProjectExcavator;
|
||||
|
||||
namespace ProjectExcavator.DrawingObjects
|
||||
{
|
||||
public class DrawingExcavator
|
||||
{
|
||||
public IMoveableObject GetMoveableObject => new DrawingObjectExcavator(this);
|
||||
private IDrawingKatki? DrawingKatki;
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityExcavator? EntityExcavator { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int _pictureHeight;
|
||||
/// <summary>
|
||||
/// /// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected int _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected int _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected readonly int _exWidth = 138;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected readonly int _exHeight = 80;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
||||
public DrawingExcavator(int speed, double weight, Color bodyColor, int width, int height, int numKatki, int numchoose)
|
||||
{
|
||||
// TODO: Продумать проверки
|
||||
if (width > _exWidth || height > _exHeight)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityExcavator = new EntityExcavator(speed, weight, bodyColor);
|
||||
int choose = numchoose % 3;
|
||||
switch (choose)
|
||||
{
|
||||
case 0:
|
||||
DrawingKatki = new DrawKatkiSquare();
|
||||
break;
|
||||
case 1:
|
||||
DrawingKatki = new DrawKatkiTriangle();
|
||||
break;
|
||||
case 2:
|
||||
DrawingKatki = new DrawKatkiCircle();
|
||||
break;
|
||||
}
|
||||
DrawingKatki.Properties = numKatki;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
/// <param name="exWidth">Ширина прорисовки автомобиля</param>
|
||||
/// <param name="exHeight">Высота прорисовки автомобиля</param>
|
||||
protected DrawingExcavator(int speed, double weight, Color bodyColor, int
|
||||
width, int height, int exWidth, int exHeight, int numKatki)
|
||||
{
|
||||
// TODO: Продумать проверки
|
||||
if (width > _exWidth || height > _exHeight)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_exWidth = exWidth;
|
||||
_exHeight = exHeight;
|
||||
EntityExcavator = new EntityExcavator(speed, weight, bodyColor);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
// TODO: Изменение x, y
|
||||
if (x < 0)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
else if (x > _pictureWidth - _exWidth)
|
||||
{
|
||||
x = _pictureWidth - _exWidth;
|
||||
}
|
||||
|
||||
if (y < 0)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
else if (y > _pictureHeight - _exHeight)
|
||||
{
|
||||
y = _pictureHeight - _exHeight;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int GetPosX => _startPosX;
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int GetPosY => _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _exWidth;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _exHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Проверка, что объект может переместится по указанному направлению
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - можно переместится по указанному направлению</returns>
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityExcavator == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
//влево
|
||||
DirectionType.Left => _startPosX - EntityExcavator.Step > 0,
|
||||
//вверх
|
||||
DirectionType.Up => _startPosY - EntityExcavator.Step > 0,
|
||||
// вправо
|
||||
DirectionType.Right => _startPosX + _exWidth + EntityExcavator.Step <= _pictureWidth,
|
||||
//влево
|
||||
DirectionType.Down => _startPosY + _exHeight + EntityExcavator.Step <= _pictureHeight,
|
||||
};
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (!CanMove(direction) || EntityExcavator == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
_startPosX -= (int)EntityExcavator.Step;
|
||||
break;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
_startPosY -= (int)EntityExcavator.Step;
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
_startPosX += (int)EntityExcavator.Step;
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
_startPosY += (int)EntityExcavator.Step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityExcavator == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//цвета
|
||||
Pen pen = new(Color.Black);
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
Brush brYellow = new SolidBrush(Color.Yellow);
|
||||
Brush brGray = new SolidBrush(Color.Gray);
|
||||
|
||||
//экскаватор
|
||||
g.DrawRectangle(pen, _startPosX + 50, _startPosY + 35, 75, 25);
|
||||
g.DrawRectangle(pen, _startPosX + 95, _startPosY + 10, 30, 25);
|
||||
g.DrawRectangle(pen, _startPosX + 60, _startPosY + 15, 10, 20);
|
||||
g.DrawRectangle(pen, _startPosX + 44, _startPosY + 65, 86, 20);
|
||||
g.DrawPie(pen, _startPosX + 34, _startPosY + 65, 20, 20, 90, 180);
|
||||
g.DrawPie(pen, _startPosX + 120, _startPosY + 65, 20, 20, 270, 180);
|
||||
g.DrawEllipse(pen, _startPosX + 40, _startPosY + 68, 15, 15);
|
||||
g.DrawEllipse(pen, _startPosX + 120, _startPosY + 68, 15, 15);
|
||||
g.DrawEllipse(pen, _startPosX + 60, _startPosY + 76, 8, 8);
|
||||
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 76, 8, 8);
|
||||
g.DrawEllipse(pen, _startPosX + 100, _startPosY + 76, 8, 8);
|
||||
g.DrawEllipse(pen, _startPosX + 72, _startPosY + 68, 6, 6);
|
||||
g.DrawEllipse(pen, _startPosX + 92, _startPosY + 68, 6, 6);
|
||||
//кабина водителя
|
||||
g.FillRectangle(brBlue, _startPosX + 96, _startPosY + 11, 29, 24);
|
||||
// кузов
|
||||
g.FillRectangle(brYellow, _startPosX + 51, _startPosY + 36, 74, 24);
|
||||
// труба
|
||||
g.FillRectangle(brYellow, _startPosX + 61, _startPosY + 16, 9, 19);
|
||||
//гусеница
|
||||
g.FillPie(brGray, _startPosX + 34, _startPosY + 65, 20, 20, 90, 180);
|
||||
g.FillPie(brGray, _startPosX + 120, _startPosY + 65, 20, 20, 270, 180);
|
||||
g.FillRectangle(brGray, _startPosX + 44, _startPosY + 65, 86, 20);
|
||||
//катки орнамент(4,5,6)
|
||||
DrawingKatki.Draw(_startPosX + 35, _startPosY + 10, EntityExcavator.BodyColor, g);
|
||||
}
|
||||
}
|
||||
}
|
93
ProjectExcavator/ProjectExcavator/DrawingExcavatorKovsh.cs
Normal file
93
ProjectExcavator/ProjectExcavator/DrawingExcavatorKovsh.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectExcavator.Entities;
|
||||
using ProjectExcavator;
|
||||
|
||||
namespace ProjectExcavator.DrawingObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawingExcavatorKovsh : DrawingExcavator
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="kovsh">Признак наличия ковша</param>
|
||||
/// <param name="katki">Признак наличия катков</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public DrawingExcavatorKovsh(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool kovsh, bool katki, int width, int height, int numKatki, int numchoose) : base(speed, weight, bodyColor, width, height, numKatki, numchoose)
|
||||
{
|
||||
if (EntityExcavator != null)
|
||||
{
|
||||
EntityExcavator = new EntityExcavatorKovsh(speed, weight, bodyColor,
|
||||
additionalColor, kovsh, katki);
|
||||
}
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityExcavator is not EntityExcavatorKovsh excavatorKovsh)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//цвета
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(excavatorKovsh.AdditionalColor);
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
|
||||
base.DrawTransport(g);
|
||||
//ковш
|
||||
g.DrawLine(pen, _startPosX + 50, _startPosY + 35, _startPosX + 10, _startPosY + 10);
|
||||
g.DrawLine(pen, _startPosX + 58, _startPosY + 35, _startPosX + 12, _startPosY + 5);
|
||||
g.DrawEllipse(pen, _startPosX + 7, _startPosY + 4, 7, 7);
|
||||
g.DrawLine(pen, _startPosX + 10, _startPosY + 10, _startPosX + 10, _startPosY + 45);
|
||||
g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY + 45);
|
||||
g.DrawPie(pen, _startPosX, _startPosY + 44, 28, 30, 90, 180);
|
||||
g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY);
|
||||
g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 7, _startPosY + 10);
|
||||
g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 12);
|
||||
g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 16);
|
||||
g.DrawLine(pen, _startPosX + 50, _startPosY + 12, _startPosX + 50, _startPosY + 29);
|
||||
|
||||
|
||||
g.FillEllipse(additionalBrush, _startPosX + 7, _startPosY + 4, 7, 7);
|
||||
g.FillPie(brBlack, _startPosX, _startPosY + 44, 28, 30, 90, 180);
|
||||
Point point1 = new Point(_startPosX + 50, _startPosY + 35);
|
||||
Point point2 = new Point(_startPosX + 10, _startPosY + 10);
|
||||
Point point3 = new Point(_startPosX + 12, _startPosY + 5);
|
||||
Point point4 = new Point(_startPosX + 58, _startPosY + 35);
|
||||
Point[] truba_1 = { point1, point2, point3, point4, point1 };
|
||||
g.FillPolygon(additionalBrush, truba_1);
|
||||
|
||||
Point point5 = new Point(_startPosX + 10, _startPosY + 10);
|
||||
Point point6 = new Point(_startPosX + 10, _startPosY + 45);
|
||||
Point point7 = new Point(_startPosX + 14, _startPosY + 45);
|
||||
Point point8 = new Point(_startPosX + 14, _startPosY + 5);
|
||||
Point[] truba_2 = { point5, point6, point7, point8, point5 };
|
||||
g.FillPolygon(additionalBrush, truba_2);
|
||||
|
||||
Point point9 = new Point(_startPosX + 14, _startPosY + 5);
|
||||
Point point10 = new Point(_startPosX + 14, _startPosY);
|
||||
Point point11 = new Point(_startPosX + 7, _startPosY + 10);
|
||||
Point[] triangle = { point9, point10, point11, point9 };
|
||||
g.FillPolygon(additionalBrush, triangle);
|
||||
|
||||
Point point12 = new Point(_startPosX + 14, _startPosY);
|
||||
Point point13 = new Point(_startPosX + 50, _startPosY + 12);
|
||||
Point point14 = new Point(_startPosX + 50, _startPosY + 16);
|
||||
Point point15 = new Point(_startPosX + 14, _startPosY);
|
||||
Point[] krepl = { point12, point13, point14, point15, point12 };
|
||||
g.FillPolygon(additionalBrush, krepl);
|
||||
}
|
||||
}
|
||||
}
|
60
ProjectExcavator/ProjectExcavator/DrawingKatki.cs
Normal file
60
ProjectExcavator/ProjectExcavator/DrawingKatki.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
public class DrawingKatki
|
||||
{
|
||||
private KatkiNumber katkiNumber;
|
||||
public int KatNum
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value <= 4 || value > 6)
|
||||
{
|
||||
katkiNumber = KatkiNumber.Four;
|
||||
}
|
||||
else if (value == 5)
|
||||
{
|
||||
katkiNumber = KatkiNumber.Five;
|
||||
}
|
||||
else if (value == 6)
|
||||
{
|
||||
katkiNumber = KatkiNumber.Six;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void DrawKatki(Graphics g, int _startPosX, int _startPosY, Color katkiColor)
|
||||
{
|
||||
Brush katColors = new SolidBrush(katkiColor);
|
||||
switch (katkiNumber)
|
||||
{
|
||||
case KatkiNumber.Four:
|
||||
g.FillEllipse(katColors, _startPosX + 5, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(katColors, _startPosX + 30, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(katColors, _startPosX + 60, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(katColors, _startPosX + 85, _startPosY + 58, 15, 15);
|
||||
break;
|
||||
case KatkiNumber.Five:
|
||||
g.FillEllipse(katColors, _startPosX + 5, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(katColors, _startPosX + 25, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(katColors, _startPosX + 45, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(katColors, _startPosX + 65, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(katColors, _startPosX + 85, _startPosY + 58, 15, 15);
|
||||
break;
|
||||
case KatkiNumber.Six:
|
||||
g.FillEllipse(katColors, _startPosX + 5, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(katColors, _startPosX + 20, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(katColors, _startPosX + 35, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(katColors, _startPosX + 50, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(katColors, _startPosX + 65, _startPosY + 58, 15, 15);
|
||||
g.FillEllipse(katColors, _startPosX + 80, _startPosY + 58, 15, 15);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
39
ProjectExcavator/ProjectExcavator/DrawingObjectExcavator.cs
Normal file
39
ProjectExcavator/ProjectExcavator/DrawingObjectExcavator.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectExcavator.DrawingObjects;
|
||||
|
||||
namespace ProjectExcavator.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar (паттерн Adapter)
|
||||
/// </summary>
|
||||
public class DrawingObjectExcavator : IMoveableObject
|
||||
{
|
||||
public DrawingExcavator _drawingExcavator { get; private set; }
|
||||
public DrawingObjectExcavator(DrawingExcavator drawingExcavator)
|
||||
{
|
||||
_drawingExcavator = drawingExcavator;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawingExcavator == null || _drawingExcavator.EntityExcavator ==
|
||||
null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawingExcavator.GetPosX,
|
||||
_drawingExcavator.GetPosY, _drawingExcavator.GetWidth, _drawingExcavator.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawingExcavator?.EntityExcavator?.Step ?? 0);
|
||||
public bool CheckCanMove(DirectionType direction) =>
|
||||
_drawingExcavator?.CanMove(direction) ?? false;
|
||||
public void MoveObject(DirectionType direction) =>
|
||||
_drawingExcavator?.MoveTransport(direction);
|
||||
}
|
||||
}
|
41
ProjectExcavator/ProjectExcavator/EntityExcavator.cs
Normal file
41
ProjectExcavator/ProjectExcavator/EntityExcavator.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator.Entities
|
||||
{
|
||||
public class EntityExcavator
|
||||
{
|
||||
public int numKatki;
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public EntityExcavator(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
}
|
43
ProjectExcavator/ProjectExcavator/EntityExcavatorKovsh.cs
Normal file
43
ProjectExcavator/ProjectExcavator/EntityExcavatorKovsh.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Экскаватор Ковш"
|
||||
/// </summary>
|
||||
public class EntityExcavatorKovsh : EntityExcavator
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Ковш
|
||||
/// </summary>
|
||||
public bool Kovsh { get; private set; }
|
||||
/// <summary>
|
||||
/// Катки гусеничные
|
||||
/// </summary>
|
||||
public bool Katki { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса экскаватора с ковшом
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="kovsh">Признак наличия ковша</param>
|
||||
/// <param name="katki">Признак наличия катков</param>
|
||||
public EntityExcavatorKovsh(int speed, double weight, Color bodyColor, Color additionalColor, bool kovsh, bool katki) : base(speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Kovsh = kovsh;
|
||||
Katki = katki;
|
||||
}
|
||||
}
|
||||
}
|
151
ProjectExcavator/ProjectExcavator/ExcavatorGenericCollection.cs
Normal file
151
ProjectExcavator/ProjectExcavator/ExcavatorGenericCollection.cs
Normal file
@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectExcavator.DrawingObjects;
|
||||
using ProjectExcavator.MovementStrategy;
|
||||
|
||||
namespace ProjectExcavator.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный класс для набора объектов DrawingExcavator
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
internal class ExcavatorGenericCollection<T, U>
|
||||
where T : DrawingExcavator
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 200;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetGeneric<T> _collection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
public ExcavatorGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(ExcavatorGenericCollection<T, U> collect, T?
|
||||
obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect?._collection.Insert(obj) ?? false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static T? operator -(ExcavatorGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowExcavator()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
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, j *
|
||||
_placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
// TODO получение объекта
|
||||
T? excavator = _collection[i];
|
||||
if (excavator == null)
|
||||
continue;
|
||||
int r = i / width;
|
||||
int s = width - 1 - (i % width);
|
||||
// TODO установка позиции
|
||||
excavator.SetPosition(s * _placeSizeWidth, r * _placeSizeHeight);
|
||||
// TODO прорисовка объекта
|
||||
excavator.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
83
ProjectExcavator/ProjectExcavator/ExcavatorGenericStorage.cs
Normal file
83
ProjectExcavator/ProjectExcavator/ExcavatorGenericStorage.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectExcavator.DrawingObjects;
|
||||
using ProjectExcavator.MovementStrategy;
|
||||
|
||||
namespace ProjectExcavator.Generics
|
||||
{
|
||||
internal class ExcavatorGenericStorage
|
||||
{
|
||||
readonly Dictionary<string, ExcavatorGenericCollection<DrawingExcavator, DrawingObjectExcavator>> _excavatorStorages;
|
||||
public List<string> Keys => _excavatorStorages.Keys.ToList();
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
public ExcavatorGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_excavatorStorages = new Dictionary<string, ExcavatorGenericCollection<DrawingExcavator, DrawingObjectExcavator>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
_removedObjects = new LinkedList<DrawingObjectExcavator>();
|
||||
}
|
||||
public void AddSet(string name)
|
||||
{
|
||||
if (!_excavatorStorages.ContainsKey(name))
|
||||
{
|
||||
ExcavatorGenericCollection<DrawingExcavator, DrawingObjectExcavator> newSet = new ExcavatorGenericCollection<DrawingExcavator, DrawingObjectExcavator>(_pictureWidth, _pictureHeight);
|
||||
_excavatorStorages.Add(name, newSet);
|
||||
}
|
||||
}
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (_excavatorStorages.ContainsKey(name))
|
||||
{
|
||||
_excavatorStorages.Remove(name);
|
||||
}
|
||||
}
|
||||
public ExcavatorGenericCollection<DrawingExcavator, DrawingObjectExcavator>? this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_excavatorStorages.ContainsKey(ind))
|
||||
{
|
||||
return _excavatorStorages[ind];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public DrawingObjectExcavator? this[string dictIndex, int objIndex]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_excavatorStorages.ContainsKey(dictIndex))
|
||||
{
|
||||
var selectedDictElement = _excavatorStorages[dictIndex];
|
||||
var selectedObject = selectedDictElement.GetU(objIndex);
|
||||
return selectedObject;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private LinkedList<DrawingObjectExcavator> _removedObjects;
|
||||
|
||||
public DrawingObjectExcavator RemovedObject
|
||||
{
|
||||
set
|
||||
{
|
||||
_removedObjects.AddLast(value);
|
||||
}
|
||||
get
|
||||
{
|
||||
if (_removedObjects == null || _removedObjects.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var removedObject = _removedObjects.Last();
|
||||
_removedObjects.RemoveLast();
|
||||
return removedObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
39
ProjectExcavator/ProjectExcavator/Form1.Designer.cs
generated
39
ProjectExcavator/ProjectExcavator/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
186
ProjectExcavator/ProjectExcavator/FormExcavator.Designer.cs
generated
Normal file
186
ProjectExcavator/ProjectExcavator/FormExcavator.Designer.cs
generated
Normal file
@ -0,0 +1,186 @@
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
partial class FormExcavator
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxExcavator = new PictureBox();
|
||||
buttonLeft = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonCreateExKovsh = new Button();
|
||||
buttonCreateEx = new Button();
|
||||
buttonStep = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonSelectExcavator = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxExcavator).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxExcavator
|
||||
//
|
||||
pictureBoxExcavator.Dock = DockStyle.Fill;
|
||||
pictureBoxExcavator.Location = new Point(0, 0);
|
||||
pictureBoxExcavator.Name = "pictureBoxExcavator";
|
||||
pictureBoxExcavator.Size = new Size(884, 461);
|
||||
pictureBoxExcavator.TabIndex = 0;
|
||||
pictureBoxExcavator.TabStop = false;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.влево;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Location = new Point(762, 404);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(30, 30);
|
||||
buttonLeft.TabIndex = 2;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = Properties.Resources.право;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Location = new Point(842, 404);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(30, 30);
|
||||
buttonRight.TabIndex = 3;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = Properties.Resources.up;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(803, 368);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(30, 30);
|
||||
buttonUp.TabIndex = 4;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = Properties.Resources.down;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(803, 404);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(30, 30);
|
||||
buttonDown.TabIndex = 5;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonCreateExKovsh
|
||||
//
|
||||
buttonCreateExKovsh.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateExKovsh.Location = new Point(12, 426);
|
||||
buttonCreateExKovsh.Name = "buttonCreateExKovsh";
|
||||
buttonCreateExKovsh.Size = new Size(180, 23);
|
||||
buttonCreateExKovsh.TabIndex = 6;
|
||||
buttonCreateExKovsh.Text = "Создать экскаватор с ковшом";
|
||||
buttonCreateExKovsh.UseVisualStyleBackColor = true;
|
||||
buttonCreateExKovsh.Click += buttonCreateExKovsh_Click;
|
||||
//
|
||||
// buttonCreateEx
|
||||
//
|
||||
buttonCreateEx.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateEx.Location = new Point(198, 426);
|
||||
buttonCreateEx.Name = "buttonCreateEx";
|
||||
buttonCreateEx.Size = new Size(133, 23);
|
||||
buttonCreateEx.TabIndex = 7;
|
||||
buttonCreateEx.Text = "Создать";
|
||||
buttonCreateEx.UseVisualStyleBackColor = true;
|
||||
buttonCreateEx.Click += buttonCreateEx_Click;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
buttonStep.Location = new Point(797, 41);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(75, 23);
|
||||
buttonStep.TabIndex = 8;
|
||||
buttonStep.Text = "Шаг";
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += buttonStep_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "0", "1" });
|
||||
comboBoxStrategy.Location = new Point(751, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(121, 23);
|
||||
comboBoxStrategy.TabIndex = 9;
|
||||
//
|
||||
// buttonSelectExcavator
|
||||
//
|
||||
buttonSelectExcavator.Location = new Point(370, 426);
|
||||
buttonSelectExcavator.Name = "buttonSelectExcavator";
|
||||
buttonSelectExcavator.Size = new Size(105, 23);
|
||||
buttonSelectExcavator.TabIndex = 10;
|
||||
buttonSelectExcavator.Text = "Выбрать обьект";
|
||||
buttonSelectExcavator.UseVisualStyleBackColor = true;
|
||||
buttonSelectExcavator.Click += ButtonSelectExcavator_Click;
|
||||
//
|
||||
// FormExcavator
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(884, 461);
|
||||
Controls.Add(buttonSelectExcavator);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(buttonCreateEx);
|
||||
Controls.Add(buttonCreateExKovsh);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(pictureBoxExcavator);
|
||||
Name = "FormExcavator";
|
||||
Text = "FormExcavator";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxExcavator).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxExcavator;
|
||||
private Button buttonLeft;
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateExKovsh;
|
||||
private Button buttonCreateEx;
|
||||
private Button buttonStep;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonSelectExcavator;
|
||||
}
|
||||
}
|
127
ProjectExcavator/ProjectExcavator/FormExcavator.cs
Normal file
127
ProjectExcavator/ProjectExcavator/FormExcavator.cs
Normal file
@ -0,0 +1,127 @@
|
||||
using ProjectExcavator.DrawingObjects;
|
||||
using ProjectExcavator.MovementStrategy;
|
||||
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
public partial class FormExcavator : Form
|
||||
{
|
||||
|
||||
private DrawingExcavator? _drawingExcavator;
|
||||
/// <summary>
|
||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawingExcavator? SelectedExcavator { get; private set; }
|
||||
public FormExcavator()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public FormExcavator(DrawingExcavator drawingObject)
|
||||
{
|
||||
_drawingExcavator = drawingObject;
|
||||
InitializeComponent();
|
||||
}
|
||||
public void Draw()
|
||||
{
|
||||
if (_drawingExcavator == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxExcavator.Width, pictureBoxExcavator.Height);
|
||||
Graphics g = Graphics.FromImage(bmp);
|
||||
_drawingExcavator.DrawTransport(g);
|
||||
pictureBoxExcavator.Image = bmp;
|
||||
}
|
||||
private void buttonCreateExKovsh_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingExcavator = new DrawingExcavatorKovsh(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxExcavator.Width, pictureBoxExcavator.Height, random.Next(1, 4), random.Next(1, 4));
|
||||
_drawingExcavator.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void buttonCreateEx_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingExcavator = new DrawingExcavator(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
pictureBoxExcavator.Width, pictureBoxExcavator.Height, random.Next(1, 4), random.Next(1, 4));
|
||||
_drawingExcavator.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingExcavator == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawingExcavator.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawingExcavator.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawingExcavator.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawingExcavator.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingExcavator == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
DrawingObjectExcavator(_drawingExcavator), pictureBoxExcavator.Width,
|
||||
pictureBoxExcavator.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
private void ButtonSelectExcavator_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedExcavator = _drawingExcavator;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
60
ProjectExcavator/ProjectExcavator/FormExcavator.resx
Normal file
60
ProjectExcavator/ProjectExcavator/FormExcavator.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
211
ProjectExcavator/ProjectExcavator/FormExcavatorCollection.Designer.cs
generated
Normal file
211
ProjectExcavator/ProjectExcavator/FormExcavatorCollection.Designer.cs
generated
Normal file
@ -0,0 +1,211 @@
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
partial class FormExcavatorCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonAddEx = new System.Windows.Forms.Button();
|
||||
this.buttonRemoveEx = new System.Windows.Forms.Button();
|
||||
this.buttonRefreshCollection = new System.Windows.Forms.Button();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.textBoxStorageName = new System.Windows.Forms.TextBox();
|
||||
this.buttonDelObject = new System.Windows.Forms.Button();
|
||||
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||
this.buttonAddObject = new System.Windows.Forms.Button();
|
||||
this.buttonGeneration = new System.Windows.Forms.Button();
|
||||
this.buttonRemoveobj = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(909, 461);
|
||||
this.pictureBoxCollection.TabIndex = 0;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(35, 339);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(100, 23);
|
||||
this.maskedTextBoxNumber.TabIndex = 1;
|
||||
//
|
||||
// buttonAddEx
|
||||
//
|
||||
this.buttonAddEx.Location = new System.Drawing.Point(13, 310);
|
||||
this.buttonAddEx.Name = "buttonAddEx";
|
||||
this.buttonAddEx.Size = new System.Drawing.Size(150, 23);
|
||||
this.buttonAddEx.TabIndex = 2;
|
||||
this.buttonAddEx.Text = "Добавить экскаватор";
|
||||
this.buttonAddEx.UseVisualStyleBackColor = true;
|
||||
this.buttonAddEx.Click += new System.EventHandler(this.ButtonAddEx_Click);
|
||||
//
|
||||
// buttonRemoveEx
|
||||
//
|
||||
this.buttonRemoveEx.Location = new System.Drawing.Point(13, 368);
|
||||
this.buttonRemoveEx.Name = "buttonRemoveEx";
|
||||
this.buttonRemoveEx.Size = new System.Drawing.Size(150, 23);
|
||||
this.buttonRemoveEx.TabIndex = 3;
|
||||
this.buttonRemoveEx.Text = "Удалить экскаватор";
|
||||
this.buttonRemoveEx.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveEx.Click += new System.EventHandler(this.ButtonRemoveEx_Click);
|
||||
//
|
||||
// buttonRefreshCollection
|
||||
//
|
||||
this.buttonRefreshCollection.Location = new System.Drawing.Point(13, 432);
|
||||
this.buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||
this.buttonRefreshCollection.Size = new System.Drawing.Size(148, 23);
|
||||
this.buttonRefreshCollection.TabIndex = 4;
|
||||
this.buttonRefreshCollection.Text = "Обновить коллекцию";
|
||||
this.buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
this.buttonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.buttonRemoveobj);
|
||||
this.groupBox1.Controls.Add(this.groupBox2);
|
||||
this.groupBox1.Controls.Add(this.buttonAddEx);
|
||||
this.groupBox1.Controls.Add(this.buttonRefreshCollection);
|
||||
this.groupBox1.Controls.Add(this.maskedTextBoxNumber);
|
||||
this.groupBox1.Controls.Add(this.buttonRemoveEx);
|
||||
this.groupBox1.Location = new System.Drawing.Point(741, 0);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(168, 461);
|
||||
this.groupBox1.TabIndex = 5;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
this.groupBox2.Controls.Add(this.textBoxStorageName);
|
||||
this.groupBox2.Controls.Add(this.buttonDelObject);
|
||||
this.groupBox2.Controls.Add(this.listBoxStorages);
|
||||
this.groupBox2.Controls.Add(this.buttonAddObject);
|
||||
this.groupBox2.Location = new System.Drawing.Point(13, 28);
|
||||
this.groupBox2.Name = "groupBox2";
|
||||
this.groupBox2.Size = new System.Drawing.Size(143, 214);
|
||||
this.groupBox2.TabIndex = 5;
|
||||
this.groupBox2.TabStop = false;
|
||||
this.groupBox2.Text = "Наборы";
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
this.textBoxStorageName.Location = new System.Drawing.Point(15, 30);
|
||||
this.textBoxStorageName.Name = "textBoxStorageName";
|
||||
this.textBoxStorageName.Size = new System.Drawing.Size(122, 23);
|
||||
this.textBoxStorageName.TabIndex = 6;
|
||||
//
|
||||
// buttonDelObject
|
||||
//
|
||||
this.buttonDelObject.Location = new System.Drawing.Point(15, 185);
|
||||
this.buttonDelObject.Name = "buttonDelObject";
|
||||
this.buttonDelObject.Size = new System.Drawing.Size(122, 23);
|
||||
this.buttonDelObject.TabIndex = 8;
|
||||
this.buttonDelObject.Text = "Удалить набор";
|
||||
this.buttonDelObject.UseVisualStyleBackColor = true;
|
||||
this.buttonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
this.listBoxStorages.FormattingEnabled = true;
|
||||
this.listBoxStorages.ItemHeight = 15;
|
||||
this.listBoxStorages.Location = new System.Drawing.Point(15, 88);
|
||||
this.listBoxStorages.Name = "listBoxStorages";
|
||||
this.listBoxStorages.Size = new System.Drawing.Size(122, 79);
|
||||
this.listBoxStorages.TabIndex = 6;
|
||||
this.listBoxStorages.Click += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged);
|
||||
//
|
||||
// buttonAddObject
|
||||
//
|
||||
this.buttonAddObject.Location = new System.Drawing.Point(15, 59);
|
||||
this.buttonAddObject.Name = "buttonAddObject";
|
||||
this.buttonAddObject.Size = new System.Drawing.Size(122, 23);
|
||||
this.buttonAddObject.TabIndex = 7;
|
||||
this.buttonAddObject.Text = "Добавить набор";
|
||||
this.buttonAddObject.UseVisualStyleBackColor = true;
|
||||
this.buttonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
|
||||
//
|
||||
// buttonGeneration
|
||||
//
|
||||
this.buttonGeneration.Location = new System.Drawing.Point(6, 332);
|
||||
this.buttonGeneration.Name = "buttonGeneration";
|
||||
this.buttonGeneration.Size = new System.Drawing.Size(150, 23);
|
||||
this.buttonGeneration.TabIndex = 5;
|
||||
this.buttonGeneration.Text = "Форма генерации";
|
||||
this.buttonGeneration.UseVisualStyleBackColor = true;
|
||||
this.buttonGeneration.Click += new System.EventHandler(this.buttonGeneration_Click);
|
||||
//
|
||||
// buttonRemoveobj
|
||||
//
|
||||
this.buttonRemoveobj.Location = new System.Drawing.Point(16, 265);
|
||||
this.buttonRemoveobj.Name = "buttonRemoveobj";
|
||||
this.buttonRemoveobj.Size = new System.Drawing.Size(145, 23);
|
||||
this.buttonRemoveobj.TabIndex = 6;
|
||||
this.buttonRemoveobj.Text = "Удалённые обьекты";
|
||||
this.buttonRemoveobj.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveobj.Click += new System.EventHandler(this.buttonRemoveobj_Click);
|
||||
//
|
||||
// FormExcavatorCollection
|
||||
//
|
||||
this.ClientSize = new System.Drawing.Size(909, 461);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.Name = "FormExcavatorCollection";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.groupBox2.ResumeLayout(false);
|
||||
this.groupBox2.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxCollection;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private Button buttonAddEx;
|
||||
private Button buttonRemoveEx;
|
||||
private Button buttonRefreshCollection;
|
||||
private GroupBox groupBox1;
|
||||
private GroupBox groupBox2;
|
||||
private TextBox textBoxStorageName;
|
||||
private Button buttonDelObject;
|
||||
private ListBox listBoxStorages;
|
||||
private Button buttonAddObject;
|
||||
private Button buttonGeneration;
|
||||
private Button buttonRemoveobj;
|
||||
}
|
||||
}
|
220
ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs
Normal file
220
ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs
Normal file
@ -0,0 +1,220 @@
|
||||
using ProjectExcavator.DrawingObjects;
|
||||
using ProjectExcavator.Generics;
|
||||
using ProjectExcavator.MovementStrategy;
|
||||
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
/// <summary>
|
||||
/// Форма для работы с набором объектов класса DrawningExcavator
|
||||
/// </summary>
|
||||
public partial class FormExcavatorCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly ExcavatorGenericStorage _storage;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormExcavatorCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new ExcavatorGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Заполнение listBoxObjects
|
||||
/// </summary>
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxStorages.SelectedIndex;
|
||||
listBoxStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
|
||||
>= listBoxStorages.Items.Count))
|
||||
{
|
||||
listBoxStorages.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
|
||||
index < listBoxStorages.Items.Count)
|
||||
{
|
||||
listBoxStorages.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowExcavator();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ListBoxObjects_SelectedIndexChanged(object sender,
|
||||
EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image =
|
||||
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowExcavator();
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
|
||||
?? string.Empty);
|
||||
ReloadObjects();
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
MessageBox.Show("Набор удален");
|
||||
pictureBoxCollection.Image = obj.ShowExcavator();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddEx_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormExcavator form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (obj + form.SelectedExcavator)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowExcavator();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveEx_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
var removableObject = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty, pos];
|
||||
if (_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
_storage.RemovedObject = (DrawingObjectExcavator)removableObject;
|
||||
pictureBoxCollection.Image = obj.ShowExcavator();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обновление рисунка по набору
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowExcavator();
|
||||
}
|
||||
|
||||
private void buttonGeneration_Click(object sender, EventArgs e)
|
||||
{
|
||||
RandGeneration form = new();
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private void buttonRemoveobj_Click(object sender, EventArgs e)
|
||||
{
|
||||
DrawingObjectExcavator removedObject = _storage.RemovedObject;
|
||||
if (removedObject == null)
|
||||
{
|
||||
MessageBox.Show("Не удалось показать удаленные объекты");
|
||||
return;
|
||||
}
|
||||
FormExcavator formRemovedObject = new FormExcavator(removedObject._drawingExcavator);
|
||||
formRemovedObject.Show();
|
||||
formRemovedObject.Draw();
|
||||
}
|
||||
}
|
||||
}
|
16
ProjectExcavator/ProjectExcavator/IDrawingKatki.cs
Normal file
16
ProjectExcavator/ProjectExcavator/IDrawingKatki.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
public interface IDrawingKatki
|
||||
{
|
||||
int Properties { get; set; }
|
||||
void Draw(int _startPosX, int _startPosY, Color katkiColor, Graphics g);
|
||||
public int GetAmount();
|
||||
public int GetShape();
|
||||
}
|
||||
}
|
34
ProjectExcavator/ProjectExcavator/IMoveableObject.cs
Normal file
34
ProjectExcavator/ProjectExcavator/IMoveableObject.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с перемещаемым объектом
|
||||
/// </summary>
|
||||
public interface IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты X объекта
|
||||
/// </summary>
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
/// <summary>
|
||||
/// Проверка, можно ли переместиться по нужному направлению
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
bool CheckCanMove(DirectionType direction);
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
void MoveObject(DirectionType direction);
|
||||
}
|
||||
}
|
24
ProjectExcavator/ProjectExcavator/KatkiNumber.cs
Normal file
24
ProjectExcavator/ProjectExcavator/KatkiNumber.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
public enum KatkiNumber
|
||||
{
|
||||
/// <summary>
|
||||
/// 4
|
||||
/// </summary>
|
||||
Four,
|
||||
/// <summary>
|
||||
/// 5
|
||||
/// </summary>
|
||||
Five,
|
||||
/// <summary>
|
||||
/// 6
|
||||
/// </summary>
|
||||
Six
|
||||
}
|
||||
}
|
60
ProjectExcavator/ProjectExcavator/MoveToBorder.cs
Normal file
60
ProjectExcavator/ProjectExcavator/MoveToBorder.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Стратегия перемещения объекта в правый нижний угол экрана
|
||||
/// </summary>
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectBorderRight <= FieldWidth &&
|
||||
objParams.ObjectBorderRight + GetStep() >= FieldWidth &&
|
||||
objParams.ObjectBorderDown <= FieldHeight &&
|
||||
objParams.ObjectBorderDown + GetStep() >= FieldHeight;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.ObjectBorderRight - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
|
||||
}
|
||||
var diffY = objParams.ObjectBorderDown - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
59
ProjectExcavator/ProjectExcavator/MoveToCenter.cs
Normal file
59
ProjectExcavator/ProjectExcavator/MoveToCenter.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Стратегия перемещения объекта в центр экрана
|
||||
/// </summary>
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
ProjectExcavator/ProjectExcavator/ObjectParameters.cs
Normal file
56
ProjectExcavator/ProjectExcavator/ObjectParameters.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator.MovementStrategy
|
||||
{
|
||||
public class ObjectParameters
|
||||
{
|
||||
private readonly int _x;
|
||||
private readonly int _y;
|
||||
private readonly int _width;
|
||||
private readonly int _height;
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
public int LeftBorder => _x;
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
public int TopBorder => _y;
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
public int RightBorder => _x + _width;
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
public int DownBorder => _y + _height;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
public int ObjectBorderRight => _x + _width;
|
||||
public int ObjectBorderDown => _y + _height;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
}
|
79
ProjectExcavator/ProjectExcavator/ParamGenericObject.cs
Normal file
79
ProjectExcavator/ProjectExcavator/ParamGenericObject.cs
Normal file
@ -0,0 +1,79 @@
|
||||
using ProjectExcavator;
|
||||
using ProjectExcavator.DrawingObjects;
|
||||
using ProjectExcavator.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
public class ParamGenericObject<T, U>
|
||||
where T : EntityExcavator
|
||||
where U : IDrawingKatki
|
||||
{
|
||||
private T[] _excavators;
|
||||
private U[] _katki;
|
||||
|
||||
private int CountExcavators = 0;
|
||||
private int CountKatki = 0;
|
||||
private readonly Random random;
|
||||
private readonly int Width;
|
||||
private readonly int Height;
|
||||
|
||||
public ParamGenericObject(int count, int width, int height)
|
||||
{
|
||||
_excavators = new T[count];
|
||||
_katki = new U[count];
|
||||
random = new Random();
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool Add(T excavator)
|
||||
{
|
||||
for (int i = 0; i < _excavators.Length; i++)
|
||||
{
|
||||
if (_excavators[i] == null)
|
||||
{
|
||||
_excavators[i] = excavator;
|
||||
CountExcavators++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Add(U katki)
|
||||
{
|
||||
for (int i = 0; i < _excavators.Length; i++)
|
||||
{
|
||||
if (_katki[i] == null)
|
||||
{
|
||||
_katki[i] = katki;
|
||||
CountKatki++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public DrawingExcavator CreateDrawObject()
|
||||
{
|
||||
Random rand = new Random();
|
||||
EntityExcavator excavator = _excavators[rand.Next(0, CountExcavators)];
|
||||
IDrawingKatki katki = _katki[rand.Next(0, CountKatki)];
|
||||
if (excavator is EntityExcavatorKovsh kovshExcavator)
|
||||
{
|
||||
return new DrawingExcavatorKovsh(excavator.Speed, excavator.Weight, excavator.BodyColor, kovshExcavator.AdditionalColor, kovshExcavator.Kovsh, kovshExcavator.Katki,
|
||||
Width, Height, katki.GetAmount(), katki.GetShape());
|
||||
}
|
||||
|
||||
return new DrawingExcavator(excavator.Speed, excavator.Weight, excavator.BodyColor, Width, Height, katki.GetAmount(), katki.GetShape());
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace ProjectExcavator
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
Application.Run(new FormExcavatorCollection());
|
||||
}
|
||||
}
|
||||
}
|
@ -8,4 +8,19 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
103
ProjectExcavator/ProjectExcavator/Properties/Resources.Designer.cs
generated
Normal file
103
ProjectExcavator/ProjectExcavator/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,103 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ProjectExcavator.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||
/// </summary>
|
||||
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||
// с помощью такого средства, как ResGen или Visual Studio.
|
||||
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||
// с параметром /str или перестройте свой проект VS.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectExcavator.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap down {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("down", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap up {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("up", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap влево {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("влево", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap право {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("право", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
133
ProjectExcavator/ProjectExcavator/Properties/Resources.resx
Normal file
133
ProjectExcavator/ProjectExcavator/Properties/Resources.resx
Normal file
@ -0,0 +1,133 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="down" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\down.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="влево" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\влево.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="право" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\право.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="up" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\up.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
74
ProjectExcavator/ProjectExcavator/RandGeneration.Designer.cs
generated
Normal file
74
ProjectExcavator/ProjectExcavator/RandGeneration.Designer.cs
generated
Normal file
@ -0,0 +1,74 @@
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
partial class RandGeneration
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.buttonGen = new System.Windows.Forms.Button();
|
||||
this.pictureBoxGen = new System.Windows.Forms.PictureBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxGen)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// buttonGen
|
||||
//
|
||||
this.buttonGen.Location = new System.Drawing.Point(12, 415);
|
||||
this.buttonGen.Name = "buttonGen";
|
||||
this.buttonGen.Size = new System.Drawing.Size(166, 23);
|
||||
this.buttonGen.TabIndex = 0;
|
||||
this.buttonGen.Text = "Сгенерировать";
|
||||
this.buttonGen.UseVisualStyleBackColor = true;
|
||||
this.buttonGen.Click += new System.EventHandler(this.buttonGen_Click);
|
||||
//
|
||||
// pictureBoxGen
|
||||
//
|
||||
this.pictureBoxGen.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxGen.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxGen.Name = "pictureBoxGen";
|
||||
this.pictureBoxGen.Size = new System.Drawing.Size(800, 450);
|
||||
this.pictureBoxGen.TabIndex = 1;
|
||||
this.pictureBoxGen.TabStop = false;
|
||||
//
|
||||
// RandGeneration
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.buttonGen);
|
||||
this.Controls.Add(this.pictureBoxGen);
|
||||
this.Name = "RandGeneration";
|
||||
this.Text = "RandGeneration";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxGen)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonGen;
|
||||
private PictureBox pictureBoxGen;
|
||||
}
|
||||
}
|
88
ProjectExcavator/ProjectExcavator/RandGeneration.cs
Normal file
88
ProjectExcavator/ProjectExcavator/RandGeneration.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using ProjectExcavator.DrawingObjects;
|
||||
using ProjectExcavator.Entities;
|
||||
using ProjectExcavator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
public partial class RandGeneration : Form
|
||||
{
|
||||
private DrawingExcavator _drawingExcavator;
|
||||
private ParamGenericObject<EntityExcavator, IDrawingKatki> objGeneric;
|
||||
private readonly int _pictureWidth = 250;
|
||||
private readonly int _pictureHeight = 185;
|
||||
Random random = new Random();
|
||||
public RandGeneration()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingExcavator == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxGen.Width, pictureBoxGen.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawingExcavator.DrawTransport(gr);
|
||||
pictureBoxGen.Image = bmp;
|
||||
}
|
||||
private void buttonGen_Click(object sender, EventArgs e)
|
||||
{
|
||||
int size = random.Next(1, 10);
|
||||
objGeneric = new ParamGenericObject<EntityExcavator, IDrawingKatki>(size, _pictureWidth, _pictureHeight);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
EntityExcavator excavator = CreateRandomExcavator();
|
||||
IDrawingKatki katki = CreateRandomKatki();
|
||||
objGeneric.Add(excavator);
|
||||
objGeneric.Add(katki);
|
||||
_drawingExcavator = objGeneric.CreateDrawObject();
|
||||
_drawingExcavator.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
public EntityExcavator CreateRandomExcavator()
|
||||
{
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
EntityExcavator excavator;
|
||||
switch (random.Next(0, 2))
|
||||
{
|
||||
case 1:
|
||||
excavator = new EntityExcavatorKovsh(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(2)), Convert.ToBoolean(random.Next(2)));
|
||||
break;
|
||||
default:
|
||||
excavator = new EntityExcavator(random.Next(100, 300), random.Next(1000, 3000), color);
|
||||
break;
|
||||
}
|
||||
return excavator;
|
||||
}
|
||||
public IDrawingKatki CreateRandomKatki()
|
||||
{
|
||||
IDrawingKatki _katki;
|
||||
switch (random.Next(3))
|
||||
{
|
||||
case 1:
|
||||
_katki = new DrawKatkiTriangle();
|
||||
break;
|
||||
case 2:
|
||||
_katki = new DrawKatkiSquare();
|
||||
break;
|
||||
default:
|
||||
_katki = new DrawKatkiCircle();
|
||||
break;
|
||||
}
|
||||
_katki.Properties = (random.Next(1, 4));
|
||||
return _katki;
|
||||
}
|
||||
}
|
||||
}
|
120
ProjectExcavator/ProjectExcavator/RandGeneration.resx
Normal file
120
ProjectExcavator/ProjectExcavator/RandGeneration.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
BIN
ProjectExcavator/ProjectExcavator/Resources/down.png
Normal file
BIN
ProjectExcavator/ProjectExcavator/Resources/down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1015 B |
BIN
ProjectExcavator/ProjectExcavator/Resources/up.png
Normal file
BIN
ProjectExcavator/ProjectExcavator/Resources/up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
BIN
ProjectExcavator/ProjectExcavator/Resources/влево.png
Normal file
BIN
ProjectExcavator/ProjectExcavator/Resources/влево.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
ProjectExcavator/ProjectExcavator/Resources/право.png
Normal file
BIN
ProjectExcavator/ProjectExcavator/Resources/право.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1015 B |
137
ProjectExcavator/ProjectExcavator/SetGeneric.cs
Normal file
137
ProjectExcavator/ProjectExcavator/SetGeneric.cs
Normal file
@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Список объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly List<T?> _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Count;
|
||||
/// <summary>
|
||||
/// Максимальное количество объектов в списке
|
||||
/// </summary>
|
||||
private readonly int _maxCount;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="excavator">Добавляемый экскаватор</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T excavator)
|
||||
{
|
||||
// TODO вставка в начало набора
|
||||
if (_places.Count >= _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_places.Insert(0, excavator);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="excavator">Добавляемый экскаватор</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T excavator, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position < 0 || position >= _places.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// TODO проверка, что есть место для вставки
|
||||
if (_places.Count >= _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// TODO вставка по позиции
|
||||
_places.Insert(position, excavator);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position > Count || _places[position] == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var result = _places[position];
|
||||
_places.RemoveAt(position);
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position < 0 || position >= _places.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position < 0 || position >= _places.Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO проверка свободных мест в списке
|
||||
if (_places.Count >= _maxCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO вставка в список по позиции
|
||||
_places.Insert(position, value);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проход по списку
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T?> GetExcavators(int? maxExcavators = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxExcavators.HasValue && i == maxExcavators.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
ProjectExcavator/ProjectExcavator/Status.cs
Normal file
13
ProjectExcavator/ProjectExcavator/Status.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator.MovementStrategy
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
NotInit, InProgress, Finish
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user