Compare commits

..

No commits in common. "895f7fd63ae62d4b8df950e3302e34a89c1555dd" and "b7e22a4fd50b044db5b26e8561f6f246bb318bfa" have entirely different histories.

9 changed files with 122 additions and 581 deletions

View File

@ -1,148 +0,0 @@
using Sailboat.DrawingObjects;
using Sailboat.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sailboat.DrawingObjects;
using Sailboat.MovementStrategy;
namespace Sailboat.Generics
{
/// <summary>
/// Параметризованный класс для набора объектов DrawingBoat
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam>
internal class BoatsGenericCollection<T, U>
where T : DrawingBoat
where U : IMoveableObject
{
/// <summary>
/// Ширина окна прорисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна прорисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 200;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 170;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetGeneric<T> _collection;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
public BoatsGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static int operator +(BoatsGenericCollection<T, U> collect, T?
obj)
{
if (obj == null)
{
return -1;
}
return collect._collection.Insert(obj);
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static bool operator -(BoatsGenericCollection<T, U> collect, int
pos)
{
T? obj = collect._collection.Get(pos);
if (obj != null)
{
collect._collection.Remove(pos);
}
return false;
}
/// <summary>
/// Получение объекта IMoveableObject
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowBoats()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
{//линия рамзетки места
g.DrawLine(pen, i * _placeSizeWidth, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
_placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawObjects(Graphics g)
{
for (int i = 0; i < _collection.Count; i++)
{
DrawingBoat boat = _collection.Get(i);
if (boat != null)
{
int width = _pictureWidth / _placeSizeWidth;
boat.SetPosition(i % width * _placeSizeWidth, i / width * _placeSizeHeight);
boat.DrawTransport(g);
}
}
}
}
}

View File

@ -5,7 +5,6 @@ using System.Text;
using System.Threading.Tasks;
using Sailboat.Entities;
using Sailboat.MovementStrategy;
namespace Sailboat.DrawingObjects
{
@ -14,20 +13,66 @@ namespace Sailboat.DrawingObjects
/// </summary>
public class DrawingBoat
{
/// <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 _boatWidth = 185;
/// <summary>
/// Высота прорисовки лодки
/// </summary>
private readonly int _boatHeight = 160;
/// <summary>
/// Координата X объекта
/// </summary>
public int GetPosX => _startPosX;
/// <summary>
/// Координата Y объекта
/// </summary>
public int GetPosY => _startPosY;
/// <summary>
/// Ширина объекта
/// </summary>
public int GetWidth => _boatWidth;
/// <summary>
/// Высота объекта
/// </summary>
public int GetHeight => _boatHeight;
public IMoveableObject GetMoveableObject => new DrawingObjectBoat(this);
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public DrawingBoat(int speed, double weight, Color bodyColor, int width, int height)
{
if (width < _boatWidth || height < _boatHeight)
@ -39,6 +84,16 @@ namespace Sailboat.DrawingObjects
EntityBoat = new EntityBoat(speed, weight, bodyColor);
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
/// <param name="boatWidth">Ширина прорисовки лодки</param>
/// <param name="boatHeight">Высота прорисовки лодки</param>
protected DrawingBoat(int speed, double weight, Color bodyColor, int width, int height, int boatWidth, int boatHeight)
{
if (width < _boatWidth || height < _boatHeight)
@ -52,6 +107,11 @@ namespace Sailboat.DrawingObjects
EntityBoat = new EntityBoat(speed, weight, bodyColor);
}
/// <summary>
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
if (x < 0 || x + _boatWidth > _pictureWidth)
@ -66,6 +126,11 @@ namespace Sailboat.DrawingObjects
_startPosY = y;
}
/// <summary>
/// Проверка, что объект может переместится по указанному направлению
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - можно переместится по указанному направлению</returns>
public bool CanMove(DirectionType direction)
{
if (EntityBoat == null)
@ -74,14 +139,22 @@ namespace Sailboat.DrawingObjects
}
return direction switch
{
//влево
DirectionType.Left => _startPosX - EntityBoat.Step > 0,
//вверх
DirectionType.Up => _startPosY - EntityBoat.Step > 0,
// вправо
DirectionType.Right => _startPosX + EntityBoat.Step < _pictureWidth,
//вниз
DirectionType.Down => _startPosY + EntityBoat.Step < _pictureHeight,
_ => false
};
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntityBoat == null)
@ -90,24 +163,28 @@ namespace Sailboat.DrawingObjects
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX - EntityBoat.Step > 0)
{
_startPosX -= (int)EntityBoat.Step;
}
break;
//вверх
case DirectionType.Up:
if (_startPosY - EntityBoat.Step > 0)
{
_startPosY -= (int)EntityBoat.Step;
}
break;
//вправо
case DirectionType.Right:
if (_startPosX + EntityBoat.Step + _boatWidth < _pictureWidth)
{
_startPosX += (int)EntityBoat.Step;
}
break;
//вниз
case DirectionType.Down:
if (_startPosY + EntityBoat.Step + _boatHeight < _pictureHeight)
{
@ -117,6 +194,10 @@ namespace Sailboat.DrawingObjects
}
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public virtual void DrawTransport(Graphics g)
{
if (EntityBoat == null)

View File

@ -1,125 +0,0 @@
namespace Sailboat
{
partial class FormBoatCollection
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
pictureBoxCollection = new PictureBox();
buttonAddBoat = new Button();
buttonRemoveBoat = new Button();
buttonRefreshCollection = new Button();
maskedTextBoxNumber = new MaskedTextBox();
groupBoxTools = new GroupBox();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
groupBoxTools.SuspendLayout();
SuspendLayout();
//
// pictureBoxCollection
//
pictureBoxCollection.Location = new Point(0, 0);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(750, 450);
pictureBoxCollection.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxCollection.TabIndex = 0;
pictureBoxCollection.TabStop = false;
//
// buttonAddBoat
//
buttonAddBoat.Location = new Point(6, 26);
buttonAddBoat.Name = "buttonAddBoat";
buttonAddBoat.Size = new Size(197, 45);
buttonAddBoat.TabIndex = 1;
buttonAddBoat.Text = "Добавить лодку";
buttonAddBoat.UseVisualStyleBackColor = true;
buttonAddBoat.Click += buttonAddBoat_Click;
//
// buttonRemoveBoat
//
buttonRemoveBoat.Location = new Point(6, 145);
buttonRemoveBoat.Name = "buttonRemoveBoat";
buttonRemoveBoat.Size = new Size(197, 45);
buttonRemoveBoat.TabIndex = 2;
buttonRemoveBoat.Text = "Удалить лодку";
buttonRemoveBoat.UseVisualStyleBackColor = true;
buttonRemoveBoat.Click += buttonRemoveBoat_Click;
//
// buttonRefreshCollection
//
buttonRefreshCollection.Location = new Point(6, 227);
buttonRefreshCollection.Name = "buttonRefreshCollection";
buttonRefreshCollection.Size = new Size(197, 45);
buttonRefreshCollection.TabIndex = 3;
buttonRefreshCollection.Text = "Обновить коллекцию";
buttonRefreshCollection.UseVisualStyleBackColor = true;
buttonRefreshCollection.Click += buttonRefreshCollection_Click;
//
// maskedTextBoxNumber
//
maskedTextBoxNumber.Location = new Point(34, 112);
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(138, 27);
maskedTextBoxNumber.TabIndex = 4;
//
// groupBoxTools
//
groupBoxTools.Controls.Add(buttonAddBoat);
groupBoxTools.Controls.Add(buttonRefreshCollection);
groupBoxTools.Controls.Add(maskedTextBoxNumber);
groupBoxTools.Controls.Add(buttonRemoveBoat);
groupBoxTools.Location = new Point(756, 12);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(209, 387);
groupBoxTools.TabIndex = 2;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// FormBoatCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(973, 403);
Controls.Add(groupBoxTools);
Controls.Add(pictureBoxCollection);
Name = "FormBoatCollection";
Text = "FormBoatCollection";
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private PictureBox pictureBoxCollection;
private Button buttonAddBoat;
private Button buttonRemoveBoat;
private Button buttonRefreshCollection;
private MaskedTextBox maskedTextBoxNumber;
private GroupBox groupBoxTools;
}
}

View File

@ -1,66 +0,0 @@
using Sailboat.DrawingObjects;
using Sailboat.Generics;
using Sailboat.MovementStrategy;
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;
namespace Sailboat
{
public partial class FormBoatCollection : Form
{
private readonly BoatsGenericCollection<DrawingBoat, DrawingObjectBoat> _boats;
public FormBoatCollection()
{
InitializeComponent();
_boats = new BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>(pictureBoxCollection.Width, pictureBoxCollection.Height);
}
private void buttonAddBoat_Click(object sender, EventArgs e)
{
FormSailboat form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_boats + form.SelectedBoat != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _boats.ShowBoats();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void buttonRemoveBoat_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (_boats - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = _boats.ShowBoats();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void buttonRefreshCollection_Click(object sender, EventArgs e)
{
pictureBoxCollection.Image = _boats.ShowBoats();
}
}
}

View File

@ -1,120 +0,0 @@
<?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

@ -37,7 +37,6 @@
buttonCreateSailboat = new Button();
comboBoxStrategy = new ComboBox();
buttonStep = new Button();
buttonSelectBoat = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxSailboat).BeginInit();
SuspendLayout();
//
@ -141,22 +140,11 @@
buttonStep.UseVisualStyleBackColor = true;
buttonStep.Click += buttonStep_Click;
//
// buttonSelectBoat
//
buttonSelectBoat.Location = new Point(618, 399);
buttonSelectBoat.Name = "buttonSelectBoat";
buttonSelectBoat.Size = new Size(122, 35);
buttonSelectBoat.TabIndex = 9;
buttonSelectBoat.Text = "Выбрать лодку";
buttonSelectBoat.UseVisualStyleBackColor = true;
buttonSelectBoat.Click += buttonSelectBoat_Click;
//
// FormSailboat
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(882, 453);
Controls.Add(buttonSelectBoat);
Controls.Add(buttonStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateSailboat);
@ -185,6 +173,5 @@
private Button buttonCreateSailboat;
private ComboBox comboBoxStrategy;
private Button buttonStep;
private Button buttonSelectBoat;
}
}

View File

@ -12,19 +12,28 @@ using System.Windows.Forms;
namespace Sailboat
{
/// <summary>
/// Форма работы с объектом "Парусная лодка"
/// </summary>
public partial class FormSailboat : Form
{
/// <summary>
/// Поле-объект для прорисовки объекта
/// </summary>
private DrawingBoat? _drawingBoat;
private AbstractStrategy? _abstractStrategy;
public DrawingBoat? SelectedBoat { get; private set; }
/// <summary>
/// Инициализация формы
/// </summary>
public FormSailboat()
{
InitializeComponent();
_abstractStrategy = null;
SelectedBoat = null;
}
/// <summary>
/// Метод прорисовки лодки
/// </summary>
private void Draw()
{
if (_drawingBoat == null)
@ -38,45 +47,40 @@ namespace Sailboat
pictureBoxSailboat.Image = bmp;
}
/// <summary>
/// Обработка нажатия кнопки "Создать лодку"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateBoat_Click(object sender, EventArgs e)
{
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_drawingBoat = new DrawingBoat(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxSailboat.Width, pictureBoxSailboat.Height);
_drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
_drawingBoat = new DrawingBoat(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), pictureBoxSailboat.Width, pictureBoxSailboat.Height);
_drawingBoat.SetPosition(random.Next(10, 100), random.Next(10,
100));
Draw();
}
/// <summary>
/// Обработка нажатия кнопки "Создать улучшеную лодку"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateSailboat_Click(object sender, EventArgs e)
{
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color dopColor = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
if (dialog.ShowDialog() == DialogResult.OK)
{
dopColor = dialog.Color;
}
_drawingBoat = new DrawingSailboat(random.Next(100, 300),
random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(0, 2)),
_drawingBoat = new DrawingSailboat(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)),
pictureBoxSailboat.Width, pictureBoxSailboat.Height);
Convert.ToBoolean(random.Next(0, 2)), pictureBoxSailboat.Width, pictureBoxSailboat.Height);
_drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
/// <summary>
/// Изменение размеров формы
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawingBoat == null)
@ -102,6 +106,11 @@ namespace Sailboat
Draw();
}
/// <summary>
/// Обработка нажатия кнопки "Шаг"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonStep_Click(object sender, EventArgs e)
{
if (_drawingBoat == null)
@ -137,11 +146,5 @@ namespace Sailboat
_abstractStrategy = null;
}
}
private void buttonSelectBoat_Click(object sender, EventArgs e)
{
SelectedBoat = _drawingBoat;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -11,7 +11,7 @@ namespace Sailboat
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormBoatCollection());
Application.Run(new FormSailboat());
}
}
}

View File

@ -1,71 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat.Generics
{
internal class SetGeneric<T> where T : class
{
private readonly T?[] _places;
public int Count => _places.Length;
public SetGeneric(int count)
{
_places = new T?[count];
}
public int Insert(T boat)
{
return Insert(boat, 0);
}
public int Insert(T boat, int position)
{
int nullIndex = -1, i;
if (position < 0 || position >= Count)
{
return -1;
}
for (i = position; i < Count; i++)
{
if (_places[i] == null)
{
nullIndex = i;
break;
}
}
if (nullIndex < 0)
{
return -1;
}
for (i = nullIndex; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = boat;
return position;
}
public bool Remove(int position)
{
if (position < 0 || position >= Count)
{
return false;
}
_places[position] = null;
return true;
}
public T? Get(int position)
{
if (position < 0 || position >= Count)
{
return null;
}
return _places[position];
}
}
}