Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
8ea47c3c98 | |||
1e10a3cb96 | |||
ac9e6959f3 | |||
d1ed841a1f |
132
Sailboat/Sailboat/AbstractStrategy.cs
Normal file
132
Sailboat/Sailboat/AbstractStrategy.cs
Normal file
@ -0,0 +1,132 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Sailboat.DrawingObjects;
|
||||
namespace Sailboat.MovementStrategy
|
||||
{
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObject? _moveableObject;
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
private Status _state = Status.NotInit;
|
||||
/// <summary>
|
||||
/// Ширина поля
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
/// <summary>
|
||||
/// Высота поля
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
public Status GetStatus() { return _state; }
|
||||
/// <summary>
|
||||
/// Установка данных
|
||||
/// </summary>
|
||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
public void SetData(IMoveableObject moveableObject, int width, int
|
||||
height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = Status.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = Status.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||
/// <summary>
|
||||
/// Перемещение вверх
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||
/// <summary>
|
||||
/// Перемещение вниз
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveDown() => MoveTo(DirectionType.Down);
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters? GetObjectParameters =>
|
||||
_moveableObject?.GetObjectPosition;
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
/// <summary>
|
||||
/// Достигнута ли цель
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
/// <summary>
|
||||
/// Попытка перемещения в требуемом направлении
|
||||
/// </summary>
|
||||
/// <param name="directionType">Направление</param>
|
||||
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||
private bool MoveTo(DirectionType directionType)
|
||||
{
|
||||
if (_state != Status.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_moveableObject?.CheckCanMove(directionType) ?? false)
|
||||
{
|
||||
_moveableObject.MoveObject(directionType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
146
Sailboat/Sailboat/BoatsGenericCollection.cs
Normal file
146
Sailboat/Sailboat/BoatsGenericCollection.cs
Normal file
@ -0,0 +1,146 @@
|
||||
using Sailboat.DrawingObjects;
|
||||
using Sailboat.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sailboat.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный класс для набора объектов DrawingBoat
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
internal class BoatsGenericCollection<T, U>
|
||||
where T : DrawingBoat
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 160;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 180
|
||||
;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetGeneric<T> _collection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
public BoatsGenericCollection(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 +(BoatsGenericCollection<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 -(BoatsGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
if (obj != null)
|
||||
{
|
||||
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 ShowBoats()
|
||||
{
|
||||
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, j *
|
||||
_placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
DrawingBoat boat = _collection.Get(i);
|
||||
|
||||
if (boat != null)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
boat.SetPosition(i % width * _placeSizeWidth, i / width * _placeSizeHeight);
|
||||
boat.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
29
Sailboat/Sailboat/Direction.cs
Normal file
29
Sailboat/Sailboat/Direction.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sailboat
|
||||
{
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
|
||||
}
|
||||
}
|
151
Sailboat/Sailboat/DrawingBoat.cs
Normal file
151
Sailboat/Sailboat/DrawingBoat.cs
Normal file
@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Sailboat.Entities;
|
||||
using Sailboat.MovementStrategy;
|
||||
|
||||
namespace Sailboat.DrawingObjects
|
||||
{
|
||||
public class DrawingBoat
|
||||
{
|
||||
public EntityBoat? EntityBoat { get; protected set; }
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
private readonly int _boatWidth = 160;
|
||||
private readonly int _boatHeight = 160;
|
||||
public int GetPosX => _startPosX;
|
||||
public int GetPosY => _startPosY;
|
||||
public int GetWidth => _boatWidth;
|
||||
public int GetHeight => _boatHeight;
|
||||
public IMoveableObject GetMoveableObject => new DrawingObjectBoat(this);
|
||||
|
||||
public DrawingBoat(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
if (width < _boatWidth || height < _boatHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityBoat = new EntityBoat(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
protected DrawingBoat(int speed, double weight, Color bodyColor, int width, int height, int boatWidth, int boatHeight)
|
||||
{
|
||||
if (width < _boatWidth || height < _boatHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_boatWidth = boatWidth;
|
||||
_boatHeight = boatHeight;
|
||||
EntityBoat = new EntityBoat(speed, weight, bodyColor);
|
||||
}
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0 || x + _boatWidth > _pictureWidth)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
if (y < 0 || y + _boatHeight > _pictureHeight)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y + 18;
|
||||
}
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityBoat == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
//влево
|
||||
DirectionType.Left => _startPosX - EntityBoat.Step > 0,
|
||||
//вверх
|
||||
DirectionType.Up => _startPosY - EntityBoat.Step > 0,
|
||||
// вправо
|
||||
DirectionType.Right => _startPosX + EntityBoat.Step < _pictureWidth,
|
||||
//вниз
|
||||
DirectionType.Down => _startPosY + EntityBoat.Step < _pictureHeight,
|
||||
};
|
||||
}
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntityBoat.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityBoat.Step;
|
||||
}
|
||||
break;
|
||||
case DirectionType.Up:
|
||||
if ((_startPosY - 15) - EntityBoat.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityBoat.Step;
|
||||
}
|
||||
break;
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + EntityBoat.Step + _boatWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityBoat.Step;
|
||||
}
|
||||
break;
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + EntityBoat.Step + _boatHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityBoat.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(EntityBoat.BodyColor);
|
||||
|
||||
//Основной корпус лодки
|
||||
Brush Brush = new
|
||||
SolidBrush(EntityBoat.BodyColor);
|
||||
|
||||
Point[] hull = new Point[]
|
||||
{
|
||||
new Point(_startPosX + 10, _startPosY + 90),
|
||||
new Point(_startPosX + 110, _startPosY + 90),
|
||||
new Point(_startPosX + 140, _startPosY + 120),
|
||||
new Point(_startPosX + 110, _startPosY + 150),
|
||||
new Point(_startPosX + 10, _startPosY + 150)
|
||||
};
|
||||
g.FillPolygon(Brush, hull);
|
||||
g.DrawPolygon(pen, hull);
|
||||
|
||||
Brush addBrush = new
|
||||
SolidBrush(Color.Aqua);
|
||||
|
||||
//Каюта лодки
|
||||
g.FillEllipse(addBrush, _startPosX + 20, _startPosY + 100, 90, 40);
|
||||
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 100, 90, 40);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
37
Sailboat/Sailboat/DrawingObjectBoat.cs
Normal file
37
Sailboat/Sailboat/DrawingObjectBoat.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Sailboat.DrawingObjects;
|
||||
|
||||
namespace Sailboat.MovementStrategy
|
||||
{
|
||||
public class DrawingObjectBoat : IMoveableObject
|
||||
{
|
||||
private readonly DrawingBoat? _drawingBoat = null;
|
||||
public DrawingObjectBoat(DrawingBoat drawingBoat)
|
||||
{
|
||||
_drawingBoat = drawingBoat;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawingBoat == null || _drawingBoat.EntityBoat ==
|
||||
null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawingBoat.GetPosX, _drawingBoat.GetPosY, _drawingBoat.GetWidth, _drawingBoat.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawingBoat?.EntityBoat?.Step ?? 0);
|
||||
public bool CheckCanMove(DirectionType direction) =>
|
||||
_drawingBoat?.CanMove(direction) ?? false;
|
||||
public void MoveObject(DirectionType direction) =>
|
||||
_drawingBoat?.MoveTransport(direction);
|
||||
|
||||
}
|
||||
}
|
81
Sailboat/Sailboat/DrawingSailboat.cs
Normal file
81
Sailboat/Sailboat/DrawingSailboat.cs
Normal file
@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Sailboat.Entities;
|
||||
|
||||
namespace Sailboat.DrawingObjects
|
||||
{
|
||||
public class DrawingSailboat : DrawingBoat
|
||||
{
|
||||
public DrawingSailboat(int speed, double weight, Color bodyColor, Color additionalColor, bool hull, bool sail, int width, int height) :
|
||||
base(speed, weight, bodyColor, width, height, 160, 160)
|
||||
{
|
||||
if (EntityBoat != null)
|
||||
{
|
||||
EntityBoat = new EntitySailboat(speed, weight, bodyColor,
|
||||
additionalColor, hull, sail);
|
||||
}
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBoat is not EntitySailboat sailboat)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(sailboat.AdditionalColor);
|
||||
|
||||
//усиленный корпус парусной лодки
|
||||
if (sailboat.Hull)
|
||||
{
|
||||
Point[] hullCooler = new Point[]
|
||||
{
|
||||
new Point(_startPosX, _startPosY + 80),
|
||||
new Point(_startPosX + 120, _startPosY + 80),
|
||||
new Point(_startPosX + 160, _startPosY + 120),
|
||||
new Point(_startPosX + 120, _startPosY + 160),
|
||||
new Point(_startPosX, _startPosY + 160)
|
||||
};
|
||||
g.FillPolygon(additionalBrush, hullCooler);
|
||||
g.DrawPolygon(pen, hullCooler);
|
||||
}
|
||||
base.DrawTransport(g);
|
||||
|
||||
//Парус с флагом
|
||||
if (sailboat.Sail)
|
||||
{
|
||||
Brush sailBrush = new
|
||||
SolidBrush(sailboat.AdditionalColor);
|
||||
|
||||
Point[] sail = new Point[]
|
||||
{
|
||||
new Point(_startPosX + 65, _startPosY),
|
||||
new Point(_startPosX + 130, _startPosY + 120),
|
||||
new Point(_startPosX + 15, _startPosY + 120)
|
||||
};
|
||||
g.FillPolygon(sailBrush, sail);
|
||||
g.DrawPolygon(pen, sail);
|
||||
//Флаг
|
||||
Brush addBrush = new
|
||||
SolidBrush(Color.Aqua);
|
||||
Brush flagBrush = new
|
||||
SolidBrush(sailboat.AdditionalColor);
|
||||
Point[] flag = new Point[]
|
||||
{
|
||||
new Point(_startPosX + 65, _startPosY - 15),
|
||||
new Point(_startPosX + 65, _startPosY + 10),
|
||||
new Point(_startPosX + 20, _startPosY + 10),
|
||||
new Point(_startPosX + 20, _startPosY - 15),
|
||||
};
|
||||
g.FillPolygon(addBrush, flag);
|
||||
g.DrawPolygon(pen, flag);
|
||||
g.DrawLine(pen, new Point(_startPosX + 65, _startPosY + 130), new Point(_startPosX + 65, _startPosY - 15));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
22
Sailboat/Sailboat/EntityBoat.cs
Normal file
22
Sailboat/Sailboat/EntityBoat.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sailboat.Entities
|
||||
{
|
||||
public class EntityBoat
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
public double Weight { get; private set; }
|
||||
public Color BodyColor { get; private set; }
|
||||
public double Step => (double)Speed * 100 / Weight;
|
||||
public EntityBoat(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
}
|
22
Sailboat/Sailboat/EntitySailboat.cs
Normal file
22
Sailboat/Sailboat/EntitySailboat.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sailboat.Entities
|
||||
{
|
||||
public class EntitySailboat : EntityBoat
|
||||
{
|
||||
public Color AdditionalColor { get; private set; }
|
||||
public bool Hull { get; private set; }
|
||||
public bool Sail { get; private set; }
|
||||
public EntitySailboat(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool hull, bool sail) : base (speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Hull = hull;
|
||||
Sail = sail;
|
||||
}
|
||||
}
|
||||
}
|
39
Sailboat/Sailboat/Form1.Designer.cs
generated
39
Sailboat/Sailboat/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace Sailboat
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace Sailboat
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
125
Sailboat/Sailboat/FormBoatCollection.Designer.cs
generated
Normal file
125
Sailboat/Sailboat/FormBoatCollection.Designer.cs
generated
Normal file
@ -0,0 +1,125 @@
|
||||
namespace Sailboat
|
||||
{
|
||||
partial class FormBoatCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.panelTools = new System.Windows.Forms.Panel();
|
||||
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonRefreshCollection = new System.Windows.Forms.Button();
|
||||
this.buttonRemoveBoat = new System.Windows.Forms.Button();
|
||||
this.buttonAddBoat = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.panelTools.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(750, 600);
|
||||
this.pictureBoxCollection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxCollection.TabIndex = 0;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// panelTools
|
||||
//
|
||||
this.panelTools.BackColor = System.Drawing.SystemColors.ScrollBar;
|
||||
this.panelTools.Controls.Add(this.maskedTextBoxNumber);
|
||||
this.panelTools.Controls.Add(this.buttonRefreshCollection);
|
||||
this.panelTools.Controls.Add(this.buttonRemoveBoat);
|
||||
this.panelTools.Controls.Add(this.buttonAddBoat);
|
||||
this.panelTools.Location = new System.Drawing.Point(756, 12);
|
||||
this.panelTools.Name = "panelTools";
|
||||
this.panelTools.Size = new System.Drawing.Size(209, 426);
|
||||
this.panelTools.TabIndex = 1;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(40, 87);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(125, 27);
|
||||
this.maskedTextBoxNumber.TabIndex = 3;
|
||||
//
|
||||
// buttonRefreshCollection
|
||||
//
|
||||
this.buttonRefreshCollection.Location = new System.Drawing.Point(16, 210);
|
||||
this.buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||
this.buttonRefreshCollection.Size = new System.Drawing.Size(180, 34);
|
||||
this.buttonRefreshCollection.TabIndex = 2;
|
||||
this.buttonRefreshCollection.Text = "Обновить коллекцию";
|
||||
this.buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
this.buttonRefreshCollection.Click += new System.EventHandler(this.buttonRefreshCollection_Click);
|
||||
//
|
||||
// buttonRemoveBoat
|
||||
//
|
||||
this.buttonRemoveBoat.Location = new System.Drawing.Point(16, 159);
|
||||
this.buttonRemoveBoat.Name = "buttonRemoveBoat";
|
||||
this.buttonRemoveBoat.Size = new System.Drawing.Size(180, 34);
|
||||
this.buttonRemoveBoat.TabIndex = 1;
|
||||
this.buttonRemoveBoat.Text = "Удалить лодку";
|
||||
this.buttonRemoveBoat.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveBoat.Click += new System.EventHandler(this.buttonRemoveBoat_Click);
|
||||
//
|
||||
// buttonAddBoat
|
||||
//
|
||||
this.buttonAddBoat.Location = new System.Drawing.Point(16, 14);
|
||||
this.buttonAddBoat.Name = "buttonAddBoat";
|
||||
this.buttonAddBoat.Size = new System.Drawing.Size(180, 34);
|
||||
this.buttonAddBoat.TabIndex = 0;
|
||||
this.buttonAddBoat.Text = "Добавить лодку";
|
||||
this.buttonAddBoat.UseVisualStyleBackColor = true;
|
||||
this.buttonAddBoat.Click += new System.EventHandler(this.buttonAddBoat_Click);
|
||||
//
|
||||
// FormBoatCollection
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(969, 450);
|
||||
this.Controls.Add(this.panelTools);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.Name = "FormBoatCollection";
|
||||
this.Text = "FormBoatCollection";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.panelTools.ResumeLayout(false);
|
||||
this.panelTools.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxCollection;
|
||||
private Panel panelTools;
|
||||
private Button buttonRefreshCollection;
|
||||
private Button buttonRemoveBoat;
|
||||
private Button buttonAddBoat;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
}
|
||||
}
|
68
Sailboat/Sailboat/FormBoatCollection.cs
Normal file
68
Sailboat/Sailboat/FormBoatCollection.cs
Normal file
@ -0,0 +1,68 @@
|
||||
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 Sailboat.DrawingObjects;
|
||||
using Sailboat.Generics;
|
||||
using Sailboat.MovementStrategy;
|
||||
|
||||
|
||||
namespace Sailboat
|
||||
{
|
||||
public partial class FormBoatCollection : Form
|
||||
{
|
||||
private readonly BoatsGenericCollection<DrawingBoat, DrawingObjectBoat> _boats;
|
||||
public FormBoatCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_boats = new BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
|
||||
private void buttonAddBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormSailboat form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_boats + form.SelectedBoat != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _boats.ShowBoats();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonRemoveBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (_boats - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
pictureBoxCollection.Image = _boats.ShowBoats();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _boats.ShowBoats();
|
||||
}
|
||||
}
|
||||
}
|
120
Sailboat/Sailboat/FormBoatCollection.resx
Normal file
120
Sailboat/Sailboat/FormBoatCollection.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>
|
232
Sailboat/Sailboat/FormSailboat.Designer.cs
generated
Normal file
232
Sailboat/Sailboat/FormSailboat.Designer.cs
generated
Normal file
@ -0,0 +1,232 @@
|
||||
namespace Sailboat
|
||||
{
|
||||
partial class FormSailboat
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormSailboat));
|
||||
this.pictureBoxSailboat = new System.Windows.Forms.PictureBox();
|
||||
this.buttonCreateBoat = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonCreateSailboat = new System.Windows.Forms.Button();
|
||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
this.buttonStep = new System.Windows.Forms.Button();
|
||||
this.buttonSelectBoat = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxSailboat)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
pictureBoxSailboat = new PictureBox();
|
||||
buttonCreateBoat = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonCreateSailboat = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxSailboat).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxSailboat
|
||||
//
|
||||
pictureBoxSailboat.Dock = DockStyle.Fill;
|
||||
pictureBoxSailboat.Location = new Point(0, 0);
|
||||
pictureBoxSailboat.Margin = new Padding(3, 2, 3, 2);
|
||||
pictureBoxSailboat.Name = "pictureBoxSailboat";
|
||||
pictureBoxSailboat.Size = new Size(834, 461);
|
||||
pictureBoxSailboat.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxSailboat.TabIndex = 0;
|
||||
pictureBoxSailboat.TabStop = false;
|
||||
//
|
||||
// buttonCreateBoat
|
||||
//
|
||||
buttonCreateBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateBoat.Location = new Point(12, 408);
|
||||
buttonCreateBoat.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonCreateBoat.Name = "buttonCreateBoat";
|
||||
buttonCreateBoat.Size = new Size(111, 42);
|
||||
buttonCreateBoat.TabIndex = 1;
|
||||
buttonCreateBoat.Text = "Создать лодку";
|
||||
buttonCreateBoat.UseVisualStyleBackColor = true;
|
||||
buttonCreateBoat.Click += buttonCreateBoat_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Location = new Point(673, 420);
|
||||
buttonLeft.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(30, 30);
|
||||
buttonLeft.TabIndex = 2;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(716, 386);
|
||||
buttonUp.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(30, 30);
|
||||
buttonUp.TabIndex = 3;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Location = new Point(760, 420);
|
||||
buttonRight.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(30, 30);
|
||||
buttonRight.TabIndex = 4;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(716, 420);
|
||||
buttonDown.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(30, 30);
|
||||
buttonDown.TabIndex = 5;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonCreateSailboat
|
||||
//
|
||||
buttonCreateSailboat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateSailboat.Location = new Point(145, 408);
|
||||
buttonCreateSailboat.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonCreateSailboat.Name = "buttonCreateSailboat";
|
||||
buttonCreateSailboat.Size = new Size(111, 42);
|
||||
buttonCreateSailboat.TabIndex = 6;
|
||||
buttonCreateSailboat.Text = "Создать парусник";
|
||||
buttonCreateSailboat.UseVisualStyleBackColor = true;
|
||||
buttonCreateSailboat.Click += buttonCreateSailboat_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "До центра", "До края" });
|
||||
comboBoxStrategy.Location = new Point(701, 0);
|
||||
comboBoxStrategy.Margin = new Padding(3, 2, 3, 2);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(133, 23);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonStep.Location = new Point(701, 27);
|
||||
buttonStep.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(133, 23);
|
||||
buttonStep.TabIndex = 8;
|
||||
buttonStep.Text = "Шаг";
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += buttonStep_Click;
|
||||
//
|
||||
// buttonSelectBoat
|
||||
//
|
||||
this.buttonSelectBoat.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonSelectBoat.Location = new System.Drawing.Point(688, 97);
|
||||
this.buttonSelectBoat.Name = "buttonSelectBoat";
|
||||
this.buttonSelectBoat.Size = new System.Drawing.Size(149, 33);
|
||||
this.buttonSelectBoat.TabIndex = 9;
|
||||
this.buttonSelectBoat.Text = "Выбрать лодку";
|
||||
this.buttonSelectBoat.UseVisualStyleBackColor = true;
|
||||
this.buttonSelectBoat.Click += new System.EventHandler(this.buttonSelectBoat_Click);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(882, 453);
|
||||
this.Controls.Add(this.buttonSelectBoat);
|
||||
this.Controls.Add(this.buttonStep);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
this.Controls.Add(this.buttonCreateSailboat);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonUp);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
this.Controls.Add(this.buttonCreateBoat);
|
||||
this.Controls.Add(this.pictureBoxSailboat);
|
||||
this.Name = "FormSailboat";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Парусник";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxSailboat)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(834, 461);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateSailboat);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreateBoat);
|
||||
Controls.Add(pictureBoxSailboat);
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "FormSailboat";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Парусник";
|
||||
Load += FormSailboat_Load;
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxSailboat).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxSailboat;
|
||||
private Button buttonCreateBoat;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateSailboat;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
private Button buttonSelectBoat;
|
||||
}
|
||||
}
|
140
Sailboat/Sailboat/FormSailboat.cs
Normal file
140
Sailboat/Sailboat/FormSailboat.cs
Normal file
@ -0,0 +1,140 @@
|
||||
using Sailboat.Entities;
|
||||
using Sailboat.DrawingObjects;
|
||||
using Sailboat.MovementStrategy;
|
||||
|
||||
namespace Sailboat
|
||||
{
|
||||
public partial class FormSailboat : Form
|
||||
{
|
||||
private DrawingBoat? _drawingBoat;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawingBoat? SelectedBoat { get; private set; }
|
||||
public FormSailboat()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedBoat = null;
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxSailboat.Width,
|
||||
pictureBoxSailboat.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawingBoat.DrawTransport(gr);
|
||||
pictureBoxSailboat.Image = bmp;
|
||||
}
|
||||
private void buttonCreateBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_drawingBoat = new DrawingBoat(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxSailboat.Width, pictureBoxSailboat.Height);
|
||||
_drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void buttonCreateSailboat_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256),
|
||||
random.Next(0, 256), random.Next(0, 256));
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialog.Color;
|
||||
}
|
||||
|
||||
_drawingBoat = new DrawingSailboat(random.Next(100, 300),
|
||||
random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxSailboat.Width, pictureBoxSailboat.Height);
|
||||
_drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_drawingBoat.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_drawingBoat.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_drawingBoat.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_drawingBoat.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(_drawingBoat.GetMoveableObject, pictureBoxSailboat.Width,
|
||||
pictureBoxSailboat.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSelectBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedBoat = _drawingBoat;
|
||||
DialogResult = DialogResult.OK;
|
||||
|
||||
}
|
||||
|
||||
private static void FormSailboat_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
1165
Sailboat/Sailboat/FormSailboat.resx
Normal file
1165
Sailboat/Sailboat/FormSailboat.resx
Normal file
File diff suppressed because it is too large
Load Diff
33
Sailboat/Sailboat/IMoveableObject.cs
Normal file
33
Sailboat/Sailboat/IMoveableObject.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Sailboat.DrawingObjects;
|
||||
|
||||
namespace Sailboat.MovementStrategy
|
||||
{
|
||||
public interface IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты X объекта
|
||||
/// </summary>
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
/// <summary>
|
||||
/// Проверка, можно ли переместиться по нужному направлению
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
bool CheckCanMove(DirectionType direction);
|
||||
/// <summary>
|
||||
/// Изменение направления пермещения объекта
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
void MoveObject(DirectionType direction);
|
||||
}
|
||||
}
|
57
Sailboat/Sailboat/MoveToBorder.cs
Normal file
57
Sailboat/Sailboat/MoveToBorder.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sailboat.MovementStrategy
|
||||
{
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
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 = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.RightBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.DownBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
Sailboat/Sailboat/MoveToCenter.cs
Normal file
56
Sailboat/Sailboat/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 Sailboat.MovementStrategy
|
||||
{
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
|
||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
var objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
54
Sailboat/Sailboat/ObjectParameters.cs
Normal file
54
Sailboat/Sailboat/ObjectParameters.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sailboat.MovementStrategy
|
||||
{
|
||||
public class ObjectParameters
|
||||
{
|
||||
private readonly int _x;
|
||||
private readonly int _y;
|
||||
private readonly int _width;
|
||||
private readonly int _height;
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
public int LeftBorder => _x;
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
public int TopBorder => _y;
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
public int RightBorder => _x + _width;
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
public int DownBorder => _y + _height;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace Sailboat
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
Application.Run(new FormBoatCollection());
|
||||
}
|
||||
}
|
||||
}
|
63
Sailboat/Sailboat/Properties/Resources.Designer.cs
generated
Normal file
63
Sailboat/Sailboat/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,63 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Sailboat.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("Sailboat.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
Sailboat/Sailboat/Resources/arrowDown.jpg
Normal file
BIN
Sailboat/Sailboat/Resources/arrowDown.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 61 KiB |
BIN
Sailboat/Sailboat/Resources/arrowLeft.jpg
Normal file
BIN
Sailboat/Sailboat/Resources/arrowLeft.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 60 KiB |
BIN
Sailboat/Sailboat/Resources/arrowRight.jpg
Normal file
BIN
Sailboat/Sailboat/Resources/arrowRight.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 60 KiB |
BIN
Sailboat/Sailboat/Resources/arrowUp.jpg
Normal file
BIN
Sailboat/Sailboat/Resources/arrowUp.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 61 KiB |
@ -8,4 +8,19 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
71
Sailboat/Sailboat/SetGeneric.cs
Normal file
71
Sailboat/Sailboat/SetGeneric.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sailboat.Generics
|
||||
{
|
||||
internal class SetGeneric<T> where T : class
|
||||
{
|
||||
private readonly T?[] _places;
|
||||
public int Count => _places.Length;
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
}
|
||||
public int Insert(T boat)
|
||||
{
|
||||
return Insert(boat, 0);
|
||||
}
|
||||
public int Insert(T boat, int position)
|
||||
{
|
||||
int nullIndex = -1, i;
|
||||
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = position; i < Count; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
nullIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (nullIndex < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = nullIndex; i > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
|
||||
_places[position] = boat;
|
||||
return position;
|
||||
}
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
18
Sailboat/Sailboat/Status.cs
Normal file
18
Sailboat/Sailboat/Status.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sailboat.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
/// </summary>
|
||||
public enum Status
|
||||
{
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user