Отрисовка

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 int? _pictureWidth = null;
private int? _pictureHeight = null;
protected readonly int _locomativeWidth = 0;
protected readonly int _locomativeHeight = 0;
protected readonly int _locomativeWidth = 110;
protected readonly int _locomativeHeight = 40;
public void Init(int speed, float weight, Color bodyColor)
{
Locomative = new EntityLocomative();

View File

@ -44,7 +44,8 @@
//
// 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.Size = new System.Drawing.Size(75, 23);
this.buttonСreate.TabIndex = 0;
@ -54,9 +55,10 @@
//
// 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.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.Size = new System.Drawing.Size(35, 35);
this.buttonDown.TabIndex = 1;
@ -104,9 +106,10 @@
//
// 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.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.Size = new System.Drawing.Size(35, 35);
this.buttonLeft.TabIndex = 4;
@ -115,9 +118,10 @@
//
// 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.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.Size = new System.Drawing.Size(35, 35);
this.buttonRight.TabIndex = 5;
@ -126,9 +130,10 @@
//
// 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.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.Size = new System.Drawing.Size(35, 35);
this.buttonUp.TabIndex = 6;

View File

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