diff --git a/SelfPropelledArtilleryUnit/Direction.cs b/SelfPropelledArtilleryUnit/Direction.cs index 00b7082..191fe7d 100644 --- a/SelfPropelledArtilleryUnit/Direction.cs +++ b/SelfPropelledArtilleryUnit/Direction.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Artilleries { - internal enum Direction + public enum Direction { Up = 1, Down = 2, diff --git a/SelfPropelledArtilleryUnit/DrawingArtillery.cs b/SelfPropelledArtilleryUnit/DrawingArtillery.cs index ff31752..52f941c 100644 --- a/SelfPropelledArtilleryUnit/DrawingArtillery.cs +++ b/SelfPropelledArtilleryUnit/DrawingArtillery.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace Artilleries { - internal class DrawingArtillery + public class DrawingArtillery { public EntityArtillery Artillery { protected set; get; } protected float _startPosX; diff --git a/SelfPropelledArtilleryUnit/EntityArtillery.cs b/SelfPropelledArtilleryUnit/EntityArtillery.cs index df6fbf5..19b79b7 100644 --- a/SelfPropelledArtilleryUnit/EntityArtillery.cs +++ b/SelfPropelledArtilleryUnit/EntityArtillery.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Artilleries { - internal class EntityArtillery + public class EntityArtillery { public int Speed { get; private set; } public float Weight { get; private set; } diff --git a/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs b/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs index 04e9c76..4e465f1 100644 --- a/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs +++ b/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs @@ -39,6 +39,8 @@ this.buttonUp = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); + this.createAdvancedButton = new System.Windows.Forms.Button(); + this.selectArtilleryButton = new System.Windows.Forms.Button(); this.statusStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit(); this.SuspendLayout(); @@ -147,11 +149,35 @@ this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); // + // createAdvancedButton + // + this.createAdvancedButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.createAdvancedButton.Location = new System.Drawing.Point(106, 382); + this.createAdvancedButton.Name = "createAdvancedButton"; + this.createAdvancedButton.Size = new System.Drawing.Size(113, 23); + this.createAdvancedButton.TabIndex = 7; + this.createAdvancedButton.Text = "Модифицировать"; + this.createAdvancedButton.UseVisualStyleBackColor = true; + this.createAdvancedButton.Click += new System.EventHandler(this.createAdvancedButton_Click); + // + // selectArtilleryButton + // + this.selectArtilleryButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.selectArtilleryButton.Location = new System.Drawing.Point(410, 379); + this.selectArtilleryButton.Name = "selectArtilleryButton"; + this.selectArtilleryButton.Size = new System.Drawing.Size(75, 23); + this.selectArtilleryButton.TabIndex = 8; + this.selectArtilleryButton.Text = "Выбрать"; + this.selectArtilleryButton.UseVisualStyleBackColor = true; + this.selectArtilleryButton.Click += new System.EventHandler(this.selectArtilleryButton_Click); + // // FormArtillery // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(624, 441); + this.Controls.Add(this.selectArtilleryButton); + this.Controls.Add(this.createAdvancedButton); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonUp); @@ -183,5 +209,7 @@ private Button buttonUp; private Button buttonDown; private Button buttonRight; + private Button createAdvancedButton; + private Button selectArtilleryButton; } } \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/FormArtillery.cs b/SelfPropelledArtilleryUnit/FormArtillery.cs index 56fe28f..e130400 100644 --- a/SelfPropelledArtilleryUnit/FormArtillery.cs +++ b/SelfPropelledArtilleryUnit/FormArtillery.cs @@ -4,6 +4,8 @@ namespace Artilleries { private DrawingArtillery _artillery; + public DrawingArtillery SelectedArtillery { get; private set; } + public FormArtillery() { InitializeComponent(); @@ -17,14 +19,53 @@ namespace Artilleries pictureBoxArtilleries.Image = bmp; } + private void SetData(DrawingArtillery artillery) + { + Random rnd = new(); + artillery.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxArtilleries.Width, pictureBoxArtilleries.Height); + SpeedStatusLabel.Text = $"Ñêîðîñòü: {artillery.Artillery.Speed}"; + WeightStatusLabel.Text = $"Âåñ: {artillery.Artillery.Weight}"; + ColorStatusLabel.Text = $"Öâåò: {artillery.Artillery.BodyColor.Name}"; + } + private void buttonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _artillery = new DrawingArtillery(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - _artillery.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxArtilleries.Width, pictureBoxArtilleries.Height); - SpeedStatusLabel.Text = $"Ñêîðîñòü: {_artillery.Artillery.Speed}"; - WeightStatusLabel.Text = $"Âåñ: {_artillery.Artillery.Weight}"; - ColorStatusLabel.Text = $"Öâåò: {_artillery.Artillery.BodyColor.Name}"; + 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; + } + _artillery = new DrawingArtillery(rnd.Next(100, 300), rnd.Next(1000, 2000), color); + SetData(_artillery); + Draw(); + } + + private void createAdvancedButton_Click(object sender, EventArgs e) + { + 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; + } + _artillery = new DrawingAdvancedArtillery( + rnd.Next(100, 300), + rnd.Next(1000, 2000), + color, + dopColor, + rnd.Next(0, 2) == 1, rnd.Next(0, 2) == 1 + ); + SetData(_artillery); Draw(); } @@ -54,5 +95,11 @@ namespace Artilleries _artillery?.ChangeBorders(pictureBoxArtilleries.Width, pictureBoxArtilleries.Height); Draw(); } + + private void selectArtilleryButton_Click(object sender, EventArgs e) + { + SelectedArtillery = _artillery; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs b/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs index 71672f8..2f87663 100644 --- a/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs +++ b/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs @@ -29,10 +29,35 @@ namespace Artilleries return false; } + if (_places[position] == null) + { + _places[position] = artillery; + return true; + } + int firstNull = -1; + + for (int i = position + 1; i < Count; i++) + { + if (_places[i] == null) + { + firstNull = i; + break; + } + } + + if (firstNull == -1) + { + return false; + } + + for (int i = firstNull; i > position; i--) + { + (_places[i], _places[i - 1]) = (_places[i - 1], _places[i]); + } _places[position] = artillery; - return true; // TODO + return true; } public bool Remove(int position)