Отрисовка

This commit is contained in:
Данила Селяев 2022-09-11 18:23:09 +04:00
parent b552c74110
commit 1a1a6cd705
3 changed files with 23 additions and 15 deletions

View File

@ -13,8 +13,8 @@ namespace Locomative
private float _startPosY; private float _startPosY;
private int? _pictureWidth = null; private int? _pictureWidth = null;
private int? _pictureHeight = null; private int? _pictureHeight = null;
protected readonly int _locomativeWidth = 0; protected readonly int _locomativeWidth = 110;
protected readonly int _locomativeHeight = 0; protected readonly int _locomativeHeight = 40;
public void Init(int speed, float weight, Color bodyColor) public void Init(int speed, float weight, Color bodyColor)
{ {
Locomative = new EntityLocomative(); Locomative = new EntityLocomative();

View File

@ -44,7 +44,8 @@
// //
// buttonСreate // buttonСreate
// //
this.buttonСreate.Location = new System.Drawing.Point(12, 390); 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.Name = "buttonСreate"; this.buttonСreate.Name = "buttonСreate";
this.buttonСreate.Size = new System.Drawing.Size(75, 23); this.buttonСreate.Size = new System.Drawing.Size(75, 23);
this.buttonСreate.TabIndex = 0; this.buttonСreate.TabIndex = 0;
@ -54,9 +55,10 @@
// //
// buttonDown // buttonDown
// //
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.BackgroundImage = global::Locomative.Properties.Resources.arrow_down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(676, 390); this.buttonDown.Location = new System.Drawing.Point(711, 381);
this.buttonDown.Name = "buttonDown"; this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(35, 35); this.buttonDown.Size = new System.Drawing.Size(35, 35);
this.buttonDown.TabIndex = 1; this.buttonDown.TabIndex = 1;
@ -104,9 +106,10 @@
// //
// buttonLeft // buttonLeft
// //
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.BackgroundImage = global::Locomative.Properties.Resources.arrow_left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(635, 390); this.buttonLeft.Location = new System.Drawing.Point(670, 381);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(35, 35); this.buttonLeft.Size = new System.Drawing.Size(35, 35);
this.buttonLeft.TabIndex = 4; this.buttonLeft.TabIndex = 4;
@ -115,9 +118,10 @@
// //
// buttonRight // buttonRight
// //
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.BackgroundImage = global::Locomative.Properties.Resources.arrow_right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(717, 390); this.buttonRight.Location = new System.Drawing.Point(752, 381);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(35, 35); this.buttonRight.Size = new System.Drawing.Size(35, 35);
this.buttonRight.TabIndex = 5; this.buttonRight.TabIndex = 5;
@ -126,9 +130,10 @@
// //
// buttonUp // buttonUp
// //
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.BackgroundImage = global::Locomative.Properties.Resources.arrow_up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(676, 349); this.buttonUp.Location = new System.Drawing.Point(711, 340);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(35, 35); this.buttonUp.Size = new System.Drawing.Size(35, 35);
this.buttonUp.TabIndex = 6; this.buttonUp.TabIndex = 6;

View File

@ -21,14 +21,17 @@ namespace Locomative
private void buttonÑreate_Click(object sender, EventArgs e) private void buttonÑreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); if (pictureBoxLocomative.Width >= 120 && pictureBoxLocomative.Height >= 50)
_loco = new DrawningLocomative(); {
_loco.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); Random rnd = new();
_loco.SetPosition(rnd.Next(10, 300), rnd.Next(10, 300), pictureBoxLocomative.Width, pictureBoxLocomative.Height); _loco = new DrawningLocomative();
toolStripStatusLabelColor.Text = $"Öâåò:{_loco.Locomative?.BodyColor.Name}"; _loco.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü:{_loco.Locomative?.Speed}"; _loco.SetPosition(rnd.Next(10, pictureBoxLocomative.Width - 100), rnd.Next(10, pictureBoxLocomative.Height - 40), pictureBoxLocomative.Width, pictureBoxLocomative.Height);
toolStripStatusLabelWeight.Text = $"Âåñ:{_loco.Locomative?.Weight}"; toolStripStatusLabelColor.Text = $"Öâåò:{_loco.Locomative?.BodyColor.Name}";
Draw(); toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü:{_loco.Locomative?.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ:{_loco.Locomative?.Weight}";
Draw();
}
} }
private void buttonMove_Click(object sender, EventArgs e) private void buttonMove_Click(object sender, EventArgs e)