Лаба 3
This commit is contained in:
parent
ddba502b60
commit
08fc6e78cd
@ -3,13 +3,13 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Bulldozer.DrawningObjects;
|
using Bulldozer.Drawnings;
|
||||||
|
|
||||||
namespace Bulldozer.MovementStrategy
|
namespace Bulldozer.MovementStrategy
|
||||||
{
|
{
|
||||||
public abstract class AbstractStrategy
|
public abstract class AbstractStrategy
|
||||||
{
|
{
|
||||||
private IMoveableObject? _movebleObject;
|
private IMoveableObject? _moveableObject;
|
||||||
private Status _state = Status.NotInit;
|
private Status _state = Status.NotInit;
|
||||||
protected int FieldWidth { get; private set; }
|
protected int FieldWidth { get; private set; }
|
||||||
protected int FieldHeight { get; private set; }
|
protected int FieldHeight { get; private set; }
|
||||||
@ -22,7 +22,7 @@ namespace Bulldozer.MovementStrategy
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_state = Status.InProgress;
|
_state = Status.InProgress;
|
||||||
_movebleObject = moveableObject;
|
_moveableObject = moveableObject;
|
||||||
FieldWidth = width;
|
FieldWidth = width;
|
||||||
FieldHeight = height;
|
FieldHeight = height;
|
||||||
}
|
}
|
||||||
@ -43,26 +43,26 @@ namespace Bulldozer.MovementStrategy
|
|||||||
protected bool MoveRight() => MoveTo(DirectionTypeBulldozer.Right);
|
protected bool MoveRight() => MoveTo(DirectionTypeBulldozer.Right);
|
||||||
protected bool MoveUp() => MoveTo(DirectionTypeBulldozer.Up);
|
protected bool MoveUp() => MoveTo(DirectionTypeBulldozer.Up);
|
||||||
protected bool MoveDown() => MoveTo(DirectionTypeBulldozer.Down);
|
protected bool MoveDown() => MoveTo(DirectionTypeBulldozer.Down);
|
||||||
protected ObjectParameters? GetObjectParametrs => _movebleObject?.GetObjectPosition;
|
protected ObjectParameters? GetObjectParametrs => _moveableObject?.GetObjectPosition;
|
||||||
protected int? GetStep()
|
protected int? GetStep()
|
||||||
{
|
{
|
||||||
if (_state != Status.InProgress)
|
if (_state != Status.InProgress)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return _movebleObject?.GetStep;
|
return _moveableObject?.GetStep;
|
||||||
}
|
}
|
||||||
protected abstract void MoveToTarget();
|
protected abstract void MoveToTarget();
|
||||||
protected abstract bool IsTargetDestination();
|
protected abstract bool IsTargetDestination();
|
||||||
private bool MoveTo(DirectionTypeBulldozer DirectionTypeBulldozer)
|
private bool MoveTo(DirectionTypeBulldozer directionType)
|
||||||
{
|
{
|
||||||
if (_state != Status.InProgress)
|
if (_state != Status.InProgress)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (_movebleObject?.CheckCanMove(DirectionTypeBulldozer) ?? false)
|
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||||
{
|
{
|
||||||
_movebleObject.MoveObject(DirectionTypeBulldozer);
|
_moveableObject.MoveObject(directionType);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
160
Bulldozer/Bulldozer/BulldozerGenericCollection.cs
Normal file
160
Bulldozer/Bulldozer/BulldozerGenericCollection.cs
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
using Bulldozer.Drawnings;
|
||||||
|
using Bulldozer.MovementStrategy;
|
||||||
|
using Bulldozer.DrawningObjects;
|
||||||
|
|
||||||
|
namespace Bulldozer.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный класс для набора объектов DrawningBulldozer
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <typeparam name="U"></typeparam>
|
||||||
|
internal class BulldozerGenericCollection<T, U>
|
||||||
|
where T : DrawningBulldozer
|
||||||
|
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 = 110;
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
public BulldozerGenericCollection(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 int? operator +(BulldozerGenericCollection<T, U> collect, T?
|
||||||
|
obj)
|
||||||
|
{
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return collect?._collection.Insert(obj);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перегрузка оператора вычитания
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collect"></param>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool operator -(BulldozerGenericCollection<T, U> collect, int
|
||||||
|
pos)
|
||||||
|
{
|
||||||
|
T? obj = collect._collection.Get(pos);
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
return collect._collection.Remove(pos);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта IMoveableObject
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод всего набора объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap ShowBulldozer()
|
||||||
|
{
|
||||||
|
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 / 2 + 8, 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 c = 11;
|
||||||
|
int k = 3;
|
||||||
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
|
{
|
||||||
|
if (i % 3 == 0 && i != 0)
|
||||||
|
{
|
||||||
|
c = c - 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (k != 0)
|
||||||
|
{
|
||||||
|
k--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
k = 2;
|
||||||
|
}
|
||||||
|
T? obj = _collection.Get(i);
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
// Получение объекта
|
||||||
|
IMoveableObject moveableObject = obj.GetMoveableObject;
|
||||||
|
// Установка позиции
|
||||||
|
int x = k % (_pictureWidth / _placeSizeWidth) * _placeSizeWidth;
|
||||||
|
int y = c / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight + 10;
|
||||||
|
moveableObject.SetPosition(x, y);
|
||||||
|
// Прорисовка объекта
|
||||||
|
moveableObject.Draw(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,16 +4,13 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Bulldozer
|
namespace Bulldozer.Drawnings
|
||||||
{
|
{
|
||||||
public enum DirectionTypeBulldozer
|
public enum DirectionTypeBulldozer
|
||||||
{
|
{
|
||||||
Up = 1,
|
Up = 1,
|
||||||
|
|
||||||
Down = 2,
|
Down = 2,
|
||||||
|
|
||||||
Left = 3,
|
Left = 3,
|
||||||
|
Right = 4,
|
||||||
Right = 4
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,44 +4,47 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Bulldozer.Entities;
|
using Bulldozer.Entities;
|
||||||
|
using Bulldozer.Drawnings;
|
||||||
|
using Bulldozer.MovementStrategy;
|
||||||
|
|
||||||
namespace Bulldozer.DrawningObjects
|
namespace Bulldozer.DrawningObjects
|
||||||
{
|
{
|
||||||
public class DrawningBulldozer
|
public class DrawningBulldozer
|
||||||
{
|
{
|
||||||
public EntityBulldozer? EntityBulldozer { get; protected set; }
|
public EntityBulldozer? EntityTractor { get; protected set; }
|
||||||
private int _pictureWidth;
|
private int _pictureWidth;
|
||||||
private int _pictureHeight;
|
private int _pictureHeight;
|
||||||
protected int _startPosX;
|
protected int _startPosX;
|
||||||
protected int _startPosY;
|
protected int _startPosY;
|
||||||
protected readonly int _bulldozerWidth = 160;
|
protected readonly int _tractorWidth = 160;
|
||||||
protected readonly int _bulldozerHeight = 80;
|
protected readonly int _tractorHeight = 80;
|
||||||
public DrawningBulldozer(int speed, double weight, Color mainColor, int width, int heigth)
|
public DrawningBulldozer(int speed, double weight, Color mainColor, int width, int heigth)
|
||||||
{
|
{
|
||||||
if (width <= _bulldozerWidth || heigth <= _bulldozerHeight)
|
if (width <= _tractorWidth || heigth <= _tractorHeight)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = heigth;
|
_pictureHeight = heigth;
|
||||||
EntityBulldozer = new EntityBulldozer(speed, weight, mainColor);
|
EntityTractor = new EntityBulldozer(speed, weight, mainColor);
|
||||||
}
|
}
|
||||||
protected DrawningBulldozer(int speed, double weight,
|
protected DrawningBulldozer(int speed, double weight,
|
||||||
Color mainColor, int width, int heigth,
|
Color mainColor, int width, int heigth,
|
||||||
int bulldozerWidth, int bulldozerHeight)
|
int tractorWidth, int tractorHeight)
|
||||||
{
|
{
|
||||||
if (width <= _bulldozerWidth || heigth <= _bulldozerHeight)
|
if (width <= tractorWidth || heigth <= tractorHeight)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_pictureHeight = heigth;
|
_pictureHeight = heigth;
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_bulldozerHeight = bulldozerHeight;
|
_tractorHeight = tractorHeight;
|
||||||
_bulldozerWidth = bulldozerWidth;
|
_tractorWidth = tractorWidth;
|
||||||
EntityBulldozer = new EntityBulldozer(speed, weight, mainColor);
|
EntityTractor = new EntityBulldozer(speed, weight, mainColor);
|
||||||
}
|
}
|
||||||
public void SetPosition(int x, int y)
|
public void SetPosition(int x, int y)
|
||||||
{
|
{
|
||||||
if (x < 0 || y < 0 || x + _bulldozerWidth > _pictureWidth || y + _bulldozerHeight > _pictureHeight)
|
if (x < 0 || y < 0 || x + _tractorWidth > _pictureWidth || y + _tractorHeight > _pictureHeight)
|
||||||
{
|
{
|
||||||
x = 10;
|
x = 10;
|
||||||
y = 10;
|
y = 10;
|
||||||
@ -49,66 +52,65 @@ namespace Bulldozer.DrawningObjects
|
|||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
}
|
}
|
||||||
|
public IMoveableObject GetMoveableObject => new DrawningObjectBulldozer(this);
|
||||||
public int GetPosX => _startPosX;
|
public int GetPosX => _startPosX;
|
||||||
public int GetPosY => _startPosY;
|
public int GetPosY => _startPosY;
|
||||||
public int GetWidth => _bulldozerWidth;
|
public int GetWidth => _tractorWidth;
|
||||||
public int GetHeight => _bulldozerHeight;
|
public int GetHeight => _tractorHeight;
|
||||||
public bool CanMove(DirectionTypeBulldozer direction)
|
public bool CanMove(DirectionTypeBulldozer direction)
|
||||||
{
|
{
|
||||||
if (EntityBulldozer == null)
|
if (EntityTractor == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return direction switch
|
return direction switch
|
||||||
{
|
{
|
||||||
DirectionTypeBulldozer.Left => _startPosX - EntityBulldozer.Step > 0,
|
DirectionTypeBulldozer.Left => _startPosX - EntityTractor.Step > 0,
|
||||||
DirectionTypeBulldozer.Up => _startPosY - EntityBulldozer.Step > 0,
|
DirectionTypeBulldozer.Up => _startPosY - EntityTractor.Step > 0,
|
||||||
DirectionTypeBulldozer.Right => _startPosX + EntityBulldozer.Step + _bulldozerWidth <= _pictureWidth,
|
DirectionTypeBulldozer.Right => _startPosX + EntityTractor.Step + _tractorWidth <= _pictureWidth,
|
||||||
DirectionTypeBulldozer.Down => _startPosY + EntityBulldozer.Step + _bulldozerHeight <= _pictureHeight,
|
DirectionTypeBulldozer.Down => _startPosY + EntityTractor.Step + _tractorHeight <= _pictureHeight,
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public void MoveTransport(DirectionTypeBulldozer direction)
|
public void MoveTransport(DirectionTypeBulldozer direction)
|
||||||
{
|
{
|
||||||
if (!CanMove(direction) || EntityBulldozer == null)
|
if (!CanMove(direction) || EntityTractor == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
case DirectionTypeBulldozer.Left:
|
case DirectionTypeBulldozer.Left:
|
||||||
_startPosX -= (int)EntityBulldozer.Step;
|
_startPosX -= (int)EntityTractor.Step;
|
||||||
break;
|
break;
|
||||||
case DirectionTypeBulldozer.Up:
|
case DirectionTypeBulldozer.Up:
|
||||||
_startPosY -= (int)EntityBulldozer.Step;
|
_startPosY -= (int)EntityTractor.Step;
|
||||||
break;
|
break;
|
||||||
case DirectionTypeBulldozer.Right:
|
case DirectionTypeBulldozer.Right:
|
||||||
_startPosX += (int)EntityBulldozer.Step;
|
_startPosX += (int)EntityTractor.Step;
|
||||||
break;
|
break;
|
||||||
case DirectionTypeBulldozer.Down:
|
case DirectionTypeBulldozer.Down:
|
||||||
_startPosY += (int)EntityBulldozer.Step;
|
_startPosY += (int)EntityTractor.Step;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public virtual void DrawTrasport(Graphics g)
|
public virtual void DrawTrasport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityBulldozer == null)
|
if (EntityTractor == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
Brush mainBrush = new SolidBrush(EntityBulldozer.MainColor);
|
Brush mainBrush = new SolidBrush(EntityTractor.MainColor);
|
||||||
// Тело трактора
|
// Тело трактора
|
||||||
Brush tractorColor = new SolidBrush(EntityBulldozer.MainColor);
|
Brush tractorColor = new SolidBrush(EntityTractor.MainColor);
|
||||||
g.FillRectangle(tractorColor, _startPosX + 50, _startPosY + 20, 100, 30);
|
g.FillRectangle(tractorColor, _startPosX + 50, _startPosY + 20, 100, 30);
|
||||||
g.FillRectangle(tractorColor, _startPosX + 80, _startPosY, 10, 30);
|
g.FillRectangle(tractorColor, _startPosX + 80, _startPosY, 10, 30);
|
||||||
//g.DrawEllipse(pen, _startPosX, _startPosY + 60, 90, 40);
|
|
||||||
int x = _startPosX + 50; // начальная позиция X
|
int x = _startPosX + 50; // начальная позиция X
|
||||||
int y = _startPosY; // начальная позиция Y
|
int y = _startPosY; // начальная позиция Y
|
||||||
int width = 110; // ширина прямоугольника
|
int width = 110; // ширина прямоугольника
|
||||||
int height = 30; // высота прямоугольника
|
int height = 30; // высота прямоугольника
|
||||||
int radius = 20; // радиус закругления углов
|
int radius = 20; // радиус закругления углов
|
||||||
|
|
||||||
// Рисуем закругленный прямоугольник
|
// Рисуем закругленный прямоугольник
|
||||||
g.DrawArc(pen, x - 5, y + 50, radius * 2, radius * 2, 180, 90); // верхний левый угол
|
g.DrawArc(pen, x - 5, y + 50, radius * 2, radius * 2, 180, 90); // верхний левый угол
|
||||||
g.DrawLine(pen, x + radius - 5, y + 50, x + width - radius - 5, y + 50); // верхняя горизонталь
|
g.DrawLine(pen, x + radius - 5, y + 50, x + width - radius - 5, y + 50); // верхняя горизонталь
|
||||||
@ -123,7 +125,7 @@ namespace Bulldozer.DrawningObjects
|
|||||||
g.DrawEllipse(pen, _startPosX + 120, _startPosY + 50, wheelRadius * 2, wheelRadius * 2);
|
g.DrawEllipse(pen, _startPosX + 120, _startPosY + 50, wheelRadius * 2, wheelRadius * 2);
|
||||||
g.FillEllipse(mainBrush, _startPosX + 120, _startPosY + 50, wheelRadius * 2, wheelRadius * 2);
|
g.FillEllipse(mainBrush, _startPosX + 120, _startPosY + 50, wheelRadius * 2, wheelRadius * 2);
|
||||||
// Кабина
|
// Кабина
|
||||||
Brush cabinColor = new SolidBrush(EntityBulldozer.MainColor);
|
Brush cabinColor = new SolidBrush(EntityTractor.MainColor);
|
||||||
g.FillRectangle(cabinColor, _startPosX + 120, _startPosY, 30, 20);
|
g.FillRectangle(cabinColor, _startPosX + 120, _startPosY, 30, 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Bulldozer.Entities;
|
using Bulldozer.Entities;
|
||||||
@ -9,47 +11,48 @@ namespace Bulldozer.DrawningObjects
|
|||||||
{
|
{
|
||||||
public class DrawningFastBulldozer : DrawningBulldozer
|
public class DrawningFastBulldozer : DrawningBulldozer
|
||||||
{
|
{
|
||||||
public DrawningFastBulldozer(int speed, double weight, Color mainColor, Color optionalColor, bool covsh, bool rearbucket, int width, int height) : base(speed, weight, mainColor, width, height, 200, 110)
|
public DrawningFastBulldozer(int speed, double weight,
|
||||||
|
Color mainColor, Color optionalColor, bool covsh,
|
||||||
|
bool rearbucket, int width, int height) :
|
||||||
|
base(speed, weight, mainColor, width, height, 200, 110)
|
||||||
{
|
{
|
||||||
if (EntityBulldozer != null)
|
if (EntityTractor != null)
|
||||||
{
|
{
|
||||||
EntityBulldozer = new EntityFastBulldozer(speed, weight, mainColor,
|
EntityTractor = new EntityFastBulldozer(speed, weight, mainColor,
|
||||||
optionalColor, covsh, rearbucket);
|
optionalColor, covsh, rearbucket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override void DrawTrasport(Graphics g)
|
public override void DrawTrasport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityBulldozer is not EntityFastBulldozer fastBulldozer)
|
if (EntityTractor is not EntityFastBulldozer fastTractor)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(fastTractor.OptionalColor, 2);
|
||||||
Brush optionalBrush = new SolidBrush(fastBulldozer.OptionalColor);
|
|
||||||
if (fastBulldozer.Covsh)
|
if (fastTractor.Covsh)
|
||||||
{
|
{
|
||||||
Point[] trianglePoints = new Point[]
|
Point[] trianglePoints = new Point[]
|
||||||
{
|
{
|
||||||
new Point(_startPosX+50, _startPosY + 60),
|
new Point(_startPosX+50, _startPosY + 30),
|
||||||
new Point(_startPosX+50, _startPosY + 110),
|
new Point(_startPosX+50, _startPosY + 80),
|
||||||
new Point(_startPosX + 10, _startPosY + 110)
|
new Point(_startPosX + 10, _startPosY + 80)
|
||||||
};
|
};
|
||||||
// Рисуем треугольник
|
// Рисуем треугольник
|
||||||
g.DrawPolygon(pen, trianglePoints);
|
g.DrawPolygon(pen, trianglePoints);
|
||||||
}
|
}
|
||||||
if (fastBulldozer.Rearbucket)
|
if (fastTractor.Rearbucket)
|
||||||
{
|
{
|
||||||
Point[] trianglePoints = new Point[]
|
Point[] trianglePoints = new Point[]
|
||||||
{
|
{
|
||||||
new Point(_startPosX+150, _startPosY + 60),
|
new Point(_startPosX+150, _startPosY + 30),
|
||||||
new Point(_startPosX+200, _startPosY + 60),
|
new Point(_startPosX+180, _startPosY + 30),
|
||||||
new Point(_startPosX + 200, _startPosY + 110)
|
new Point(_startPosX + 180, _startPosY + 80)
|
||||||
};
|
};
|
||||||
// Рисуем треугольник
|
// Рисуем треугольник
|
||||||
g.DrawPolygon(pen, trianglePoints);
|
g.DrawPolygon(pen, trianglePoints);
|
||||||
}
|
}
|
||||||
_startPosY += 30;
|
|
||||||
base.DrawTrasport(g);
|
base.DrawTrasport(g);
|
||||||
_startPosY -= 30;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,31 +4,48 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Bulldozer.DrawningObjects;
|
using Bulldozer.DrawningObjects;
|
||||||
|
using Bulldozer.Drawnings;
|
||||||
|
|
||||||
namespace Bulldozer.MovementStrategy
|
namespace Bulldozer.MovementStrategy
|
||||||
{
|
{
|
||||||
public class DrawningObjectBulldozer : IMoveableObject
|
public class DrawningObjectBulldozer : IMoveableObject
|
||||||
{
|
{
|
||||||
private readonly DrawningBulldozer? _drawningBulldozer = null;
|
private readonly DrawningBulldozer? _drawningTractor = null;
|
||||||
public DrawningObjectBulldozer(DrawningBulldozer drawningBulldozer)
|
public DrawningObjectBulldozer(DrawningBulldozer drawingTractor)
|
||||||
{
|
{
|
||||||
_drawningBulldozer = drawningBulldozer;
|
_drawningTractor = drawingTractor;
|
||||||
}
|
}
|
||||||
public ObjectParameters? GetObjectPosition
|
public ObjectParameters? GetObjectPosition
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_drawningBulldozer == null || _drawningBulldozer.EntityBulldozer == null)
|
if (_drawningTractor == null || _drawningTractor.EntityTractor == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new ObjectParameters(_drawningBulldozer.GetPosX,
|
return new ObjectParameters(_drawningTractor.GetPosX,
|
||||||
_drawningBulldozer.GetPosY, _drawningBulldozer.GetWidth,
|
_drawningTractor.GetPosY, _drawningTractor.GetWidth,
|
||||||
_drawningBulldozer.GetHeight);
|
_drawningTractor.GetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int GetStep => (int)(_drawningTractor?.EntityTractor?.Step ?? 0);
|
||||||
|
public bool CheckCanMove(DirectionTypeBulldozer direction) =>
|
||||||
|
_drawningTractor?.CanMove(direction) ?? false;
|
||||||
|
public void MoveObject(DirectionTypeBulldozer direction) =>
|
||||||
|
_drawningTractor?.MoveTransport(direction);
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
if (_drawningTractor != null)
|
||||||
|
{
|
||||||
|
_drawningTractor.SetPosition(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void Draw(Graphics g)
|
||||||
|
{
|
||||||
|
if (_drawningTractor != null)
|
||||||
|
{
|
||||||
|
_drawningTractor.DrawTrasport(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int GetStep => (int)(_drawningBulldozer?.EntityBulldozer?.Step ?? 0);
|
|
||||||
public bool CheckCanMove(DirectionTypeBulldozer direction) => _drawningBulldozer?.CanMove(direction) ?? false;
|
|
||||||
public void MoveObject(DirectionTypeBulldozer direction) => _drawningBulldozer?.MoveTransport(direction);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using Bulldozer.Entities;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -12,7 +11,9 @@ namespace Bulldozer.Entities
|
|||||||
public Color OptionalColor { get; private set; }
|
public Color OptionalColor { get; private set; }
|
||||||
public bool Covsh { get; private set; }
|
public bool Covsh { get; private set; }
|
||||||
public bool Rearbucket { get; private set; }
|
public bool Rearbucket { get; private set; }
|
||||||
public EntityFastBulldozer(int speed, double weight, Color mainColor, Color optionalColor, bool covsh, bool rearbucket) : base(speed, weight, mainColor)
|
public EntityFastBulldozer(int speed, double weight,
|
||||||
|
Color mainColor, Color optionalColor,
|
||||||
|
bool covsh, bool rearbucket) : base (speed, weight, mainColor)
|
||||||
{
|
{
|
||||||
OptionalColor = optionalColor;
|
OptionalColor = optionalColor;
|
||||||
Covsh = covsh;
|
Covsh = covsh;
|
||||||
|
14
Bulldozer/Bulldozer/FormBulldozer.Designer.cs
generated
14
Bulldozer/Bulldozer/FormBulldozer.Designer.cs
generated
@ -37,6 +37,7 @@
|
|||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
comboBoxStrategy = new ComboBox();
|
comboBoxStrategy = new ComboBox();
|
||||||
buttonStep = new Button();
|
buttonStep = new Button();
|
||||||
|
ButtonSelectBulldozer = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxFastBulldozer).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxFastBulldozer).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -141,11 +142,23 @@
|
|||||||
buttonStep.UseVisualStyleBackColor = true;
|
buttonStep.UseVisualStyleBackColor = true;
|
||||||
buttonStep.Click += Buttonstep_Click;
|
buttonStep.Click += Buttonstep_Click;
|
||||||
//
|
//
|
||||||
|
// ButtonSelectBulldozer
|
||||||
|
//
|
||||||
|
ButtonSelectBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
ButtonSelectBulldozer.Location = new Point(318, 426);
|
||||||
|
ButtonSelectBulldozer.Name = "ButtonSelectBulldozer";
|
||||||
|
ButtonSelectBulldozer.Size = new Size(162, 23);
|
||||||
|
ButtonSelectBulldozer.TabIndex = 9;
|
||||||
|
ButtonSelectBulldozer.Text = "Выбор";
|
||||||
|
ButtonSelectBulldozer.UseVisualStyleBackColor = true;
|
||||||
|
ButtonSelectBulldozer.Click += ButtonSelectBulldozer_Click;
|
||||||
|
//
|
||||||
// FastBulldozer
|
// FastBulldozer
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(884, 461);
|
ClientSize = new Size(884, 461);
|
||||||
|
Controls.Add(ButtonSelectBulldozer);
|
||||||
Controls.Add(buttonStep);
|
Controls.Add(buttonStep);
|
||||||
Controls.Add(comboBoxStrategy);
|
Controls.Add(comboBoxStrategy);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
@ -174,5 +187,6 @@
|
|||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private ComboBox comboBoxStrategy;
|
private ComboBox comboBoxStrategy;
|
||||||
private Button buttonStep;
|
private Button buttonStep;
|
||||||
|
private Button ButtonSelectBulldozer;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,57 +1,79 @@
|
|||||||
using Bulldozer.DrawningObjects;
|
using Bulldozer.DrawningObjects;
|
||||||
using Bulldozer.MovementStrategy;
|
using Bulldozer.MovementStrategy;
|
||||||
|
using Bulldozer.Drawnings;
|
||||||
|
|
||||||
namespace Bulldozer
|
namespace Bulldozer
|
||||||
{
|
{
|
||||||
public partial class FastBulldozer : Form
|
public partial class FastBulldozer : Form
|
||||||
{
|
{
|
||||||
private DrawningBulldozer? _drawningBulldozer;
|
private DrawningBulldozer? _drawningTractor;
|
||||||
private AbstractStrategy? _abstractStrategy;
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
public DrawningBulldozer? SelectedTractor { get; private set; }
|
||||||
public FastBulldozer()
|
public FastBulldozer()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_abstractStrategy = null;
|
||||||
|
SelectedTractor = null;
|
||||||
}
|
}
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawningBulldozer == null)
|
if (_drawningTractor == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new(pictureBoxFastBulldozer.Width,
|
Bitmap bmp = new(pictureBoxFastBulldozer.Width,
|
||||||
pictureBoxFastBulldozer.Height);
|
pictureBoxFastBulldozer.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawningBulldozer.DrawTrasport(gr);
|
_drawningTractor.DrawTrasport(gr);
|
||||||
pictureBoxFastBulldozer.Image = bmp;
|
pictureBoxFastBulldozer.Image = bmp;
|
||||||
}
|
}
|
||||||
private void ButtonCreateFastBulldozer_Click(object sender, EventArgs e)
|
private void ButtonCreateFastBulldozer_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
_drawningBulldozer = new DrawningFastBulldozer(
|
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog_dop = new();
|
||||||
|
if (dialog_dop.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = dialog_dop.Color;
|
||||||
|
}
|
||||||
|
Color dopColor2 = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog_dop2 = new();
|
||||||
|
if (dialog_dop2.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor2 = dialog_dop2.Color;
|
||||||
|
}
|
||||||
|
_drawningTractor = new DrawningFastBulldozer(
|
||||||
random.Next(100, 300), random.Next(1000, 3000),
|
random.Next(100, 300), random.Next(1000, 3000),
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
dopColor,
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
dopColor2,
|
||||||
Convert.ToBoolean(random.Next(0, 2)),
|
Convert.ToBoolean(random.Next(0, 2)),
|
||||||
Convert.ToBoolean(random.Next(0, 2)),
|
Convert.ToBoolean(random.Next(0, 2)),
|
||||||
pictureBoxFastBulldozer.Width,
|
pictureBoxFastBulldozer.Width,
|
||||||
pictureBoxFastBulldozer.Height);
|
pictureBoxFastBulldozer.Height);
|
||||||
_drawningBulldozer.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawningTractor.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
private void ButtonCreateBulldozer_Click(object sender, EventArgs e)
|
private void ButtonCreateBulldozer_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
_drawningBulldozer = new DrawningBulldozer(
|
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog_dop = new();
|
||||||
|
if (dialog_dop.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = dialog_dop.Color;
|
||||||
|
}
|
||||||
|
_drawningTractor = new DrawningBulldozer(
|
||||||
random.Next(100, 300),
|
random.Next(100, 300),
|
||||||
random.Next(1000, 3000),
|
random.Next(1000, 3000),
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
dopColor,
|
||||||
pictureBoxFastBulldozer.Width,
|
pictureBoxFastBulldozer.Width,
|
||||||
pictureBoxFastBulldozer.Height);
|
pictureBoxFastBulldozer.Height);
|
||||||
_drawningBulldozer.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawningTractor.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningBulldozer == null)
|
if (_drawningTractor == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -59,23 +81,24 @@ namespace Bulldozer
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
_drawningBulldozer.MoveTransport(DirectionTypeBulldozer.Up);
|
_drawningTractor.MoveTransport(DirectionTypeBulldozer.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
_drawningBulldozer.MoveTransport(DirectionTypeBulldozer.Down);
|
_drawningTractor.MoveTransport(DirectionTypeBulldozer.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
_drawningBulldozer.MoveTransport(DirectionTypeBulldozer.Left);
|
_drawningTractor.MoveTransport(DirectionTypeBulldozer.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
_drawningBulldozer.MoveTransport(DirectionTypeBulldozer.Right);
|
_drawningTractor.MoveTransport(DirectionTypeBulldozer.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Buttonstep_Click(object sender, EventArgs e)
|
private void Buttonstep_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawningBulldozer == null)
|
if (_drawningTractor == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -93,7 +116,7 @@ namespace Bulldozer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_abstractStrategy.SetData(
|
_abstractStrategy.SetData(
|
||||||
new DrawningObjectBulldozer(_drawningBulldozer),
|
new DrawningObjectBulldozer(_drawningTractor),
|
||||||
pictureBoxFastBulldozer.Width,
|
pictureBoxFastBulldozer.Width,
|
||||||
pictureBoxFastBulldozer.Height);
|
pictureBoxFastBulldozer.Height);
|
||||||
comboBoxStrategy.Enabled = false;
|
comboBoxStrategy.Enabled = false;
|
||||||
@ -110,5 +133,11 @@ namespace Bulldozer
|
|||||||
_abstractStrategy = null;
|
_abstractStrategy = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonSelectBulldozer_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedTractor = _drawningTractor;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
125
Bulldozer/Bulldozer/FormBulldozerCollection.Designer.cs
generated
Normal file
125
Bulldozer/Bulldozer/FormBulldozerCollection.Designer.cs
generated
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
namespace Bulldozer
|
||||||
|
{
|
||||||
|
partial class FormBulldozerCollection
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
ButtonAddBulldozer = new Button();
|
||||||
|
ButtonRemoveBulldozer = new Button();
|
||||||
|
ButtonRefreshCollection = new Button();
|
||||||
|
pictureBoxCollection = new PictureBox();
|
||||||
|
maskedTextBoxNumber = new MaskedTextBox();
|
||||||
|
groupBox1 = new GroupBox();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// ButtonAddBulldozer
|
||||||
|
//
|
||||||
|
ButtonAddBulldozer.Location = new Point(668, 45);
|
||||||
|
ButtonAddBulldozer.Name = "ButtonAddBulldozer";
|
||||||
|
ButtonAddBulldozer.Size = new Size(166, 31);
|
||||||
|
ButtonAddBulldozer.TabIndex = 0;
|
||||||
|
ButtonAddBulldozer.Text = "Добавить трактор";
|
||||||
|
ButtonAddBulldozer.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddBulldozer.Click += ButtonAddBulldozer_Click;
|
||||||
|
//
|
||||||
|
// ButtonRemoveBulldozer
|
||||||
|
//
|
||||||
|
ButtonRemoveBulldozer.Location = new Point(668, 129);
|
||||||
|
ButtonRemoveBulldozer.Name = "ButtonRemoveBulldozer";
|
||||||
|
ButtonRemoveBulldozer.Size = new Size(166, 31);
|
||||||
|
ButtonRemoveBulldozer.TabIndex = 1;
|
||||||
|
ButtonRemoveBulldozer.Text = "Удалить трактор";
|
||||||
|
ButtonRemoveBulldozer.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRemoveBulldozer.Click += ButtonRemoveBulldozer_Click;
|
||||||
|
//
|
||||||
|
// ButtonRefreshCollection
|
||||||
|
//
|
||||||
|
ButtonRefreshCollection.Location = new Point(668, 215);
|
||||||
|
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
|
ButtonRefreshCollection.Size = new Size(166, 31);
|
||||||
|
ButtonRefreshCollection.TabIndex = 2;
|
||||||
|
ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||||
|
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
pictureBoxCollection.Location = new Point(0, 0);
|
||||||
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
pictureBoxCollection.Size = new Size(624, 457);
|
||||||
|
pictureBoxCollection.SizeMode = PictureBoxSizeMode.Zoom;
|
||||||
|
pictureBoxCollection.TabIndex = 3;
|
||||||
|
pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
maskedTextBoxNumber.Font = new Font("Showcard Gothic", 9F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
maskedTextBoxNumber.Location = new Point(698, 100);
|
||||||
|
maskedTextBoxNumber.Mask = "00";
|
||||||
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
maskedTextBoxNumber.Size = new Size(100, 22);
|
||||||
|
maskedTextBoxNumber.TabIndex = 4;
|
||||||
|
maskedTextBoxNumber.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
groupBox1.Location = new Point(646, 12);
|
||||||
|
groupBox1.Name = "groupBox1";
|
||||||
|
groupBox1.Size = new Size(209, 412);
|
||||||
|
groupBox1.TabIndex = 5;
|
||||||
|
groupBox1.TabStop = false;
|
||||||
|
groupBox1.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// FormBulldozerCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(877, 469);
|
||||||
|
Controls.Add(ButtonRefreshCollection);
|
||||||
|
Controls.Add(ButtonRemoveBulldozer);
|
||||||
|
Controls.Add(maskedTextBoxNumber);
|
||||||
|
Controls.Add(ButtonAddBulldozer);
|
||||||
|
Controls.Add(groupBox1);
|
||||||
|
Controls.Add(pictureBoxCollection);
|
||||||
|
Name = "FormBulldozerCollection";
|
||||||
|
Text = "Набор трактористов";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button ButtonAddBulldozer;
|
||||||
|
private Button ButtonRemoveBulldozer;
|
||||||
|
private Button ButtonRefreshCollection;
|
||||||
|
private PictureBox pictureBoxCollection;
|
||||||
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
|
private GroupBox groupBox1;
|
||||||
|
}
|
||||||
|
}
|
65
Bulldozer/Bulldozer/FormBulldozerCollection.cs
Normal file
65
Bulldozer/Bulldozer/FormBulldozerCollection.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
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;
|
||||||
|
using Bulldozer.DrawningObjects;
|
||||||
|
using Bulldozer.Drawnings;
|
||||||
|
using Bulldozer.Generics;
|
||||||
|
using Bulldozer.MovementStrategy;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Bulldozer
|
||||||
|
{
|
||||||
|
public partial class FormBulldozerCollection : Form
|
||||||
|
{
|
||||||
|
private readonly BulldozerGenericCollection<DrawningBulldozer, DrawningObjectBulldozer> _tractor;
|
||||||
|
public FormBulldozerCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_tractor = new BulldozerGenericCollection<DrawningBulldozer, DrawningObjectBulldozer>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
private void ButtonAddBulldozer_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FastBulldozer form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_tractor + form.SelectedTractor > -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = _tractor.ShowBulldozer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ButtonRemoveBulldozer_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
if (_tractor - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBoxCollection.Image = _tractor.ShowBulldozer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _tractor.ShowBulldozer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
Bulldozer/Bulldozer/FormBulldozerCollection.resx
Normal file
120
Bulldozer/Bulldozer/FormBulldozerCollection.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>
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Bulldozer.DrawningObjects;
|
using Bulldozer.DrawningObjects;
|
||||||
|
using Bulldozer.Drawnings;
|
||||||
|
|
||||||
namespace Bulldozer.MovementStrategy
|
namespace Bulldozer.MovementStrategy
|
||||||
{
|
{
|
||||||
@ -28,5 +29,7 @@ namespace Bulldozer.MovementStrategy
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="direction"></param>
|
/// <param name="direction"></param>
|
||||||
void MoveObject(DirectionTypeBulldozer direction);
|
void MoveObject(DirectionTypeBulldozer direction);
|
||||||
|
void SetPosition(int x, int y);
|
||||||
|
void Draw(Graphics g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ namespace Bulldozer
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FastBulldozer());
|
Application.Run(new FormBulldozerCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
108
Bulldozer/Bulldozer/SetGeneric.cs
Normal file
108
Bulldozer/Bulldozer/SetGeneric.cs
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
namespace Bulldozer.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный набор объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
internal class SetGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Массив объектов, которые храним
|
||||||
|
/// </summary>
|
||||||
|
private readonly T?[] _places;
|
||||||
|
/// <summary>
|
||||||
|
/// Количество объектов в массиве
|
||||||
|
/// </summary>
|
||||||
|
public int Count => _places.Length;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="count"></param>
|
||||||
|
public SetGeneric(int count)
|
||||||
|
{
|
||||||
|
_places = new T?[count];
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tractor">Добавляемая установка</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T tractor)
|
||||||
|
{
|
||||||
|
return Insert(tractor, 0);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tractor">Добавляемая установкаь</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T tractor, int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
{
|
||||||
|
// Позиция недопустима
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (_places[position] != null)
|
||||||
|
{
|
||||||
|
int d = 0;
|
||||||
|
for(int j = 1; j < Count; j++)
|
||||||
|
{
|
||||||
|
if (_places[position + j] == null)
|
||||||
|
{
|
||||||
|
d = position + j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(d == 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for(int j = d; j > position; j--)
|
||||||
|
{
|
||||||
|
_places[j] = _places[j - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_places[position] = tractor;
|
||||||
|
return position;
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
// Проверка позиции
|
||||||
|
if (position < 0 || position >= _places.Length)
|
||||||
|
{
|
||||||
|
// Позиция недопустима
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||||
|
_places[position] = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта из набора по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
if (position < 0 || position >= _places.Length)
|
||||||
|
{
|
||||||
|
// Позиция недопустима
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user