From 27ab04d2f65801ec48acfe3b1ad5e62d8a778fc1 Mon Sep 17 00:00:00 2001 From: the Date: Sun, 2 Oct 2022 20:12:08 +0400 Subject: [PATCH] Form changes --- Ship/Ship/Direction.cs | 2 +- Ship/Ship/DrawingShip.cs | 2 +- Ship/Ship/EntityShip.cs | 2 +- Ship/Ship/FormMapWithSetShips.Designer.cs | 215 ++++++++++++++++++++++ Ship/Ship/FormMapWithSetShips.cs | 166 +++++++++++++++++ Ship/Ship/FormMapWithSetShips.resx | 60 ++++++ Ship/Ship/FormShip.Designer.cs | 14 ++ Ship/Ship/FormShip.cs | 13 ++ Ship/Ship/MapWithSetShipsGeneric.cs | 173 +++++++++++++++++ Ship/Ship/Program.cs | 2 +- Ship/Ship/SetShipsGeneric.cs | 77 ++++++++ 11 files changed, 722 insertions(+), 4 deletions(-) create mode 100644 Ship/Ship/FormMapWithSetShips.Designer.cs create mode 100644 Ship/Ship/FormMapWithSetShips.cs create mode 100644 Ship/Ship/FormMapWithSetShips.resx create mode 100644 Ship/Ship/MapWithSetShipsGeneric.cs create mode 100644 Ship/Ship/SetShipsGeneric.cs diff --git a/Ship/Ship/Direction.cs b/Ship/Ship/Direction.cs index 4b51bae..56b321d 100644 --- a/Ship/Ship/Direction.cs +++ b/Ship/Ship/Direction.cs @@ -9,7 +9,7 @@ namespace Ship /// /// Направление перемещения /// - internal enum Direction + public enum Direction { None = 0, Up = 1, diff --git a/Ship/Ship/DrawingShip.cs b/Ship/Ship/DrawingShip.cs index 40ccd18..07e9db2 100644 --- a/Ship/Ship/DrawingShip.cs +++ b/Ship/Ship/DrawingShip.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Ship { - internal class DrawingShip + public class DrawingShip { /// /// Класс-сущность diff --git a/Ship/Ship/EntityShip.cs b/Ship/Ship/EntityShip.cs index b556451..d3326e7 100644 --- a/Ship/Ship/EntityShip.cs +++ b/Ship/Ship/EntityShip.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Ship { - internal class EntityShip + public class EntityShip { /// /// Скорость diff --git a/Ship/Ship/FormMapWithSetShips.Designer.cs b/Ship/Ship/FormMapWithSetShips.Designer.cs new file mode 100644 index 0000000..23b2cf7 --- /dev/null +++ b/Ship/Ship/FormMapWithSetShips.Designer.cs @@ -0,0 +1,215 @@ +namespace Ship +{ + partial class FormMapWithSetShips + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.groupBoxTools = new System.Windows.Forms.GroupBox(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.buttonRemoveShip = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.buttonAddShip = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.SuspendLayout(); + // + // groupBoxTools + // + this.groupBoxTools.Controls.Add(this.buttonRight); + this.groupBoxTools.Controls.Add(this.buttonDown); + this.groupBoxTools.Controls.Add(this.buttonLeft); + this.groupBoxTools.Controls.Add(this.buttonUp); + this.groupBoxTools.Controls.Add(this.buttonShowOnMap); + this.groupBoxTools.Controls.Add(this.buttonShowStorage); + this.groupBoxTools.Controls.Add(this.buttonRemoveShip); + this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); + this.groupBoxTools.Controls.Add(this.buttonAddShip); + this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap); + this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; + this.groupBoxTools.Location = new System.Drawing.Point(600, 0); + this.groupBoxTools.Name = "groupBoxTools"; + this.groupBoxTools.Size = new System.Drawing.Size(200, 450); + this.groupBoxTools.TabIndex = 0; + this.groupBoxTools.TabStop = false; + this.groupBoxTools.Text = "Инструменты"; + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::Ship.Properties.Resources.arrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(124, 408); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 10; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.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::Ship.Properties.Resources.arrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(88, 408); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 9; + 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::Ship.Properties.Resources.arrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(52, 408); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 8; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::Ship.Properties.Resources.arrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(88, 372); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 7; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonShowOnMap + // + this.buttonShowOnMap.Location = new System.Drawing.Point(19, 315); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(169, 37); + this.buttonShowOnMap.TabIndex = 5; + this.buttonShowOnMap.Text = "Посмотреть карту"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); + // + // buttonShowStorage + // + this.buttonShowStorage.Location = new System.Drawing.Point(19, 240); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(169, 37); + this.buttonShowStorage.TabIndex = 4; + this.buttonShowStorage.Text = "Посмотреть хранилище"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); + // + // buttonRemoveShip + // + this.buttonRemoveShip.Location = new System.Drawing.Point(19, 166); + this.buttonRemoveShip.Name = "buttonRemoveShip"; + this.buttonRemoveShip.Size = new System.Drawing.Size(169, 37); + this.buttonRemoveShip.TabIndex = 3; + this.buttonRemoveShip.Text = "Удалить корабль"; + this.buttonRemoveShip.UseVisualStyleBackColor = true; + this.buttonRemoveShip.Click += new System.EventHandler(this.ButtonRemoveShip_Click); + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 137); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(169, 23); + this.maskedTextBoxPosition.TabIndex = 2; + // + // buttonAddShip + // + this.buttonAddShip.Location = new System.Drawing.Point(19, 94); + this.buttonAddShip.Name = "buttonAddShip"; + this.buttonAddShip.Size = new System.Drawing.Size(169, 37); + this.buttonAddShip.TabIndex = 1; + this.buttonAddShip.Text = "Добавить корабль"; + this.buttonAddShip.UseVisualStyleBackColor = true; + this.buttonAddShip.Click += new System.EventHandler(this.ButtonAddShip_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(19, 22); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(169, 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; + // + // FormMapWithSetShips + // + 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.groupBoxTools); + this.Name = "FormMapWithSetShips"; + this.Text = "FormMapWithSetShips"; + this.Load += new System.EventHandler(this.FormMapWithSetShips_Load); + this.groupBoxTools.ResumeLayout(false); + this.groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBoxTools; + private Button buttonShowOnMap; + private Button buttonShowStorage; + private Button buttonRemoveShip; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonAddShip; + private ComboBox comboBoxSelectorMap; + private PictureBox pictureBox; + private Button buttonRight; + private Button buttonDown; + private Button buttonLeft; + private Button buttonUp; + } +} \ No newline at end of file diff --git a/Ship/Ship/FormMapWithSetShips.cs b/Ship/Ship/FormMapWithSetShips.cs new file mode 100644 index 0000000..1f38abb --- /dev/null +++ b/Ship/Ship/FormMapWithSetShips.cs @@ -0,0 +1,166 @@ +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 Ship +{ + public partial class FormMapWithSetShips : Form + { + /// + /// Объект от класса карты с набором объектов + /// + private MapWithSetShipsGeneric _mapShipsCollectionGeneric; + /// + /// Конструктор + /// + public FormMapWithSetShips() + { + InitializeComponent(); + } + /// + /// Выбор карты + /// + /// + /// + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + map = new SimpleMap(); + break; + } + if (map != null) + { + _mapShipsCollectionGeneric = new + MapWithSetShipsGeneric(pictureBox.Width, pictureBox.Height, map); + } + else + { + _mapShipsCollectionGeneric = null; + } + } + /// + /// Добавление объекта + /// + /// + /// + private void ButtonAddShip_Click(object sender, EventArgs e) + { + if (_mapShipsCollectionGeneric == null) + { + return; + } + FormShip form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + DrawingObject car = new(form.SelectedShip); + if (_mapShipsCollectionGeneric + car) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapShipsCollectionGeneric.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 (_mapShipsCollectionGeneric - pos) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _mapShipsCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Вывод набора + /// + /// + /// + private void ButtonShowStorage_Click(object sender, EventArgs e) + { + if (_mapShipsCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapShipsCollectionGeneric.ShowSet(); + } + /// + /// Вывод карты + /// + /// + /// + private void ButtonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapShipsCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapShipsCollectionGeneric.ShowOnMap(); + } + /// + /// Перемещение + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_mapShipsCollectionGeneric == 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 = _mapShipsCollectionGeneric.MoveObject(dir); + } + private void FormMapWithSetShips_Load(object sender, EventArgs e) + { + + } + } +} diff --git a/Ship/Ship/FormMapWithSetShips.resx b/Ship/Ship/FormMapWithSetShips.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Ship/Ship/FormMapWithSetShips.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/Ship/Ship/FormShip.Designer.cs b/Ship/Ship/FormShip.Designer.cs index 3e16931..678cf1e 100644 --- a/Ship/Ship/FormShip.Designer.cs +++ b/Ship/Ship/FormShip.Designer.cs @@ -39,6 +39,7 @@ this.buttonDown = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonCreateModif = new System.Windows.Forms.Button(); + this.buttonSelectShip = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -152,11 +153,22 @@ this.buttonCreateModif.UseVisualStyleBackColor = true; this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click); // + // buttonSelectShip + // + this.buttonSelectShip.Location = new System.Drawing.Point(605, 402); + this.buttonSelectShip.Name = "buttonSelectShip"; + this.buttonSelectShip.Size = new System.Drawing.Size(75, 23); + this.buttonSelectShip.TabIndex = 8; + this.buttonSelectShip.Text = "Выбрать"; + this.buttonSelectShip.UseVisualStyleBackColor = true; + this.buttonSelectShip.Click += new System.EventHandler(this.buttonSelectShip_Click); + // // FormShip // 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.buttonRight); this.Controls.Add(this.buttonDown); @@ -167,6 +179,7 @@ this.Controls.Add(this.statusStrip); this.Name = "FormShip"; this.Text = "Корабль"; + this.Load += new System.EventHandler(this.FormShip_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit(); this.statusStrip.ResumeLayout(false); this.statusStrip.PerformLayout(); @@ -188,5 +201,6 @@ private Button buttonDown; private Button buttonRight; private Button buttonCreateModif; + private Button buttonSelectShip; } } \ No newline at end of file diff --git a/Ship/Ship/FormShip.cs b/Ship/Ship/FormShip.cs index f846cc3..14aad64 100644 --- a/Ship/Ship/FormShip.cs +++ b/Ship/Ship/FormShip.cs @@ -4,6 +4,8 @@ namespace Ship { private DrawingShip _ship; + public DrawingShip SelectedShip { get; private set; } + public FormShip() { InitializeComponent(); @@ -94,5 +96,16 @@ namespace Ship SetData(); Draw(); } + + private void FormShip_Load(object sender, EventArgs e) + { + + } + + private void buttonSelectShip_Click(object sender, EventArgs e) + { + SelectedShip = _ship; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/Ship/Ship/MapWithSetShipsGeneric.cs b/Ship/Ship/MapWithSetShipsGeneric.cs new file mode 100644 index 0000000..22bd7d8 --- /dev/null +++ b/Ship/Ship/MapWithSetShipsGeneric.cs @@ -0,0 +1,173 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Ship +{ + internal class MapWithSetShipsGeneric + where T : class, IDrawingObject + where U : AbstractMap + { + /// + /// Ширина окна отрисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна отрисовки + /// + private readonly int _pictureHeight; + /// + /// Размер занимаемого объектом места (ширина) + /// + private readonly int _placeSizeWidth = 210; + /// + /// Размер занимаемого объектом места (высота) + /// + private readonly int _placeSizeHeight = 90; + /// + /// Набор объектов + /// + private readonly SetShipsGeneric _setShips; + /// + /// Карта + /// + private readonly U _map; + /// + /// Конструктор + /// + /// + /// + /// + public MapWithSetShipsGeneric(int picWidth, int picHeight, U map) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _setShips = new SetShipsGeneric(width * height); + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _map = map; + } + /// + /// Перегрузка оператора сложения + /// + /// + /// + /// + public static bool operator +(MapWithSetShipsGeneric map, T car) + { + return map._setShips.Insert(car); + } + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static bool operator -(MapWithSetShipsGeneric map, int + position) + { + return map._setShips.Remove(position); + } + /// + /// Вывод всего набора объектов + /// + /// + public Bitmap ShowSet() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawCars(gr); + return bmp; + } + /// + /// Просмотр объекта на карте + /// + /// + public Bitmap ShowOnMap() + { + Shaking(); + for (int i = 0; i < _setShips.Count; i++) + { + var car = _setShips.Get(i); + if (car != null) + { + return _map.CreateMap(_pictureWidth, _pictureHeight, car); + } + } + 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 car = _setShips.Get(j); + if (car != null) + { + _setShips.Insert(car, 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 DrawCars(Graphics g) + { + for (int i = 0; i < _setShips.Count; i++) + { + // TODO установка позиции + _setShips.Get(i)?.DrawningObject(g); + } + } + } +} diff --git a/Ship/Ship/Program.cs b/Ship/Ship/Program.cs index 85afd21..f783bbe 100644 --- a/Ship/Ship/Program.cs +++ b/Ship/Ship/Program.cs @@ -11,7 +11,7 @@ namespace Ship // 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 FormMapWithSetShips()); } } } \ No newline at end of file diff --git a/Ship/Ship/SetShipsGeneric.cs b/Ship/Ship/SetShipsGeneric.cs new file mode 100644 index 0000000..5778455 --- /dev/null +++ b/Ship/Ship/SetShipsGeneric.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Ship +{ + internal class SetShipsGeneric + where T: class + { + /// + /// Массив объектов, которые храним + /// + private readonly T[] _places; + /// + /// Количество объектов в массиве + /// + public int Count => _places.Length; + /// + /// Конструктор + /// + /// + public SetShipsGeneric(int count) + { + _places = new T[count]; + } + /// + /// Добавление объекта в набор + /// + /// Добавляемый автомобиль + /// + public bool Insert(T car) + { + // TODO вставка в начало набора + return true; + } + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемый автомобиль + /// Позиция + /// + public bool Insert(T car, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // проверка, что после вставляемого элемента в массиве есть пустой элемент + // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента + // TODO вставка по позиции + _places[position] = car; + return true; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присовив элементу массива значение null + return true; + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T Get(int position) + { + // TODO проверка позиции + return _places[position]; + } + + } +}