diff --git a/SelfPropelledArtilleryUnit/Direction.cs b/SelfPropelledArtilleryUnit/Direction.cs index 8d54af8..00b7082 100644 --- a/SelfPropelledArtilleryUnit/Direction.cs +++ b/SelfPropelledArtilleryUnit/Direction.cs @@ -11,6 +11,7 @@ namespace Artilleries Up = 1, Down = 2, Left = 3, - Right = 4 + Right = 4, + None } } diff --git a/SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs b/SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs index 34133c9..7efa81c 100644 --- a/SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs +++ b/SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Artilleries { - internal class DrawingObjectArtillery : IDrawningObject + internal class DrawingObjectArtillery : IDrawingObject { private DrawingArtillery _artillery = null; diff --git a/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs b/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs index 24c8c47..04e9c76 100644 --- a/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs +++ b/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs @@ -39,7 +39,6 @@ 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.statusStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit(); this.SuspendLayout(); @@ -148,23 +147,11 @@ 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(105, 382); - this.createAdvancedButton.Name = "createAdvancedButton"; - this.createAdvancedButton.Size = new System.Drawing.Size(142, 23); - this.createAdvancedButton.TabIndex = 7; - this.createAdvancedButton.Text = "Создать модификацию"; - this.createAdvancedButton.UseVisualStyleBackColor = true; - this.createAdvancedButton.Click += new System.EventHandler(this.createAdvancedButton_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.createAdvancedButton); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonUp); @@ -196,6 +183,5 @@ private Button buttonUp; private Button buttonDown; private Button buttonRight; - private Button createAdvancedButton; } } \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/FormArtillery.cs b/SelfPropelledArtilleryUnit/FormArtillery.cs index dbdbc43..56fe28f 100644 --- a/SelfPropelledArtilleryUnit/FormArtillery.cs +++ b/SelfPropelledArtilleryUnit/FormArtillery.cs @@ -17,34 +17,14 @@ namespace Artilleries pictureBoxArtilleries.Image = bmp; } - private void SetData() - { - 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))); - SetData(); - Draw(); - } - - private void createAdvancedButton_Click(object sender, EventArgs e) - { - Random rnd = new(); - _artillery = new DrawingAdvancedArtillery( - rnd.Next(100, 300), - rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), - rnd.Next(0, 2) == 1, rnd.Next(0, 2) == 1 - ); - SetData(); + _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}"; Draw(); } diff --git a/SelfPropelledArtilleryUnit/FormMap.Designer.cs b/SelfPropelledArtilleryUnit/FormMap.Designer.cs new file mode 100644 index 0000000..c44fd36 --- /dev/null +++ b/SelfPropelledArtilleryUnit/FormMap.Designer.cs @@ -0,0 +1,207 @@ +namespace Artilleries +{ + 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.createAdvancedButton = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.pictureBoxArtilleries = new System.Windows.Forms.PictureBox(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.SpeedStatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); + this.WeightStatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); + this.ColorStatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit(); + this.statusStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // 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(105, 382); + this.createAdvancedButton.Name = "createAdvancedButton"; + this.createAdvancedButton.Size = new System.Drawing.Size(95, 23); + this.createAdvancedButton.TabIndex = 15; + this.createAdvancedButton.Text = "Модификация"; + this.createAdvancedButton.UseVisualStyleBackColor = true; + this.createAdvancedButton.Click += new System.EventHandler(this.createAdvancedButton_Click); + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonRight.Location = new System.Drawing.Point(579, 375); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 14; + 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::SelfPropelledArtilleryUnit.Properties.Resources.ArrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonDown.Location = new System.Drawing.Point(543, 375); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 13; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.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::SelfPropelledArtilleryUnit.Properties.Resources.ArrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonUp.Location = new System.Drawing.Point(543, 342); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 12; + 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::SelfPropelledArtilleryUnit.Properties.Resources.ArrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonLeft.Location = new System.Drawing.Point(509, 375); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 11; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.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, 382); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(75, 23); + this.buttonCreate.TabIndex = 10; + this.buttonCreate.Text = "Создать"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); + // + // pictureBoxArtilleries + // + this.pictureBoxArtilleries.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxArtilleries.Location = new System.Drawing.Point(0, 0); + this.pictureBoxArtilleries.Name = "pictureBoxArtilleries"; + this.pictureBoxArtilleries.Size = new System.Drawing.Size(624, 419); + this.pictureBoxArtilleries.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxArtilleries.TabIndex = 9; + this.pictureBoxArtilleries.TabStop = false; + // + // statusStrip1 + // + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.SpeedStatusLabel, + this.WeightStatusLabel, + this.ColorStatusLabel}); + this.statusStrip1.Location = new System.Drawing.Point(0, 419); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(624, 22); + this.statusStrip1.TabIndex = 8; + // + // SpeedStatusLabel + // + this.SpeedStatusLabel.Name = "SpeedStatusLabel"; + this.SpeedStatusLabel.Size = new System.Drawing.Size(62, 17); + this.SpeedStatusLabel.Text = "Скорость:"; + // + // WeightStatusLabel + // + this.WeightStatusLabel.Name = "WeightStatusLabel"; + this.WeightStatusLabel.Size = new System.Drawing.Size(29, 17); + this.WeightStatusLabel.Text = "Вес:"; + // + // ColorStatusLabel + // + this.ColorStatusLabel.Name = "ColorStatusLabel"; + this.ColorStatusLabel.Size = new System.Drawing.Size(36, 17); + this.ColorStatusLabel.Text = "Цвет:"; + // + // 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 = 16; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged); + // + // FormMap + // + 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.comboBoxSelectorMap); + this.Controls.Add(this.createAdvancedButton); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.buttonDown); + this.Controls.Add(this.buttonUp); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.pictureBoxArtilleries); + this.Controls.Add(this.statusStrip1); + this.Name = "FormMap"; + this.Text = "Artillery"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).EndInit(); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button createAdvancedButton; + private Button buttonRight; + private Button buttonDown; + private Button buttonUp; + private Button buttonLeft; + private Button buttonCreate; + private PictureBox pictureBoxArtilleries; + private StatusStrip statusStrip1; + private ToolStripStatusLabel SpeedStatusLabel; + private ToolStripStatusLabel WeightStatusLabel; + private ToolStripStatusLabel ColorStatusLabel; + private ComboBox comboBoxSelectorMap; + } +} \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/FormMap.cs b/SelfPropelledArtilleryUnit/FormMap.cs new file mode 100644 index 0000000..daa8dce --- /dev/null +++ b/SelfPropelledArtilleryUnit/FormMap.cs @@ -0,0 +1,85 @@ +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 Artilleries +{ + public partial class FormMap : Form + { + private AbstractMap _abstractMap; + + public FormMap() + { + InitializeComponent(); + _abstractMap = new SimpleMap(); + } + + 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}"; + pictureBoxArtilleries.Image = _abstractMap.CreateMap(pictureBoxArtilleries.Width, pictureBoxArtilleries.Height, new DrawingObjectArtillery(artillery)); + } + + private void createAdvancedButton_Click(object sender, EventArgs e) + { + Random rnd = new(); + var artillery = new DrawingAdvancedArtillery( + rnd.Next(100, 300), + rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + rnd.Next(0, 2) == 1, rnd.Next(0, 2) == 1 + ); + SetData(artillery); + } + + private void buttonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + var 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))); + SetData(artillery); + } + + private void buttonMove_Click(object sender, EventArgs e) + { + 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; + } + pictureBoxArtilleries.Image = _abstractMap?.MoveObject(dir); + } + + private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + _abstractMap = new SimpleMap(); + break; + } + } + } +} diff --git a/SelfPropelledArtilleryUnit/FormMap.resx b/SelfPropelledArtilleryUnit/FormMap.resx new file mode 100644 index 0000000..5cb320f --- /dev/null +++ b/SelfPropelledArtilleryUnit/FormMap.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SelfPropelledArtilleryUnit/Program.cs b/SelfPropelledArtilleryUnit/Program.cs index e993022..2b37e99 100644 --- a/SelfPropelledArtilleryUnit/Program.cs +++ b/SelfPropelledArtilleryUnit/Program.cs @@ -6,7 +6,7 @@ namespace Artilleries static void Main() { ApplicationConfiguration.Initialize(); - Application.Run(new FormArtillery()); + Application.Run(new FormMap()); } } } \ No newline at end of file