diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..bf35846 --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectCatamaran.Drawnings; + +namespace ProjectCatamaran.CollectionGenericObjects; +public abstract class AbstractCompany +{ + protected readonly int _placeSizeWidth = 90; + protected readonly int _placeSizeHeight = 50; + protected readonly int _pictureWidth; + protected readonly int _pictureHeight; + protected ICollectionGenericObjects _collection = null; + private int GetMaxCount => (_pictureWidth / _placeSizeWidth + 1) * (_pictureHeight / _placeSizeHeight / 2) - (_pictureHeight / _placeSizeHeight / 2); + public AbstractCompany(int picWidth,int picHeight,ICollectionGenericObjects collection) + { + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = collection; + _collection.SetMaxCount = GetMaxCount; + } + public static int operator +(AbstractCompany company, DrawningBoat boat) + { + return company._collection?.Insert(boat) ?? -1; + } + public static DrawningBoat? operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position); + } + public DrawningBoat? GetRandomObject() + { + Random rnd = new Random(); + return _collection?.Get(rnd.Next(GetMaxCount)); + } + public Bitmap Show() + { + Bitmap bitmap = new(_pictureWidth, _pictureHeight); + Graphics graphics = Graphics.FromImage(bitmap); + DrawBackground(graphics); + SetObjectPosition(); + for (int i = 0; i < (_collection?.Count ?? 0); ++i) + { + DrawningBoat? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + + return bitmap; + } + protected abstract void DrawBackground(Graphics g); + protected abstract void SetObjectPosition(); +} + diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/Harbour.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/Harbour.cs new file mode 100644 index 0000000..06bddaa --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/Harbour.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectCatamaran.Drawnings; + +namespace ProjectCatamaran.CollectionGenericObjects; +public class Harbour : AbstractCompany +{ + public Harbour(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + protected override void DrawBackground(Graphics g) + { + Pen pen = new Pen(Color.Black,2); + for (int i = 0; i < _pictureHeight / _placeSizeHeight / 2; i++) + { + g.DrawLine(pen, 0, _pictureHeight - 10 - (2*i* _placeSizeHeight) + , _pictureWidth , _pictureHeight - 10 - (2*i * _placeSizeHeight)); + for (int j = 0; j - 1 < _pictureWidth / _placeSizeWidth; j++) + { + g.DrawLine(pen, (j * _placeSizeWidth), _pictureHeight - 10 - (2 * i * _placeSizeHeight), + (j * _placeSizeWidth), _pictureHeight - 10 - (2 *i * _placeSizeHeight)- _placeSizeHeight); + } + } + } + protected override void SetObjectPosition() + { + int curPosX = 0; + int curPosY = 0; + + for (int i = 0; i < (_collection?.Count ?? 0); i++) + { + + if (_collection?.Get(i) != null) + { + + _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); + _collection?.Get(i)?.SetPosition((curPosX * _placeSizeWidth) + 15,_pictureHeight - 2 * curPosY * _placeSizeHeight - _placeSizeHeight - 5); + } + curPosX += 1; + + + if (curPosX > 6) + { + curPosX = 0; + curPosY++; + } + } + } +} diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..0134704 --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCatamaran.CollectionGenericObjects; + +public interface ICollectionGenericObjects where T : class +{ + int Count { get; } + int SetMaxCount { set; } + int Insert(T obj); + int Insert(T obj, int position); + T? Remove(int position); + + T? Get(int position); +} + diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..a9c52a4 --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCatamaran.CollectionGenericObjects; + +public class MassiveGenericObjects : ICollectionGenericObjects where T : class +{ + private T?[] _collection; + public int Count => _collection.Length; + public int SetMaxCount + { + set + { + if (value > 0) + { + _collection = new T?[value]; + } + } + } + public MassiveGenericObjects() + { + _collection = Array.Empty(); + } + public T? Get(int position) + { + if (position >= 0 && position < Count) + { + return _collection[position]; + } + + return null; + } + public int Insert(T obj) + { + for (int i = 0; i < Count; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return i; + } + } + + return -1; + } + public int Insert(T obj, int position) + { + if (!(position > 0 && position < _collection.Length)) + { + return -1; + } + if (_collection[position] == null) + _collection[position] = obj; + else + { + for (int i = position + 1; i < Count; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return i; + } + } + for (int i = position - 1; i >= 0; i--) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return i; + } + } + } + return -1; + } + public T? Remove(int position) + { + if (!(position >= 0 && position < _collection.Length) || _collection[position] == null ) + { + return null; + } + T? deletedElement = _collection[position]; + _collection[position] = null; + return deletedElement; + } +} + diff --git a/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs b/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs index 34b2b2c..f9f0a7e 100644 --- a/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs +++ b/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs @@ -73,18 +73,16 @@ public class DrawningBoat public DrawningBoat(int speed, double weight, Color bodyColor) : this() { EntityBoat = new EntityBoat(speed, weight, bodyColor); - } /// /// Конструктор /// - /// Ширина катера - /// высота катера + /// Ширина катера + /// высота катера public DrawningBoat(int drawningBoatWidth, int drawningBoatHeight) : this() { _drawningBoatWidth = drawningBoatWidth; _drawningBoatHeight = drawningBoatHeight; - } /// /// установка границ поля diff --git a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs new file mode 100644 index 0000000..46b8509 --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs @@ -0,0 +1,173 @@ +namespace ProjectCatamaran +{ + 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() + { + groupBoxTools = new GroupBox(); + buttonRefresh = new Button(); + buttonGoToCheck = new Button(); + buttonRemoveBoat = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonAddCatamaran = new Button(); + buttonAddBoat = new Button(); + comboBoxSelectorCompany = new ComboBox(); + pictureBox = new PictureBox(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(buttonGoToCheck); + groupBoxTools.Controls.Add(buttonRemoveBoat); + groupBoxTools.Controls.Add(maskedTextBoxPosition); + groupBoxTools.Controls.Add(buttonAddCatamaran); + groupBoxTools.Controls.Add(buttonAddBoat); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(631, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(169, 450); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(6, 381); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(157, 39); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(6, 324); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(157, 39); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemoveBoat + // + buttonRemoveBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveBoat.Location = new Point(6, 279); + buttonRemoveBoat.Name = "buttonRemoveBoat"; + buttonRemoveBoat.Size = new Size(157, 39); + buttonRemoveBoat.TabIndex = 4; + buttonRemoveBoat.Text = "Удалить лодку"; + buttonRemoveBoat.UseVisualStyleBackColor = true; + buttonRemoveBoat.Click += ButtonRemoveBoat_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(1, 233); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(162, 23); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonAddCatamaran + // + buttonAddCatamaran.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddCatamaran.Location = new Point(6, 125); + buttonAddCatamaran.Name = "buttonAddCatamaran"; + buttonAddCatamaran.Size = new Size(157, 39); + buttonAddCatamaran.TabIndex = 2; + buttonAddCatamaran.Text = "Добавление катамарана"; + buttonAddCatamaran.UseVisualStyleBackColor = true; + buttonAddCatamaran.Click += ButtonAddCatamaran_Click; + // + // buttonAddBoat + // + buttonAddBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddBoat.Location = new Point(6, 80); + buttonAddBoat.Name = "buttonAddBoat"; + buttonAddBoat.Size = new Size(157, 39); + buttonAddBoat.TabIndex = 1; + buttonAddBoat.Text = "Добавление лодки"; + buttonAddBoat.UseVisualStyleBackColor = true; + buttonAddBoat.Click += ButtonAddBoat_Click; + // + // comboBoxSelectorCompany + // + comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectorCompany.FormattingEnabled = true; + comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); + comboBoxSelectorCompany.Location = new Point(6, 22); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(157, 23); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(631, 450); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormBoatCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormBoatCollection"; + Text = "Коллекция лодок"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private Button buttonAddCatamaran; + private Button buttonAddBoat; + private ComboBox comboBoxSelectorCompany; + private MaskedTextBox maskedTextBoxPosition; + private PictureBox pictureBox; + private Button buttonRemoveBoat; + private Button buttonRefresh; + private Button buttonGoToCheck; + } +} \ No newline at end of file diff --git a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs new file mode 100644 index 0000000..c253d60 --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs @@ -0,0 +1,149 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ProjectCatamaran.CollectionGenericObjects; +using ProjectCatamaran.Drawnings; + +namespace ProjectCatamaran; +public partial class FormBoatCollection : Form +{ + private AbstractCompany? _company; + public FormBoatCollection() + { + InitializeComponent(); + } + + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new Harbour(pictureBox.Width, pictureBox.Height, + new MassiveGenericObjects()); + break; + } + } + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + Random random = new(); + DrawningBoat drawningBoat; + switch (type) + { + case nameof(DrawningBoat): + drawningBoat = new DrawningBoat(random.Next(100, 300), random.Next(1000, 3000), + GetColor(random)); + break; + case nameof(DrawningCatamaran): + drawningBoat = new DrawningCatamaran(random.Next(100, 300), random.Next(1000, 3000), + GetColor(random), GetColor(random), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + } + + if (_company + drawningBoat != -1) + { + MessageBox.Show(("Объект добавлен")); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + + private static Color GetColor(Random random) + { + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + + return color; + } + + private void ButtonAddBoat_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningBoat)); + } + + private void ButtonAddCatamaran_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningCatamaran)); + + } + + private void ButtonRemoveBoat_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) + { + return; + } + + if (MessageBox.Show("Удалить объект", "Удаление", MessageBoxButtons.YesNo, + MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_company - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + private void ButtonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawningBoat? boat = null; + int counter = 100; + while (boat == null) + { + boat = _company.GetRandomObject(); + counter--; + if (counter <= 0) + break; + } + + if (boat == null) + return; + FormCatamaran form = new() + { + SetBoat = boat + }; + form.ShowDialog(); + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } +} diff --git a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.resx b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/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/ProjectCatamaran/ProjectCatamaran/FormCatamaran.Designer.cs b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.Designer.cs index 5c03681..6b7659f 100644 --- a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.Designer.cs +++ b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.Designer.cs @@ -29,14 +29,13 @@ private void InitializeComponent() { pictureBoxCatamaran = new PictureBox(); - buttonCreateCatamaran = new Button(); buttonUp = new Button(); buttonRight = new Button(); buttonLeft = new Button(); buttonDown = new Button(); - buttonCreateBoat = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); + colorDialog1 = new ColorDialog(); ((System.ComponentModel.ISupportInitialize)pictureBoxCatamaran).BeginInit(); SuspendLayout(); // @@ -45,21 +44,10 @@ pictureBoxCatamaran.Dock = DockStyle.Fill; pictureBoxCatamaran.Location = new Point(0, 0); pictureBoxCatamaran.Name = "pictureBoxCatamaran"; - pictureBoxCatamaran.Size = new Size(801, 450); + pictureBoxCatamaran.Size = new Size(800, 450); pictureBoxCatamaran.TabIndex = 0; pictureBoxCatamaran.TabStop = false; // - // buttonCreateCatamaran - // - buttonCreateCatamaran.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonCreateCatamaran.Location = new Point(12, 402); - buttonCreateCatamaran.Name = "buttonCreateCatamaran"; - buttonCreateCatamaran.Size = new Size(166, 40); - buttonCreateCatamaran.TabIndex = 1; - buttonCreateCatamaran.Text = "Создать катамаран"; - buttonCreateCatamaran.UseVisualStyleBackColor = true; - buttonCreateCatamaran.Click += ButtonCreateCatamaran_Click; - // // buttonUp // buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -108,17 +96,6 @@ buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += ButtonMove_Click; // - // buttonCreateBoat - // - buttonCreateBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonCreateBoat.Location = new Point(184, 402); - buttonCreateBoat.Name = "buttonCreateBoat"; - buttonCreateBoat.Size = new Size(166, 40); - buttonCreateBoat.TabIndex = 6; - buttonCreateBoat.Text = "Создать лодку"; - buttonCreateBoat.UseVisualStyleBackColor = true; - buttonCreateBoat.Click += ButtonCreateBoat_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -147,12 +124,10 @@ ClientSize = new Size(800, 450); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateBoat); Controls.Add(buttonDown); Controls.Add(buttonLeft); Controls.Add(buttonRight); Controls.Add(buttonUp); - Controls.Add(buttonCreateCatamaran); Controls.Add(pictureBoxCatamaran); Name = "FormCatamaran"; Text = "Катамаран"; @@ -163,13 +138,12 @@ #endregion private PictureBox pictureBoxCatamaran; - private Button buttonCreateCatamaran; private Button buttonUp; private Button buttonRight; private Button buttonLeft; private Button buttonDown; - private Button buttonCreateBoat; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; + private ColorDialog colorDialog1; } } \ No newline at end of file diff --git a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.cs b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.cs index e008569..c547223 100644 --- a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.cs +++ b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.cs @@ -17,6 +17,18 @@ namespace ProjectCatamaran { private DrawningBoat? _drawningBoat; private AbstractStrategy? _strategy; + + public DrawningBoat SetBoat + { + set + { + _drawningBoat = value; + _drawningBoat.SetPictureSize(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } public FormCatamaran() { InitializeComponent(); @@ -64,39 +76,6 @@ namespace ProjectCatamaran } } - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningBoat): - _drawningBoat = new DrawningBoat(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); - break; - case nameof(DrawningCatamaran): - _drawningBoat = new DrawningCatamaran(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))); - break; - default: - return; - } - _drawningBoat.SetPictureSize(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height); - _drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - private void ButtonCreateCatamaran_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawningCatamaran)); - } - - private void ButtonCreateBoat_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawningBoat)); - } /// /// Обработка нажатия кнопки "Шаг" /// diff --git a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.resx b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.resx index af32865..818dfae 100644 --- a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.resx +++ b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.resx @@ -117,4 +117,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/ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveToBorder.cs b/ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveToBorder.cs index 188f4f3..da1d690 100644 --- a/ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveToBorder.cs +++ b/ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveToBorder.cs @@ -30,8 +30,8 @@ public class MoveToBorder : AbstractStrategy ObjectParameters? objParams = GetObjectParameters; if (objParams == null) return false; - return objParams.RightBorder + GetStep() >= FieldWidth && - objParams.DownBorder + GetStep() >= FieldHeight ; + return objParams.RightBorder + GetStep() > FieldWidth && + objParams.DownBorder + GetStep() > FieldHeight ; } } diff --git a/ProjectCatamaran/ProjectCatamaran/Program.cs b/ProjectCatamaran/ProjectCatamaran/Program.cs index 4d620b5..59feea7 100644 --- a/ProjectCatamaran/ProjectCatamaran/Program.cs +++ b/ProjectCatamaran/ProjectCatamaran/Program.cs @@ -11,7 +11,7 @@ namespace ProjectCatamaran // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormCatamaran()); + Application.Run(new FormBoatCollection()); } } } \ No newline at end of file