Laba03
This commit is contained in:
parent
bc9b12c8fe
commit
5c698b6514
@ -90,8 +90,7 @@ namespace ProjectContainerShip.MovementStrategy
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Параметры объекта
|
/// Параметры объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected ObjectParameters? GetObjectParameters =>
|
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
|
||||||
_moveableObject?.GetObjectPosition;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Шаг объекта
|
/// Шаг объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
146
ContainerShip/ContainerShip/ContainerGenericCollection.cs
Normal file
146
ContainerShip/ContainerShip/ContainerGenericCollection.cs
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectContainerShip.DrawningObjects;
|
||||||
|
using ProjectContainerShip.Generics;
|
||||||
|
using ProjectContainerShip.MovementStrategy;
|
||||||
|
|
||||||
|
namespace ProjectContainerShip.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный класс для набора объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <typeparam name="U"></typeparam>
|
||||||
|
internal class ContainerGenericCollection<T, U>
|
||||||
|
where T : DrawningShip
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeWidth = 200;
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (высота)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeHeight = 90;
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
public ContainerGenericCollection(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 +(ContainerGenericCollection<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 -(ContainerGenericCollection<T, U> collect, int
|
||||||
|
pos)
|
||||||
|
{
|
||||||
|
T? obj = collect._collection.Get(pos);
|
||||||
|
if (obj is not null)
|
||||||
|
{
|
||||||
|
collect._collection.Remove(pos);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта IMoveableObject
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pos"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)_collection.Get(pos)?.GetObjectPosition;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Вывод всего набора объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Bitmap ShowContainer()
|
||||||
|
{
|
||||||
|
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, 2);
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||||
|
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth , j *
|
||||||
|
_placeSizeHeight);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||||
|
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Метод прорисовки объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
private void DrawObjects(Graphics g)
|
||||||
|
{
|
||||||
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
|
{
|
||||||
|
DrawningShip? ship = _collection.Get(i);
|
||||||
|
if (ship == null)
|
||||||
|
continue;
|
||||||
|
int row = height - 1 - (i / width);
|
||||||
|
int col = width - 1 - (i % width);
|
||||||
|
ship.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight + 25 );
|
||||||
|
ship.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -39,24 +39,15 @@ namespace ProjectContainerShip.DrawningObjects
|
|||||||
}
|
}
|
||||||
Brush additionalBrush = new SolidBrush(containerShip.AdditionalColor);
|
Brush additionalBrush = new SolidBrush(containerShip.AdditionalColor);
|
||||||
// Контейнер
|
// Контейнер
|
||||||
if (containerShip.Container)
|
|
||||||
{
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX + 55, _startPosY + 7, 35, 5);
|
g.FillRectangle(additionalBrush, _startPosX + 55, _startPosY + 7, 35, 5);
|
||||||
}
|
|
||||||
//кран
|
//кран
|
||||||
if (containerShip.Crane)
|
|
||||||
{
|
|
||||||
Brush brBl = new SolidBrush(Color.Black);
|
Brush brBl = new SolidBrush(Color.Black);
|
||||||
g.FillRectangle(brBl, _startPosX + 110, _startPosY + 0, 3, 12);
|
g.FillRectangle(brBl, _startPosX + 110, _startPosY + 0, 3, 12);
|
||||||
g.FillRectangle(brBl, _startPosX + 105, _startPosY + 1, 20, 2);
|
g.FillRectangle(brBl, _startPosX + 105, _startPosY + 1, 20, 2);
|
||||||
}
|
|
||||||
// несколько контенеров
|
// несколько контенеров
|
||||||
if (containerShip.Container)
|
|
||||||
{
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX + 55, _startPosY + 2, 35, 5);
|
g.FillRectangle(additionalBrush, _startPosX + 55, _startPosY + 2, 35, 5);
|
||||||
g.FillRectangle(additionalBrush, _startPosX + 135, _startPosY + 7, 35, 5);
|
g.FillRectangle(additionalBrush, _startPosX + 135, _startPosY + 7, 35, 5);
|
||||||
g.FillRectangle(additionalBrush, _startPosX + 135, _startPosY + 2, 35, 5);
|
g.FillRectangle(additionalBrush, _startPosX + 135, _startPosY + 2, 35, 5);
|
||||||
}
|
|
||||||
base.DrawTransport(g);
|
base.DrawTransport(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ using static ProjectContainerShip.Direction;
|
|||||||
namespace ProjectContainerShip.MovementStrategy
|
namespace ProjectContainerShip.MovementStrategy
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningShip (паттерн Adapter)
|
/// Реализация интерфейса IMoveableObject для работы с объектом DrawningShip
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DrawningObjectShip : IMoveableObject
|
public class DrawningObjectShip : IMoveableObject
|
||||||
{
|
{
|
||||||
|
@ -97,7 +97,6 @@ namespace ProjectContainerShip.DrawningObjects
|
|||||||
else _startPosX = 0;
|
else _startPosX = 0;
|
||||||
if ((y > 0) && (y < _pictureHeight))
|
if ((y > 0) && (y < _pictureHeight))
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
|
|
||||||
else _startPosY = 0;
|
else _startPosY = 0;
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
@ -182,18 +181,18 @@ namespace ProjectContainerShip.DrawningObjects
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Brush bodyBrush = new SolidBrush(EntityShip.BodyColor);
|
||||||
//границы корабля
|
//границы корабля
|
||||||
Brush brRD = new SolidBrush(Color.Red);
|
Brush brRd = new SolidBrush(Color.Red);
|
||||||
Point point1 = new Point(_startPosX, _startPosY + 12);
|
Point point1 = new Point(_startPosX, _startPosY + 12);
|
||||||
Point point2 = new Point(_startPosX + 25, _startPosY + 35);
|
Point point2 = new Point(_startPosX + 25, _startPosY + 35);
|
||||||
Point point3 = new Point(_startPosX + 175, _startPosY + 35);
|
Point point3 = new Point(_startPosX + 175, _startPosY + 35);
|
||||||
Point point4 = new Point(_startPosX + 200, _startPosY + 12);
|
Point point4 = new Point(_startPosX + 200, _startPosY + 12);
|
||||||
Point[] curvePoints1 = { point1, point2, point3, point4 };
|
Point[] curvePoints1 = { point1, point2, point3, point4 };
|
||||||
g.FillPolygon(brRD, curvePoints1);
|
g.FillPolygon(brRd, curvePoints1);
|
||||||
|
|
||||||
//граница палубы
|
//граница палубы
|
||||||
Brush brBlue = new SolidBrush(Color.Blue);
|
Brush brBlue = new SolidBrush(Color.Blue);
|
||||||
g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 0, 16, 12);
|
g.FillRectangle(bodyBrush, _startPosX + 35, _startPosY + 0, 16, 12);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectContainerShip
|
|
||||||
{
|
|
||||||
public class EntityContainer
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Скорость
|
|
||||||
/// </summary>
|
|
||||||
public int Speed { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Вес
|
|
||||||
/// </summary>
|
|
||||||
public double Weight { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Основной цвет
|
|
||||||
/// </summary>
|
|
||||||
public Color BodyColor { get; private set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Дополнительный цвет (для опциональных элементов)
|
|
||||||
/// </summary>
|
|
||||||
public double Step => (double)Speed * 100 / Weight;
|
|
||||||
/// <summary>
|
|
||||||
/// Инициализация полей объекта-класса конетейнеровоза
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="speed">Скорость</param>
|
|
||||||
/// <param name="weight">Вес Контейнеровоза</param>
|
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
|
||||||
public void Init(int speed, double weight, Color bodyColor)
|
|
||||||
{
|
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -28,8 +28,8 @@ namespace ProjectContainerShip.Entities
|
|||||||
/// <param name="weight">Вес </param>
|
/// <param name="weight">Вес </param>
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
/// <param name="Crane">Признак наличия крана</param>
|
/// <param name="сrane">Признак наличия труб</param>
|
||||||
/// <param name="Container">Признак наличия контейнеров</param>
|
/// <param name="сontainer">Признак наличия топлива</param>
|
||||||
public EntityContainerShip(int speed, double weight, Color bodyColor, Color additionalColor, bool crane, bool container) : base(speed, weight, bodyColor)
|
public EntityContainerShip(int speed, double weight, Color bodyColor, Color additionalColor, bool crane, bool container) : base(speed, weight, bodyColor)
|
||||||
{
|
{
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
namespace ProjectWarmlyShip
|
namespace ProjectContainerShip
|
||||||
{
|
{
|
||||||
partial class FormContainerShip
|
partial class FormContainerShip
|
||||||
{
|
{
|
||||||
@ -29,7 +29,7 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormContainerShip));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormContainerShip));
|
||||||
pictureBoxWarmlyShip = new PictureBox();
|
pictureBoxContainerShip = new PictureBox();
|
||||||
buttonCreate = new Button();
|
buttonCreate = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
@ -38,19 +38,20 @@
|
|||||||
comboBoxStrategy = new ComboBox();
|
comboBoxStrategy = new ComboBox();
|
||||||
buttonStep = new Button();
|
buttonStep = new Button();
|
||||||
buttonCreateDeckShip = new Button();
|
buttonCreateDeckShip = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyShip).BeginInit();
|
buttonSelectShip = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxContainerShip).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBoxWarmlyShip
|
// pictureBoxContainerShip
|
||||||
//
|
//
|
||||||
pictureBoxWarmlyShip.Dock = DockStyle.Fill;
|
pictureBoxContainerShip.Dock = DockStyle.Fill;
|
||||||
pictureBoxWarmlyShip.Location = new Point(0, 0);
|
pictureBoxContainerShip.Location = new Point(0, 0);
|
||||||
pictureBoxWarmlyShip.Margin = new Padding(3, 4, 3, 4);
|
pictureBoxContainerShip.Margin = new Padding(3, 4, 3, 4);
|
||||||
pictureBoxWarmlyShip.Name = "pictureBoxWarmlyShip";
|
pictureBoxContainerShip.Name = "pictureBoxContainerShip";
|
||||||
pictureBoxWarmlyShip.Size = new Size(1010, 615);
|
pictureBoxContainerShip.Size = new Size(1010, 615);
|
||||||
pictureBoxWarmlyShip.SizeMode = PictureBoxSizeMode.AutoSize;
|
pictureBoxContainerShip.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
pictureBoxWarmlyShip.TabIndex = 0;
|
pictureBoxContainerShip.TabIndex = 0;
|
||||||
pictureBoxWarmlyShip.TabStop = false;
|
pictureBoxContainerShip.TabStop = false;
|
||||||
//
|
//
|
||||||
// buttonCreate
|
// buttonCreate
|
||||||
//
|
//
|
||||||
@ -142,11 +143,23 @@
|
|||||||
buttonCreateDeckShip.UseVisualStyleBackColor = true;
|
buttonCreateDeckShip.UseVisualStyleBackColor = true;
|
||||||
buttonCreateDeckShip.Click += buttonCreateDeckShip_Click;
|
buttonCreateDeckShip.Click += buttonCreateDeckShip_Click;
|
||||||
//
|
//
|
||||||
|
// buttonSelectShip
|
||||||
|
//
|
||||||
|
buttonSelectShip.Location = new Point(317, 564);
|
||||||
|
buttonSelectShip.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
buttonSelectShip.Name = "buttonSelectShip";
|
||||||
|
buttonSelectShip.Size = new Size(86, 31);
|
||||||
|
buttonSelectShip.TabIndex = 9;
|
||||||
|
buttonSelectShip.Text = "Выбрать";
|
||||||
|
buttonSelectShip.UseVisualStyleBackColor = true;
|
||||||
|
buttonSelectShip.Click += buttonSelectShip_Click;
|
||||||
|
//
|
||||||
// FormContainerShip
|
// FormContainerShip
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(1010, 615);
|
ClientSize = new Size(1010, 615);
|
||||||
|
Controls.Add(buttonSelectShip);
|
||||||
Controls.Add(buttonCreateDeckShip);
|
Controls.Add(buttonCreateDeckShip);
|
||||||
Controls.Add(buttonStep);
|
Controls.Add(buttonStep);
|
||||||
Controls.Add(comboBoxStrategy);
|
Controls.Add(comboBoxStrategy);
|
||||||
@ -155,19 +168,19 @@
|
|||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonCreate);
|
Controls.Add(buttonCreate);
|
||||||
Controls.Add(pictureBoxWarmlyShip);
|
Controls.Add(pictureBoxContainerShip);
|
||||||
Margin = new Padding(3, 4, 3, 4);
|
Margin = new Padding(3, 4, 3, 4);
|
||||||
Name = "FormContainerShip";
|
Name = "FormContainerShip";
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
Text = "WarmlyShip";
|
Load += FormContainerShip_Load;
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyShip).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxContainerShip).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
PerformLayout();
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxWarmlyShip;
|
private PictureBox pictureBoxContainerShip;
|
||||||
private Button buttonCreate;
|
private Button buttonCreate;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
@ -176,5 +189,6 @@
|
|||||||
private ComboBox comboBoxStrategy;
|
private ComboBox comboBoxStrategy;
|
||||||
private Button buttonStep;
|
private Button buttonStep;
|
||||||
private Button buttonCreateDeckShip;
|
private Button buttonCreateDeckShip;
|
||||||
|
private Button buttonSelectShip;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,7 @@ using ProjectContainerShip.DrawningObjects;
|
|||||||
using ProjectContainerShip.MovementStrategy;
|
using ProjectContainerShip.MovementStrategy;
|
||||||
using static ProjectContainerShip.Direction;
|
using static ProjectContainerShip.Direction;
|
||||||
|
|
||||||
namespace ProjectWarmlyShip
|
namespace ProjectContainerShip
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ôîðìà ðàáîòû ñ îáúåêòîì "Êîíòåéíåðîâîç"
|
/// Ôîðìà ðàáîòû ñ îáúåêòîì "Êîíòåéíåðîâîç"
|
||||||
@ -17,14 +17,15 @@ namespace ProjectWarmlyShip
|
|||||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private AbstractStrategy? _abstractStrategy;
|
private AbstractStrategy? _abstractStrategy;
|
||||||
|
public DrawningShip? SelectedShip { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Èíèöèàëèçàöèÿ ôîðìû
|
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormContainerShip()
|
public FormContainerShip()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
comboBoxStrategy.Items.Add(0);
|
_abstractStrategy = null;
|
||||||
comboBoxStrategy.Items.Add(1);
|
_drawingContainerShip = null;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ìåòîä ïðîðèñîâêè
|
/// Ìåòîä ïðîðèñîâêè
|
||||||
@ -35,10 +36,10 @@ namespace ProjectWarmlyShip
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Bitmap bmp = new(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
Bitmap bmp = new(pictureBoxContainerShip.Width, pictureBoxContainerShip.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawingContainerShip.DrawTransport(gr);
|
_drawingContainerShip.DrawTransport(gr);
|
||||||
pictureBoxWarmlyShip.Image = bmp;
|
pictureBoxContainerShip.Image = bmp;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||||
@ -48,8 +49,15 @@ namespace ProjectWarmlyShip
|
|||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
private void buttonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
_drawingContainerShip = new DrawningShip(random.Next(100, 300), random.Next(1000, 3000),
|
Color color = Color.FromArgb(random.Next(0, 256),
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialog = new();
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialog.Color;
|
||||||
|
}
|
||||||
|
_drawingContainerShip = new DrawningShip(random.Next(100, 300), random.Next(1000, 3000), color,
|
||||||
|
pictureBoxContainerShip.Width, pictureBoxContainerShip.Height);
|
||||||
_drawingContainerShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawingContainerShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
@ -61,11 +69,21 @@ namespace ProjectWarmlyShip
|
|||||||
private void buttonCreateDeckShip_Click(object sender, EventArgs e)
|
private void buttonCreateDeckShip_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
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));
|
||||||
|
ColorDialog dialog2 = new();
|
||||||
|
if (dialog2.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = dialog2.Color;
|
||||||
|
}
|
||||||
_drawingContainerShip = new DrawningContainerShip(random.Next(100, 300), random.Next(1000, 3000),
|
_drawingContainerShip = new DrawningContainerShip(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
color, dopColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
pictureBoxContainerShip.Width, pictureBoxContainerShip.Height);
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
|
||||||
pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
|
||||||
_drawingContainerShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawingContainerShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
@ -116,13 +134,13 @@ namespace ProjectWarmlyShip
|
|||||||
{
|
{
|
||||||
0 => new MoveToCenter(),
|
0 => new MoveToCenter(),
|
||||||
1 => new MoveToBorder(),
|
1 => new MoveToBorder(),
|
||||||
|
_ => null,
|
||||||
};
|
};
|
||||||
if (_abstractStrategy == null)
|
if (_abstractStrategy == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_abstractStrategy.SetData(new DrawningObjectShip(_drawingContainerShip), pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
_abstractStrategy.SetData(new DrawningObjectShip(_drawingContainerShip), pictureBoxContainerShip.Width, pictureBoxContainerShip.Height);
|
||||||
comboBoxStrategy.Enabled = false;
|
comboBoxStrategy.Enabled = false;
|
||||||
}
|
}
|
||||||
if (_abstractStrategy == null)
|
if (_abstractStrategy == null)
|
||||||
@ -137,5 +155,13 @@ namespace ProjectWarmlyShip
|
|||||||
_abstractStrategy = null;
|
_abstractStrategy = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void buttonSelectShip_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedShip = _drawingContainerShip;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
|
private void FormContainerShip_Load(object sender, EventArgs e)
|
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SYDj
|
||||||
du+Z0XrADVMX/WJ8axLheExqxVMCHJfJrHhOgKPZJrXOcpEIxqKdCu/Z8orxOakVlwlw9Eep9WMCHM1b
|
du+Z0XrADVMX/WJ8axLheExqxVMCHJfJrHhOgKPZJrXOcpEIxqKdCu/Z8orxOakVlwlw9Eep9WMCHM1b
|
||||||
@ -140,7 +140,7 @@
|
|||||||
iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAABGdBTUEAALGPC/xhBQAAAG9QTFRF////
|
iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAABGdBTUEAALGPC/xhBQAAAG9QTFRF////
|
||||||
AAAAWVlZ8fHx9PT0REREtLS0Ojo6+Pj4a2trp6enj4+P3t7eXl5efX1919fXh4eHw8PD6+vrdXV10dHR
|
AAAAWVlZ8fHx9PT0REREtLS0Ojo6+Pj4a2trp6enj4+P3t7eXl5efX1919fXh4eHw8PD6+vrdXV10dHR
|
||||||
5ubmDAwMy8vLTU1NlZWVvLy8iIiINjY2nJycFhYWYWFhJycnUVFRHR0dr6+vKioqoesKnwAAAAlwSFlz
|
5ubmDAwMy8vLTU1NlZWVvLy8iIiINjY2nJycFhYWYWFhJycnUVFRHR0dr6+vKioqoesKnwAAAAlwSFlz
|
||||||
AAAOvgAADr4B6kKxwAAAA01JREFUeF7t3dluo0AURVHwEGdO7DjznPT/f2PHcAgULsD90FKd0l5P7jKR
|
AAAOvAAADrwBlbxySQAAA01JREFUeF7t3dluo0AURVHwEGdO7DjznPT/f2PHcAgULsD90FKd0l5P7jKR
|
||||||
2FF0jYuWXQAAAAAAAAAAAAAAAADA/7JZP643epyls3LnTP/K0GUVWJaX+nd2vhVYlt9aycyV8nautJaV
|
2FF0jYuWXQAAAAAAAAAAAAAAAADA/7JZP643epyls3LnTP/K0GUVWJaX+nd2vhVYlt9aycyV8nautJaV
|
||||||
xZvqdt4WWs3JUnG1pVYz0kyZRnbTpp0yjcymzVZZXVs9l4W5ok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nIQQSrmFW///b+wCR6LY/Vg3nqP3+cJE
|
||||||
O5Nhh1kjrSQ3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAACMyVQ/Tc02P1J6WuuToUP6dKfPds6VYErXGjFz
|
O5Nhh1kjrSQ3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAACMyVQ/Tc02P1J6WuuToUP6dKfPds6VYErXGjFz
|
||||||
pfTCRkNWpgtl926uQSeHeMR8WWjUyFcJfpho2MdGmWVuD9PpTyWWPSngYvuqxLKVAi7OlFfxqICLnfIq
|
pfTCRkNWpgtl926uQSeHeMR8WWjUyFcJfpho2MdGmWVuD9PpTyWWPSngYvuqxLKVAi7OlFfxqICLnfIq
|
||||||
bhQwseyW4MJsOrP+pcSy1VIRE3fKq7hVwMW98iouFTCxbJVX9mC2Llw/KLFsYlaCl8qruFfAxa3yKsxm
|
bhQwseyW4MJsOrP+pcSy1VIRE3fKq7hVwMW98iouFTCxbJVX9mC2Llw/KLFsYlaCl8qruFfAxa3yKsxm
|
||||||
|
121
ContainerShip/ContainerShip/FormShipCollection.Designer.cs
generated
Normal file
121
ContainerShip/ContainerShip/FormShipCollection.Designer.cs
generated
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
namespace ProjectContainerShip
|
||||||
|
{
|
||||||
|
partial class FormShipCollection
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
pictureBoxCollection = new PictureBox();
|
||||||
|
maskedTextBoxNumber = new MaskedTextBox();
|
||||||
|
buttonAddShip = new Button();
|
||||||
|
buttonRemoveShip = new Button();
|
||||||
|
buttonRefreshCollection = new Button();
|
||||||
|
groupBox1 = new GroupBox();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
groupBox1.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
pictureBoxCollection.Dock = DockStyle.Fill;
|
||||||
|
pictureBoxCollection.Location = new Point(0, 0);
|
||||||
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
pictureBoxCollection.Size = new Size(932, 503);
|
||||||
|
pictureBoxCollection.TabIndex = 0;
|
||||||
|
pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
maskedTextBoxNumber.Location = new Point(6, 120);
|
||||||
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
maskedTextBoxNumber.Size = new Size(108, 27);
|
||||||
|
maskedTextBoxNumber.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// buttonAddShip
|
||||||
|
//
|
||||||
|
buttonAddShip.Location = new Point(6, 57);
|
||||||
|
buttonAddShip.Name = "buttonAddShip";
|
||||||
|
buttonAddShip.Size = new Size(108, 30);
|
||||||
|
buttonAddShip.TabIndex = 2;
|
||||||
|
buttonAddShip.Text = "Добавить ";
|
||||||
|
buttonAddShip.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddShip.Click += ButtonAddShip_Click;
|
||||||
|
//
|
||||||
|
// buttonRemoveShip
|
||||||
|
//
|
||||||
|
buttonRemoveShip.Location = new Point(6, 166);
|
||||||
|
buttonRemoveShip.Name = "buttonRemoveShip";
|
||||||
|
buttonRemoveShip.Size = new Size(108, 30);
|
||||||
|
buttonRemoveShip.TabIndex = 3;
|
||||||
|
buttonRemoveShip.Text = "Удалить ";
|
||||||
|
buttonRemoveShip.UseVisualStyleBackColor = true;
|
||||||
|
buttonRemoveShip.Click += ButtonRemoveShip_Click;
|
||||||
|
//
|
||||||
|
// buttonRefreshCollection
|
||||||
|
//
|
||||||
|
buttonRefreshCollection.Location = new Point(6, 230);
|
||||||
|
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||||
|
buttonRefreshCollection.Size = new Size(108, 30);
|
||||||
|
buttonRefreshCollection.TabIndex = 4;
|
||||||
|
buttonRefreshCollection.Text = "Обновить ";
|
||||||
|
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
|
buttonRefreshCollection.Click += ButtonRefreshCollection_Click;
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
groupBox1.Controls.Add(buttonAddShip);
|
||||||
|
groupBox1.Controls.Add(buttonRefreshCollection);
|
||||||
|
groupBox1.Controls.Add(maskedTextBoxNumber);
|
||||||
|
groupBox1.Controls.Add(buttonRemoveShip);
|
||||||
|
groupBox1.Location = new Point(812, 21);
|
||||||
|
groupBox1.Name = "groupBox1";
|
||||||
|
groupBox1.Size = new Size(120, 461);
|
||||||
|
groupBox1.TabIndex = 5;
|
||||||
|
groupBox1.TabStop = false;
|
||||||
|
groupBox1.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// FormShipCollection
|
||||||
|
//
|
||||||
|
ClientSize = new Size(932, 503);
|
||||||
|
Controls.Add(groupBox1);
|
||||||
|
Controls.Add(pictureBoxCollection);
|
||||||
|
Name = "FormShipCollection";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
groupBox1.ResumeLayout(false);
|
||||||
|
groupBox1.PerformLayout();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private PictureBox pictureBoxCollection;
|
||||||
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
|
private Button buttonAddShip;
|
||||||
|
private Button buttonRemoveShip;
|
||||||
|
private Button buttonRefreshCollection;
|
||||||
|
private GroupBox groupBox1;
|
||||||
|
}
|
||||||
|
}
|
82
ContainerShip/ContainerShip/FormShipCollection.cs
Normal file
82
ContainerShip/ContainerShip/FormShipCollection.cs
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
using ProjectContainerShip.DrawningObjects;
|
||||||
|
using ProjectContainerShip.Generics;
|
||||||
|
using ProjectContainerShip.MovementStrategy;
|
||||||
|
|
||||||
|
namespace ProjectContainerShip
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Форма для работы с набором объектов класса
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormShipCollection : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly ContainerGenericCollection<DrawningShip,
|
||||||
|
DrawningObjectShip> _containerShip;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormShipCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_containerShip = new ContainerGenericCollection<DrawningShip,
|
||||||
|
DrawningObjectShip>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddShip_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FormContainerShip form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_containerShip + form.SelectedShip > -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = _containerShip.ShowContainer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonRemoveShip_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
if (_containerShip - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBoxCollection.Image = _containerShip.ShowContainer();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обновление рисунка по набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _containerShip.ShowContainer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
120
ContainerShip/ContainerShip/FormShipCollection.resx
Normal file
120
ContainerShip/ContainerShip/FormShipCollection.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>
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||||||
namespace ProjectContainerShip.MovementStrategy
|
namespace ProjectContainerShip.MovementStrategy
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Стратегия перемещения объекта к краю
|
/// Стратегия перемещения объекта в центр экрана
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MoveToBorder : AbstractStrategy
|
public class MoveToBorder : AbstractStrategy
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
using ProjectWarmlyShip;
|
using ProjectContainerShip;
|
||||||
|
|
||||||
namespace ProjectContainerShip
|
namespace ProjectContainerShip
|
||||||
{
|
{
|
||||||
@ -13,8 +13,11 @@ namespace ProjectContainerShip
|
|||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
Application.Run(new FormContainerShip());
|
Application.Run(new FormShipCollection());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
105
ContainerShip/ContainerShip/SetGeneric.cs
Normal file
105
ContainerShip/ContainerShip/SetGeneric.cs
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectContainerShip.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный набор объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
internal class SetGeneric<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Массив объектов, которые храним
|
||||||
|
/// </summary>
|
||||||
|
private readonly T?[] _places;
|
||||||
|
/// <summary>
|
||||||
|
/// Количество объектов в массиве
|
||||||
|
/// </summary>
|
||||||
|
public int Count => _places.Length;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="count"></param>
|
||||||
|
public SetGeneric(int count)
|
||||||
|
{
|
||||||
|
_places = new T?[count];
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ship">Добавляемый корабль</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T ship)
|
||||||
|
{
|
||||||
|
return Insert(ship, 0);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ship">Добавляемый корабля</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T ship, int position)
|
||||||
|
{
|
||||||
|
if (position < 0 && position > Count)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (_places[position] != null)
|
||||||
|
{
|
||||||
|
int d = 0;
|
||||||
|
for (int j = 1; j < Count - position; j++)
|
||||||
|
{
|
||||||
|
if (_places[position + j] == null)
|
||||||
|
{
|
||||||
|
d = position + j;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (d == 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for (int j = d; j > position; j--)
|
||||||
|
{
|
||||||
|
_places[j] = _places[j - 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_places[position] = ship;
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _places.Length)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_places[position] = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта из набора по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _places.Length)
|
||||||
|
return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user