From 98ce97ea6f986e2bcb4205ffec2e6eb767643c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 18 Oct 2022 23:48:38 +0400 Subject: [PATCH 01/12] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=203=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/Direction.cs | 2 +- WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs | 2 +- WarmlyShip/WarmlyShip/EntityWarmlyShip.cs | 2 +- WarmlyShip/WarmlyShip/FormClass.Designer.cs | 13 ++ WarmlyShip/WarmlyShip/FormClass.cs | 8 ++ .../WarmlyShip/MapWithSetShipGeneric.cs | 122 ++++++++++++++++++ WarmlyShip/WarmlyShip/SetShipGeneric.cs | 49 +++++++ 7 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs create mode 100644 WarmlyShip/WarmlyShip/SetShipGeneric.cs diff --git a/WarmlyShip/WarmlyShip/Direction.cs b/WarmlyShip/WarmlyShip/Direction.cs index 09a6267..3669bef 100644 --- a/WarmlyShip/WarmlyShip/Direction.cs +++ b/WarmlyShip/WarmlyShip/Direction.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace WarmlyShip { - internal enum Direction //Направление при перемещении + public enum Direction //Направление при перемещении { None = 0, Left = 1, //Влево diff --git a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs index aa3dab2..05f9aff 100644 --- a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace WarmlyShip { - internal class DrawingWarmlyShip + public class DrawingWarmlyShip { public EntityWarmlyShip warmlyShip { protected set; get; } //Класс-сущность protected float _startPosX; //Координаты отрисовки по оси x diff --git a/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs b/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs index 1da24c8..e36f167 100644 --- a/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace WarmlyShip { - internal class EntityWarmlyShip + public class EntityWarmlyShip { public int Speed { get; private set; } //Скорость public float Weight { get; private set; } //Вес diff --git a/WarmlyShip/WarmlyShip/FormClass.Designer.cs b/WarmlyShip/WarmlyShip/FormClass.Designer.cs index d24e401..7e5c168 100644 --- a/WarmlyShip/WarmlyShip/FormClass.Designer.cs +++ b/WarmlyShip/WarmlyShip/FormClass.Designer.cs @@ -39,6 +39,7 @@ this.buttonDown = new System.Windows.Forms.Button(); this.ButtonCreate = new System.Windows.Forms.Button(); this.buttonCreateModif = new System.Windows.Forms.Button(); + this.buttonSelectShip = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -154,11 +155,22 @@ this.buttonCreateModif.UseVisualStyleBackColor = true; this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); // + // buttonSelectShip + // + this.buttonSelectShip.Location = new System.Drawing.Point(522, 402); + this.buttonSelectShip.Name = "buttonSelectShip"; + this.buttonSelectShip.Size = new System.Drawing.Size(75, 23); + this.buttonSelectShip.TabIndex = 9; + this.buttonSelectShip.Text = "Выбрать"; + this.buttonSelectShip.UseVisualStyleBackColor = true; + this.buttonSelectShip.Click += new System.EventHandler(this.ButtonSelectShip_Click); + // // FormClass // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonSelectShip); this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.ButtonCreate); this.Controls.Add(this.buttonDown); @@ -190,5 +202,6 @@ private Button buttonDown; private Button ButtonCreate; private Button buttonCreateModif; + private Button buttonSelectShip; } } \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/FormClass.cs b/WarmlyShip/WarmlyShip/FormClass.cs index 2e0cb90..7fdaa22 100644 --- a/WarmlyShip/WarmlyShip/FormClass.cs +++ b/WarmlyShip/WarmlyShip/FormClass.cs @@ -4,6 +4,8 @@ namespace WarmlyShip { private DrawingWarmlyShip _warmlyShip; + public DrawingWarmlyShip SelectedShip { get; private set; } + public FormClass() { InitializeComponent(); @@ -71,5 +73,11 @@ namespace WarmlyShip SetData(); Draw(); } + + private void ButtonSelectShip_Click(object sender, EventArgs e) + { + SelectedShip = _warmlyShip; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs new file mode 100644 index 0000000..476b183 --- /dev/null +++ b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal class MapWithSetShipGeneric + where T : class, IDrawningObject + where U : AbstractMap + { + private readonly int _pictureWidth; + private readonly int _pictureHeight; + private readonly int _placeSizeWidth = 210; + private readonly int _placeSizeHeight = 90; + private readonly SetShipGeneric _setShips; + private readonly U _map; + + public MapWithSetShipGeneric(int picWidth, int picHeight, U map) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _setShips = new SetShipGeneric(width * height); + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _map = map; + } + + public static bool operator +(MapWithSetShipGeneric map, T ship) + { + return map._setShips.Insert(ship); + } + + public static bool operator -(MapWithSetShipGeneric map, int position) + { + return map._setShips.Remove(position); + } + + public Bitmap ShowSet() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawShips(gr); + return bmp; + } + + public Bitmap ShowOnMap() + { + Shaking(); + for (int i = 0; i < _setShips.Count; i++) + { + var ship = _setShips.Get(i); + if (ship != null) + { + return _map.CreateMap(_pictureWidth, _pictureHeight, ship); + } + } + 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 = _setShips.Count - 1; + for (int i = 0; i < _setShips.Count; i++) + { + if (_setShips.Get(i) == null) + { + for (; j > i; j--) + { + var ship = _setShips.Get(j); + if (ship != null) + { + _setShips.Insert(ship, i); + _setShips.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 DrawShips(Graphics g) + { + for (int i = 0; i < _setShips.Count; i++) + { + // TODO установка позиции + _setShips.Get(i)?.DrawningObject(g); + } + } + + } +} diff --git a/WarmlyShip/WarmlyShip/SetShipGeneric.cs b/WarmlyShip/WarmlyShip/SetShipGeneric.cs new file mode 100644 index 0000000..e334b1d --- /dev/null +++ b/WarmlyShip/WarmlyShip/SetShipGeneric.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal class SetShipGeneric + where T : class + { + private readonly T[] _places; + public int Count => _places.Length; + public SetShipGeneric(int count) + { + _places = new T[count]; + } + public bool Insert(T ship) + { + // TODO вставка в начало набора + return true; + } + + public bool Insert(T ship, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // проверка, что после вставляемого элемента в массиве есть пустой элемент + // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента + // TODO вставка по позиции + _places[position] = ship; + return true; + } + + public bool Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присовив элементу массива значение null + return true; + } + + public T Get(int position) + { + // TODO проверка позиции + return _places[position]; + } + + } +} -- 2.25.1 From 164be62345a27c8e34b2e360c0ddf6ce5013e87c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 19 Oct 2022 10:36:34 +0400 Subject: [PATCH 02/12] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WarmlyShip/FormMapWithSetShip.Designer.cs | 211 ++++++++++++++++++ WarmlyShip/WarmlyShip/FormMapWithSetShip.cs | 130 +++++++++++ WarmlyShip/WarmlyShip/FormMapWithSetShip.resx | 60 +++++ .../WarmlyShip/MapWithSetShipGeneric.cs | 3 +- 4 files changed, 402 insertions(+), 2 deletions(-) create mode 100644 WarmlyShip/WarmlyShip/FormMapWithSetShip.Designer.cs create mode 100644 WarmlyShip/WarmlyShip/FormMapWithSetShip.cs create mode 100644 WarmlyShip/WarmlyShip/FormMapWithSetShip.resx diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetShip.Designer.cs b/WarmlyShip/WarmlyShip/FormMapWithSetShip.Designer.cs new file mode 100644 index 0000000..4625b4d --- /dev/null +++ b/WarmlyShip/WarmlyShip/FormMapWithSetShip.Designer.cs @@ -0,0 +1,211 @@ +namespace WarmlyShip +{ + partial class FormMapWithSetShip + { + /// + /// 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.groupBox1 = new System.Windows.Forms.GroupBox(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.buttonAddShip = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.maskedTextBoxPosition); + this.groupBox1.Controls.Add(this.buttonDown); + this.groupBox1.Controls.Add(this.buttonLeft); + this.groupBox1.Controls.Add(this.buttonUp); + this.groupBox1.Controls.Add(this.buttonRight); + this.groupBox1.Controls.Add(this.button4); + this.groupBox1.Controls.Add(this.button3); + this.groupBox1.Controls.Add(this.button2); + this.groupBox1.Controls.Add(this.buttonAddShip); + this.groupBox1.Controls.Add(this.comboBoxSelectorMap); + this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; + this.groupBox1.Location = new System.Drawing.Point(600, 0); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(200, 450); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Инструменты"; + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::WarmlyShip.Properties.Resources.todown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(75, 391); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(50, 50); + this.buttonDown.TabIndex = 10; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.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::WarmlyShip.Properties.Resources.toleft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(19, 391); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(50, 50); + this.buttonLeft.TabIndex = 9; + 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::WarmlyShip.Properties.Resources.totop; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(75, 335); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(50, 50); + this.buttonUp.TabIndex = 8; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.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::WarmlyShip.Properties.Resources.toright; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(131, 391); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(50, 50); + this.buttonRight.TabIndex = 7; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // button4 + // + this.button4.Location = new System.Drawing.Point(6, 281); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(188, 23); + this.button4.TabIndex = 5; + this.button4.Text = "Посмотреть карту"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(6, 226); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(188, 23); + this.button3.TabIndex = 4; + this.button3.Text = "Посмотреть хранилище"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(6, 170); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(188, 23); + this.button2.TabIndex = 3; + this.button2.Text = "Удалить корабль"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.ButtonRemoveShip_Click); + // + // buttonAddShip + // + this.buttonAddShip.Location = new System.Drawing.Point(6, 65); + this.buttonAddShip.Name = "buttonAddShip"; + this.buttonAddShip.Size = new System.Drawing.Size(188, 23); + this.buttonAddShip.TabIndex = 1; + this.buttonAddShip.Text = "Добавить корабль"; + this.buttonAddShip.UseVisualStyleBackColor = true; + this.buttonAddShip.Click += new System.EventHandler(this.ButtonAddShip_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 22); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 23); + this.comboBoxSelectorMap.TabIndex = 0; + // + // pictureBox + // + this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox.Location = new System.Drawing.Point(0, 0); + this.pictureBox.Name = "pictureBox"; + this.pictureBox.Size = new System.Drawing.Size(600, 450); + this.pictureBox.TabIndex = 1; + this.pictureBox.TabStop = false; + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 116); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(188, 23); + this.maskedTextBoxPosition.TabIndex = 11; + // + // FormMapWithSetShip + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.pictureBox); + this.Controls.Add(this.groupBox1); + this.Name = "FormMapWithSetShip"; + this.Text = "FormMapWithSetShip"; + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBox1; + private PictureBox pictureBox; + private Button buttonAddShip; + private ComboBox comboBoxSelectorMap; + private Button button4; + private Button button3; + private Button button2; + private Button buttonDown; + private Button buttonLeft; + private Button buttonUp; + private Button buttonRight; + private MaskedTextBox maskedTextBoxPosition; + } +} \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs new file mode 100644 index 0000000..78795d4 --- /dev/null +++ b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs @@ -0,0 +1,130 @@ +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 static System.Windows.Forms.DataFormats; + +namespace WarmlyShip +{ + public partial class FormMapWithSetShip : Form + { + private MapWithSetShipGeneric _mapCarsCollectionGeneric; + + public FormMapWithSetShip() + { + InitializeComponent(); + } + + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + map = new SimpleMap(); + break; + } + if (map != null) + { + _mapCarsCollectionGeneric = new MapWithSetShipGeneric(pictureBox.Width, pictureBox.Height, map); + } + else + { + _mapCarsCollectionGeneric = null; + } + } + + private void ButtonAddShip_Click(object sender, EventArgs e) + { + if (_mapCarsCollectionGeneric == null) + { + return; + } + FormClass form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + DrawningObjectShip ship = new(form.SelectedShip); + if (_mapCarsCollectionGeneric + ship) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapCarsCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + + private void ButtonRemoveShip_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 (_mapCarsCollectionGeneric - pos) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _mapCarsCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + private void ButtonShowStorage_Click(object sender, EventArgs e) + { + if (_mapCarsCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapCarsCollectionGeneric.ShowSet(); + } + + private void ButtonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapCarsCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapCarsCollectionGeneric.ShowOnMap(); + } + + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_mapCarsCollectionGeneric == 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 = _mapCarsCollectionGeneric.MoveObject(dir); + } + } +} diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetShip.resx b/WarmlyShip/WarmlyShip/FormMapWithSetShip.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/WarmlyShip/WarmlyShip/FormMapWithSetShip.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs index 476b183..1fba030 100644 --- a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs @@ -104,8 +104,7 @@ namespace WarmlyShip g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); } - g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, - (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); } } -- 2.25.1 From a23ecbf81c252425eafdf7923edfdcb596048c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 19 Oct 2022 10:37:57 +0400 Subject: [PATCH 03/12] =?UTF-8?q?=D0=9D=D0=B0=D0=BB=D0=BE=D0=B6=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=88=D1=82=D0=B0=D0=BD=D1=8B=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=BE=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/FormMap.Designer.cs | 210 ---------------------- WarmlyShip/WarmlyShip/FormMap.cs | 88 --------- WarmlyShip/WarmlyShip/FormMap.resx | 63 ------- WarmlyShip/WarmlyShip/Program.cs | 2 +- 4 files changed, 1 insertion(+), 362 deletions(-) delete mode 100644 WarmlyShip/WarmlyShip/FormMap.Designer.cs delete mode 100644 WarmlyShip/WarmlyShip/FormMap.cs delete mode 100644 WarmlyShip/WarmlyShip/FormMap.resx diff --git a/WarmlyShip/WarmlyShip/FormMap.Designer.cs b/WarmlyShip/WarmlyShip/FormMap.Designer.cs deleted file mode 100644 index f89a930..0000000 --- a/WarmlyShip/WarmlyShip/FormMap.Designer.cs +++ /dev/null @@ -1,210 +0,0 @@ -namespace WarmlyShip -{ - 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.pictureBox = new System.Windows.Forms.PictureBox(); - this.statusStrip = new System.Windows.Forms.StatusStrip(); - this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); - this.buttonRight = new System.Windows.Forms.Button(); - this.buttonUp = new System.Windows.Forms.Button(); - this.buttonLeft = new System.Windows.Forms.Button(); - this.buttonDown = new System.Windows.Forms.Button(); - this.ButtonCreate = new System.Windows.Forms.Button(); - this.buttonCreateModif = new System.Windows.Forms.Button(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); - this.statusStrip.SuspendLayout(); - this.SuspendLayout(); - // - // pictureBox - // - this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBox.Location = new System.Drawing.Point(0, 0); - this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(800, 428); - this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.pictureBox.TabIndex = 0; - this.pictureBox.TabStop = false; - // - // statusStrip - // - this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripStatusSpeed, - this.toolStripStatusWeight, - this.toolStripStatusLabelBodyColor}); - this.statusStrip.Location = new System.Drawing.Point(0, 428); - this.statusStrip.Name = "statusStrip"; - this.statusStrip.Size = new System.Drawing.Size(800, 22); - this.statusStrip.TabIndex = 1; - this.statusStrip.Text = "statusStrip1"; - // - // toolStripStatusSpeed - // - this.toolStripStatusSpeed.Name = "toolStripStatusSpeed"; - this.toolStripStatusSpeed.Size = new System.Drawing.Size(62, 17); - this.toolStripStatusSpeed.Text = "Скорость:"; - // - // toolStripStatusWeight - // - this.toolStripStatusWeight.Name = "toolStripStatusWeight"; - this.toolStripStatusWeight.Size = new System.Drawing.Size(29, 17); - this.toolStripStatusWeight.Text = "Вес:"; - // - // toolStripStatusLabelBodyColor - // - this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; - this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17); - this.toolStripStatusLabelBodyColor.Text = "Цвет:"; - // - // buttonRight - // - this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.BackgroundImage = global::WarmlyShip.Properties.Resources.toright; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(738, 375); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(50, 50); - this.buttonRight.TabIndex = 3; - this.buttonRight.UseVisualStyleBackColor = true; - this.buttonRight.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::WarmlyShip.Properties.Resources.totop; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(682, 319); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(50, 50); - this.buttonUp.TabIndex = 4; - this.buttonUp.UseVisualStyleBackColor = true; - this.buttonUp.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::WarmlyShip.Properties.Resources.toleft; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(626, 375); - this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(50, 50); - this.buttonLeft.TabIndex = 5; - this.buttonLeft.UseVisualStyleBackColor = true; - this.buttonLeft.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::WarmlyShip.Properties.Resources.todown; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(682, 375); - this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(50, 50); - this.buttonDown.TabIndex = 6; - this.buttonDown.UseVisualStyleBackColor = true; - this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); - // - // 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(12, 402); - this.ButtonCreate.Name = "ButtonCreate"; - this.ButtonCreate.Size = new System.Drawing.Size(75, 23); - this.ButtonCreate.TabIndex = 7; - this.ButtonCreate.Text = "Создать"; - this.ButtonCreate.UseVisualStyleBackColor = true; - this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_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(93, 402); - this.buttonCreateModif.Name = "buttonCreateModif"; - this.buttonCreateModif.Size = new System.Drawing.Size(100, 23); - this.buttonCreateModif.TabIndex = 8; - 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(12, 12); - this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); - this.comboBoxSelectorMap.TabIndex = 9; - this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.СomboBoxSelectorMap_SelectedIndexChanged); - // - // FormMap - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.comboBoxSelectorMap); - this.Controls.Add(this.buttonCreateModif); - this.Controls.Add(this.ButtonCreate); - this.Controls.Add(this.buttonDown); - this.Controls.Add(this.buttonLeft); - this.Controls.Add(this.buttonUp); - this.Controls.Add(this.buttonRight); - this.Controls.Add(this.pictureBox); - this.Controls.Add(this.statusStrip); - this.Name = "FormMap"; - this.Text = "FormMap"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); - this.statusStrip.ResumeLayout(false); - this.statusStrip.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private PictureBox pictureBox; - private StatusStrip statusStrip; - private ToolStripStatusLabel toolStripStatusSpeed; - private ToolStripStatusLabel toolStripStatusWeight; - private ToolStripStatusLabel toolStripStatusLabelBodyColor; - private Button buttonRight; - private Button buttonUp; - private Button buttonLeft; - private Button buttonDown; - private Button ButtonCreate; - private Button buttonCreateModif; - private ComboBox comboBoxSelectorMap; - } -} \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/FormMap.cs b/WarmlyShip/WarmlyShip/FormMap.cs deleted file mode 100644 index 3d6c502..0000000 --- a/WarmlyShip/WarmlyShip/FormMap.cs +++ /dev/null @@ -1,88 +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 WarmlyShip -{ - public partial class FormMap : Form - { - private AbstractMap _abstractMap; - - public FormMap() - { - InitializeComponent(); - _abstractMap = new SimpleMap(); - } - - private void SetData(DrawingWarmlyShip warmlyShip) - { - toolStripStatusSpeed.Text = $"Скорость: {warmlyShip.warmlyShip?.Speed}"; - toolStripStatusWeight.Text = $"Вес: {warmlyShip.warmlyShip?.Weight}"; - toolStripStatusLabelBodyColor.Text = $"Цвет: {warmlyShip.warmlyShip?.BodyColor}"; - pictureBox.Image = _abstractMap.CreateMap(pictureBox.Width, pictureBox.Height, new DrawningObjectShip(warmlyShip)); - } - - - private void ButtonCreate_Click(object sender, EventArgs e) - { - Random random = new Random(); - var warmlyShip = new DrawingWarmlyShip(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); - SetData(warmlyShip); - } - - private void ButtonMove_Click(object sender, EventArgs e) - { - string name = ((Button)sender)?.Name ?? string.Empty; - Direction direction = Direction.None; - switch (name) - { - case "buttonLeft": - direction = Direction.Left; - break; - case "buttonUp": - direction = Direction.Up; - break; - case "buttonRight": - direction = Direction.Right; - break; - case "buttonDown": - direction = Direction.Down; - break; - } - pictureBox.Image = _abstractMap?.MoveObject(direction); - } - - private void ButtonCreateModif_Click(object sender, EventArgs e) - { - Random random = new Random(); - var warmlyShip = new DrawningMotorShip(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))); - SetData(warmlyShip); - } - - private void СomboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) - { - switch (comboBoxSelectorMap.Text) - { - case "Простая карта": - _abstractMap = new SimpleMap(); - break; - case "Вторая карта": - _abstractMap = new SecondMap(); - break; - case "Последняя карта": - _abstractMap = new LastMap(); - break; - } - - } - } -} diff --git a/WarmlyShip/WarmlyShip/FormMap.resx b/WarmlyShip/WarmlyShip/FormMap.resx deleted file mode 100644 index 2c0949d..0000000 --- a/WarmlyShip/WarmlyShip/FormMap.resx +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 - - - 17, 17 - - \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/Program.cs b/WarmlyShip/WarmlyShip/Program.cs index 9bf5de7..de3a3a8 100644 --- a/WarmlyShip/WarmlyShip/Program.cs +++ b/WarmlyShip/WarmlyShip/Program.cs @@ -11,7 +11,7 @@ namespace WarmlyShip // 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 FormMapWithSetShip()); } } } \ No newline at end of file -- 2.25.1 From 8f20040737b6f05d3bbdd7975286958751579808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Sun, 23 Oct 2022 17:43:37 +0400 Subject: [PATCH 04/12] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/FormMapWithSetShip.cs | 28 ++++++++-------- .../WarmlyShip/MapWithSetShipGeneric.cs | 4 +-- WarmlyShip/WarmlyShip/SetShipGeneric.cs | 33 ++++++++++++++----- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs index 78795d4..ba1ce3f 100644 --- a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs +++ b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs @@ -13,7 +13,7 @@ namespace WarmlyShip { public partial class FormMapWithSetShip : Form { - private MapWithSetShipGeneric _mapCarsCollectionGeneric; + private MapWithSetShipGeneric _mapShipsCollectionGeneric; public FormMapWithSetShip() { @@ -31,17 +31,17 @@ namespace WarmlyShip } if (map != null) { - _mapCarsCollectionGeneric = new MapWithSetShipGeneric(pictureBox.Width, pictureBox.Height, map); + _mapShipsCollectionGeneric = new MapWithSetShipGeneric(pictureBox.Width, pictureBox.Height, map); } else { - _mapCarsCollectionGeneric = null; + _mapShipsCollectionGeneric = null; } } private void ButtonAddShip_Click(object sender, EventArgs e) { - if (_mapCarsCollectionGeneric == null) + if (_mapShipsCollectionGeneric == null) { return; } @@ -49,10 +49,10 @@ namespace WarmlyShip if (form.ShowDialog() == DialogResult.OK) { DrawningObjectShip ship = new(form.SelectedShip); - if (_mapCarsCollectionGeneric + ship) + if (_mapShipsCollectionGeneric + ship) { MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapCarsCollectionGeneric.ShowSet(); + pictureBox.Image = _mapShipsCollectionGeneric.ShowSet(); } else { @@ -72,10 +72,10 @@ namespace WarmlyShip return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapCarsCollectionGeneric - pos) + if (_mapShipsCollectionGeneric - pos) { MessageBox.Show("Объект удален"); - pictureBox.Image = _mapCarsCollectionGeneric.ShowSet(); + pictureBox.Image = _mapShipsCollectionGeneric.ShowSet(); } else { @@ -85,25 +85,25 @@ namespace WarmlyShip private void ButtonShowStorage_Click(object sender, EventArgs e) { - if (_mapCarsCollectionGeneric == null) + if (_mapShipsCollectionGeneric == null) { return; } - pictureBox.Image = _mapCarsCollectionGeneric.ShowSet(); + pictureBox.Image = _mapShipsCollectionGeneric.ShowSet(); } private void ButtonShowOnMap_Click(object sender, EventArgs e) { - if (_mapCarsCollectionGeneric == null) + if (_mapShipsCollectionGeneric == null) { return; } - pictureBox.Image = _mapCarsCollectionGeneric.ShowOnMap(); + pictureBox.Image = _mapShipsCollectionGeneric.ShowOnMap(); } private void ButtonMove_Click(object sender, EventArgs e) { - if (_mapCarsCollectionGeneric == null) + if (_mapShipsCollectionGeneric == null) { return; } @@ -124,7 +124,7 @@ namespace WarmlyShip dir = Direction.Right; break; } - pictureBox.Image = _mapCarsCollectionGeneric.MoveObject(dir); + pictureBox.Image = _mapShipsCollectionGeneric.MoveObject(dir); } } } diff --git a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs index 1fba030..04dd7af 100644 --- a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs @@ -99,8 +99,8 @@ namespace WarmlyShip Pen pen = new(Color.Black, 3); for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { - for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) - {//линия рамзетки места + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) //линия рамзетки места + { g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); } diff --git a/WarmlyShip/WarmlyShip/SetShipGeneric.cs b/WarmlyShip/WarmlyShip/SetShipGeneric.cs index e334b1d..86ad35e 100644 --- a/WarmlyShip/WarmlyShip/SetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/SetShipGeneric.cs @@ -11,37 +11,52 @@ namespace WarmlyShip { private readonly T[] _places; public int Count => _places.Length; + public SetShipGeneric(int count) { _places = new T[count]; } + public bool Insert(T ship) { - // TODO вставка в начало набора + _places[0] = ship; return true; } + private bool CanInsert(int position) + { + for (int i = position; i < _places.Length; ++i) + if (_places[i] != null) return true; + return false; + } + public bool Insert(T ship, int position) { - // TODO проверка позиции - // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // проверка, что после вставляемого элемента в массиве есть пустой элемент - // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента - // TODO вставка по позиции + if (position < 0 || position > _places.Length) return false; + if (_places[position] != null && CanInsert(position)) + { + for (int i = _places.Length - 1; i > position; --i) + { + if (_places[i] == null) + { + _places[i] = _places[i - 1]; + _places[i - 1] = null; + } + } + } _places[position] = ship; return true; } public bool Remove(int position) { - // TODO проверка позиции - // TODO удаление объекта из массива, присовив элементу массива значение null + _places[position] = null; return true; } public T Get(int position) { - // TODO проверка позиции + if (position < 0 || position > _places.Length) return null; return _places[position]; } -- 2.25.1 From 3f669751ffec8351a75847b75464cdbe40042dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Sun, 23 Oct 2022 18:27:08 +0400 Subject: [PATCH 05/12] Urdack --- .../WarmlyShip/FormMapWithSetShip.Designer.cs | 89 ++++++++++--------- WarmlyShip/WarmlyShip/FormMapWithSetShip.cs | 44 +++++---- 2 files changed, 74 insertions(+), 59 deletions(-) diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetShip.Designer.cs b/WarmlyShip/WarmlyShip/FormMapWithSetShip.Designer.cs index 4625b4d..f522302 100644 --- a/WarmlyShip/WarmlyShip/FormMapWithSetShip.Designer.cs +++ b/WarmlyShip/WarmlyShip/FormMapWithSetShip.Designer.cs @@ -29,17 +29,17 @@ private void InitializeComponent() { this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.buttonDown = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); - this.button4 = new System.Windows.Forms.Button(); - this.button3 = new System.Windows.Forms.Button(); - this.button2 = new System.Windows.Forms.Button(); + this.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.buttonRemoveShip = new System.Windows.Forms.Button(); this.buttonAddShip = new System.Windows.Forms.Button(); this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.pictureBox = new System.Windows.Forms.PictureBox(); - this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.SuspendLayout(); @@ -51,9 +51,9 @@ this.groupBox1.Controls.Add(this.buttonLeft); this.groupBox1.Controls.Add(this.buttonUp); this.groupBox1.Controls.Add(this.buttonRight); - this.groupBox1.Controls.Add(this.button4); - this.groupBox1.Controls.Add(this.button3); - this.groupBox1.Controls.Add(this.button2); + this.groupBox1.Controls.Add(this.buttonShowOnMap); + this.groupBox1.Controls.Add(this.buttonShowStorage); + this.groupBox1.Controls.Add(this.buttonRemoveShip); this.groupBox1.Controls.Add(this.buttonAddShip); this.groupBox1.Controls.Add(this.comboBoxSelectorMap); this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; @@ -64,6 +64,14 @@ this.groupBox1.TabStop = false; this.groupBox1.Text = "Инструменты"; // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 116); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(188, 23); + this.maskedTextBoxPosition.TabIndex = 11; + // // buttonDown // this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); @@ -112,35 +120,35 @@ this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); // - // button4 + // buttonShowOnMap // - this.button4.Location = new System.Drawing.Point(6, 281); - this.button4.Name = "button4"; - this.button4.Size = new System.Drawing.Size(188, 23); - this.button4.TabIndex = 5; - this.button4.Text = "Посмотреть карту"; - this.button4.UseVisualStyleBackColor = true; - this.button4.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + this.buttonShowOnMap.Location = new System.Drawing.Point(6, 281); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(188, 23); + this.buttonShowOnMap.TabIndex = 5; + this.buttonShowOnMap.Text = "Посмотреть карту"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); // - // button3 + // buttonShowStorage // - this.button3.Location = new System.Drawing.Point(6, 226); - this.button3.Name = "button3"; - this.button3.Size = new System.Drawing.Size(188, 23); - this.button3.TabIndex = 4; - this.button3.Text = "Посмотреть хранилище"; - this.button3.UseVisualStyleBackColor = true; - this.button3.Click += new System.EventHandler(this.ButtonShowStorage_Click); + this.buttonShowStorage.Location = new System.Drawing.Point(6, 226); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(188, 23); + this.buttonShowStorage.TabIndex = 4; + this.buttonShowStorage.Text = "Посмотреть хранилище"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); // - // button2 + // buttonRemoveShip // - this.button2.Location = new System.Drawing.Point(6, 170); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(188, 23); - this.button2.TabIndex = 3; - this.button2.Text = "Удалить корабль"; - this.button2.UseVisualStyleBackColor = true; - this.button2.Click += new System.EventHandler(this.ButtonRemoveShip_Click); + this.buttonRemoveShip.Location = new System.Drawing.Point(6, 170); + this.buttonRemoveShip.Name = "buttonRemoveShip"; + this.buttonRemoveShip.Size = new System.Drawing.Size(188, 23); + this.buttonRemoveShip.TabIndex = 3; + this.buttonRemoveShip.Text = "Удалить корабль"; + this.buttonRemoveShip.UseVisualStyleBackColor = true; + this.buttonRemoveShip.Click += new System.EventHandler(this.ButtonRemoveShip_Click); // // buttonAddShip // @@ -155,10 +163,15 @@ // comboBoxSelectorMap // this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта", + "Вторая карта", + "Последняя карта"}); this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 22); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 23); this.comboBoxSelectorMap.TabIndex = 0; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); // // pictureBox // @@ -169,14 +182,6 @@ this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // - // maskedTextBoxPosition - // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 116); - this.maskedTextBoxPosition.Mask = "00"; - this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - this.maskedTextBoxPosition.Size = new System.Drawing.Size(188, 23); - this.maskedTextBoxPosition.TabIndex = 11; - // // FormMapWithSetShip // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -199,9 +204,9 @@ private PictureBox pictureBox; private Button buttonAddShip; private ComboBox comboBoxSelectorMap; - private Button button4; - private Button button3; - private Button button2; + private Button buttonShowOnMap; + private Button buttonShowStorage; + private Button buttonRemoveShip; private Button buttonDown; private Button buttonLeft; private Button buttonUp; diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs index ba1ce3f..45e86f9 100644 --- a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs +++ b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs @@ -7,13 +7,14 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -using static System.Windows.Forms.DataFormats; +using WarmlyShip; namespace WarmlyShip { public partial class FormMapWithSetShip : Form { - private MapWithSetShipGeneric _mapShipsCollectionGeneric; + private MapWithSetShipGeneric _mapShipCollectionGeneric; + public bool ShipOnMap = false; public FormMapWithSetShip() { @@ -28,20 +29,25 @@ namespace WarmlyShip case "Простая карта": map = new SimpleMap(); break; + case "Вторая карта": + map = new SecondMap(); + break; + case "Последняя карта": + map = new LastMap(); + break; } if (map != null) { - _mapShipsCollectionGeneric = new MapWithSetShipGeneric(pictureBox.Width, pictureBox.Height, map); + _mapShipCollectionGeneric = new MapWithSetShipGeneric(pictureBox.Width, pictureBox.Height, map); } else { - _mapShipsCollectionGeneric = null; + _mapShipCollectionGeneric = null; } } - private void ButtonAddShip_Click(object sender, EventArgs e) { - if (_mapShipsCollectionGeneric == null) + if (_mapShipCollectionGeneric == null) { return; } @@ -49,10 +55,10 @@ namespace WarmlyShip if (form.ShowDialog() == DialogResult.OK) { DrawningObjectShip ship = new(form.SelectedShip); - if (_mapShipsCollectionGeneric + ship) + if (_mapShipCollectionGeneric + ship) { MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapShipsCollectionGeneric.ShowSet(); + pictureBox.Image = _mapShipCollectionGeneric.ShowSet(); } else { @@ -67,15 +73,16 @@ namespace WarmlyShip { return; } - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapShipsCollectionGeneric - pos) + if (_mapShipCollectionGeneric - pos) { MessageBox.Show("Объект удален"); - pictureBox.Image = _mapShipsCollectionGeneric.ShowSet(); + pictureBox.Image = _mapShipCollectionGeneric.ShowSet(); } else { @@ -85,28 +92,31 @@ namespace WarmlyShip private void ButtonShowStorage_Click(object sender, EventArgs e) { - if (_mapShipsCollectionGeneric == null) + if (_mapShipCollectionGeneric == null) { return; } - pictureBox.Image = _mapShipsCollectionGeneric.ShowSet(); + pictureBox.Image = _mapShipCollectionGeneric.ShowSet(); + ShipOnMap = false; } private void ButtonShowOnMap_Click(object sender, EventArgs e) { - if (_mapShipsCollectionGeneric == null) + if (_mapShipCollectionGeneric == null) { return; } - pictureBox.Image = _mapShipsCollectionGeneric.ShowOnMap(); + pictureBox.Image = _mapShipCollectionGeneric.ShowOnMap(); + ShipOnMap = true; } private void ButtonMove_Click(object sender, EventArgs e) { - if (_mapShipsCollectionGeneric == null) + if (_mapShipCollectionGeneric == null || !ShipOnMap) { return; } + //получаем имя кнопки string name = ((Button)sender)?.Name ?? string.Empty; Direction dir = Direction.None; switch (name) @@ -124,7 +134,7 @@ namespace WarmlyShip dir = Direction.Right; break; } - pictureBox.Image = _mapShipsCollectionGeneric.MoveObject(dir); + pictureBox.Image = _mapShipCollectionGeneric.MoveObject(dir); } } } -- 2.25.1 From 572df7efe3aaf98609524358327f8435f94664d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Sun, 23 Oct 2022 18:37:20 +0400 Subject: [PATCH 06/12] 101 --- WarmlyShip/WarmlyShip/SetShipGeneric.cs | 26 ++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/WarmlyShip/WarmlyShip/SetShipGeneric.cs b/WarmlyShip/WarmlyShip/SetShipGeneric.cs index 86ad35e..8c4e42f 100644 --- a/WarmlyShip/WarmlyShip/SetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/SetShipGeneric.cs @@ -17,16 +17,28 @@ namespace WarmlyShip _places = new T[count]; } - public bool Insert(T ship) - { - _places[0] = ship; - return true; - } - private bool CanInsert(int position) { for (int i = position; i < _places.Length; ++i) - if (_places[i] != null) return true; + if (_places[i] == null) return true; + return false; + } + + public bool Insert(T ship) + { + if (CanInsert(0)) + { + for (int i = _places.Length - 1; i > 0; --i) + { + if (_places[i] == null) + { + _places[i] = _places[i - 1]; + _places[i - 1] = null; + } + } + _places[0] = ship; + return true; + } return false; } -- 2.25.1 From 3c945af49efdd76b8cd3d8121a025a17dd633b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Sun, 23 Oct 2022 18:47:37 +0400 Subject: [PATCH 07/12] =?UTF-8?q?=D0=9F=D1=80=D0=B5=D0=B4=D0=BF=D0=BE?= =?UTF-8?q?=D1=81=D0=BB=D0=B5=D0=B4=D0=BD=D0=B5=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs index 04dd7af..1f8a387 100644 --- a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs @@ -72,16 +72,16 @@ namespace WarmlyShip private void Shaking() { int j = _setShips.Count - 1; - for (int i = 0; i < _setShips.Count; i++) + for (int i = 0; i < _setShips.Count; ++i) { if (_setShips.Get(i) == null) { - for (; j > i; j--) + for (; j > i; --j) { - var ship = _setShips.Get(j); - if (ship != null) + var car = _setShips.Get(j); + if (car != null) { - _setShips.Insert(ship, i); + _setShips.Insert(car, i); _setShips.Remove(j); break; } -- 2.25.1 From 0e2fe47f201dd3a0a053f51247cdf78bd21fdd60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Sun, 23 Oct 2022 20:55:43 +0400 Subject: [PATCH 08/12] =?UTF-8?q?=D0=B7=D0=B0=D1=84=D0=B8=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs index 1f8a387..50b81eb 100644 --- a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs @@ -110,9 +110,12 @@ namespace WarmlyShip private void DrawShips(Graphics g) { - for (int i = 0; i < _setShips.Count; i++) + for (int i = 0; i < _setShips.Count; ++i) { - // TODO установка позиции + if (_setShips.Get(i) != null ) + { + + } _setShips.Get(i)?.DrawningObject(g); } } -- 2.25.1 From 88bca293e8040d0faf1c982748742585f0ecf688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Mon, 24 Oct 2022 00:44:39 +0400 Subject: [PATCH 09/12] =?UTF-8?q?3=20=D0=BB=D0=B0=D0=B1=D0=B0=20=D1=81?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs index 50b81eb..f5d97d0 100644 --- a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs @@ -13,7 +13,7 @@ namespace WarmlyShip private readonly int _pictureWidth; private readonly int _pictureHeight; private readonly int _placeSizeWidth = 210; - private readonly int _placeSizeHeight = 90; + private readonly int _placeSizeHeight = 100; private readonly SetShipGeneric _setShips; private readonly U _map; @@ -97,7 +97,7 @@ namespace WarmlyShip private void DrawBackground(Graphics g) { Pen pen = new(Color.Black, 3); - for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + for (int i = 0; i < _pictureWidth / _placeSizeWidth; ++i) { for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) //линия рамзетки места { @@ -110,13 +110,17 @@ namespace WarmlyShip private void DrawShips(Graphics g) { + int j = 0; for (int i = 0; i < _setShips.Count; ++i) { + if (i >= _pictureHeight / _placeSizeHeight) ++j; if (_setShips.Get(i) != null ) { - + int temp = 0; + if (_setShips.Get(i).GetCurrentPosition().Bottom - _setShips.Get(i).GetCurrentPosition().Top < 75) temp = (int)(_setShips.Get(i).GetCurrentPosition().Bottom - _setShips.Get(i).GetCurrentPosition().Top) / 2; + _setShips.Get(i).SetObject(j * _placeSizeWidth, i * _placeSizeHeight + temp, _pictureWidth, _pictureHeight); + _setShips.Get(i).DrawningObject(g); } - _setShips.Get(i)?.DrawningObject(g); } } -- 2.25.1 From e641141175b9bcdf19d37a338bc7d37867d14a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Mon, 24 Oct 2022 22:57:48 +0400 Subject: [PATCH 10/12] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs index f5d97d0..2636a8d 100644 --- a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs @@ -41,8 +41,8 @@ namespace WarmlyShip { Bitmap bmp = new(_pictureWidth, _pictureHeight); Graphics gr = Graphics.FromImage(bmp); - DrawBackground(gr); DrawShips(gr); + DrawBackground(gr); return bmp; } @@ -96,13 +96,14 @@ namespace WarmlyShip private void DrawBackground(Graphics g) { - Pen pen = new(Color.Black, 3); + Pen pen = new(Color.Brown, 8); for (int i = 0; i < _pictureWidth / _placeSizeWidth; ++i) { - for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) //линия рамзетки места + for (int j = 1; j < _pictureHeight / _placeSizeHeight + 1; ++j) //линия рамзетки места { - g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * - _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + for (int k = 0; k < _placeSizeWidth / (30 * 2); ++k) + g.DrawLine(pen, i * _placeSizeWidth + (k + 1) * 30, j * _placeSizeHeight, i * _placeSizeWidth + (k + 1) * 30, j * _placeSizeHeight + 30); } g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); } @@ -110,15 +111,13 @@ namespace WarmlyShip private void DrawShips(Graphics g) { - int j = 0; for (int i = 0; i < _setShips.Count; ++i) { - if (i >= _pictureHeight / _placeSizeHeight) ++j; if (_setShips.Get(i) != null ) { int temp = 0; if (_setShips.Get(i).GetCurrentPosition().Bottom - _setShips.Get(i).GetCurrentPosition().Top < 75) temp = (int)(_setShips.Get(i).GetCurrentPosition().Bottom - _setShips.Get(i).GetCurrentPosition().Top) / 2; - _setShips.Get(i).SetObject(j * _placeSizeWidth, i * _placeSizeHeight + temp, _pictureWidth, _pictureHeight); + _setShips.Get(i).SetObject((_pictureWidth / _placeSizeWidth - (i % (_pictureWidth / _placeSizeWidth)) - 1) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight + temp, _pictureWidth, _pictureHeight); _setShips.Get(i).DrawningObject(g); } } -- 2.25.1 From d29a47f44ec35dabc4d7383926a8bfeb28e3f4af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Sat, 29 Oct 2022 18:06:35 +0400 Subject: [PATCH 11/12] =?UTF-8?q?=D0=9F=D0=BE=D1=81=D0=BB=D0=B5=D0=B4?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9=20=D1=84=D0=B8=D0=BA=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/FormClass.cs | 32 ++++++++++++++----- WarmlyShip/WarmlyShip/FormMapWithSetShip.cs | 7 ++-- .../WarmlyShip/MapWithSetShipGeneric.cs | 6 ++-- WarmlyShip/WarmlyShip/SetShipGeneric.cs | 16 +++++----- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/WarmlyShip/WarmlyShip/FormClass.cs b/WarmlyShip/WarmlyShip/FormClass.cs index 7fdaa22..d9fd1be 100644 --- a/WarmlyShip/WarmlyShip/FormClass.cs +++ b/WarmlyShip/WarmlyShip/FormClass.cs @@ -30,13 +30,20 @@ namespace WarmlyShip private void ButtonCreate_Click(object sender, EventArgs e) { - Random random = new Random(); - _warmlyShip = new DrawingWarmlyShip(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); + Random rnd = new(); + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + _warmlyShip = new DrawingWarmlyShip(rnd.Next(100, 300), rnd.Next(1000, 2000), color); SetData(); Draw(); + } - private void ButtonMove_Click(object sender, EventArgs e) + private void ButtonMove_Click(object sender, EventArgs e) { string name = ((Button)sender)?.Name ?? string.Empty; switch (name) @@ -65,11 +72,20 @@ namespace WarmlyShip private void ButtonCreateModif_Click(object sender, EventArgs e) { - Random random = new Random(); - _warmlyShip = new DrawningMotorShip(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))); + Random rnd = new(); + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialogDop = new(); + if (dialogDop.ShowDialog() == DialogResult.OK) + { + dopColor = dialogDop.Color; + } + _warmlyShip = new DrawningMotorShip(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); SetData(); Draw(); } diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs index 45e86f9..3df2a6b 100644 --- a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs +++ b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs @@ -55,7 +55,7 @@ namespace WarmlyShip if (form.ShowDialog() == DialogResult.OK) { DrawningObjectShip ship = new(form.SelectedShip); - if (_mapShipCollectionGeneric + ship) + if (_mapShipCollectionGeneric + ship == 1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapShipCollectionGeneric.ShowSet(); @@ -73,13 +73,12 @@ namespace WarmlyShip { return; } - if (MessageBox.Show("Удалить объект?", "Удаление", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapShipCollectionGeneric - pos) + if (_mapShipCollectionGeneric - pos == 1) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapShipCollectionGeneric.ShowSet(); diff --git a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs index 2636a8d..8b7019a 100644 --- a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs @@ -27,12 +27,12 @@ namespace WarmlyShip _map = map; } - public static bool operator +(MapWithSetShipGeneric map, T ship) + public static int operator +(MapWithSetShipGeneric map, T ship) { return map._setShips.Insert(ship); } - public static bool operator -(MapWithSetShipGeneric map, int position) + public static int operator -(MapWithSetShipGeneric map, int position) { return map._setShips.Remove(position); } @@ -116,7 +116,7 @@ namespace WarmlyShip if (_setShips.Get(i) != null ) { int temp = 0; - if (_setShips.Get(i).GetCurrentPosition().Bottom - _setShips.Get(i).GetCurrentPosition().Top < 75) temp = (int)(_setShips.Get(i).GetCurrentPosition().Bottom - _setShips.Get(i).GetCurrentPosition().Top) / 2; + if (_setShips.Get(i).GetCurrentPosition().Bottom - _setShips.Get(i).GetCurrentPosition().Top < 75) temp = (int)(_setShips.Get(i).GetCurrentPosition().Bottom - _setShips.Get(i).GetCurrentPosition().Top); _setShips.Get(i).SetObject((_pictureWidth / _placeSizeWidth - (i % (_pictureWidth / _placeSizeWidth)) - 1) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight + temp, _pictureWidth, _pictureHeight); _setShips.Get(i).DrawningObject(g); } diff --git a/WarmlyShip/WarmlyShip/SetShipGeneric.cs b/WarmlyShip/WarmlyShip/SetShipGeneric.cs index 8c4e42f..e22a337 100644 --- a/WarmlyShip/WarmlyShip/SetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/SetShipGeneric.cs @@ -24,7 +24,7 @@ namespace WarmlyShip return false; } - public bool Insert(T ship) + public int Insert(T ship) { if (CanInsert(0)) { @@ -37,14 +37,14 @@ namespace WarmlyShip } } _places[0] = ship; - return true; + return 1; } - return false; + return 0; } - public bool Insert(T ship, int position) + public int Insert(T ship, int position) { - if (position < 0 || position > _places.Length) return false; + if (position < 0 || position > _places.Length) return 0; if (_places[position] != null && CanInsert(position)) { for (int i = _places.Length - 1; i > position; --i) @@ -57,13 +57,13 @@ namespace WarmlyShip } } _places[position] = ship; - return true; + return 1; } - public bool Remove(int position) + public int Remove(int position) { _places[position] = null; - return true; + return 1; } public T Get(int position) -- 2.25.1 From 3e7c3c7f5f82a14538580654cdd303cb046f728d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 2 Nov 2022 09:32:14 +0400 Subject: [PATCH 12/12] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/FormMapWithSetShip.cs | 4 ++-- .../WarmlyShip/MapWithSetShipGeneric.cs | 2 +- WarmlyShip/WarmlyShip/SetShipGeneric.cs | 24 +++++-------------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs index 3df2a6b..4bece63 100644 --- a/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs +++ b/WarmlyShip/WarmlyShip/FormMapWithSetShip.cs @@ -55,7 +55,7 @@ namespace WarmlyShip if (form.ShowDialog() == DialogResult.OK) { DrawningObjectShip ship = new(form.SelectedShip); - if (_mapShipCollectionGeneric + ship == 1) + if (_mapShipCollectionGeneric + ship > -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapShipCollectionGeneric.ShowSet(); @@ -78,7 +78,7 @@ namespace WarmlyShip return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapShipCollectionGeneric - pos == 1) + if (_mapShipCollectionGeneric - pos != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapShipCollectionGeneric.ShowSet(); diff --git a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs index 8b7019a..c0edbc9 100644 --- a/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/MapWithSetShipGeneric.cs @@ -32,7 +32,7 @@ namespace WarmlyShip return map._setShips.Insert(ship); } - public static int operator -(MapWithSetShipGeneric map, int position) + public static T operator -(MapWithSetShipGeneric map, int position) { return map._setShips.Remove(position); } diff --git a/WarmlyShip/WarmlyShip/SetShipGeneric.cs b/WarmlyShip/WarmlyShip/SetShipGeneric.cs index e22a337..1184902 100644 --- a/WarmlyShip/WarmlyShip/SetShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/SetShipGeneric.cs @@ -26,25 +26,12 @@ namespace WarmlyShip public int Insert(T ship) { - if (CanInsert(0)) - { - for (int i = _places.Length - 1; i > 0; --i) - { - if (_places[i] == null) - { - _places[i] = _places[i - 1]; - _places[i - 1] = null; - } - } - _places[0] = ship; - return 1; - } - return 0; + return Insert(ship, 0); } public int Insert(T ship, int position) { - if (position < 0 || position > _places.Length) return 0; + if (position < 0 || position > _places.Length) return -1; if (_places[position] != null && CanInsert(position)) { for (int i = _places.Length - 1; i > position; --i) @@ -57,13 +44,14 @@ namespace WarmlyShip } } _places[position] = ship; - return 1; + return position; } - public int Remove(int position) + public T Remove(int position) { + T DelElement = _places[position]; _places[position] = null; - return 1; + return DelElement; } public T Get(int position) -- 2.25.1