diff --git a/SailBoat/SailBoat/DrawningObjects/DrawningBoat.cs b/SailBoat/SailBoat/DrawningObjects/DrawningBoat.cs
index 24a14ca..2df043f 100644
--- a/SailBoat/SailBoat/DrawningObjects/DrawningBoat.cs
+++ b/SailBoat/SailBoat/DrawningObjects/DrawningBoat.cs
@@ -1,4 +1,5 @@
using SailBoat.Entities;
+using SailBoat.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Configuration;
@@ -106,5 +107,7 @@ namespace SailBoat.DrawningObjects
g.FillEllipse(BodyBrush, _startPosX + 15, _startPosY + 65, 95, 50);
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 65, 95, 50);
}
+
+ public IMoveableObject GetMoveableObjects => new DrawningObjectBoat(this);
}
}
diff --git a/SailBoat/SailBoat/DrawningObjects/DrawningSailBoat.cs b/SailBoat/SailBoat/DrawningObjects/DrawningSailBoat.cs
index 242f800..e0a93a1 100644
--- a/SailBoat/SailBoat/DrawningObjects/DrawningSailBoat.cs
+++ b/SailBoat/SailBoat/DrawningObjects/DrawningSailBoat.cs
@@ -21,6 +21,7 @@ namespace SailBoat.DrawningObjects
{
if (EntityBoat is not EntitySailBoat sailBoat) { return; }
Pen pen = new(Color.Black);
+ Brush bodyColor = new SolidBrush(sailBoat.BodyColor);
Brush additionalBrush = new SolidBrush(sailBoat.AdditionalColor);
g.DrawLine(pen, _startPosX + 10, _startPosY + 60, _startPosX + 110, _startPosY + 60);
@@ -28,19 +29,18 @@ namespace SailBoat.DrawningObjects
g.DrawLine(pen, _startPosX + 180, _startPosY + 90, _startPosX + 110, _startPosY + 120);
g.DrawLine(pen, _startPosX + 110, _startPosY + 120, _startPosX + 10, _startPosY + 120);
g.DrawLine(pen, _startPosX + 10, _startPosY + 120, _startPosX + 10, _startPosY + 60);
- g.FillEllipse(additionalBrush, _startPosX + 15, _startPosY + 65, 95, 50);
+ g.FillEllipse(bodyColor, _startPosX + 15, _startPosY + 65, 95, 50);
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 65, 95, 50);
base.DrawTransport(g);
if (sailBoat.RainforcedBody)
{
- Brush rainforcedBody = new SolidBrush(Color.DarkGray);
- g.FillRectangle(rainforcedBody, _startPosX + 2, _startPosY + 65, 10, 50);
+ g.FillRectangle(additionalBrush, _startPosX + 2, _startPosY + 65, 10, 50);
g.DrawRectangle(pen, _startPosX + 2, _startPosY + 65, 10, 50);
- g.FillRectangle(rainforcedBody, _startPosX + 15, _startPosY + 53, 90, 10);
+ g.FillRectangle(additionalBrush, _startPosX + 15, _startPosY + 53, 90, 10);
g.DrawRectangle(pen, _startPosX + 15, _startPosY + 53, 90, 10);
- g.FillRectangle(rainforcedBody, _startPosX + 15, _startPosY + 118, 90, 10);
+ g.FillRectangle(additionalBrush, _startPosX + 15, _startPosY + 118, 90, 10);
g.DrawRectangle(pen, _startPosX + 15, _startPosY + 118, 90, 10);
}
diff --git a/SailBoat/SailBoat/FormBoatCollection.Designer.cs b/SailBoat/SailBoat/FormBoatCollection.Designer.cs
new file mode 100644
index 0000000..f16b1a1
--- /dev/null
+++ b/SailBoat/SailBoat/FormBoatCollection.Designer.cs
@@ -0,0 +1,126 @@
+namespace SailBoat
+{
+ partial class FormBoatCollection
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ tools = new GroupBox();
+ maskedTextBoxNumber = new MaskedTextBox();
+ buttonRefreshCollection = new Button();
+ buttonRemoveBoat = new Button();
+ buttonAddBoat = new Button();
+ pictureBoxCollection = new PictureBox();
+ tools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
+ SuspendLayout();
+ //
+ // tools
+ //
+ tools.Controls.Add(maskedTextBoxNumber);
+ tools.Controls.Add(buttonRefreshCollection);
+ tools.Controls.Add(buttonRemoveBoat);
+ tools.Controls.Add(buttonAddBoat);
+ tools.Dock = DockStyle.Right;
+ tools.Location = new Point(716, 0);
+ tools.Name = "tools";
+ tools.Size = new Size(200, 608);
+ tools.TabIndex = 0;
+ tools.TabStop = false;
+ tools.Text = "Инструменты";
+ //
+ // maskedTextBoxNumber
+ //
+ maskedTextBoxNumber.Location = new Point(45, 104);
+ maskedTextBoxNumber.Mask = "00000";
+ maskedTextBoxNumber.Name = "maskedTextBoxNumber";
+ maskedTextBoxNumber.Size = new Size(112, 23);
+ maskedTextBoxNumber.TabIndex = 4;
+ maskedTextBoxNumber.ValidatingType = typeof(int);
+ //
+ // buttonRefreshCollection
+ //
+ buttonRefreshCollection.Location = new Point(6, 211);
+ buttonRefreshCollection.Name = "buttonRefreshCollection";
+ buttonRefreshCollection.Size = new Size(188, 39);
+ buttonRefreshCollection.TabIndex = 3;
+ buttonRefreshCollection.Text = "Обновить коллекцию";
+ buttonRefreshCollection.UseVisualStyleBackColor = true;
+ buttonRefreshCollection.Click += buttonRefreshCollection_Click;
+ //
+ // buttonRemoveBoat
+ //
+ buttonRemoveBoat.Location = new Point(6, 133);
+ buttonRemoveBoat.Name = "buttonRemoveBoat";
+ buttonRemoveBoat.Size = new Size(188, 39);
+ buttonRemoveBoat.TabIndex = 1;
+ buttonRemoveBoat.Text = "Удалить лодку";
+ buttonRemoveBoat.UseVisualStyleBackColor = true;
+ buttonRemoveBoat.Click += buttonRemoveBoat_Click;
+ //
+ // buttonAddBoat
+ //
+ buttonAddBoat.Location = new Point(6, 22);
+ buttonAddBoat.Name = "buttonAddBoat";
+ buttonAddBoat.Size = new Size(188, 39);
+ buttonAddBoat.TabIndex = 0;
+ buttonAddBoat.Text = "Добавить лодку";
+ buttonAddBoat.UseVisualStyleBackColor = true;
+ buttonAddBoat.Click += buttonAddBoat_Click;
+ //
+ // pictureBoxCollection
+ //
+ pictureBoxCollection.Location = new Point(0, 0);
+ pictureBoxCollection.Name = "pictureBoxCollection";
+ pictureBoxCollection.Size = new Size(710, 608);
+ pictureBoxCollection.TabIndex = 1;
+ pictureBoxCollection.TabStop = false;
+ //
+ // FormBoatCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(916, 608);
+ Controls.Add(pictureBoxCollection);
+ Controls.Add(tools);
+ Name = "FormBoatCollection";
+ Text = "Набор лодок";
+ tools.ResumeLayout(false);
+ tools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox tools;
+ private Button buttonAddBoat;
+ private Button buttonRemoveBoat;
+ private Button buttonRefreshCollection;
+ private PictureBox pictureBoxCollection;
+ private MaskedTextBox maskedTextBoxNumber;
+ }
+}
\ No newline at end of file
diff --git a/SailBoat/SailBoat/FormBoatCollection.cs b/SailBoat/SailBoat/FormBoatCollection.cs
new file mode 100644
index 0000000..b1dbe3b
--- /dev/null
+++ b/SailBoat/SailBoat/FormBoatCollection.cs
@@ -0,0 +1,67 @@
+using SailBoat.DrawningObjects;
+using SailBoat.MovementStrategy;
+using SailBoat.Generics;
+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 _boats;
+
+ public FormBoatCollection()
+ {
+ InitializeComponent();
+ _boats = new BoatsGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ }
+
+ private void buttonAddBoat_Click(object sender, EventArgs e)
+ {
+ FormSailBoat form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if ((_boats + form.SelectedBoat) == 0)
+ {
+ 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;
+ }
+ if (maskedTextBoxNumber.Text == "") { return; }
+ int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
+ if (_boats - pos)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBoxCollection.Image = _boats.ShowBoats();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+
+ private void buttonRefreshCollection_Click(object sender, EventArgs e)
+ {
+ pictureBoxCollection.Image = _boats.ShowBoats();
+ }
+ }
+}
diff --git a/SailBoat/SailBoat/FormBoatCollection.resx b/SailBoat/SailBoat/FormBoatCollection.resx
new file mode 100644
index 0000000..a395bff
--- /dev/null
+++ b/SailBoat/SailBoat/FormBoatCollection.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/SailBoat/SailBoat/FormSailBoat.Designer.cs b/SailBoat/SailBoat/FormSailBoat.Designer.cs
index a701cba..e4d4b18 100644
--- a/SailBoat/SailBoat/FormSailBoat.Designer.cs
+++ b/SailBoat/SailBoat/FormSailBoat.Designer.cs
@@ -37,6 +37,7 @@
comboBoxStrategy = new ComboBox();
buttonStep = new Button();
buttonCreateBoat = new Button();
+ buttonSelectBoat = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxSailBoat).BeginInit();
SuspendLayout();
//
@@ -139,11 +140,22 @@
buttonCreateBoat.UseVisualStyleBackColor = true;
buttonCreateBoat.Click += buttonCreateBoat_Click;
//
+ // buttonSelectBoat
+ //
+ buttonSelectBoat.Location = new Point(195, 407);
+ buttonSelectBoat.Name = "buttonSelectBoat";
+ buttonSelectBoat.Size = new Size(106, 42);
+ buttonSelectBoat.TabIndex = 14;
+ buttonSelectBoat.Text = "Выбрать";
+ buttonSelectBoat.UseVisualStyleBackColor = true;
+ buttonSelectBoat.Click += buttonSelectBoat_Click;
+ //
// FormSailBoat
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(884, 461);
+ Controls.Add(buttonSelectBoat);
Controls.Add(buttonCreateBoat);
Controls.Add(buttonStep);
Controls.Add(comboBoxStrategy);
@@ -172,5 +184,6 @@
private ComboBox comboBoxStrategy;
private Button buttonStep;
private Button buttonCreateBoat;
+ private Button buttonSelectBoat;
}
}
\ No newline at end of file
diff --git a/SailBoat/SailBoat/FormSailBoat.cs b/SailBoat/SailBoat/FormSailBoat.cs
index 5028065..bd68014 100644
--- a/SailBoat/SailBoat/FormSailBoat.cs
+++ b/SailBoat/SailBoat/FormSailBoat.cs
@@ -1,5 +1,6 @@
using SailBoat.DrawningObjects;
using SailBoat.MovementStrategy;
+using System.Drawing;
namespace SailBoat
{
@@ -8,12 +9,18 @@ namespace SailBoat
private DrawningBoat? _drawningBoat;
private AbstractStrategy? _abstractStrategy;
+
+ public DrawningBoat? SelectedBoat { get; private set; }
+
public FormSailBoat()
{
InitializeComponent();
+ _abstractStrategy = null;
+ SelectedBoat = null;
}
private void Draw()
{
+ if (_drawningBoat == null) return;
Bitmap bmp = new(pictureBoxSailBoat.Width, pictureBoxSailBoat.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningBoat.DrawTransport(gr);
@@ -24,15 +31,33 @@ namespace SailBoat
private void buttonCreateSailBoat_Click(object sender, EventArgs e)
{
Random random = new();
- _drawningBoat = new DrawningSailBoat(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)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxSailBoat.Width, pictureBoxSailBoat.Height);
- _drawningBoat.SetPosition(random.Next(10, 100), random.Next(10,100));
+ 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;
+ }
+ _drawningBoat = new DrawningSailBoat(random.Next(100, 300), random.Next(1000, 3000), color, dopcolor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxSailBoat.Width, pictureBoxSailBoat.Height);
+ _drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void buttonCreateBoat_Click(object sender, EventArgs e)
{
Random random = new();
- _drawningBoat = new DrawningBoat(random.Next(300, 700), random.Next(2000, 4000), Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)), pictureBoxSailBoat.Width, pictureBoxSailBoat.Height);
+ 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;
+ }
+
+ _drawningBoat = new DrawningBoat(random.Next(300, 700), random.Next(2000, 4000), color, pictureBoxSailBoat.Width, pictureBoxSailBoat.Height);
_drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
@@ -76,6 +101,7 @@ namespace SailBoat
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null) return;
+ comboBoxStrategy.Enabled = false;
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
@@ -84,5 +110,11 @@ namespace SailBoat
_abstractStrategy = null;
}
}
+
+ private void buttonSelectBoat_Click(object sender, EventArgs e)
+ {
+ SelectedBoat = _drawningBoat;
+ DialogResult = DialogResult.OK;
+ }
}
}
\ No newline at end of file
diff --git a/SailBoat/SailBoat/Generics/BoatsGenericCollection.cs b/SailBoat/SailBoat/Generics/BoatsGenericCollection.cs
new file mode 100644
index 0000000..e86b572
--- /dev/null
+++ b/SailBoat/SailBoat/Generics/BoatsGenericCollection.cs
@@ -0,0 +1,95 @@
+using SailBoat.DrawningObjects;
+using SailBoat.MovementStrategy;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SailBoat.Generics
+{
+ internal class BoatsGenericCollection
+ where T : DrawningBoat
+ where U : IMoveableObject
+ {
+ private readonly int _pictureWidth;
+
+ private readonly int _pictureHeight;
+
+ private readonly int _placeSizeWidth = 220;
+
+ private readonly int _placeSizeHeight = 150;
+
+ private readonly SetGeneric _collection;
+
+ public BoatsGenericCollection(int picWidth, int picHeight)
+ {
+ int width = picWidth / _placeSizeWidth;
+ int height = picHeight / _placeSizeHeight;
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+
+ _collection = new SetGeneric(width * height);
+ }
+
+ public static int? operator +(BoatsGenericCollection collect, T? obj)
+ {
+ if (obj == null) return -1;
+ return collect?._collection.Insert(obj);
+ }
+
+ public static bool operator -(BoatsGenericCollection collect, int pos)
+ {
+ T? obj = collect._collection.Get(pos);
+ if(obj == null)
+ {
+ return false;
+ }
+ collect._collection.Remove(pos);
+
+ return true;
+ }
+ public U? GetU(int pos)
+ {
+ return (U?)_collection.Get(pos)?.GetMoveableObjects;
+ }
+
+
+ public Bitmap ShowBoats()
+ {
+ Bitmap bmp = new(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawBackground(gr);
+ DrawObjects(gr);
+ return bmp;
+ }
+ 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);
+ }
+ }
+
+ private void DrawObjects(Graphics g)
+ {
+ int height = _pictureHeight / _placeSizeHeight;
+ int width = _pictureWidth / _placeSizeWidth;
+ for (int i = 0; i < _collection.Count ; i++)
+ {
+ DrawningBoat boat = _collection.Get(i);
+ if(boat == null)
+ {
+ continue;
+ }
+ boat.SetPosition((i % width) * _placeSizeWidth, (i / (height - 1)) * _placeSizeHeight);
+ boat.DrawTransport(g);
+ }
+ }
+ }
+}
diff --git a/SailBoat/SailBoat/Generics/SetGeneric.cs b/SailBoat/SailBoat/Generics/SetGeneric.cs
new file mode 100644
index 0000000..578de1f
--- /dev/null
+++ b/SailBoat/SailBoat/Generics/SetGeneric.cs
@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SailBoat.Generics
+{
+ internal class SetGeneric
+ 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)
+ {
+ int index = 0;
+ while (_places[index] != null) {
+ index++;
+ if(index == Count) { return -1; }
+ }
+
+ while (index != 0)
+ {
+ _places[index] = _places[index - 1];
+ index--;
+ }
+ _places[0] = boat;
+ return 0;
+ }
+
+ public bool Insert(T boat, int position)
+ {
+ if (position < 0 || position >= Count)
+ {
+ return false;
+ }
+ if (_places[position] == null)
+ {
+ _places[position] = boat;
+ return true;
+ }
+ int index = position;
+ while (_places[index] != null) index++;
+ if (index == Count) return false;
+ for(int i = index; i > position; i--)
+ {
+ _places[i] = _places[i - 1];
+ }
+ _places[position] = boat;
+ return true;
+ }
+
+ 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];
+ }
+ }
+}
diff --git a/SailBoat/SailBoat/Program.cs b/SailBoat/SailBoat/Program.cs
index 78fbf59..00690c9 100644
--- a/SailBoat/SailBoat/Program.cs
+++ b/SailBoat/SailBoat/Program.cs
@@ -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 FormSailBoat());
+ Application.Run(new FormBoatCollection());
}
}
}
\ No newline at end of file