Compare commits

..

25 Commits

Author SHA1 Message Date
Nikita
20fa07507f delete useless comments 2025-02-25 21:01:20 +04:00
Nikita
9a97f4378d delete ws 2025-02-25 20:59:41 +04:00
Nikita
fb452c0f70 task 5 2025-02-24 21:31:48 +04:00
Nikita
aac002fb3a fixed logic to border 2025-02-24 19:56:46 +04:00
Nikita
91bc8d454c fix conflicts 2025-02-22 23:01:34 +04:00
Nikita
a7aa7c41bc rename params in ctor 2025-02-22 22:59:39 +04:00
Nikita
062dbc8a0c private speed and weight 2025-02-22 22:57:59 +04:00
Nikita
eca2103158 test1 2025-02-22 22:52:54 +04:00
Nikita
8db1ac8fc3 fix conflicts 2025-02-22 22:45:11 +04:00
Nikita
d9dff2745f Revert "some fixes"
This reverts commit 4a4c658554820c82099c5585384ad98bc3b844de.
2025-02-22 22:43:37 +04:00
Nikita
14c3ee914f some fixes 2025-02-22 21:26:35 +04:00
Nikita
7a4d86902f Merge branch 'LabWork02' of https://git.is.ulstu.ru/nikskob/PIbd-14_Skobelev_N.N._Base into LabWork02 2025-02-22 21:24:18 +04:00
Nikita
9fe56faa90 fixes 2025-02-22 21:23:34 +04:00
Nikita
4a4c658554 some fixes 2025-02-22 21:22:03 +04:00
Nikita
2235a53cf3 little fix 2025-02-22 21:16:29 +04:00
7f00fa01bb somefixes 2025-02-22 17:35:05 +04:00
432fe934aa Обновить ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveableBoat.cs
fix
2025-02-22 15:37:03 +04:00
Nikita
9003758c6b 2/3 done 2025-02-16 15:32:34 +04:00
Nikita
c8d9b3ece7 part 1 2025-02-15 15:47:50 +04:00
Nikita
19fd6bc82d rename base classes 2025-02-15 13:49:15 +04:00
Nikita
4a835f6a16 поменял коммнтарий 2025-02-14 23:09:02 +04:00
Nikita
ef97c035ad поменя название параметра 2025-02-13 19:47:39 +04:00
Nikita
336c2e7d1c 2 часть лаб работа 2 2025-02-13 18:50:39 +04:00
Nikita
7d2726f5f7 лаб.раб 2 (1 часть) 2025-02-13 16:51:00 +04:00
Nikita
aa6f572492 лаб работа 1 2025-02-11 21:06:48 +04:00
33 changed files with 2078 additions and 50 deletions

View File

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectCatamaran.Drawnings;
namespace ProjectCatamaran.CollectionGenericObjects;
public abstract class AbstractCompany
{
protected readonly int _placeSizeWidth = 90;
protected readonly int _placeSizeHeight = 50;
protected readonly int _pictureWidth;
protected readonly int _pictureHeight;
protected ICollectionGenericObjects<DrawningBoat?> _collection = null;
private int GetMaxCount => (_pictureWidth / _placeSizeWidth + 1) * (_pictureHeight / _placeSizeHeight / 2) - (_pictureHeight / _placeSizeHeight / 2);
public AbstractCompany(int picWidth,int picHeight,ICollectionGenericObjects<DrawningBoat?> collection)
{
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
_collection.SetMaxCount = GetMaxCount;
}
public static int operator +(AbstractCompany company, DrawningBoat boat)
{
return company._collection?.Insert(boat) ?? -1;
}
public static DrawningBoat? operator -(AbstractCompany company, int position)
{
return company._collection?.Remove(position);
}
public DrawningBoat? GetRandomObject()
{
Random rnd = new Random();
return _collection?.Get(rnd.Next(GetMaxCount));
}
public Bitmap Show()
{
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
Graphics graphics = Graphics.FromImage(bitmap);
DrawBackground(graphics);
SetObjectPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
DrawningBoat? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
}
return bitmap;
}
protected abstract void DrawBackground(Graphics g);
protected abstract void SetObjectPosition();
}

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectCatamaran.Drawnings;
namespace ProjectCatamaran.CollectionGenericObjects;
public class Harbour : AbstractCompany
{
public Harbour(int picWidth, int picHeight, ICollectionGenericObjects<DrawningBoat?> collection) : base(picWidth, picHeight, collection)
{
}
protected override void DrawBackground(Graphics g)
{
Pen pen = new Pen(Color.Black,2);
for (int i = 0; i < _pictureHeight / _placeSizeHeight / 2; i++)
{
g.DrawLine(pen, 0, _pictureHeight - 10 - (2*i* _placeSizeHeight)
, _pictureWidth , _pictureHeight - 10 - (2*i * _placeSizeHeight));
for (int j = 0; j - 1 < _pictureWidth / _placeSizeWidth; j++)
{
g.DrawLine(pen, (j * _placeSizeWidth), _pictureHeight - 10 - (2 * i * _placeSizeHeight),
(j * _placeSizeWidth), _pictureHeight - 10 - (2 *i * _placeSizeHeight)- _placeSizeHeight);
}
}
}
protected override void SetObjectPosition()
{
int curPosX = 0;
int curPosY = 0;
for (int i = 0; i < (_collection?.Count ?? 0); i++)
{
if (_collection?.Get(i) != null)
{
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection?.Get(i)?.SetPosition((curPosX * _placeSizeWidth) + 15,_pictureHeight - 2 * curPosY * _placeSizeHeight - _placeSizeHeight - 5);
}
curPosX += 1;
if (curPosX > 6)
{
curPosX = 0;
curPosY++;
}
}
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCatamaran.CollectionGenericObjects;
public interface ICollectionGenericObjects<T> where T : class
{
int Count { get; }
int SetMaxCount { set; }
int Insert(T obj);
int Insert(T obj, int position);
T? Remove(int position);
T? Get(int position);
}

View File

@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCatamaran.CollectionGenericObjects;
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T> where T : class
{
private T?[] _collection;
public int Count => _collection.Length;
public int SetMaxCount
{
set
{
if (value > 0)
{
_collection = new T?[value];
}
}
}
public MassiveGenericObjects()
{
_collection = Array.Empty<T?>();
}
public T? Get(int position)
{
if (position >= 0 && position < Count)
{
return _collection[position];
}
return null;
}
public int Insert(T obj)
{
for (int i = 0; i < Count; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return i;
}
}
return -1;
}
public int Insert(T obj, int position)
{
if (!(position > 0 && position < _collection.Length))
{
return -1;
}
if (_collection[position] == null)
_collection[position] = obj;
else
{
for (int i = position + 1; i < Count; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return i;
}
}
for (int i = position - 1; i >= 0; i--)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return i;
}
}
}
return -1;
}
public T? Remove(int position)
{
if (!(position >= 0 && position < _collection.Length) || _collection[position] == null )
{
return null;
}
T? deletedElement = _collection[position];
_collection[position] = null;
return deletedElement;
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCatamaran.Drawnings;
public enum DirectionType
{
/// <summary>
/// неизвестное направление
/// </summary>
Unknown = -1,
/// <summary>
/// Вверх
/// </summary>
Up = 1,
/// <summary>
/// Вниз
/// </summary>
Down = 2,
/// <summary>
/// Влево
/// </summary>
Left = 3,
/// <summary>
/// Вправо
/// </summary>
Right = 4
}

View File

@ -0,0 +1,190 @@
using ProjectCatamaran.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCatamaran.Drawnings;
public class DrawningBoat
{
/// <summary>
/// класс-сущность
/// </summary>
public EntityBoat? EntityBoat { get; protected set; }
/// <summary>
/// ширина окна
/// </summary>
private int? _pictureWidth;
/// <summary>
/// высота окна
/// </summary>
private int? _pictureHeight;
/// <summary>
/// Левая координата прорисовки автопоезда
/// </summary>
protected int? _startPosX;
/// <summary>
/// Верхняя координата прорисовки автопоезда
/// </summary>
protected int? _startPosY;
/// <summary>
/// Ширина прорисовки лодки
/// </summary>
private readonly int _drawningBoatWidth = 60;
/// <summary>
/// Высота прорисовки лодки
/// </summary>
private readonly int _drawningBoatHeight = 22;
/// <summary>
/// координата х обьекта
/// </summary>
public int? GetPosX => _startPosX;
/// <summary>
/// координата Y обьекта
/// </summary>
public int? GetPosY => _startPosY;
/// <summary>
/// ширина обьекта
/// </summary>
public int GetWidth => _drawningBoatWidth;
/// <summary>
/// высота обьекта
/// </summary>
public int GetHeight => _drawningBoatHeight;
/// <summary>
/// пустой конструктор
/// </summary>
private DrawningBoat()
{
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес катера</param>
/// <param name="bodyColor">Основной цвет</param>
public DrawningBoat(int speed, double weight, Color bodyColor) : this()
{
EntityBoat = new EntityBoat(speed, weight, bodyColor);
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="drawningBoatWidth">Ширина катера</param>
/// <param name="drawningBoatHeight">высота катера</param>
public DrawningBoat(int drawningBoatWidth, int drawningBoatHeight) : this()
{
_drawningBoatWidth = drawningBoatWidth;
_drawningBoatHeight = drawningBoatHeight;
}
/// <summary>
/// установка границ поля
/// </summary>
/// <param name="width">ширина</param>
/// <param name="height">высота</param>
/// <returns></returns>
public bool SetPictureSize(int width, int height)
{
if (_drawningBoatHeight < height && _drawningBoatWidth < width)
{
_pictureHeight = height;
_pictureWidth = width;
return true;
}
return false;
}
/// <summary>
/// установка позиции
/// </summary>
/// <param name="x">координата x</param>
/// <param name="y">координата y</param>
public void SetPosition(int x, int y)
{
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}
if (x > _pictureWidth - _drawningBoatWidth || x < 0)
_startPosX = x < 0 ? 0 : _pictureWidth - _drawningBoatWidth;
else
_startPosX = x;
if (y > _pictureHeight - _drawningBoatHeight || y < 0)
_startPosY = y < 0 ? 0 : _pictureHeight - _drawningBoatHeight;
else
_startPosY = y;
}
/// <summary>
/// изменение направления перемещения
/// </summary>
/// <param name="direction">направление</param>
/// <returns>true - перемещение выполнено , false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction)
{
if (EntityBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
switch (direction)
{
case DirectionType.Left:
if (_startPosX.Value - EntityBoat.Step > 0)
{
_startPosX -= (int)EntityBoat.Step;
}
return true;
case DirectionType.Up:
if (_startPosY.Value - EntityBoat.Step > 0)
{
_startPosY -= (int)EntityBoat.Step;
}
return true;
case DirectionType.Right:
if (_startPosX.Value + (int)EntityBoat.Step + _drawningBoatWidth <= _pictureWidth)
{
_startPosX += (int)EntityBoat.Step;
}
return true;
case DirectionType.Down:
if (_startPosY.Value + (int)EntityBoat.Step + _drawningBoatHeight <= _pictureHeight)
{
_startPosY += (int)EntityBoat.Step;
}
return true;
default:
return false;
}
}
/// <summary>
/// отрисовка
/// </summary>
/// <param name="g"></param>
public virtual void DrawTransport(Graphics g)
{
if (EntityBoat == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Brush brBody = new SolidBrush(EntityBoat.BodyColor);
g.FillRectangle(brBody, _startPosX.Value, _startPosY.Value, 40, 20);
Point[] triangle =
{
new Point(_startPosX.Value + 40,_startPosY.Value),
new Point(_startPosX.Value + 60,_startPosY.Value + 10),
new Point(_startPosX.Value + 40,_startPosY.Value + 20),
};
g.FillPolygon(brBody, triangle);
g.FillEllipse(new SolidBrush(Color.Black), _startPosX.Value + 7, _startPosY.Value + 4, 23, 10);
}
}

View File

@ -0,0 +1,60 @@
using ProjectCatamaran.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCatamaran.Drawnings;
/// <summary>
/// класс отвечающиай за перемещение и отрисовку
/// </summary>
public class DrawningCatamaran : DrawningBoat
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес катера</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет(для опциональных элементов)</param>
/// <param name="floats">Признак (опция) наличие плавников</param>
/// <param name="sail">Признак (опция) наличие парус</param>
public DrawningCatamaran(int speed, double weight, Color bodyColor, Color additionalColor, bool floats, bool sail) :
base(65,40)
{
EntityBoat = new EntityCatamaran(speed, weight, bodyColor, additionalColor, floats, sail);
}
public override void DrawTransport(Graphics g)
{
if (EntityBoat == null || EntityBoat is not EntityCatamaran catamaran || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
_startPosX += 5;
_startPosY += 15;
base.DrawTransport(g);
_startPosX -= 5;
_startPosY -= 15;
Brush brFloatsAndSail = new SolidBrush(catamaran.AdditionalColor);
//плавники
if (catamaran.Floats)
{
g.FillRectangle(brFloatsAndSail, _startPosX.Value, _startPosY.Value + 10, 45, 5);
g.FillRectangle(brFloatsAndSail, _startPosX.Value, _startPosY.Value + 35, 45, 5);
}
// парус
if (catamaran.Sail)
{
Point[] sailFigure =
{
new Point(_startPosX.Value + 25,_startPosY.Value + 25),
new Point(_startPosX.Value + 35 ,_startPosY.Value + 25),
new Point(_startPosX.Value + 25,_startPosY.Value),
};
g.FillPolygon(brFloatsAndSail, sailFigure);
}
}
}

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCatamaran.Entities;
/// <summary>
/// класс-сущность "лодка"
/// </summary>
public class EntityBoat
{
/// <summary>
/// Скорость
/// </summary>
public int Speed { get;private set; }
/// <summary>
/// Вес авто
/// </summary>
public double Weight { get;private set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
/// Шаг перемещения
/// </summary>
public double Step => Speed * 100 / Weight;
/// <summary>
/// конструктор сущности
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес авто</param>
/// <param name="bodyColor">Основной цвет</param>
public EntityBoat(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}

View File

@ -0,0 +1,35 @@
namespace ProjectCatamaran.Entities;
/// <summary>
/// Класс-сущность "Катамарана"
/// </summary>
public class EntityCatamaran : EntityBoat
{
/// <summary>
/// Дополнительный цвет(для опциональных элементов)
/// </summary>
public Color AdditionalColor { get; private set; }
/// <summary>
/// Признак (опция) наличие поплавков
/// </summary>
public bool Floats { get; private set; }
/// <summary>
/// Признак (опция) наличие паруса
/// </summary>
public bool Sail { get; private set; }
/// <summary>
/// Инициализация полей обьекта-класса спортивного автомобиля
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес авто</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет(для опциональных элементов)</param>
/// <param name="floats">Признак (опция) наличие плавников</param>
/// <param name="sail">Признак (опция) наличие паруса</param>
public EntityCatamaran(int speed, double weight, Color bodyColor, Color additionalColor, bool floats, bool sail)
: base(speed,weight,bodyColor)
{
AdditionalColor = additionalColor;
Floats = floats;
Sail = sail;
}
}

View File

@ -1,39 +0,0 @@
namespace ProjectCatamaran
{
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
}
}

View File

@ -1,10 +0,0 @@
namespace ProjectCatamaran
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,173 @@
namespace ProjectCatamaran
{
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()
{
groupBoxTools = new GroupBox();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonRemoveBoat = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonAddCatamaran = new Button();
buttonAddBoat = new Button();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
groupBoxTools.Controls.Add(buttonRefresh);
groupBoxTools.Controls.Add(buttonGoToCheck);
groupBoxTools.Controls.Add(buttonRemoveBoat);
groupBoxTools.Controls.Add(maskedTextBoxPosition);
groupBoxTools.Controls.Add(buttonAddCatamaran);
groupBoxTools.Controls.Add(buttonAddBoat);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(631, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(169, 450);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(6, 381);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(157, 39);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(6, 324);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(157, 39);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonRemoveBoat
//
buttonRemoveBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveBoat.Location = new Point(6, 279);
buttonRemoveBoat.Name = "buttonRemoveBoat";
buttonRemoveBoat.Size = new Size(157, 39);
buttonRemoveBoat.TabIndex = 4;
buttonRemoveBoat.Text = "Удалить лодку";
buttonRemoveBoat.UseVisualStyleBackColor = true;
buttonRemoveBoat.Click += ButtonRemoveBoat_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(1, 233);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(162, 23);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonAddCatamaran
//
buttonAddCatamaran.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddCatamaran.Location = new Point(6, 125);
buttonAddCatamaran.Name = "buttonAddCatamaran";
buttonAddCatamaran.Size = new Size(157, 39);
buttonAddCatamaran.TabIndex = 2;
buttonAddCatamaran.Text = "Добавление катамарана";
buttonAddCatamaran.UseVisualStyleBackColor = true;
buttonAddCatamaran.Click += ButtonAddCatamaran_Click;
//
// buttonAddBoat
//
buttonAddBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddBoat.Location = new Point(6, 80);
buttonAddBoat.Name = "buttonAddBoat";
buttonAddBoat.Size = new Size(157, 39);
buttonAddBoat.TabIndex = 1;
buttonAddBoat.Text = "Добавление лодки";
buttonAddBoat.UseVisualStyleBackColor = true;
buttonAddBoat.Click += ButtonAddBoat_Click;
//
// comboBoxSelectorCompany
//
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(6, 22);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(157, 23);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
//
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(631, 450);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// FormBoatCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormBoatCollection";
Text = "Коллекция лодок";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
private Button buttonAddCatamaran;
private Button buttonAddBoat;
private ComboBox comboBoxSelectorCompany;
private MaskedTextBox maskedTextBoxPosition;
private PictureBox pictureBox;
private Button buttonRemoveBoat;
private Button buttonRefresh;
private Button buttonGoToCheck;
}
}

View File

@ -0,0 +1,149 @@
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 ProjectCatamaran.CollectionGenericObjects;
using ProjectCatamaran.Drawnings;
namespace ProjectCatamaran;
public partial class FormBoatCollection : Form
{
private AbstractCompany? _company;
public FormBoatCollection()
{
InitializeComponent();
}
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new Harbour(pictureBox.Width, pictureBox.Height,
new MassiveGenericObjects<DrawningBoat?>());
break;
}
}
private void CreateObject(string type)
{
if (_company == null)
{
return;
}
Random random = new();
DrawningBoat drawningBoat;
switch (type)
{
case nameof(DrawningBoat):
drawningBoat = new DrawningBoat(random.Next(100, 300), random.Next(1000, 3000),
GetColor(random));
break;
case nameof(DrawningCatamaran):
drawningBoat = new DrawningCatamaran(random.Next(100, 300), random.Next(1000, 3000),
GetColor(random), GetColor(random),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
if (_company + drawningBoat != -1)
{
MessageBox.Show(("Объект добавлен"));
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
private static Color GetColor(Random random)
{
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;
}
return color;
}
private void ButtonAddBoat_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawningBoat));
}
private void ButtonAddCatamaran_Click(object sender, EventArgs e)
{
CreateObject(nameof(DrawningCatamaran));
}
private void ButtonRemoveBoat_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
{
return;
}
if (MessageBox.Show("Удалить объект", "Удаление", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_company - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonGoToCheck_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
DrawningBoat? boat = null;
int counter = 100;
while (boat == null)
{
boat = _company.GetRandomObject();
counter--;
if (counter <= 0)
break;
}
if (boat == null)
return;
FormCatamaran form = new()
{
SetBoat = boat
};
form.ShowDialog();
}
private void ButtonRefresh_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
pictureBox.Image = _company.Show();
}
}

View 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>

View File

@ -0,0 +1,149 @@
namespace ProjectCatamaran
{
partial class FormCatamaran
{
/// <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()
{
pictureBoxCatamaran = new PictureBox();
buttonUp = new Button();
buttonRight = new Button();
buttonLeft = new Button();
buttonDown = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
colorDialog1 = new ColorDialog();
((System.ComponentModel.ISupportInitialize)pictureBoxCatamaran).BeginInit();
SuspendLayout();
//
// pictureBoxCatamaran
//
pictureBoxCatamaran.Dock = DockStyle.Fill;
pictureBoxCatamaran.Location = new Point(0, 0);
pictureBoxCatamaran.Name = "pictureBoxCatamaran";
pictureBoxCatamaran.Size = new Size(800, 450);
pictureBoxCatamaran.TabIndex = 0;
pictureBoxCatamaran.TabStop = false;
//
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.fdcc84704da3ed14a83779fbf91e00fb;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(709, 359);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(35, 35);
buttonUp.TabIndex = 2;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.right;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(750, 400);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(35, 35);
buttonRight.TabIndex = 3;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.left;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(668, 400);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(35, 35);
buttonLeft.TabIndex = 4;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
//
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.down;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(709, 400);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(35, 35);
buttonDown.TabIndex = 5;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
comboBoxStrategy.Location = new Point(668, 12);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(121, 23);
comboBoxStrategy.TabIndex = 7;
//
// buttonStrategyStep
//
buttonStrategyStep.Location = new Point(709, 41);
buttonStrategyStep.Name = "buttonStrategyStep";
buttonStrategyStep.RightToLeft = RightToLeft.Yes;
buttonStrategyStep.Size = new Size(75, 23);
buttonStrategyStep.TabIndex = 8;
buttonStrategyStep.Text = "Шаг";
buttonStrategyStep.UseVisualStyleBackColor = true;
buttonStrategyStep.Click += ButtonStrategyStep_Click;
//
// FormCatamaran
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(buttonRight);
Controls.Add(buttonUp);
Controls.Add(pictureBoxCatamaran);
Name = "FormCatamaran";
Text = "Катамаран";
((System.ComponentModel.ISupportInitialize)pictureBoxCatamaran).EndInit();
ResumeLayout(false);
}
#endregion
private PictureBox pictureBoxCatamaran;
private Button buttonUp;
private Button buttonRight;
private Button buttonLeft;
private Button buttonDown;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
private ColorDialog colorDialog1;
}
}

View File

@ -0,0 +1,119 @@
using ProjectCatamaran.Drawnings;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ProjectCatamaran.MovementStrategy;
namespace ProjectCatamaran
{
public partial class FormCatamaran : Form
{
private DrawningBoat? _drawningBoat;
private AbstractStrategy? _strategy;
public DrawningBoat SetBoat
{
set
{
_drawningBoat = value;
_drawningBoat.SetPictureSize(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
public FormCatamaran()
{
InitializeComponent();
_strategy = null;
}
private void Draw()
{
if (_drawningBoat == null)
{
return;
}
Bitmap bmp = new(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningBoat.DrawTransport(gr);
pictureBoxCatamaran.Image = bmp;
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningBoat == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
{
case "buttonUp":
result = _drawningBoat.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
result = _drawningBoat.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
result = _drawningBoat.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result = _drawningBoat.MoveTransport(DirectionType.Right);
break;
}
if (result)
{
Draw();
}
}
/// <summary>
/// Обработка нажатия кнопки "Шаг"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonStrategyStep_Click(object sender, EventArgs e)
{
if (_drawningBoat == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_strategy = comboBoxStrategy.SelectedIndex switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_strategy == null)
{
return;
}
_strategy.SetData(new MoveableBoat(_drawningBoat),
pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
}
if (_strategy == null)
{
return;
}
comboBoxStrategy.Enabled = false;
_strategy.MakeStep();
Draw();
if (_strategy.GetStatus() == StrategyStatus.Finish)
{
comboBoxStrategy.Enabled = true;
_strategy = null;
}
}
}
}

View File

@ -0,0 +1,123 @@
<?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>
<metadata name="colorDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCatamaran.MovementStrategy;
public abstract class AbstractStrategy
{
/// <summary>
/// Перемещаемый объект
/// </summary>
private IMoveableObject? _moveableObject;
/// <summary>
/// Статус перемещения
/// </summary>
private StrategyStatus _state = StrategyStatus.NotInit;
/// <summary>
/// Ширина поля
/// </summary>
protected int FieldWidth { get; private set; }
/// <summary>
/// Высота поля
/// </summary>
protected int FieldHeight { get; private set; }
/// <summary>
/// Статус перемещения
/// </summary>
public StrategyStatus 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 = StrategyStatus.NotInit;
return;
}
_state = StrategyStatus.InProgress;
_moveableObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
/// <summary>
/// Шаг перемещения
/// </summary>
public void MakeStep()
{
if (_state != StrategyStatus.InProgress)
{
return;
}
if (IsTargetDestination())
{
_state = StrategyStatus.Finish;
return;
}
MoveToTarget();
}
/// <summary>
/// Перемещение влево
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
/// <summary>
/// Перемещение вправо
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveRight() => MoveTo(MovementDirection.Right);
/// <summary>
/// Перемещение вверх
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveUp() => MoveTo(MovementDirection.Up);
/// <summary>
/// Перемещение вниз
/// </summary>
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
protected bool MoveDown() => MoveTo(MovementDirection.Down);
/// <summary>
/// Параметры объекта
/// </summary>
protected ObjectParameters? GetObjectParameters =>
_moveableObject?.GetObjectPosition;
/// <summary>
/// Шаг объекта
/// </summary>
/// <returns></returns>
protected int? GetStep()
{
if (_state != StrategyStatus.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
/// <summary>
/// Перемещение к цели
/// </summary>
protected abstract void MoveToTarget();
/// <summary>
/// Достигнута ли цель
/// </summary>
/// <returns></returns>
protected abstract bool IsTargetDestination();
/// <summary>
/// Попытка перемещения в требуемом направлении
/// </summary>
/// <param name="movementDirection">Направление</param>
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
private bool MoveTo(MovementDirection movementDirection)
{
if (_state != StrategyStatus.InProgress)
{
return false;
}
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCatamaran.MovementStrategy;
public interface IMoveableObject
{
/// <summary>
/// Получение координаты объекта
/// </summary>
ObjectParameters? GetObjectPosition { get; }
/// <summary>
/// Шаг объекта
/// </summary>
int GetStep { get; }
/// <summary>
/// Попытка переместить объект в указанном направлении
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - объект перемещен, false - перемещение невозможно</returns>
bool TryMoveObject(MovementDirection direction);
}

View File

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCatamaran.MovementStrategy;
public class MoveToBorder : AbstractStrategy
{
/// <summary>
/// движение до правого края
/// </summary>
protected override void MoveToTarget()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
return;
if (objParams.RightBorder + GetStep() <= FieldWidth)
MoveRight();
if (objParams.DownBorder + GetStep() <= FieldHeight)
MoveDown();
}
/// <summary>
/// проверка достижения цели
/// </summary>
/// <returns>true - достиг , false - нет </returns>
protected override bool IsTargetDestination()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
return false;
return objParams.RightBorder + GetStep() > FieldWidth &&
objParams.DownBorder + GetStep() > FieldHeight ;
}
}

View File

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCatamaran.MovementStrategy;
/// <summary>
/// стратегия перемещения обьекта в центр экрана
/// </summary>
public class MoveToCenter : AbstractStrategy
{
protected override void MoveToTarget()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
protected override bool IsTargetDestination()
{
ObjectParameters? objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2
&& objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2
&& objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
}

View File

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectCatamaran.Drawnings;
namespace ProjectCatamaran.MovementStrategy
{
internal class MoveableBoat : IMoveableObject
{
/// <summary>
/// Поле-объект класса DrawningBoat или его наследника
/// </summary>
private readonly DrawningBoat? _boat = null;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="car">Объект класса DrawningBoat</param>
public MoveableBoat(DrawningBoat boat)
{
_boat = boat;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_boat == null || _boat.EntityBoat == null || !_boat.GetPosX.HasValue
|| !_boat.GetPosY.HasValue)
{
return null;
}
return new ObjectParameters(_boat.GetPosX.Value, _boat.GetPosY.Value,
_boat.GetWidth, _boat.GetHeight);
}
}
public int GetStep => (int)(_boat?.EntityBoat?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
if (_boat == null || _boat.EntityBoat == null)
{
return false;
}
return _boat.MoveTransport(GetDirectionType(direction));
}
/// <summary>
/// Конвертация из MovementDirection в DirectionType
/// </summary>
/// <param name="direction"></param>
/// <returns>DirectionType</returns>
private static DirectionType GetDirectionType(MovementDirection direction)
{
return direction switch
{
MovementDirection.Left => DirectionType.Left,
MovementDirection.Right => DirectionType.Right,
MovementDirection.Up => DirectionType.Up,
MovementDirection.Down => DirectionType.Down,
_ => DirectionType.Unknown
};
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCatamaran.MovementStrategy;
public enum MovementDirection
{
/// <summary>
/// Вверх
/// </summary>
Up = 1,
/// <summary>
/// Вниз
/// </summary>
Down = 2,
/// <summary>
/// Влево
/// </summary>
Left = 3,
/// <summary>
/// Вправо
/// </summary>
Right = 4
}

View File

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCatamaran.MovementStrategy;
public class ObjectParameters
{
/// <summary>
/// Координата X
/// </summary>
private readonly int _x;
/// <summary>
/// Координата Y
/// </summary>
private readonly int _y;
/// <summary>
/// Ширина объекта
/// </summary>
private readonly int _width;
/// <summary>
/// Высота объекта
/// </summary>
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;
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCatamaran.MovementStrategy;
public enum StrategyStatus
{
NotInit,
InProgress,
Finish
}

View File

@ -11,7 +11,7 @@ namespace ProjectCatamaran
// 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());
}
}
}

View File

@ -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>

View File

@ -0,0 +1,103 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ProjectCatamaran.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[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>
/// Returns the cached ResourceManager instance used by this class.
/// </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("ProjectCatamaran.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap down {
get {
object obj = ResourceManager.GetObject("down", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap fdcc84704da3ed14a83779fbf91e00fb {
get {
object obj = ResourceManager.GetObject("fdcc84704da3ed14a83779fbf91e00fb", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap left {
get {
object obj = ResourceManager.GetObject("left", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap right {
get {
object obj = ResourceManager.GetObject("right", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -0,0 +1,133 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="down" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\down.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="fdcc84704da3ed14a83779fbf91e00fb" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\fdcc84704da3ed14a83779fbf91e00fb.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="left" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\left.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="right" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\right.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB