diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/ComboGenericCollection.cs b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/ComboGenericCollection.cs new file mode 100644 index 0000000..4c98526 --- /dev/null +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/ComboGenericCollection.cs @@ -0,0 +1,78 @@ +using ProjectWarmlyShip.DrawningObjects; +using ProjectWarmlyShip.Entities; +using ProjectWarmlyShip; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectWarmlyShipHard +{ + public class ComboGenericCollection + where T : EntityShip + where U : IDrawingDecks + { + private T[] _ships; + private U[] _decks; + + private int CountShips = 0; + private int CountDecks = 0; + private readonly Random random; + private readonly int Width; + private readonly int Height; + + public ComboGenericCollection(int count, int width, int height) + { + _ships = new T[count]; + _decks = new U[count]; + random = new Random(); + Width = width; + Height = height; + } + + + + public bool Add(T ship) + { + for (int i = 0; i < _ships.Length; i++) + { + if (_ships[i] == null) + { + _ships[i] = ship; + CountShips++; + return true; + } + } + return false; + } + + public bool Add(U deck) + { + for (int i = 0; i < _ships.Length; i++) + { + if (_decks[i] == null) + { + _decks[i] = deck; + CountDecks++; + return true; + } + } + return false; + } + + public DrawningShip CreateDrawObject() + { + Random rand = new Random(); + EntityShip ship = _ships[rand.Next(0, CountShips)]; + IDrawingDecks decks = _decks[rand.Next(0, CountDecks)]; + if (ship is EntityWarmlyShip warmlyShip) + { + return new DrawingWarmlyShip(ship.Speed, ship.Weight, ship.BodyColor, warmlyShip.AdditionalColor, warmlyShip.ShipPipes, warmlyShip.ShipFuel, + Width, Height, decks.GetAmount(), decks.GetShape()); + } + + return new DrawningShip(ship.Speed, ship.Weight, ship.BodyColor, Width, Height, decks.GetAmount(), decks.GetShape()); + } + } +} diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/DrawDecksParal.cs b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/DrawDecksParal.cs index 1eff479..49b72c3 100644 --- a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/DrawDecksParal.cs +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/DrawDecksParal.cs @@ -86,5 +86,20 @@ namespace ProjectWarmlyShip g.FillPolygon(os, curvePoints3); } } + public int GetShape() + { + return 2; + } + public int GetAmount() + { + int x = 0; + if (numDecks == NumDecks.OneDeck) + x = 1; + if (numDecks == NumDecks.TwoDecks) + x = 2; + if (numDecks == NumDecks.ThreeDecks) + x = 3; + return x; + } } } diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/DrawDecksSquare.cs b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/DrawDecksSquare.cs index adb393e..39dfc7e 100644 --- a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/DrawDecksSquare.cs +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/DrawDecksSquare.cs @@ -58,5 +58,20 @@ namespace ProjectWarmlyShip g.FillRectangle(os, _startPosX + 100, _startPosY, 25, 12); } } + public int GetShape() + { + return 0; + } + public int GetAmount() + { + int x = 0; + if (numDecks == NumDecks.OneDeck) + x = 1; + if (numDecks == NumDecks.TwoDecks) + x = 2; + if (numDecks == NumDecks.ThreeDecks) + x = 3; + return x; + } } } diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/DrawDecksTrapeze.cs b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/DrawDecksTrapeze.cs index fdf0c2b..2b183f5 100644 --- a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/DrawDecksTrapeze.cs +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/DrawDecksTrapeze.cs @@ -85,5 +85,20 @@ namespace ProjectWarmlyShip g.FillPolygon(os, curvePoints3); } } + public int GetShape() + { + return 1; + } + public int GetAmount() + { + int x = 0; + if (numDecks == NumDecks.OneDeck) + x = 1; + if (numDecks == NumDecks.TwoDecks) + x = 2; + if (numDecks == NumDecks.ThreeDecks) + x = 3; + return x; + } } } diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/DrawningShip.cs b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/DrawningShip.cs index ee4f848..f8fcf0e 100644 --- a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/DrawningShip.cs +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/DrawningShip.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using ProjectWarmlyShip.Entities; +using ProjectWarmlyShip.MovementStrategy; namespace ProjectWarmlyShip.DrawningObjects { @@ -232,5 +233,7 @@ namespace ProjectWarmlyShip.DrawningObjects } DrawingDecks.Draw(_startPosX, _startPosY, EntityShip.BodyColor, g); } - } + public IMoveableObject GetMoveableObject => new DrawningObjectShip(this); + +} } diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormCombo.Designer.cs b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormCombo.Designer.cs new file mode 100644 index 0000000..7a74dcf --- /dev/null +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormCombo.Designer.cs @@ -0,0 +1,73 @@ +namespace ProjectWarmlyShipHard +{ + partial class FormCombo + { + /// + /// 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() + { + pictureBoxObject = new PictureBox(); + buttonCreate = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + SuspendLayout(); + // + // pictureBoxObject + // + pictureBoxObject.Dock = DockStyle.Fill; + pictureBoxObject.Location = new Point(0, 0); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(800, 450); + pictureBoxObject.TabIndex = 0; + pictureBoxObject.TabStop = false; + // + // buttonCreate + // + buttonCreate.Location = new Point(641, 415); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(115, 23); + buttonCreate.TabIndex = 1; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // FormCombo + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonCreate); + Controls.Add(pictureBoxObject); + Name = "FormCombo"; + Text = "FormCombo"; + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + ResumeLayout(false); + } + + #endregion + + private PictureBox pictureBoxObject; + private Button buttonCreate; + } +} \ No newline at end of file diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormCombo.cs b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormCombo.cs new file mode 100644 index 0000000..9480110 --- /dev/null +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormCombo.cs @@ -0,0 +1,89 @@ +using ProjectWarmlyShip.DrawningObjects; +using ProjectWarmlyShip.Entities; +using ProjectWarmlyShip; +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 ProjectWarmlyShipHard +{ + public partial class FormCombo : Form + { + private DrawningShip _drawningShip; + private ComboGenericCollection comboGeneric; + private readonly int _pictureWidth = 400; + private readonly int _pictureHeight = 400; + Random random = new Random(); + public FormCombo() + { + InitializeComponent(); + } + private void Draw() + { + if (_drawningShip == null) + { + return; + } + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningShip.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + private void buttonCreate_Click(object sender, EventArgs e) + { + int size = random.Next(1, 10); + comboGeneric = new ComboGenericCollection(size, _pictureWidth, _pictureHeight); + for (int i = 0; i < size; i++) + { + EntityShip ship = CreateRandomShip(); + IDrawingDecks engines = CreateRandomDecks(); + comboGeneric.Add(ship); + comboGeneric.Add(engines); + _drawningShip = comboGeneric.CreateDrawObject(); + _drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + } + } + + public EntityShip CreateRandomShip() + { + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + EntityShip ship; + switch (random.Next(0, 2)) + { + case 1: + ship = new EntityWarmlyShip(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(2)), Convert.ToBoolean(random.Next(2))); + break; + default: + ship = new EntityShip(random.Next(100, 300), random.Next(1000, 3000), color); + break; + } + return ship; + } + public IDrawingDecks CreateRandomDecks() + { + IDrawingDecks _decks; + switch (random.Next(3)) + { + case 1: + _decks = new DrawDecksSquare(); + break; + case 2: + _decks = new DrawDecksTrapeze(); + break; + default: + _decks = new DrawDecksParal(); + break; + } + _decks.SomeProperty = (random.Next(1, 4)); + return _decks; + } + } +} diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormCombo.resx b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormCombo.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormCombo.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormShipCollection.Designer.cs b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormShipCollection.Designer.cs new file mode 100644 index 0000000..0294c2a --- /dev/null +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormShipCollection.Designer.cs @@ -0,0 +1,126 @@ +namespace ProjectWarmlyShipHard +{ + partial class FormShipCollection + { + /// + /// 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() + { + pictureBoxCollection = new PictureBox(); + groupBox1 = new GroupBox(); + maskedTextBoxNumber = new MaskedTextBox(); + buttonRefreshCollection = new Button(); + buttonRemoveShip = new Button(); + ButtonAddShip = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); + groupBox1.SuspendLayout(); + SuspendLayout(); + // + // pictureBoxCollection + // + pictureBoxCollection.Dock = DockStyle.Fill; + pictureBoxCollection.Location = new Point(0, 0); + pictureBoxCollection.Name = "pictureBoxCollection"; + pictureBoxCollection.Size = new Size(800, 450); + pictureBoxCollection.SizeMode = PictureBoxSizeMode.AutoSize; + pictureBoxCollection.TabIndex = 0; + pictureBoxCollection.TabStop = false; + // + // groupBox1 + // + groupBox1.Controls.Add(maskedTextBoxNumber); + groupBox1.Controls.Add(buttonRefreshCollection); + groupBox1.Controls.Add(buttonRemoveShip); + groupBox1.Controls.Add(ButtonAddShip); + groupBox1.Location = new Point(625, 0); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(175, 450); + groupBox1.TabIndex = 1; + groupBox1.TabStop = false; + groupBox1.Text = "Инструменты"; + // + // maskedTextBoxNumber + // + maskedTextBoxNumber.Location = new Point(16, 175); + maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + maskedTextBoxNumber.Size = new Size(136, 23); + maskedTextBoxNumber.TabIndex = 3; + // + // buttonRefreshCollection + // + buttonRefreshCollection.Location = new Point(16, 305); + buttonRefreshCollection.Name = "buttonRefreshCollection"; + buttonRefreshCollection.Size = new Size(136, 23); + buttonRefreshCollection.TabIndex = 2; + buttonRefreshCollection.Text = "Обновить коллекцию"; + buttonRefreshCollection.UseVisualStyleBackColor = true; + buttonRefreshCollection.Click += ButtonRefreshCollection_Click; + // + // buttonRemoveShip + // + buttonRemoveShip.Location = new Point(16, 214); + buttonRemoveShip.Name = "buttonRemoveShip"; + buttonRemoveShip.Size = new Size(136, 23); + buttonRemoveShip.TabIndex = 1; + buttonRemoveShip.Text = "Удалить корабль"; + buttonRemoveShip.UseVisualStyleBackColor = true; + buttonRemoveShip.Click += ButtonRemoveShip_Click; + // + // ButtonAddShip + // + ButtonAddShip.Location = new Point(16, 39); + ButtonAddShip.Name = "ButtonAddShip"; + ButtonAddShip.Size = new Size(136, 23); + ButtonAddShip.TabIndex = 0; + ButtonAddShip.Text = "Добавить корабль"; + ButtonAddShip.UseVisualStyleBackColor = true; + ButtonAddShip.Click += ButtonAddShip_Click; + // + // FormShipCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(groupBox1); + Controls.Add(pictureBoxCollection); + Name = "FormShipCollection"; + Text = "FormShipCollection"; + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private PictureBox pictureBoxCollection; + private GroupBox groupBox1; + private Button buttonRefreshCollection; + private Button buttonRemoveShip; + private Button ButtonAddShip; + private MaskedTextBox maskedTextBoxNumber; + } +} \ No newline at end of file diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormShipCollection.cs b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormShipCollection.cs new file mode 100644 index 0000000..458c226 --- /dev/null +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormShipCollection.cs @@ -0,0 +1,92 @@ +using ProjectWarmlyShip.DrawningObjects; +using ProjectWarmlyShip.Generics; +using ProjectWarmlyShip.MovementStrategy; +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 ProjectWarmlyShipHard +{ + /// + /// Форма для работы с набором объектов класса DrawningCar + /// + public partial class FormShipCollection : Form + { + /// + /// Набор объектов + /// + private readonly ShipsGenericCollection _ships; + /// + /// Конструктор + /// + public FormShipCollection() + { + InitializeComponent(); + _ships = new ShipsGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + } + /// + /// Добавление объекта в набор + /// + /// + /// + private void ButtonAddShip_Click(object sender, EventArgs e) + { + FormWarmlyShip form = new FormWarmlyShip(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_ships + form.SelectedShip != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = _ships.ShowShips(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + /// + /// Удаление объекта из набора + /// + /// + /// + private void ButtonRemoveShip_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = -1; + try + { + pos = Convert.ToInt32(maskedTextBoxNumber.Text); + } + catch (Exception ex) { } + if (_ships - pos) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = _ships.ShowShips(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Обновление рисунка по набору + /// + /// + /// + private void ButtonRefreshCollection_Click(object sender, EventArgs e) + { + pictureBoxCollection.Image = _ships.ShowShips(); + } + } +} diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormShipCollection.resx b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormShipCollection.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormShipCollection.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormWarmlyShip.Designer.cs b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormWarmlyShip.Designer.cs index 7951362..89d2d4c 100644 --- a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormWarmlyShip.Designer.cs +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormWarmlyShip.Designer.cs @@ -34,6 +34,7 @@ buttonCreateDeckShip = new Button(); comboBoxStrategy = new ComboBox(); buttonStep = new Button(); + buttonButtonSelectShip = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyShip).BeginInit(); SuspendLayout(); // @@ -128,11 +129,21 @@ buttonStep.UseVisualStyleBackColor = true; buttonStep.Click += ButtonStep_Click; // + // buttonButtonSelectShip + // + buttonButtonSelectShip.Location = new Point(276, 426); + buttonButtonSelectShip.Name = "buttonButtonSelectShip"; + buttonButtonSelectShip.Size = new Size(75, 23); + buttonButtonSelectShip.TabIndex = 9; + buttonButtonSelectShip.Text = "Выбрать"; + buttonButtonSelectShip.UseVisualStyleBackColor = true; + // // FormWarmlyShip // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(884, 461); + Controls.Add(buttonButtonSelectShip); Controls.Add(buttonStep); Controls.Add(comboBoxStrategy); Controls.Add(buttonCreateDeckShip); @@ -160,5 +171,6 @@ private Button buttonCreateDeckShip; private ComboBox comboBoxStrategy; private Button buttonStep; + private Button buttonButtonSelectShip; } } \ No newline at end of file diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormWarmlyShip.cs b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormWarmlyShip.cs index cd59e0a..56503e6 100644 --- a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormWarmlyShip.cs +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormWarmlyShip.cs @@ -17,6 +17,10 @@ namespace ProjectWarmlyShipHard /// /// /// + /// /// + /// + /// + public DrawningShip? SelectedShip { get; private set; } public FormWarmlyShip() { InitializeComponent(); @@ -135,5 +139,15 @@ namespace ProjectWarmlyShipHard _abstractStrategy = null; } } + /// + /// + /// + /// + /// + private void ButtonSelectShip_Click(object sender, EventArgs e) + { + SelectedShip = _drawingWarmlyShip; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormWarmlyShip.resx b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormWarmlyShip.resx index 8c18930..4414b14 100644 --- a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormWarmlyShip.resx +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/FormWarmlyShip.resx @@ -123,7 +123,7 @@ iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAABGdBTUEAALGPC/xhBQAAAG9QTFRF//// AAAAWVlZ8fHx9PT0REREtLS0Ojo6+Pj4a2trp6enj4+P3t7eXl5efX1919fXh4eHw8PD6+vrdXV10dHR 5ubmDAwMy8vLTU1NlZWVvLy8iIiINjY2nJycFhYWYWFhJycnUVFRHR0dr6+vKioqoesKnwAAAAlwSFlz - AAAOvwAADr8BOAVTJAAAAkFJREFUeF7t3GtT2zAQhWErF5JAnIQQSrmFW///b+wCR6LY/Vg3nqP3+cJE + AAAOvgAADr4B6kKxwAAAAkFJREFU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juk1mxSYDj du+Z0XrADVMX/WJ8axLheExqxVMCHJfJrHhOgKPZJrXOcpEIxqKdCu/Z8orxOakVlwlw9Eep9WMCHM1b diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/IDrawingDecks.cs b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/IDrawingDecks.cs index 261e4fb..37ab5ca 100644 --- a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/IDrawingDecks.cs +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/IDrawingDecks.cs @@ -10,5 +10,8 @@ namespace ProjectWarmlyShip { int SomeProperty { set;} void Draw(int _startPosX, int _startPosY, Color Os, Graphics g); + + public int GetAmount(); + public int GetShape(); } } diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/Program.cs b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/Program.cs index 4a5ecf0..9afdf3c 100644 --- a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/Program.cs +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/Program.cs @@ -11,7 +11,7 @@ namespace ProjectWarmlyShipHard // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormWarmlyShip()); ; + Application.Run(new FormCombo()); ; } } } \ No newline at end of file diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/SetGeneric.cs b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/SetGeneric.cs new file mode 100644 index 0000000..d5c13e4 --- /dev/null +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/SetGeneric.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectWarmlyShip.Generics +{/// + /// Параметризованный набор объектов + /// + /// + internal class SetGeneric + where T : class + { + /// + /// Массив объектов, которые храним + /// + private readonly T?[] _places; + /// + /// Количество объектов в массиве + /// + public int Count => _places.Length; + /// + /// Конструктор + /// + /// + public SetGeneric(int count) + { + _places = new T?[count]; + } + /// + /// Добавление объекта в набор + /// + /// Добавляемый корабль + /// + public int Insert(T ship) + { + int index = -1; + for (int i = 0; i < _places.Length; i++) + { + if (_places[i] == null) + { + index = i; break; + } + } + if (index < 0) + { + return -1; + } + for (int i = index; i > 0; i--) + { + _places[i] = _places[i - 1]; + } + _places[0] = ship; + return 0; + } + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемый корабль + /// Позиция + /// + public int Insert(T plane, int position) + { + if (position < 0 || position >= Count) + return -1; + if (_places[position] == null) + { + _places[position] = plane; + return position; + } + int index = -1; + for (int i = position; i < Count; i++) + { + if (_places[i] == null) + { + index = i; break; + } + } + if (index < 0) + return -1; + for (int i = index; index > position; i--) + { + _places[i] = _places[i - 1]; + } + _places[position] = plane; + return position; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + if (position < 0 || position >= _places.Length) + return false; + _places[position] = null; + return true; + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T? Get(int position) + { + if (position < 0 || position >= _places.Length) + return null; + + return _places[position]; + } + } + +} diff --git a/ProjectWarmlyShipHard/ProjectWarmlyShipHard/ShipsGenericCollection.cs b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/ShipsGenericCollection.cs new file mode 100644 index 0000000..6ce2838 --- /dev/null +++ b/ProjectWarmlyShipHard/ProjectWarmlyShipHard/ShipsGenericCollection.cs @@ -0,0 +1,147 @@ +using ProjectWarmlyShip.DrawningObjects; +using ProjectWarmlyShip.MovementStrategy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectWarmlyShip.Generics +{ + /// + /// Параметризованный класс для набора объектов DrawningCar + /// + /// + /// + internal class ShipsGenericCollection + where T : DrawningShip + where U : IMoveableObject + { + /// + /// Ширина окна прорисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна прорисовки + /// + private readonly int _pictureHeight; + /// + /// Размер занимаемого объектом места (ширина) + /// + private readonly int _placeSizeWidth = 210; + /// + /// Размер занимаемого объектом места (высота) + /// + private readonly int _placeSizeHeight = 90; + /// + /// Набор объектов + /// + private readonly SetGeneric _collection; + /// + /// Конструктор + /// + /// + /// + public ShipsGenericCollection(int picWidth, int picHeight) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = new SetGeneric(width * height); + } + /// + /// Перегрузка оператора сложения + /// + /// + /// + /// + public static int? operator +(ShipsGenericCollection collect, T? obj) + { + if (obj == null) + { + return -1; + } + return collect?._collection.Insert(obj); + } + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static bool operator -(ShipsGenericCollection collect, int + pos) + { + T? obj = collect._collection.Get(pos); + if (obj == null) + { + return false; + } + return collect._collection.Remove(pos); + } + /// + /// Получение объекта IMoveableObject + /// + /// + /// + public U? GetU(int pos) + { + return (U?)_collection.Get(pos)?.GetMoveableObject; + } + /// + /// Вывод всего набора объектов + /// + /// + public Bitmap ShowShips() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawObjects(gr); + return bmp; + } + /// + /// Метод отрисовки фона + /// + /// + private void DrawBackground(Graphics g) + { + Pen pen = new(Color.Black, 3); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + + 1; ++j) + {//линия рамзетки места + g.DrawLine(pen, i * _placeSizeWidth, j * + _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth, j * + _placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * + _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); + } + } + /// + /// Метод прорисовки объектов + /// + /// + private void DrawObjects(Graphics g) + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + for (int i = 0; i < _collection.Count; i++) + { + // TODO получение объекта + DrawningShip? Ship = _collection.Get(i); + if (Ship == null) + continue; + int r = i / width; + int s = width - 1 - (i % width); + // TODO установка позиции + Ship.SetPosition(s * _placeSizeWidth, r * _placeSizeHeight + 50); + // TODO прорисовка объекта + Ship.DrawTransport(g); + } + } + } +}