diff --git a/Locomative/Locomative/Direction.cs b/Locomative/Locomative/Direction.cs index 44ce77a..a5422e5 100644 --- a/Locomative/Locomative/Direction.cs +++ b/Locomative/Locomative/Direction.cs @@ -8,6 +8,7 @@ namespace Locomative { internal enum Direction { + None = 0, Up = 1, Down = 2, Left = 3, diff --git a/Locomative/Locomative/FormMap.Designer.cs b/Locomative/Locomative/FormMap.Designer.cs index f65dcdc..0279047 100644 --- a/Locomative/Locomative/FormMap.Designer.cs +++ b/Locomative/Locomative/FormMap.Designer.cs @@ -47,9 +47,10 @@ // buttonСreate // this.buttonСreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonСreate.Location = new System.Drawing.Point(12, 393); + this.buttonСreate.Location = new System.Drawing.Point(14, 453); + this.buttonСreate.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.buttonСreate.Name = "buttonСreate"; - this.buttonСreate.Size = new System.Drawing.Size(75, 23); + this.buttonСreate.Size = new System.Drawing.Size(88, 27); this.buttonСreate.TabIndex = 0; this.buttonСreate.Text = "Создание"; this.buttonСreate.UseVisualStyleBackColor = true; @@ -60,9 +61,10 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::Locomative.Properties.Resources.arrow_down; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(711, 381); + this.buttonDown.Location = new System.Drawing.Point(830, 440); + this.buttonDown.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(35, 35); + this.buttonDown.Size = new System.Drawing.Size(41, 40); this.buttonDown.TabIndex = 1; this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click); @@ -71,12 +73,12 @@ // this.pictureBoxLocomative.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBoxLocomative.Location = new System.Drawing.Point(0, 0); + this.pictureBoxLocomative.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.pictureBoxLocomative.Name = "pictureBoxLocomative"; - this.pictureBoxLocomative.Size = new System.Drawing.Size(800, 428); + this.pictureBoxLocomative.Size = new System.Drawing.Size(933, 497); this.pictureBoxLocomative.TabIndex = 2; this.pictureBoxLocomative.TabStop = false; this.pictureBoxLocomative.Click += new System.EventHandler(this.pictureBoxLocomative_Click); - this.pictureBoxLocomative.Resize += new System.EventHandler(this.PictureBoxResize); // // statusStrip1 // @@ -84,22 +86,23 @@ this.toolStripStatusLabelSpeed, this.toolStripStatusLabelWeight, this.toolStripStatusLabelColor}); - this.statusStrip1.Location = new System.Drawing.Point(0, 428); + this.statusStrip1.Location = new System.Drawing.Point(0, 497); this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Size = new System.Drawing.Size(800, 22); + this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 16, 0); + this.statusStrip1.Size = new System.Drawing.Size(933, 22); this.statusStrip1.TabIndex = 3; this.statusStrip1.Text = "statusStrip1"; // // toolStripStatusLabelSpeed // this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; - this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(55, 17); + this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(59, 17); this.toolStripStatusLabelSpeed.Text = "Скорость"; // // toolStripStatusLabelWeight // this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; - this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(24, 17); + this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(26, 17); this.toolStripStatusLabelWeight.Text = "Вес"; // // toolStripStatusLabelColor @@ -113,9 +116,10 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::Locomative.Properties.Resources.arrow_left; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(670, 381); + this.buttonLeft.Location = new System.Drawing.Point(782, 440); + this.buttonLeft.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(35, 35); + this.buttonLeft.Size = new System.Drawing.Size(41, 40); this.buttonLeft.TabIndex = 4; this.buttonLeft.UseVisualStyleBackColor = true; // @@ -124,9 +128,10 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::Locomative.Properties.Resources.arrow_right; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(752, 381); + this.buttonRight.Location = new System.Drawing.Point(877, 440); + this.buttonRight.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(35, 35); + this.buttonRight.Size = new System.Drawing.Size(41, 40); this.buttonRight.TabIndex = 5; this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); @@ -136,9 +141,10 @@ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::Locomative.Properties.Resources.arrow_up; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(711, 340); + this.buttonUp.Location = new System.Drawing.Point(830, 392); + this.buttonUp.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(35, 35); + this.buttonUp.Size = new System.Drawing.Size(41, 40); this.buttonUp.TabIndex = 6; this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click); @@ -146,9 +152,10 @@ // ButtonFastCreate // this.ButtonFastCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.ButtonFastCreate.Location = new System.Drawing.Point(101, 393); + this.ButtonFastCreate.Location = new System.Drawing.Point(118, 453); + this.ButtonFastCreate.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.ButtonFastCreate.Name = "ButtonFastCreate"; - this.ButtonFastCreate.Size = new System.Drawing.Size(97, 23); + this.ButtonFastCreate.Size = new System.Drawing.Size(113, 27); this.ButtonFastCreate.TabIndex = 7; this.ButtonFastCreate.Text = "Модификация"; this.ButtonFastCreate.UseVisualStyleBackColor = true; @@ -158,16 +165,20 @@ // this.comboBoxSelectirMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxSelectirMap.FormattingEnabled = true; - this.comboBoxSelectirMap.Location = new System.Drawing.Point(12, 12); + this.comboBoxSelectirMap.Items.AddRange(new object[] { + "Простая карта"}); + this.comboBoxSelectirMap.Location = new System.Drawing.Point(14, 14); + this.comboBoxSelectirMap.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.comboBoxSelectirMap.Name = "comboBoxSelectirMap"; - this.comboBoxSelectirMap.Size = new System.Drawing.Size(103, 21); + this.comboBoxSelectirMap.Size = new System.Drawing.Size(119, 23); this.comboBoxSelectirMap.TabIndex = 8; + this.comboBoxSelectirMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectirMap_SelectedIndexChanged); // // FormMap // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(933, 519); this.Controls.Add(this.comboBoxSelectirMap); this.Controls.Add(this.ButtonFastCreate); this.Controls.Add(this.buttonUp); @@ -177,6 +188,7 @@ this.Controls.Add(this.buttonDown); this.Controls.Add(this.pictureBoxLocomative); this.Controls.Add(this.statusStrip1); + this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.Name = "FormMap"; this.Text = "FormMap"; ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomative)).EndInit(); diff --git a/Locomative/Locomative/FormMap.cs b/Locomative/Locomative/FormMap.cs index 38d6d9e..d635d5b 100644 --- a/Locomative/Locomative/FormMap.cs +++ b/Locomative/Locomative/FormMap.cs @@ -18,25 +18,39 @@ namespace Locomative InitializeComponent(); _abstractMap = new SimpleMap(); } - public void SetData(DrawningLocomative loco) + private void SetData(DrawningLocomative loco) { toolStripStatusLabelColor.Text = $"Цвет:{loco.Locomative.BodyColor.Name}"; toolStripStatusLabelSpeed.Text = $"Скорость:{loco.Locomative.Speed}"; toolStripStatusLabelWeight.Text = $"Вес:{loco.Locomative.Weight}"; - + pictureBoxLocomative.Image = _abstractMap.CreateMap(pictureBoxLocomative.Width, pictureBoxLocomative.Height, new DrawningObjectLoco(loco)); } private void buttonСreate_Click(object sender, EventArgs e) { Random rnd = new(); - _loco = new DrawningLocomative(rnd.Next(1, 200), rnd.Next(10, 300), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - _loco.SetPosition(rnd.Next(10, 300), rnd.Next(10, 300), pictureBoxLocomative.Width, pictureBoxLocomative.Height); - SetData(); - Draw(); + var car = new DrawningLocomative(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255))); + SetData(car); } private void buttonMove_Click(object sender, EventArgs e) { - buttonMove_Click(sender, e, _loco); + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "ButtonUp": + pictureBoxLocomative.Image = _abstractMap?.MoveObject(Direction.Up); + break; + case "ButtonUpDwon": + pictureBoxLocomative.Image = _abstractMap?.MoveObject(Direction.Down); + break; + case "ButtonLeft": + pictureBoxLocomative.Image = _abstractMap?.MoveObject(Direction.Left); + break; + case "ButtonRight": + pictureBoxLocomative.Image = _abstractMap?.MoveObject(Direction.Right); + break; + + } } private void buttonMove_Click(object sender, EventArgs e, DrawningLocomative _loco) @@ -65,19 +79,10 @@ namespace Locomative } - private void PictureBoxResize(object sender, EventArgs e) - { - _loco?.ChangeBorders(pictureBoxLocomative.Width, pictureBoxLocomative.Height); - Draw(); - } private void ButtonFastCreate_Click(object sender, EventArgs e) { Random rnd = new(); - /*_loco = new DrawningFastLoco(rnd.Next(1, 200), rnd.Next(100, 300), - 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)), - Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));*/ _loco = new DrawningFastLoco(rnd.Next(1, 200), rnd.Next(100, 300), 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)), @@ -85,5 +90,15 @@ namespace Locomative SetData(); Draw(); } + + private void comboBoxSelectirMap_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectirMap.Text) + { + case "Простая карта": + _abstractMap = new SimpleMap(); + break; + } + } } }