логика Setposition
This commit is contained in:
parent
1a1a6cd705
commit
12990f7e9e
@ -22,6 +22,16 @@ namespace Locomative
|
||||
}
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
Random rnd1 = new();
|
||||
if (width < 120 || height < 50) return;
|
||||
if (x > width - _locomativeWidth)
|
||||
{
|
||||
x = rnd1.Next(10, width - _locomativeWidth - 1);
|
||||
}
|
||||
if( y > height- _locomativeHeight)
|
||||
{
|
||||
y = rnd1.Next(10, height - _locomativeHeight - 1);
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
_pictureHeight = height;
|
||||
|
@ -21,17 +21,14 @@ namespace Locomative
|
||||
|
||||
private void buttonÑreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
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();
|
||||
}
|
||||
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, 400), 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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user