diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/AbstractMap.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/AbstractMap.cs
index db52a5e..680ffb5 100644
--- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/AbstractMap.cs
+++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/AbstractMap.cs
@@ -89,6 +89,8 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
int left = Convert.ToInt32((_drawningObject.GetCurrentPosition().Left + x) / _size_x) > 0 ? Convert.ToInt32((_drawningObject.GetCurrentPosition().Left + x) / _size_x) : 0;
int up = Convert.ToInt32((_drawningObject.GetCurrentPosition().Top + y) / _size_y) > 0 ? Convert.ToInt32((_drawningObject.GetCurrentPosition().Top + y) / _size_y) : 0;
int down = Convert.ToInt32((_drawningObject.GetCurrentPosition().Bottom + y) / _size_y) > 0 ? Convert.ToInt32((_drawningObject.GetCurrentPosition().Bottom + y) / _size_y) : 0;
+ if (_drawningObject.GetCurrentPosition().Bottom + y > _height || _drawningObject.GetCurrentPosition().Right + x > _width ||
+ _drawningObject.GetCurrentPosition().Top + y < 0 || _drawningObject.GetCurrentPosition().Left + x < 0) return false;
for (int i = left; i <= right; i++)
{
for (int j = up; j <= down; j++)
diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/Direction.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/Direction.cs
index c202e3c..d505ab3 100644
--- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/Direction.cs
+++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/Direction.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
{
- internal enum Direction
+ public enum Direction
{
None = 0,
Up = 1,
diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/DrawningBoat.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/DrawningBoat.cs
index 39c1573..db7d4c9 100644
--- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/DrawningBoat.cs
+++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/DrawningBoat.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
{
- internal class DrawningBoat
+ public class DrawningBoat
{
///
/// Класс-сущность
diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/EntityBoat.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/EntityBoat.cs
index cc06a28..e0bf322 100644
--- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/EntityBoat.cs
+++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/EntityBoat.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
{
- internal class EntityBoat
+ public class EntityBoat
{
public int Speed { get; private set; }
public float Weight { get; private set; }
diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormBoat.Designer.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormBoat.Designer.cs
index 771a114..5579268 100644
--- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormBoat.Designer.cs
+++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormBoat.Designer.cs
@@ -28,7 +28,7 @@
///
private void InitializeComponent()
{
- this.statusStrip1 = new System.Windows.Forms.StatusStrip();
+ this.statusStrip = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
@@ -39,23 +39,24 @@
this.buttonUp = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
- this.statusStrip1.SuspendLayout();
+ this.buttonSelectBoat = new System.Windows.Forms.Button();
+ this.statusStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBoat)).BeginInit();
this.SuspendLayout();
//
- // statusStrip1
+ // statusStrip
//
- this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
- this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.statusStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
+ this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor});
- this.statusStrip1.Location = new System.Drawing.Point(0, 318);
- this.statusStrip1.Name = "statusStrip1";
- this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 12, 0);
- this.statusStrip1.Size = new System.Drawing.Size(772, 22);
- this.statusStrip1.TabIndex = 0;
- this.statusStrip1.Text = "statusStrip1";
+ this.statusStrip.Location = new System.Drawing.Point(0, 318);
+ this.statusStrip.Name = "statusStrip";
+ this.statusStrip.Padding = new System.Windows.Forms.Padding(1, 0, 12, 0);
+ this.statusStrip.Size = new System.Drawing.Size(772, 22);
+ this.statusStrip.TabIndex = 0;
+ this.statusStrip.Text = "statusStrip1";
//
// toolStripStatusLabelSpeed
//
@@ -82,7 +83,7 @@
this.pictureBoxBoat.Location = new System.Drawing.Point(0, 0);
this.pictureBoxBoat.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.pictureBoxBoat.Name = "pictureBoxBoat";
- this.pictureBoxBoat.Size = new System.Drawing.Size(772, 318);
+ this.pictureBoxBoat.Size = new System.Drawing.Size(772, 340);
this.pictureBoxBoat.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxBoat.TabIndex = 1;
this.pictureBoxBoat.TabStop = false;
@@ -164,6 +165,17 @@
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
//
+ // buttonSelectBoat
+ //
+ this.buttonSelectBoat.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonSelectBoat.Location = new System.Drawing.Point(547, 289);
+ this.buttonSelectBoat.Name = "buttonSelectBoat";
+ this.buttonSelectBoat.Size = new System.Drawing.Size(75, 22);
+ this.buttonSelectBoat.TabIndex = 8;
+ this.buttonSelectBoat.Text = "Выбрать";
+ this.buttonSelectBoat.UseVisualStyleBackColor = true;
+ this.buttonSelectBoat.Click += new System.EventHandler(this.ButtonSelectBoat_Click);
+ //
// FormBoat
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@@ -175,13 +187,14 @@
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonCreate);
+ this.Controls.Add(this.statusStrip);
+ this.Controls.Add(this.buttonSelectBoat);
this.Controls.Add(this.pictureBoxBoat);
- this.Controls.Add(this.statusStrip1);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormBoat";
this.Text = "Лодка";
- this.statusStrip1.ResumeLayout(false);
- this.statusStrip1.PerformLayout();
+ this.statusStrip.ResumeLayout(false);
+ this.statusStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBoat)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@@ -190,7 +203,7 @@
#endregion
- private StatusStrip statusStrip1;
+ private StatusStrip statusStrip;
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
@@ -201,5 +214,6 @@
private Button buttonUp;
private Button buttonDown;
private Button buttonCreateModif;
+ private Button buttonSelectBoat;
}
}
\ No newline at end of file
diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormBoat.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormBoat.cs
index 6f706e2..5c5cbf3 100644
--- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormBoat.cs
+++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormBoat.cs
@@ -4,6 +4,10 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
{
private DrawningBoat _boat;
+ ///
+ ///
+ ///
+ public DrawningBoat SelectedBoat { get; private set; }
public FormBoat()
{
InitializeComponent();
@@ -89,5 +93,15 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
SetData();
Draw();
}
+ ///
+ /// ""
+ ///
+ ///
+ ///
+ private void ButtonSelectBoat_Click(object sender, EventArgs e)
+ {
+ SelectedBoat = _boat;
+ DialogResult = DialogResult.OK;
+ }
}
}
\ No newline at end of file
diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormBoat.resx b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormBoat.resx
index 5cb320f..2c0949d 100644
--- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormBoat.resx
+++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormBoat.resx
@@ -57,7 +57,7 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
+
17, 17
\ No newline at end of file
diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMap.Designer.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMap.Designer.cs
deleted file mode 100644
index c535860..0000000
--- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMap.Designer.cs
+++ /dev/null
@@ -1,214 +0,0 @@
-namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
-{
- partial class FormMap
- {
- ///
- /// 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()
- {
- this.statusStrip1 = new System.Windows.Forms.StatusStrip();
- this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
- this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
- this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
- this.pictureBoxBoat = new System.Windows.Forms.PictureBox();
- this.buttonCreate = new System.Windows.Forms.Button();
- this.buttonRight = new System.Windows.Forms.Button();
- this.buttonLeft = new System.Windows.Forms.Button();
- this.buttonUp = new System.Windows.Forms.Button();
- this.buttonDown = new System.Windows.Forms.Button();
- this.buttonCreateModif = new System.Windows.Forms.Button();
- this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
- this.statusStrip1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxBoat)).BeginInit();
- this.SuspendLayout();
- //
- // statusStrip1
- //
- this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
- this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.toolStripStatusLabelSpeed,
- this.toolStripStatusLabelWeight,
- this.toolStripStatusLabelBodyColor});
- this.statusStrip1.Location = new System.Drawing.Point(0, 427);
- this.statusStrip1.Name = "statusStrip1";
- this.statusStrip1.Size = new System.Drawing.Size(882, 26);
- this.statusStrip1.TabIndex = 0;
- this.statusStrip1.Text = "statusStrip1";
- //
- // toolStripStatusLabelSpeed
- //
- this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
- this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(76, 20);
- this.toolStripStatusLabelSpeed.Text = "Скорость:";
- //
- // toolStripStatusLabelWeight
- //
- this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
- this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(36, 20);
- this.toolStripStatusLabelWeight.Text = "Вес:";
- //
- // toolStripStatusLabelBodyColor
- //
- this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
- this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(45, 20);
- this.toolStripStatusLabelBodyColor.Text = "Цвет:";
- //
- // pictureBoxBoat
- //
- this.pictureBoxBoat.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
- this.pictureBoxBoat.Dock = System.Windows.Forms.DockStyle.Fill;
- this.pictureBoxBoat.Location = new System.Drawing.Point(0, 0);
- this.pictureBoxBoat.Name = "pictureBoxBoat";
- this.pictureBoxBoat.Size = new System.Drawing.Size(882, 427);
- this.pictureBoxBoat.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
- this.pictureBoxBoat.TabIndex = 1;
- this.pictureBoxBoat.TabStop = false;
- //
- // buttonCreate
- //
- this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
- this.buttonCreate.Location = new System.Drawing.Point(11, 385);
- this.buttonCreate.Name = "buttonCreate";
- this.buttonCreate.Size = new System.Drawing.Size(94, 29);
- this.buttonCreate.TabIndex = 2;
- this.buttonCreate.Text = "Создать";
- this.buttonCreate.UseVisualStyleBackColor = true;
- this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
- //
- // buttonRight
- //
- this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonRight.BackgroundImage = global::PIbd_22_Kalyshev_Y_V_MotorBoat_Base.Properties.Resources.right;
- this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonRight.Location = new System.Drawing.Point(821, 373);
- this.buttonRight.Name = "buttonRight";
- this.buttonRight.Size = new System.Drawing.Size(40, 40);
- this.buttonRight.TabIndex = 3;
- this.buttonRight.UseVisualStyleBackColor = true;
- this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
- //
- // buttonLeft
- //
- this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonLeft.BackgroundImage = global::PIbd_22_Kalyshev_Y_V_MotorBoat_Base.Properties.Resources.left;
- this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonLeft.Location = new System.Drawing.Point(728, 373);
- this.buttonLeft.Name = "buttonLeft";
- this.buttonLeft.Size = new System.Drawing.Size(40, 40);
- this.buttonLeft.TabIndex = 4;
- this.buttonLeft.UseVisualStyleBackColor = true;
- this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
- //
- // buttonUp
- //
- this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonUp.BackgroundImage = global::PIbd_22_Kalyshev_Y_V_MotorBoat_Base.Properties.Resources.up;
- this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonUp.Location = new System.Drawing.Point(774, 328);
- this.buttonUp.Name = "buttonUp";
- this.buttonUp.Size = new System.Drawing.Size(40, 40);
- this.buttonUp.TabIndex = 5;
- this.buttonUp.UseVisualStyleBackColor = true;
- this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
- //
- // buttonDown
- //
- this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonDown.BackgroundImage = global::PIbd_22_Kalyshev_Y_V_MotorBoat_Base.Properties.Resources.down;
- this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonDown.Location = new System.Drawing.Point(774, 373);
- this.buttonDown.Name = "buttonDown";
- this.buttonDown.Size = new System.Drawing.Size(40, 40);
- this.buttonDown.TabIndex = 6;
- this.buttonDown.UseVisualStyleBackColor = true;
- this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
- //
- // buttonCreateModif
- //
- this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
- this.buttonCreateModif.Location = new System.Drawing.Point(112, 385);
- this.buttonCreateModif.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
- this.buttonCreateModif.Name = "buttonCreateModif";
- this.buttonCreateModif.Size = new System.Drawing.Size(113, 29);
- this.buttonCreateModif.TabIndex = 7;
- this.buttonCreateModif.Text = "Модификация";
- this.buttonCreateModif.UseVisualStyleBackColor = true;
- this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
- //
- // comboBoxSelectorMap
- //
- this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comboBoxSelectorMap.FormattingEnabled = true;
- this.comboBoxSelectorMap.Items.AddRange(new object[] {
- "Простая карта",
- "Своя карта"});
- this.comboBoxSelectorMap.Location = new System.Drawing.Point(11, 16);
- this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
- this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
- this.comboBoxSelectorMap.Size = new System.Drawing.Size(130, 28);
- this.comboBoxSelectorMap.TabIndex = 8;
- this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
- //
- // FormMap
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(882, 453);
- this.Controls.Add(this.comboBoxSelectorMap);
- this.Controls.Add(this.buttonCreateModif);
- this.Controls.Add(this.buttonDown);
- this.Controls.Add(this.buttonUp);
- this.Controls.Add(this.buttonLeft);
- this.Controls.Add(this.buttonRight);
- this.Controls.Add(this.buttonCreate);
- this.Controls.Add(this.pictureBoxBoat);
- this.Controls.Add(this.statusStrip1);
- this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
- this.Name = "FormMap";
- this.Text = "Карта";
- this.statusStrip1.ResumeLayout(false);
- this.statusStrip1.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxBoat)).EndInit();
- this.ResumeLayout(false);
- this.PerformLayout();
-
- }
-
- #endregion
-
- private StatusStrip statusStrip1;
- private ToolStripStatusLabel toolStripStatusLabelSpeed;
- private ToolStripStatusLabel toolStripStatusLabelWeight;
- private ToolStripStatusLabel toolStripStatusLabelBodyColor;
- private PictureBox pictureBoxBoat;
- private Button buttonCreate;
- private Button buttonRight;
- private Button buttonLeft;
- private Button buttonUp;
- private Button buttonDown;
- private Button buttonCreateModif;
- private ComboBox comboBoxSelectorMap;
- }
-}
\ No newline at end of file
diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMap.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMap.cs
deleted file mode 100644
index b1d5b6d..0000000
--- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMap.cs
+++ /dev/null
@@ -1,102 +0,0 @@
-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 PIbd_22_Kalyshev_Y_V_MotorBoat_Base
-{
- public partial class FormMap : Form
- {
- private AbstractMap _abstractMap;
- public FormMap()
- {
- InitializeComponent();
- _abstractMap = new SimpleMap();
- }
- ///
- /// Заполнение информации по объекту
- ///
- ///
- private void SetData(DrawningBoat boat)
- {
- toolStripStatusLabelSpeed.Text = $"Скорость: {boat.Boat.Speed}";
- toolStripStatusLabelWeight.Text = $"Вес: {boat.Boat.Weight}";
- toolStripStatusLabelBodyColor.Text = $"Цвет: {boat.Boat.BodyColor.Name}";
- pictureBoxBoat.Image = _abstractMap.CreateMap(pictureBoxBoat.Width, pictureBoxBoat.Height, new DrawningObjectBoat(boat));
- }
- ///
- /// Обработка нажатия кнопки "Создать"
- ///
- ///
- ///
- private void ButtonCreate_Click(object sender, EventArgs e)
- {
- Random rnd = new();
- var boat = new DrawningBoat(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
- SetData(boat);
- }
- ///
- /// Изменение размеров формы
- ///
- ///
- ///
- private void ButtonMove_Click(object sender, EventArgs e)
- {
- //получаем имя кнопки
- string name = ((Button)sender)?.Name ?? string.Empty;
- Direction dir = Direction.None;
- switch (name)
- {
- case "buttonUp":
- dir = Direction.Up;
- break;
- case "buttonDown":
- dir = Direction.Down;
- break;
- case "buttonLeft":
- dir = Direction.Left;
- break;
- case "buttonRight":
- dir = Direction.Right;
- break;
- }
- pictureBoxBoat.Image = _abstractMap?.MoveObject(dir);
- }
- ///
- /// Обработка нажатия кнопки "Модификация"
- ///
- ///
- ///
- private void ButtonCreateModif_Click(object sender, EventArgs e)
- {
- Random rnd = new();
- var boat = new DrawningSpeedboat(rnd.Next(100, 300), rnd.Next(1000, 2000),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
- Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
- SetData(boat);
- }
- ///
- /// Смена карты
- ///
- ///
- ///
- private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
- {
- switch (comboBoxSelectorMap.Text)
- {
- case "Простая карта":
- _abstractMap = new SimpleMap();
- break;
- case "Своя карта":
- _abstractMap = new MySecondMap();
- break;
- }
- }
- }
-}
diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMapWithSetBoats.Designer.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMapWithSetBoats.Designer.cs
new file mode 100644
index 0000000..ad6b79a
--- /dev/null
+++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMapWithSetBoats.Designer.cs
@@ -0,0 +1,231 @@
+namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
+{
+ partial class FormMapWithSetBoats
+ {
+ ///
+ /// 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()
+ {
+ this.groupBoxTools = new System.Windows.Forms.GroupBox();
+ this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
+ this.buttonRemoveBoat = new System.Windows.Forms.Button();
+ this.buttonShowStorage = new System.Windows.Forms.Button();
+ this.buttonDown = new System.Windows.Forms.Button();
+ this.buttonRight = new System.Windows.Forms.Button();
+ this.buttonLeft = new System.Windows.Forms.Button();
+ this.buttonUp = new System.Windows.Forms.Button();
+ this.buttonShowOnMap = new System.Windows.Forms.Button();
+ this.buttonAddBoat = new System.Windows.Forms.Button();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
+ this.pictureBox = new System.Windows.Forms.PictureBox();
+ this.groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
+ this.SuspendLayout();
+ //
+ // groupBoxTools
+ //
+ this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
+ this.groupBoxTools.Controls.Add(this.buttonRemoveBoat);
+ this.groupBoxTools.Controls.Add(this.buttonShowStorage);
+ this.groupBoxTools.Controls.Add(this.buttonDown);
+ this.groupBoxTools.Controls.Add(this.buttonRight);
+ this.groupBoxTools.Controls.Add(this.buttonLeft);
+ this.groupBoxTools.Controls.Add(this.buttonUp);
+ this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
+ this.groupBoxTools.Controls.Add(this.buttonAddBoat);
+ this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
+ this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
+ this.groupBoxTools.Location = new System.Drawing.Point(927, 0);
+ this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.groupBoxTools.Name = "groupBoxTools";
+ this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.groupBoxTools.Size = new System.Drawing.Size(233, 739);
+ this.groupBoxTools.TabIndex = 0;
+ this.groupBoxTools.TabStop = false;
+ this.groupBoxTools.Text = "Инструменты";
+ //
+ // maskedTextBoxPosition
+ //
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 221);
+ this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.maskedTextBoxPosition.Mask = "00";
+ this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ this.maskedTextBoxPosition.Size = new System.Drawing.Size(199, 27);
+ this.maskedTextBoxPosition.TabIndex = 2;
+ this.maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonRemoveBoat
+ //
+ this.buttonRemoveBoat.Location = new System.Drawing.Point(19, 260);
+ this.buttonRemoveBoat.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonRemoveBoat.Name = "buttonRemoveBoat";
+ this.buttonRemoveBoat.Size = new System.Drawing.Size(200, 47);
+ this.buttonRemoveBoat.TabIndex = 3;
+ this.buttonRemoveBoat.Text = "Удалить лодку";
+ this.buttonRemoveBoat.UseVisualStyleBackColor = true;
+ this.buttonRemoveBoat.Click += new System.EventHandler(this.ButtonRemoveBoat_Click);
+ //
+ // buttonShowStorage
+ //
+ this.buttonShowStorage.Location = new System.Drawing.Point(19, 383);
+ this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonShowStorage.Name = "buttonShowStorage";
+ this.buttonShowStorage.Size = new System.Drawing.Size(200, 47);
+ this.buttonShowStorage.TabIndex = 4;
+ this.buttonShowStorage.Text = "Посмотреть гавань";
+ this.buttonShowStorage.UseVisualStyleBackColor = true;
+ this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
+ //
+ // buttonDown
+ //
+ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonDown.BackgroundImage = global::PIbd_22_Kalyshev_Y_V_MotorBoat_Base.Properties.Resources.down;
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonDown.Location = new System.Drawing.Point(104, 672);
+ this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(34, 40);
+ this.buttonDown.TabIndex = 10;
+ this.buttonDown.UseVisualStyleBackColor = true;
+ this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonRight
+ //
+ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRight.BackgroundImage = global::PIbd_22_Kalyshev_Y_V_MotorBoat_Base.Properties.Resources.right;
+ this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonRight.Location = new System.Drawing.Point(145, 672);
+ this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(34, 40);
+ this.buttonRight.TabIndex = 9;
+ this.buttonRight.UseVisualStyleBackColor = true;
+ this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonLeft
+ //
+ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonLeft.BackgroundImage = global::PIbd_22_Kalyshev_Y_V_MotorBoat_Base.Properties.Resources.left;
+ this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonLeft.Location = new System.Drawing.Point(63, 672);
+ this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonLeft.Name = "buttonLeft";
+ this.buttonLeft.Size = new System.Drawing.Size(34, 40);
+ this.buttonLeft.TabIndex = 8;
+ this.buttonLeft.UseVisualStyleBackColor = true;
+ this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonUp
+ //
+ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonUp.BackgroundImage = global::PIbd_22_Kalyshev_Y_V_MotorBoat_Base.Properties.Resources.up;
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonUp.Location = new System.Drawing.Point(104, 624);
+ this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonUp.Name = "buttonUp";
+ this.buttonUp.Size = new System.Drawing.Size(34, 40);
+ this.buttonUp.TabIndex = 7;
+ this.buttonUp.UseVisualStyleBackColor = true;
+ this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonShowOnMap
+ //
+ this.buttonShowOnMap.Location = new System.Drawing.Point(19, 521);
+ this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonShowOnMap.Name = "buttonShowOnMap";
+ this.buttonShowOnMap.Size = new System.Drawing.Size(200, 47);
+ this.buttonShowOnMap.TabIndex = 5;
+ this.buttonShowOnMap.Text = "Посмотреть карту";
+ this.buttonShowOnMap.UseVisualStyleBackColor = true;
+ this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
+ //
+ // buttonAddBoat
+ //
+ this.buttonAddBoat.Location = new System.Drawing.Point(19, 141);
+ this.buttonAddBoat.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonAddBoat.Name = "buttonAddBoat";
+ this.buttonAddBoat.Size = new System.Drawing.Size(200, 47);
+ this.buttonAddBoat.TabIndex = 1;
+ this.buttonAddBoat.Text = "Добавить лодку";
+ this.buttonAddBoat.UseVisualStyleBackColor = true;
+ this.buttonAddBoat.Click += new System.EventHandler(this.ButtonAddBoat_Click);
+ //
+ // comboBoxSelectorMap
+ //
+ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.comboBoxSelectorMap.FormattingEnabled = true;
+ this.comboBoxSelectorMap.Items.AddRange(new object[] {
+ "Простая карта",
+ "Собственная карта"});
+ this.comboBoxSelectorMap.Location = new System.Drawing.Point(19, 43);
+ this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(199, 28);
+ this.comboBoxSelectorMap.TabIndex = 0;
+ this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
+ //
+ // pictureBox
+ //
+ this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBox.Location = new System.Drawing.Point(0, 0);
+ this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.pictureBox.Name = "pictureBox";
+ this.pictureBox.Size = new System.Drawing.Size(927, 739);
+ this.pictureBox.TabIndex = 1;
+ this.pictureBox.TabStop = false;
+ //
+ // FormMapWithSetBoats
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(1160, 739);
+ this.Controls.Add(this.pictureBox);
+ this.Controls.Add(this.groupBoxTools);
+ this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.Name = "FormMapWithSetBoats";
+ this.Text = "Карта с набором объектов";
+ this.groupBoxTools.ResumeLayout(false);
+ this.groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private PictureBox pictureBox;
+ private ComboBox comboBoxSelectorMap;
+ private Button buttonShowOnMap;
+ private Button buttonAddBoat;
+ private Button buttonDown;
+ private Button buttonRight;
+ private Button buttonLeft;
+ private Button buttonUp;
+ private Button buttonShowStorage;
+ private Button buttonRemoveBoat;
+ private MaskedTextBox maskedTextBoxPosition;
+ }
+}
\ No newline at end of file
diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMapWithSetBoats.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMapWithSetBoats.cs
new file mode 100644
index 0000000..ce0ce2c
--- /dev/null
+++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMapWithSetBoats.cs
@@ -0,0 +1,152 @@
+namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
+{
+ public partial class FormMapWithSetBoats : Form
+ {
+ ///
+ /// Объект от класса карты с набором объектов
+ ///
+ private MapWithSetBoatsGeneric _mapBoatsCollectionGeneric;
+ ///
+ /// Конструктор
+ ///
+ public FormMapWithSetBoats()
+ {
+ InitializeComponent();
+ }
+ ///
+ /// Выбор карты
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ AbstractMap map = null;
+ switch (comboBoxSelectorMap.Text)
+ {
+ case "Простая карта":
+ map = new SimpleMap();
+ break;
+ case "Собственная карта":
+ map = new MySecondMap();
+ break;
+ }
+ if (map != null)
+ {
+ _mapBoatsCollectionGeneric = new MapWithSetBoatsGeneric(pictureBox.Width, pictureBox.Height, map);
+ }
+ else
+ {
+ _mapBoatsCollectionGeneric = null;
+ }
+ }
+ ///
+ /// Добавление объекта
+ ///
+ ///
+ ///
+ private void ButtonAddBoat_Click(object sender, EventArgs e)
+ {
+ if (_mapBoatsCollectionGeneric == null)
+ {
+ return;
+ }
+ FormBoat form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ DrawningObjectBoat boat = new(form.SelectedBoat);
+ if (_mapBoatsCollectionGeneric + boat != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+ }
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void ButtonRemoveBoat_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
+ {
+ return;
+ }
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
+ if (_mapBoatsCollectionGeneric - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+ ///
+ /// Вывод набора
+ ///
+ ///
+ ///
+ private void ButtonShowStorage_Click(object sender, EventArgs e)
+ {
+ if (_mapBoatsCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapBoatsCollectionGeneric.ShowSet();
+ }
+ ///
+ /// Вывод карты
+ ///
+ ///
+ ///
+ private void ButtonShowOnMap_Click(object sender, EventArgs e)
+ {
+ if (_mapBoatsCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapBoatsCollectionGeneric.ShowOnMap();
+ }
+ ///
+ /// Перемещение
+ ///
+ ///
+ ///
+ private void ButtonMove_Click(object sender, EventArgs e)
+ {
+ if (_mapBoatsCollectionGeneric == null)
+ {
+ return;
+ }
+ //получаем имя кнопки
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ Direction dir = Direction.None;
+ switch (name)
+ {
+ case "buttonUp":
+ dir = Direction.Up;
+ break;
+ case "buttonDown":
+ dir = Direction.Down;
+ break;
+ case "buttonLeft":
+ dir = Direction.Left;
+ break;
+ case "buttonRight":
+ dir = Direction.Right;
+ break;
+ }
+ pictureBox.Image = _mapBoatsCollectionGeneric.MoveObject(dir);
+ }
+ }
+}
\ No newline at end of file
diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMap.resx b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMapWithSetBoats.resx
similarity index 93%
rename from PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMap.resx
rename to PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMapWithSetBoats.resx
index 5cb320f..f298a7b 100644
--- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMap.resx
+++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/FormMapWithSetBoats.resx
@@ -57,7 +57,4 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
- 17, 17
-
\ No newline at end of file
diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/MapWithSetBoatsGeneric.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/MapWithSetBoatsGeneric.cs
new file mode 100644
index 0000000..27a36b4
--- /dev/null
+++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/MapWithSetBoatsGeneric.cs
@@ -0,0 +1,180 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
+{
+ internal class MapWithSetBoatsGeneric
+ where T : class, IDrawningObject
+ where U : AbstractMap
+ {
+ ///
+ /// Ширина окна отрисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна отрисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Размер занимаемого объектом места (ширина)
+ ///
+ private readonly int _placeSizeWidth = 250;
+ ///
+ /// Размер занимаемого объектом места (высота)
+ ///
+ private readonly int _placeSizeHeight = 90;
+ ///
+ /// Набор объектов
+ ///
+ private readonly SetBoatsGeneric _setBoats;
+ ///
+ /// Карта
+ ///
+ private readonly U _map;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public MapWithSetBoatsGeneric(int picWidth, int picHeight, U map)
+ {
+ int width = picWidth / _placeSizeWidth;
+ int height = picHeight / _placeSizeHeight;
+ _setBoats = new SetBoatsGeneric(width * height);
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _map = map;
+ }
+ ///
+ /// Перегрузка оператора сложения
+ ///
+ ///
+ ///
+ ///
+ public static int operator +(MapWithSetBoatsGeneric map, T boat)
+ {
+ return map._setBoats.Insert(boat);
+ }
+ ///
+ /// Перегрузка оператора вычитания
+ ///
+ ///
+ ///
+ ///
+ public static T operator -(MapWithSetBoatsGeneric map, int position)
+ {
+ return map._setBoats.Remove(position);
+ }
+ ///
+ /// Вывод всего набора объектов
+ ///
+ ///
+ public Bitmap ShowSet()
+ {
+ Bitmap bmp = new(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ ShowOnMap();
+ DrawBackground(gr);
+ DrawBoats(gr);
+ return bmp;
+ }
+ ///
+ /// Просмотр объекта на карте
+ ///
+ ///
+ public Bitmap ShowOnMap()
+ {
+ Shaking();
+ for (int i = 0; i < _setBoats.Count; i++)
+ {
+ var boat = _setBoats.Get(i);
+ if (boat != null)
+ {
+ return _map.CreateMap(_pictureWidth, _pictureHeight, boat);
+ }
+ }
+ return new(_pictureWidth, _pictureHeight);
+ }
+ ///
+ /// Перемещение объекта по крате
+ ///
+ ///
+ ///
+ public Bitmap MoveObject(Direction direction)
+ {
+ if (_map != null)
+ {
+ return _map.MoveObject(direction);
+ }
+ return new(_pictureWidth, _pictureHeight);
+ }
+ ///
+ /// "Взбалтываем" набор, чтобы все элементы оказались в начале
+ ///
+ private void Shaking()
+ {
+ int j = _setBoats.Count - 1;
+ for (int i = 0; i < _setBoats.Count; i++)
+ {
+ if (_setBoats.Get(i) == null)
+ {
+ for (; j > i; j--)
+ {
+ var boat = _setBoats.Get(j);
+ if (boat != null)
+ {
+ _setBoats.Insert(boat, i);
+ _setBoats.Remove(j);
+ break;
+ }
+ }
+ if (j <= i)
+ {
+ return;
+ }
+ }
+ }
+ }
+ ///
+ /// Метод отрисовки фона
+ ///
+ ///
+ 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 DrawBoats(Graphics g)
+ {
+ int x = 5;
+ int y = 5;
+ for (int i = 0; i < _setBoats.Count; i++)
+ {
+ _setBoats.Get(i)?.SetObject(x, y, _pictureWidth, _pictureHeight);
+ _setBoats.Get(i)?.DrawningObject(g);
+ x += _placeSizeWidth;
+ if (x + _placeSizeWidth > _pictureWidth)
+ {
+ y += _placeSizeHeight;
+ x = 5;
+ }
+ }
+ }
+ }
+}
diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/Program.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/Program.cs
index de015b0..1ab4654 100644
--- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/Program.cs
+++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/Program.cs
@@ -11,7 +11,7 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormMap());
+ Application.Run(new FormMapWithSetBoats());
}
}
}
\ No newline at end of file
diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/SetBoatsGeneric.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/SetBoatsGeneric.cs
new file mode 100644
index 0000000..058bdc3
--- /dev/null
+++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/SetBoatsGeneric.cs
@@ -0,0 +1,111 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.Metrics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
+{
+ internal class SetBoatsGeneric
+ where T : class
+ {
+ ///
+ /// Массив объектов, которые храним
+ ///
+ private readonly T[] _places;
+ ///
+ /// Количество объектов в массиве
+ ///
+ public int Count => _places.Length;
+ ///
+ /// Конструктор
+ ///
+ ///
+ public SetBoatsGeneric(int count)
+ {
+ _places = new T[count];
+ }
+ ///
+ /// Добавление объекта в набор
+ ///
+ /// Добавляемый автомобиль
+ ///
+ public int Insert(T boat)
+ {
+ for (int i = 0; i < _places.Length; i++)
+ {
+ if (_places[i] == null)
+ {
+ _places[i] = boat;
+ return i;
+ }
+ }
+ return -1;
+ }
+ ///
+ /// Добавление объекта в набор на конкретную позицию
+ ///
+ /// Добавляемый автомобиль
+ /// Позиция
+ ///
+ public bool Insert(T boat, int position)
+ {
+ if (position < 0 || position > _places.Length)
+ {
+ return false;
+ }
+ if (_places[position] != null)
+ {
+ int pos = -1;
+ for (int i = position+1; i < _places.Length; i++)
+ {
+ if (_places[i] == null)
+ {
+ pos = i;
+ }
+ }
+ if (pos != -1)
+ {
+ for (int i = pos; i > position; i--)
+ {
+ _places[i] = _places[i - 1];
+ }
+ } else
+ {
+ return false;
+ }
+ }
+ _places[position] = boat;
+ return false;
+ }
+ ///
+ /// Удаление объекта из набора с конкретной позиции
+ ///
+ ///
+ ///
+ public T Remove(int position)
+ {
+ if (position < 0 || position > _places.Length)
+ {
+ return null;
+ }
+ T removed = _places[position];
+ _places[position] = null;
+ return removed;
+ }
+ ///
+ /// Получение объекта из набора по позиции
+ ///
+ ///
+ ///
+ public T Get(int position)
+ {
+ if (position < 0 || position > _places.Length)
+ {
+ return null;
+ }
+ return _places[position];
+ }
+ }
+}