Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
3a6b043a1b | ||
|
08fc6e78cd | ||
|
ddba502b60 | ||
|
0c0472e328 | ||
|
f8096ea10a | ||
|
5940b3ee19 |
71
Bulldozer/Bulldozer/AbstractStrategy.cs
Normal file
71
Bulldozer/Bulldozer/AbstractStrategy.cs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Bulldozer.Drawnings;
|
||||||
|
|
||||||
|
namespace Bulldozer.MovementStrategy
|
||||||
|
{
|
||||||
|
public abstract class AbstractStrategy
|
||||||
|
{
|
||||||
|
private IMoveableObject? _moveableObject;
|
||||||
|
private Status _state = Status.NotInit;
|
||||||
|
protected int FieldWidth { get; private set; }
|
||||||
|
protected int FieldHeight { get; private set; }
|
||||||
|
public Status GetStatus() { return _state; }
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
public void MakeStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IsTargetDestination())
|
||||||
|
{
|
||||||
|
_state = Status.Finish;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MoveToTarget();
|
||||||
|
}
|
||||||
|
protected bool MoveLeft() => MoveTo(DirectionTypeBulldozer.Left);
|
||||||
|
protected bool MoveRight() => MoveTo(DirectionTypeBulldozer.Right);
|
||||||
|
protected bool MoveUp() => MoveTo(DirectionTypeBulldozer.Up);
|
||||||
|
protected bool MoveDown() => MoveTo(DirectionTypeBulldozer.Down);
|
||||||
|
protected ObjectParameters? GetObjectParametrs => _moveableObject?.GetObjectPosition;
|
||||||
|
protected int? GetStep()
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return _moveableObject?.GetStep;
|
||||||
|
}
|
||||||
|
protected abstract void MoveToTarget();
|
||||||
|
protected abstract bool IsTargetDestination();
|
||||||
|
private bool MoveTo(DirectionTypeBulldozer directionType)
|
||||||
|
{
|
||||||
|
if (_state != Status.InProgress)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||||
|
{
|
||||||
|
_moveableObject.MoveObject(directionType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
159
Bulldozer/Bulldozer/BulldozerGenericCollection.cs
Normal file
159
Bulldozer/Bulldozer/BulldozerGenericCollection.cs
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
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[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[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;
|
||||||
|
foreach (var tractor in _collection.GetBulldozer())
|
||||||
|
{
|
||||||
|
if (tractor != null)
|
||||||
|
{
|
||||||
|
int i = _collection.GetBulldozer().ToList().IndexOf(tractor);
|
||||||
|
if (i % 3 == 0 && i != 0)
|
||||||
|
{
|
||||||
|
c = c - 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (k != 0)
|
||||||
|
{
|
||||||
|
k--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
k = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Установка позиции
|
||||||
|
int x = k % (_pictureWidth / _placeSizeWidth) * _placeSizeWidth;
|
||||||
|
int y = c / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight + 10;
|
||||||
|
tractor.SetPosition(x, y);
|
||||||
|
// Прорисовка объекта
|
||||||
|
tractor.DrawTrasport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
87
Bulldozer/Bulldozer/BulldozersGenericStorage.cs
Normal file
87
Bulldozer/Bulldozer/BulldozersGenericStorage.cs
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Bulldozer.DrawningObjects;
|
||||||
|
using Bulldozer.Generics;
|
||||||
|
using Bulldozer.MovementStrategy;
|
||||||
|
using Bulldozer.Drawnings;
|
||||||
|
|
||||||
|
namespace Bulldozer.Generics
|
||||||
|
{
|
||||||
|
internal class BulldozersGenericStorage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Словарь (хранилище)
|
||||||
|
/// </summary>
|
||||||
|
readonly Dictionary<string, BulldozerGenericCollection<DrawningBulldozer,
|
||||||
|
DrawningObjectBulldozer>> _tractorStorages;
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращение списка названий наборов
|
||||||
|
/// </summary>
|
||||||
|
public List<string> Keys => _tractorStorages.Keys.ToList();
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pictureWidth"></param>
|
||||||
|
/// <param name="pictureHeight"></param>
|
||||||
|
public BulldozersGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_tractorStorages = new Dictionary<string,
|
||||||
|
BulldozerGenericCollection<DrawningBulldozer, DrawningObjectBulldozer>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для добавления
|
||||||
|
if (!_tractorStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
var tractorCollection = new BulldozerGenericCollection<DrawningBulldozer, DrawningObjectBulldozer>(_pictureWidth, _pictureHeight);
|
||||||
|
_tractorStorages.Add(name, tractorCollection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для удаления
|
||||||
|
if (_tractorStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
_tractorStorages.Remove(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ind"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public BulldozerGenericCollection<DrawningBulldozer, DrawningObjectBulldozer>? this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// TODO Продумать логику получения набора
|
||||||
|
if (_tractorStorages.ContainsKey(ind))
|
||||||
|
{
|
||||||
|
return _tractorStorages[ind];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
Bulldozer/Bulldozer/DirectionBulldozer.cs
Normal file
16
Bulldozer/Bulldozer/DirectionBulldozer.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Bulldozer.Drawnings
|
||||||
|
{
|
||||||
|
public enum DirectionTypeBulldozer
|
||||||
|
{
|
||||||
|
Up = 1,
|
||||||
|
Down = 2,
|
||||||
|
Left = 3,
|
||||||
|
Right = 4,
|
||||||
|
}
|
||||||
|
}
|
132
Bulldozer/Bulldozer/DrawningBulldozer.cs
Normal file
132
Bulldozer/Bulldozer/DrawningBulldozer.cs
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Bulldozer.Entities;
|
||||||
|
using Bulldozer.Drawnings;
|
||||||
|
using Bulldozer.MovementStrategy;
|
||||||
|
|
||||||
|
namespace Bulldozer.DrawningObjects
|
||||||
|
{
|
||||||
|
public class DrawningBulldozer
|
||||||
|
{
|
||||||
|
public EntityBulldozer? EntityTractor { get; protected set; }
|
||||||
|
private int _pictureWidth;
|
||||||
|
private int _pictureHeight;
|
||||||
|
protected int _startPosX;
|
||||||
|
protected int _startPosY;
|
||||||
|
protected readonly int _tractorWidth = 160;
|
||||||
|
protected readonly int _tractorHeight = 80;
|
||||||
|
public DrawningBulldozer(int speed, double weight, Color mainColor, int width, int heigth)
|
||||||
|
{
|
||||||
|
if (width <= _tractorWidth || heigth <= _tractorHeight)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = heigth;
|
||||||
|
EntityTractor = new EntityBulldozer(speed, weight, mainColor);
|
||||||
|
}
|
||||||
|
protected DrawningBulldozer(int speed, double weight,
|
||||||
|
Color mainColor, int width, int heigth,
|
||||||
|
int tractorWidth, int tractorHeight)
|
||||||
|
{
|
||||||
|
if (width <= tractorWidth || heigth <= tractorHeight)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_pictureHeight = heigth;
|
||||||
|
_pictureWidth = width;
|
||||||
|
_tractorHeight = tractorHeight;
|
||||||
|
_tractorWidth = tractorWidth;
|
||||||
|
EntityTractor = new EntityBulldozer(speed, weight, mainColor);
|
||||||
|
}
|
||||||
|
public void SetPosition(int x, int y)
|
||||||
|
{
|
||||||
|
if (x < 0 || y < 0 || x + _tractorWidth > _pictureWidth || y + _tractorHeight > _pictureHeight)
|
||||||
|
{
|
||||||
|
x = 10;
|
||||||
|
y = 10;
|
||||||
|
}
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
}
|
||||||
|
public IMoveableObject GetMoveableObject => new DrawningObjectBulldozer(this);
|
||||||
|
public int GetPosX => _startPosX;
|
||||||
|
public int GetPosY => _startPosY;
|
||||||
|
public int GetWidth => _tractorWidth;
|
||||||
|
public int GetHeight => _tractorHeight;
|
||||||
|
public bool CanMove(DirectionTypeBulldozer direction)
|
||||||
|
{
|
||||||
|
if (EntityTractor == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return direction switch
|
||||||
|
{
|
||||||
|
DirectionTypeBulldozer.Left => _startPosX - EntityTractor.Step > 0,
|
||||||
|
DirectionTypeBulldozer.Up => _startPosY - EntityTractor.Step > 0,
|
||||||
|
DirectionTypeBulldozer.Right => _startPosX + EntityTractor.Step + _tractorWidth <= _pictureWidth,
|
||||||
|
DirectionTypeBulldozer.Down => _startPosY + EntityTractor.Step + _tractorHeight <= _pictureHeight,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void MoveTransport(DirectionTypeBulldozer direction)
|
||||||
|
{
|
||||||
|
if (!CanMove(direction) || EntityTractor == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
case DirectionTypeBulldozer.Left:
|
||||||
|
_startPosX -= (int)EntityTractor.Step;
|
||||||
|
break;
|
||||||
|
case DirectionTypeBulldozer.Up:
|
||||||
|
_startPosY -= (int)EntityTractor.Step;
|
||||||
|
break;
|
||||||
|
case DirectionTypeBulldozer.Right:
|
||||||
|
_startPosX += (int)EntityTractor.Step;
|
||||||
|
break;
|
||||||
|
case DirectionTypeBulldozer.Down:
|
||||||
|
_startPosY += (int)EntityTractor.Step;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public virtual void DrawTrasport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityTractor == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush mainBrush = new SolidBrush(EntityTractor.MainColor);
|
||||||
|
// Тело трактора
|
||||||
|
Brush tractorColor = new SolidBrush(EntityTractor.MainColor);
|
||||||
|
g.FillRectangle(tractorColor, _startPosX + 50, _startPosY + 20, 100, 30);
|
||||||
|
g.FillRectangle(tractorColor, _startPosX + 80, _startPosY, 10, 30);
|
||||||
|
int x = _startPosX + 50; // начальная позиция X
|
||||||
|
int y = _startPosY; // начальная позиция Y
|
||||||
|
int width = 110; // ширина прямоугольника
|
||||||
|
int height = 30; // высота прямоугольника
|
||||||
|
int radius = 20; // радиус закругления углов
|
||||||
|
// Рисуем закругленный прямоугольник
|
||||||
|
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.DrawArc(pen, x + width - radius * 2 - 5, y + 50, radius * 2, radius * 2, 270, 90); // верхний правый угол
|
||||||
|
g.DrawArc(pen, x + width - radius * 2 - 5, y + height - radius * 2 + 50, radius * 2, radius * 2, 0, 90); // нижний правый угол
|
||||||
|
g.DrawLine(pen, x + width - radius - 5, y + height + 50, x + radius - 5, y + height + 50); // нижняя горизонталь
|
||||||
|
g.DrawArc(pen, x - 5, y + height - radius * 2 + 50, radius * 2, radius * 2, 90, 90); // нижний левый угол
|
||||||
|
int wheelRadius = 15;
|
||||||
|
// Рисуем колеса трактора
|
||||||
|
g.DrawEllipse(pen, _startPosX + 50, _startPosY + 50, wheelRadius * 2, wheelRadius * 2);
|
||||||
|
g.FillEllipse(mainBrush, _startPosX + 50, _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);
|
||||||
|
// Кабина
|
||||||
|
Brush cabinColor = new SolidBrush(EntityTractor.MainColor);
|
||||||
|
g.FillRectangle(cabinColor, _startPosX + 120, _startPosY, 30, 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
58
Bulldozer/Bulldozer/DrawningFastBulldozer.cs
Normal file
58
Bulldozer/Bulldozer/DrawningFastBulldozer.cs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Bulldozer.Entities;
|
||||||
|
|
||||||
|
namespace Bulldozer.DrawningObjects
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
if (EntityTractor != null)
|
||||||
|
{
|
||||||
|
EntityTractor = new EntityFastBulldozer(speed, weight, mainColor,
|
||||||
|
optionalColor, covsh, rearbucket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void DrawTrasport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityTractor is not EntityFastBulldozer fastTractor)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(fastTractor.OptionalColor, 2);
|
||||||
|
|
||||||
|
if (fastTractor.Covsh)
|
||||||
|
{
|
||||||
|
Point[] trianglePoints = new Point[]
|
||||||
|
{
|
||||||
|
new Point(_startPosX+50, _startPosY + 30),
|
||||||
|
new Point(_startPosX+50, _startPosY + 80),
|
||||||
|
new Point(_startPosX + 10, _startPosY + 80)
|
||||||
|
};
|
||||||
|
// Рисуем треугольник
|
||||||
|
g.DrawPolygon(pen, trianglePoints);
|
||||||
|
}
|
||||||
|
if (fastTractor.Rearbucket)
|
||||||
|
{
|
||||||
|
Point[] trianglePoints = new Point[]
|
||||||
|
{
|
||||||
|
new Point(_startPosX+150, _startPosY + 30),
|
||||||
|
new Point(_startPosX+180, _startPosY + 30),
|
||||||
|
new Point(_startPosX + 180, _startPosY + 80)
|
||||||
|
};
|
||||||
|
// Рисуем треугольник
|
||||||
|
g.DrawPolygon(pen, trianglePoints);
|
||||||
|
}
|
||||||
|
base.DrawTrasport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
51
Bulldozer/Bulldozer/DrawningObjectBulldozer.cs
Normal file
51
Bulldozer/Bulldozer/DrawningObjectBulldozer.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Bulldozer.DrawningObjects;
|
||||||
|
using Bulldozer.Drawnings;
|
||||||
|
|
||||||
|
namespace Bulldozer.MovementStrategy
|
||||||
|
{
|
||||||
|
public class DrawningObjectBulldozer : IMoveableObject
|
||||||
|
{
|
||||||
|
private readonly DrawningBulldozer? _drawningTractor = null;
|
||||||
|
public DrawningObjectBulldozer(DrawningBulldozer drawingTractor)
|
||||||
|
{
|
||||||
|
_drawningTractor = drawingTractor;
|
||||||
|
}
|
||||||
|
public ObjectParameters? GetObjectPosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_drawningTractor == null || _drawningTractor.EntityTractor == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ObjectParameters(_drawningTractor.GetPosX,
|
||||||
|
_drawningTractor.GetPosY, _drawningTractor.GetWidth,
|
||||||
|
_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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
Bulldozer/Bulldozer/EntityBulldozer.cs
Normal file
22
Bulldozer/Bulldozer/EntityBulldozer.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Bulldozer.Entities
|
||||||
|
{
|
||||||
|
public class EntityBulldozer
|
||||||
|
{
|
||||||
|
public int Speed { get; private set; }
|
||||||
|
public double Weight { get; private set; }
|
||||||
|
public Color MainColor{ get; private set; }
|
||||||
|
public double Step => (double)Speed * 100 / Weight;
|
||||||
|
public EntityBulldozer(int speed, double weight, Color mainColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
MainColor = mainColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
Bulldozer/Bulldozer/EntityFastBulldozer.cs
Normal file
23
Bulldozer/Bulldozer/EntityFastBulldozer.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Bulldozer.Entities
|
||||||
|
{
|
||||||
|
public class EntityFastBulldozer : EntityBulldozer
|
||||||
|
{
|
||||||
|
public Color OptionalColor { get; private set; }
|
||||||
|
public bool Covsh { 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)
|
||||||
|
{
|
||||||
|
OptionalColor = optionalColor;
|
||||||
|
Covsh = covsh;
|
||||||
|
Rearbucket = rearbucket;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
45
Bulldozer/Bulldozer/Form1.Designer.cs
generated
45
Bulldozer/Bulldozer/Form1.Designer.cs
generated
@ -1,45 +0,0 @@
|
|||||||
namespace Bulldozer
|
|
||||||
{
|
|
||||||
partial class FormBulldozer
|
|
||||||
{
|
|
||||||
/// <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()
|
|
||||||
{
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// FormBulldozer
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
ClientSize = new Size(800, 450);
|
|
||||||
Name = "FormBulldozer";
|
|
||||||
Text = "Form1";
|
|
||||||
ResumeLayout(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
namespace Bulldozer
|
|
||||||
{
|
|
||||||
public partial class FormBulldozer : Form
|
|
||||||
{
|
|
||||||
public FormBulldozer()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
192
Bulldozer/Bulldozer/FormBulldozer.Designer.cs
generated
Normal file
192
Bulldozer/Bulldozer/FormBulldozer.Designer.cs
generated
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
namespace Bulldozer
|
||||||
|
{
|
||||||
|
partial class FastBulldozer
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
pictureBoxFastBulldozer = new PictureBox();
|
||||||
|
buttonCreateBulldozer = new Button();
|
||||||
|
buttonCreateFastBulldozer = new Button();
|
||||||
|
buttonRight = new Button();
|
||||||
|
buttonDown = new Button();
|
||||||
|
buttonLeft = new Button();
|
||||||
|
buttonUp = new Button();
|
||||||
|
comboBoxStrategy = new ComboBox();
|
||||||
|
buttonStep = new Button();
|
||||||
|
ButtonSelectBulldozer = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxFastBulldozer).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBoxFastBulldozer
|
||||||
|
//
|
||||||
|
pictureBoxFastBulldozer.Dock = DockStyle.Fill;
|
||||||
|
pictureBoxFastBulldozer.Location = new Point(0, 0);
|
||||||
|
pictureBoxFastBulldozer.Name = "pictureBoxFastBulldozer";
|
||||||
|
pictureBoxFastBulldozer.Size = new Size(884, 461);
|
||||||
|
pictureBoxFastBulldozer.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
|
pictureBoxFastBulldozer.TabIndex = 0;
|
||||||
|
pictureBoxFastBulldozer.TabStop = false;
|
||||||
|
//
|
||||||
|
// buttonCreateBulldozer
|
||||||
|
//
|
||||||
|
buttonCreateBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreateBulldozer.Location = new Point(12, 426);
|
||||||
|
buttonCreateBulldozer.Name = "buttonCreateBulldozer";
|
||||||
|
buttonCreateBulldozer.Size = new Size(119, 23);
|
||||||
|
buttonCreateBulldozer.TabIndex = 1;
|
||||||
|
buttonCreateBulldozer.Text = "Создать Трактор";
|
||||||
|
buttonCreateBulldozer.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateBulldozer.Click += ButtonCreateBulldozer_Click;
|
||||||
|
//
|
||||||
|
// buttonCreateFastBulldozer
|
||||||
|
//
|
||||||
|
buttonCreateFastBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreateFastBulldozer.Location = new Point(137, 426);
|
||||||
|
buttonCreateFastBulldozer.Name = "buttonCreateFastBulldozer";
|
||||||
|
buttonCreateFastBulldozer.Size = new Size(162, 23);
|
||||||
|
buttonCreateFastBulldozer.TabIndex = 2;
|
||||||
|
buttonCreateFastBulldozer.Text = "Создать быстрый трактор";
|
||||||
|
buttonCreateFastBulldozer.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateFastBulldozer.Click += ButtonCreateFastBulldozer_Click;
|
||||||
|
//
|
||||||
|
// buttonRight
|
||||||
|
//
|
||||||
|
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonRight.Location = new Point(842, 419);
|
||||||
|
buttonRight.Name = "buttonRight";
|
||||||
|
buttonRight.Size = new Size(30, 30);
|
||||||
|
buttonRight.TabIndex = 3;
|
||||||
|
buttonRight.Text = ">";
|
||||||
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
buttonRight.Click += ButtonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonDown
|
||||||
|
//
|
||||||
|
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonDown.Location = new Point(806, 419);
|
||||||
|
buttonDown.Name = "buttonDown";
|
||||||
|
buttonDown.Size = new Size(30, 30);
|
||||||
|
buttonDown.TabIndex = 4;
|
||||||
|
buttonDown.Text = "v";
|
||||||
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
buttonDown.Click += ButtonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonLeft
|
||||||
|
//
|
||||||
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonLeft.Location = new Point(770, 419);
|
||||||
|
buttonLeft.Name = "buttonLeft";
|
||||||
|
buttonLeft.Size = new Size(30, 30);
|
||||||
|
buttonLeft.TabIndex = 5;
|
||||||
|
buttonLeft.Text = "<";
|
||||||
|
buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
buttonLeft.Click += ButtonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonUp
|
||||||
|
//
|
||||||
|
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonUp.Location = new Point(806, 383);
|
||||||
|
buttonUp.Name = "buttonUp";
|
||||||
|
buttonUp.Size = new Size(30, 30);
|
||||||
|
buttonUp.TabIndex = 6;
|
||||||
|
buttonUp.Text = "^";
|
||||||
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
buttonUp.Click += ButtonMove_Click;
|
||||||
|
//
|
||||||
|
// comboBoxStrategy
|
||||||
|
//
|
||||||
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
|
comboBoxStrategy.Items.AddRange(new object[] { "Move to center", "Move to border" });
|
||||||
|
comboBoxStrategy.Location = new Point(751, 12);
|
||||||
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
|
comboBoxStrategy.Size = new Size(121, 23);
|
||||||
|
comboBoxStrategy.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// buttonStep
|
||||||
|
//
|
||||||
|
buttonStep.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
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;
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(884, 461);
|
||||||
|
Controls.Add(ButtonSelectBulldozer);
|
||||||
|
Controls.Add(buttonStep);
|
||||||
|
Controls.Add(comboBoxStrategy);
|
||||||
|
Controls.Add(buttonUp);
|
||||||
|
Controls.Add(buttonLeft);
|
||||||
|
Controls.Add(buttonDown);
|
||||||
|
Controls.Add(buttonRight);
|
||||||
|
Controls.Add(buttonCreateFastBulldozer);
|
||||||
|
Controls.Add(buttonCreateBulldozer);
|
||||||
|
Controls.Add(pictureBoxFastBulldozer);
|
||||||
|
Name = "FastBulldozer";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "FastBulldozer";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxFastBulldozer).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private PictureBox pictureBoxFastBulldozer;
|
||||||
|
private Button buttonCreateBulldozer;
|
||||||
|
private Button buttonCreateFastBulldozer;
|
||||||
|
private Button buttonRight;
|
||||||
|
private Button buttonDown;
|
||||||
|
private Button buttonLeft;
|
||||||
|
private Button buttonUp;
|
||||||
|
private ComboBox comboBoxStrategy;
|
||||||
|
private Button buttonStep;
|
||||||
|
private Button ButtonSelectBulldozer;
|
||||||
|
}
|
||||||
|
}
|
143
Bulldozer/Bulldozer/FormBulldozer.cs
Normal file
143
Bulldozer/Bulldozer/FormBulldozer.cs
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
using Bulldozer.DrawningObjects;
|
||||||
|
using Bulldozer.MovementStrategy;
|
||||||
|
using Bulldozer.Drawnings;
|
||||||
|
|
||||||
|
namespace Bulldozer
|
||||||
|
{
|
||||||
|
public partial class FastBulldozer : Form
|
||||||
|
{
|
||||||
|
private DrawningBulldozer? _drawningTractor;
|
||||||
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
public DrawningBulldozer? SelectedTractor { get; private set; }
|
||||||
|
public FastBulldozer()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_abstractStrategy = null;
|
||||||
|
SelectedTractor = null;
|
||||||
|
}
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
if (_drawningTractor == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bitmap bmp = new(pictureBoxFastBulldozer.Width,
|
||||||
|
pictureBoxFastBulldozer.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_drawningTractor.DrawTrasport(gr);
|
||||||
|
pictureBoxFastBulldozer.Image = bmp;
|
||||||
|
}
|
||||||
|
private void ButtonCreateFastBulldozer_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new Random();
|
||||||
|
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),
|
||||||
|
dopColor,
|
||||||
|
dopColor2,
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)),
|
||||||
|
Convert.ToBoolean(random.Next(0, 2)),
|
||||||
|
pictureBoxFastBulldozer.Width,
|
||||||
|
pictureBoxFastBulldozer.Height);
|
||||||
|
_drawningTractor.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void ButtonCreateBulldozer_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new Random();
|
||||||
|
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(1000, 3000),
|
||||||
|
dopColor,
|
||||||
|
pictureBoxFastBulldozer.Width,
|
||||||
|
pictureBoxFastBulldozer.Height);
|
||||||
|
_drawningTractor.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningTractor == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
_drawningTractor.MoveTransport(DirectionTypeBulldozer.Up);
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
_drawningTractor.MoveTransport(DirectionTypeBulldozer.Down);
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
_drawningTractor.MoveTransport(DirectionTypeBulldozer.Left);
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
_drawningTractor.MoveTransport(DirectionTypeBulldozer.Right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Buttonstep_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningTractor == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxStrategy.Enabled)
|
||||||
|
{
|
||||||
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||||
|
switch
|
||||||
|
{
|
||||||
|
0 => new MoveToCenter(),
|
||||||
|
1 => new MoveToBorder(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.SetData(
|
||||||
|
new DrawningObjectBulldozer(_drawningTractor),
|
||||||
|
pictureBoxFastBulldozer.Width,
|
||||||
|
pictureBoxFastBulldozer.Height);
|
||||||
|
comboBoxStrategy.Enabled = false;
|
||||||
|
}
|
||||||
|
if (_abstractStrategy == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_abstractStrategy.MakeStep();
|
||||||
|
Draw();
|
||||||
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||||
|
{
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_abstractStrategy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSelectBulldozer_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedTractor = _drawningTractor;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
191
Bulldozer/Bulldozer/FormBulldozerCollection.Designer.cs
generated
Normal file
191
Bulldozer/Bulldozer/FormBulldozerCollection.Designer.cs
generated
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
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();
|
||||||
|
groupBox2 = new GroupBox();
|
||||||
|
listBoxStorage = new ListBox();
|
||||||
|
ButtonDelObject = new Button();
|
||||||
|
ButtonAddObject = new Button();
|
||||||
|
textBoxStorageName = new TextBox();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
groupBox1.SuspendLayout();
|
||||||
|
groupBox2.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// ButtonAddBulldozer
|
||||||
|
//
|
||||||
|
ButtonAddBulldozer.Location = new Point(26, 314);
|
||||||
|
ButtonAddBulldozer.Name = "ButtonAddBulldozer";
|
||||||
|
ButtonAddBulldozer.Size = new Size(166, 40);
|
||||||
|
ButtonAddBulldozer.TabIndex = 0;
|
||||||
|
ButtonAddBulldozer.Text = "Добавить трактор";
|
||||||
|
ButtonAddBulldozer.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddBulldozer.Click += ButtonAddBulldozer_Click;
|
||||||
|
//
|
||||||
|
// ButtonRemoveBulldozer
|
||||||
|
//
|
||||||
|
ButtonRemoveBulldozer.Location = new Point(26, 400);
|
||||||
|
ButtonRemoveBulldozer.Name = "ButtonRemoveBulldozer";
|
||||||
|
ButtonRemoveBulldozer.Size = new Size(166, 39);
|
||||||
|
ButtonRemoveBulldozer.TabIndex = 1;
|
||||||
|
ButtonRemoveBulldozer.Text = "Удалить трактор";
|
||||||
|
ButtonRemoveBulldozer.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRemoveBulldozer.Click += ButtonRemoveBulldozer_Click;
|
||||||
|
//
|
||||||
|
// ButtonRefreshCollection
|
||||||
|
//
|
||||||
|
ButtonRefreshCollection.Location = new Point(26, 478);
|
||||||
|
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
|
ButtonRefreshCollection.Size = new Size(166, 40);
|
||||||
|
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(637, 530);
|
||||||
|
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(56, 371);
|
||||||
|
maskedTextBoxNumber.Mask = "00";
|
||||||
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
maskedTextBoxNumber.Size = new Size(100, 22);
|
||||||
|
maskedTextBoxNumber.TabIndex = 4;
|
||||||
|
maskedTextBoxNumber.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
groupBox1.Controls.Add(groupBox2);
|
||||||
|
groupBox1.Controls.Add(ButtonAddBulldozer);
|
||||||
|
groupBox1.Controls.Add(ButtonRefreshCollection);
|
||||||
|
groupBox1.Controls.Add(maskedTextBoxNumber);
|
||||||
|
groupBox1.Controls.Add(ButtonRemoveBulldozer);
|
||||||
|
groupBox1.Location = new Point(643, 12);
|
||||||
|
groupBox1.Name = "groupBox1";
|
||||||
|
groupBox1.Size = new Size(209, 533);
|
||||||
|
groupBox1.TabIndex = 5;
|
||||||
|
groupBox1.TabStop = false;
|
||||||
|
groupBox1.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// groupBox2
|
||||||
|
//
|
||||||
|
groupBox2.Controls.Add(listBoxStorage);
|
||||||
|
groupBox2.Controls.Add(ButtonDelObject);
|
||||||
|
groupBox2.Controls.Add(ButtonAddObject);
|
||||||
|
groupBox2.Controls.Add(textBoxStorageName);
|
||||||
|
groupBox2.Location = new Point(6, 22);
|
||||||
|
groupBox2.Name = "groupBox2";
|
||||||
|
groupBox2.Size = new Size(197, 274);
|
||||||
|
groupBox2.TabIndex = 6;
|
||||||
|
groupBox2.TabStop = false;
|
||||||
|
groupBox2.Text = "Наборы";
|
||||||
|
//
|
||||||
|
// listBoxStorage
|
||||||
|
//
|
||||||
|
listBoxStorage.FormattingEnabled = true;
|
||||||
|
listBoxStorage.ItemHeight = 15;
|
||||||
|
listBoxStorage.Location = new Point(20, 106);
|
||||||
|
listBoxStorage.Name = "listBoxStorage";
|
||||||
|
listBoxStorage.Size = new Size(158, 109);
|
||||||
|
listBoxStorage.TabIndex = 9;
|
||||||
|
listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// ButtonDelObject
|
||||||
|
//
|
||||||
|
ButtonDelObject.Location = new Point(33, 235);
|
||||||
|
ButtonDelObject.Name = "ButtonDelObject";
|
||||||
|
ButtonDelObject.Size = new Size(136, 33);
|
||||||
|
ButtonDelObject.TabIndex = 8;
|
||||||
|
ButtonDelObject.Text = "Удалить набор";
|
||||||
|
ButtonDelObject.UseVisualStyleBackColor = true;
|
||||||
|
ButtonDelObject.Click += ButtonDelObject_Click;
|
||||||
|
//
|
||||||
|
// ButtonAddObject
|
||||||
|
//
|
||||||
|
ButtonAddObject.Location = new Point(33, 54);
|
||||||
|
ButtonAddObject.Name = "ButtonAddObject";
|
||||||
|
ButtonAddObject.Size = new Size(136, 33);
|
||||||
|
ButtonAddObject.TabIndex = 7;
|
||||||
|
ButtonAddObject.Text = "Добавить набор";
|
||||||
|
ButtonAddObject.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddObject.Click += ButtonAddObject_Click;
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
textBoxStorageName.Location = new Point(20, 22);
|
||||||
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
textBoxStorageName.Size = new Size(158, 23);
|
||||||
|
textBoxStorageName.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// FormBulldozerCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(867, 584);
|
||||||
|
Controls.Add(groupBox1);
|
||||||
|
Controls.Add(pictureBoxCollection);
|
||||||
|
Name = "FormBulldozerCollection";
|
||||||
|
Text = "Набор тракторов";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
groupBox1.ResumeLayout(false);
|
||||||
|
groupBox1.PerformLayout();
|
||||||
|
groupBox2.ResumeLayout(false);
|
||||||
|
groupBox2.PerformLayout();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button ButtonAddBulldozer;
|
||||||
|
private Button ButtonRemoveBulldozer;
|
||||||
|
private Button ButtonRefreshCollection;
|
||||||
|
private PictureBox pictureBoxCollection;
|
||||||
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
|
private GroupBox groupBox1;
|
||||||
|
private GroupBox groupBox2;
|
||||||
|
private TextBox textBoxStorageName;
|
||||||
|
private ListBox listBoxStorage;
|
||||||
|
private Button ButtonDelObject;
|
||||||
|
private Button ButtonAddObject;
|
||||||
|
}
|
||||||
|
}
|
181
Bulldozer/Bulldozer/FormBulldozerCollection.cs
Normal file
181
Bulldozer/Bulldozer/FormBulldozerCollection.cs
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
|
||||||
|
using Bulldozer.DrawningObjects;
|
||||||
|
using Bulldozer.Drawnings;
|
||||||
|
using Bulldozer.Generics;
|
||||||
|
using Bulldozer.MovementStrategy;
|
||||||
|
|
||||||
|
namespace Bulldozer
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Форма для работы с набором объектов класса DrawningCar
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormBulldozerCollection : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly BulldozersGenericStorage _storage;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormBulldozerCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_storage = new BulldozersGenericStorage(pictureBoxCollection.Width,
|
||||||
|
pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Заполнение listBoxObjects
|
||||||
|
/// </summary>
|
||||||
|
private void ReloadObjects()
|
||||||
|
{
|
||||||
|
int index = listBoxStorage.SelectedIndex;
|
||||||
|
listBoxStorage.Items.Clear();
|
||||||
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxStorage.Items.Add(_storage.Keys[i]);
|
||||||
|
}
|
||||||
|
if (listBoxStorage.Items.Count > 0 && (index == -1 || index
|
||||||
|
>= listBoxStorage.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxStorage.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxStorage.Items.Count > 0 && index > -1 &&
|
||||||
|
index < listBoxStorage.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxStorage.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();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Выбор набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void listBoxStorage_SelectedIndexChanged(object sender,
|
||||||
|
EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image =
|
||||||
|
_storage[listBoxStorage.SelectedItem?.ToString() ?? string.Empty]?.ShowBulldozer();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show($"Удалить объект {listBoxStorage.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
|
||||||
|
{
|
||||||
|
_storage.DelSet(listBoxStorage.SelectedItem.ToString()
|
||||||
|
?? string.Empty);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddBulldozer_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FastBulldozer form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (obj + form.SelectedTractor > -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = obj.ShowBulldozer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonRemoveBulldozer_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
if (obj - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBoxCollection.Image = obj.ShowBulldozer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обновление рисунка по набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonRefreshCollection_Click(object sender, EventArgs
|
||||||
|
e)
|
||||||
|
{
|
||||||
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxCollection.Image = obj.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>
|
35
Bulldozer/Bulldozer/IMoveableObject.cs
Normal file
35
Bulldozer/Bulldozer/IMoveableObject.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Bulldozer.DrawningObjects;
|
||||||
|
using Bulldozer.Drawnings;
|
||||||
|
|
||||||
|
namespace Bulldozer.MovementStrategy
|
||||||
|
{
|
||||||
|
public interface IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// получение координаты
|
||||||
|
/// </summary>
|
||||||
|
ObjectParameters? GetObjectPosition { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// шаг
|
||||||
|
/// </summary>
|
||||||
|
int GetStep { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// проверка можно ли инди в этом направлении
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool CheckCanMove(DirectionTypeBulldozer direction);
|
||||||
|
/// <summary>
|
||||||
|
/// изменение напрвления перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction"></param>
|
||||||
|
void MoveObject(DirectionTypeBulldozer direction);
|
||||||
|
void SetPosition(int x, int y);
|
||||||
|
void Draw(Graphics g);
|
||||||
|
}
|
||||||
|
}
|
42
Bulldozer/Bulldozer/MoveToBorder.cs
Normal file
42
Bulldozer/Bulldozer/MoveToBorder.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Bulldozer.MovementStrategy
|
||||||
|
{
|
||||||
|
internal class MoveToBorder : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestination()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParametrs;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return objParams.RightBorder <= FieldWidth &&
|
||||||
|
objParams.RightBorder + GetStep() >= FieldWidth&&
|
||||||
|
objParams.DownBorder <= FieldHeight &&
|
||||||
|
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||||
|
}
|
||||||
|
protected override void MoveToTarget()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParametrs;
|
||||||
|
if (objParams == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var diffX = objParams.RightBorder - FieldWidth;
|
||||||
|
if (Math.Abs(diffX) > GetStep())
|
||||||
|
{
|
||||||
|
MoveRight();
|
||||||
|
}
|
||||||
|
var diffY = objParams.DownBorder - FieldHeight;
|
||||||
|
if (Math.Abs(diffY) > GetStep())
|
||||||
|
{
|
||||||
|
MoveDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
56
Bulldozer/Bulldozer/MoveToCenter.cs
Normal file
56
Bulldozer/Bulldozer/MoveToCenter.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Bulldozer.MovementStrategy
|
||||||
|
{
|
||||||
|
public class MoveToCenter : AbstractStrategy
|
||||||
|
{
|
||||||
|
protected override bool IsTargetDestination()
|
||||||
|
{
|
||||||
|
var objParams = GetObjectParametrs;
|
||||||
|
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 = GetObjectParametrs;
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
Bulldozer/Bulldozer/ObjectParameters.cs
Normal file
29
Bulldozer/Bulldozer/ObjectParameters.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Bulldozer.MovementStrategy
|
||||||
|
{
|
||||||
|
public class ObjectParameters
|
||||||
|
{
|
||||||
|
private readonly int _x;
|
||||||
|
private readonly int _y;
|
||||||
|
private readonly int _width;
|
||||||
|
private readonly int _height;
|
||||||
|
public int LeftBorder => _x;
|
||||||
|
public int TopBorder => _y;
|
||||||
|
public int RightBorder => _x + _width;
|
||||||
|
public int DownBorder => _y + _height;
|
||||||
|
public int ObjectMiddleHorizontal => _x + _width/2;
|
||||||
|
public int ObjectMiddleVertical => _y + _height/2;
|
||||||
|
public ObjectParameters(int x, int y, int width, int height)
|
||||||
|
{
|
||||||
|
_x = x;
|
||||||
|
_y = y;
|
||||||
|
_width = width;
|
||||||
|
_height = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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 FormBulldozer());
|
Application.Run(new FormBulldozerCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
103
Bulldozer/Bulldozer/Properties/Resources.Designer.cs
generated
Normal file
103
Bulldozer/Bulldozer/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код создан программой.
|
||||||
|
// Исполняемая версия:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||||
|
// повторной генерации кода.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace Bulldozer.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("Bulldozer_Lab1.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 arrow_down {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("arrow_down", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap arrow_left {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("arrow_left", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap arrow_right {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("arrow_right", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap arrow_up {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("arrow_up", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
133
Bulldozer/Bulldozer/Properties/Resources.resx
Normal file
133
Bulldozer/Bulldozer/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="arrow_down" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\arrow_down.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="arrow_left" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\arrow_left.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="arrow_right" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\arrow_right.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="arrow_up" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\arrow_up.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
BIN
Bulldozer/Bulldozer/Resources/arrow_down.png
Normal file
BIN
Bulldozer/Bulldozer/Resources/arrow_down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 264 B |
BIN
Bulldozer/Bulldozer/Resources/arrow_left.png
Normal file
BIN
Bulldozer/Bulldozer/Resources/arrow_left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 225 B |
BIN
Bulldozer/Bulldozer/Resources/arrow_right.png
Normal file
BIN
Bulldozer/Bulldozer/Resources/arrow_right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
BIN
Bulldozer/Bulldozer/Resources/arrow_up.png
Normal file
BIN
Bulldozer/Bulldozer/Resources/arrow_up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 294 B |
116
Bulldozer/Bulldozer/SetGeneric.cs
Normal file
116
Bulldozer/Bulldozer/SetGeneric.cs
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
namespace Bulldozer.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="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 >= _maxCount)
|
||||||
|
{
|
||||||
|
// Позиция недопустима
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (Count >= _maxCount)
|
||||||
|
return -1;
|
||||||
|
_places.Insert(position, tractor);
|
||||||
|
return position;
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
// Проверка позиции
|
||||||
|
if ((position < 0) || (position > _maxCount))
|
||||||
|
{
|
||||||
|
// Позиция недопустима
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||||
|
_places.RemoveAt(position);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта из набора по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T? this[int position]
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (position < 0 || position > _maxCount)
|
||||||
|
return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (position < 0 || position > _maxCount)
|
||||||
|
return;
|
||||||
|
_places[position] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Проход по списку
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<T?> GetBulldozer(int? maxTractor = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxTractor.HasValue && i == maxTractor.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
15
Bulldozer/Bulldozer/Status.cs
Normal file
15
Bulldozer/Bulldozer/Status.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Bulldozer.MovementStrategy
|
||||||
|
{
|
||||||
|
public enum Status
|
||||||
|
{
|
||||||
|
NotInit,
|
||||||
|
InProgress,
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user