diff --git a/WarmlyShip/WarmlyShip/AbstractMap.cs b/WarmlyShip/WarmlyShip/AbstractMap.cs index b488da9..d0fdf65 100644 --- a/WarmlyShip/WarmlyShip/AbstractMap.cs +++ b/WarmlyShip/WarmlyShip/AbstractMap.cs @@ -82,6 +82,4 @@ namespace WarmlyShip protected abstract void DrawRoadPart(Graphics g, int i, int j); protected abstract void DrawBarrierPart(Graphics g, int i, int j); } - -} } diff --git a/WarmlyShip/WarmlyShip/Direction.cs b/WarmlyShip/WarmlyShip/Direction.cs index fa7a4e8..09a6267 100644 --- a/WarmlyShip/WarmlyShip/Direction.cs +++ b/WarmlyShip/WarmlyShip/Direction.cs @@ -8,6 +8,7 @@ namespace WarmlyShip { internal enum Direction //Направление при перемещении { + None = 0, Left = 1, //Влево Up = 2, //Вверх Right = 3, //Вправо diff --git a/WarmlyShip/WarmlyShip/FormMap.Designer.cs b/WarmlyShip/WarmlyShip/FormMap.Designer.cs index 820357b..2b82e57 100644 --- a/WarmlyShip/WarmlyShip/FormMap.Designer.cs +++ b/WarmlyShip/WarmlyShip/FormMap.Designer.cs @@ -28,10 +28,166 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + 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 @@ -47,5 +203,6 @@ 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 index 1463ce6..7dd8e94 100644 --- a/WarmlyShip/WarmlyShip/FormMap.cs +++ b/WarmlyShip/WarmlyShip/FormMap.cs @@ -12,9 +12,71 @@ namespace WarmlyShip { public partial class FormMap : Form { + private AbstractMap _abstractMap; + public FormMap() { InitializeComponent(); + _abstractMap = new SimpleMap(); + } + + private void SetData(DrawningWarmlyShip 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 DrawningWarmlyShip(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; + } + } } } diff --git a/WarmlyShip/WarmlyShip/FormMap.resx b/WarmlyShip/WarmlyShip/FormMap.resx index 1af7de1..2c0949d 100644 --- a/WarmlyShip/WarmlyShip/FormMap.resx +++ b/WarmlyShip/WarmlyShip/FormMap.resx @@ -1,64 +1,4 @@ - - - + @@ -117,4 +57,7 @@ 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 a894d54..9bf5de7 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 FormClass()); + Application.Run(new FormMap()); } } } \ No newline at end of file