From 74cc61815ce0c710e18e1fd3aa1670e580202f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 21 Sep 2022 09:47:59 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D0=BE=20=D0=BF=D1=80=D0=B5=D0=BF=D0=BE=D0=B4=D0=BE?= =?UTF-8?q?=D0=BC.=20=D0=9D=D0=B5=20pull=20request?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs | 5 +++-- WarmlyShip/WarmlyShip/FormClass.cs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs index b942956..b131644 100644 --- a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs @@ -24,9 +24,10 @@ namespace WarmlyShip public void SetPosition(int x, int y, int width, int height) { + if (width < _warmlyShipWidth || height < _warmlyShipHeight) return; Random random = new Random(); - _startPosX = x < 0 || x > width ? random.Next(0, width) : x; - _startPosY = y < 0 || y > height ? random.Next(0, height) : y; + _startPosX = x < 0 || x + _warmlyShipWidth > width ? random.Next(0, width - _warmlyShipWidth) : x; + _startPosY = y < 0 || y + _warmlyShipHeight > height ? random.Next(0, height - _warmlyShipHeight) : y; _pictureWidth = width; _pictureHeight = height; } diff --git a/WarmlyShip/WarmlyShip/FormClass.cs b/WarmlyShip/WarmlyShip/FormClass.cs index abaae2a..23e86ce 100644 --- a/WarmlyShip/WarmlyShip/FormClass.cs +++ b/WarmlyShip/WarmlyShip/FormClass.cs @@ -22,7 +22,7 @@ namespace WarmlyShip Random random = new Random(); _warmlyShip = new DrawingWarmlyShip(); _warmlyShip.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); - _warmlyShip.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBox.Width, pictureBox.Height); + _warmlyShip.SetPosition(random.Next(pictureBox.Width - 150, pictureBox.Width - 125), random.Next(pictureBox.Height - 150, pictureBox.Height - 50), pictureBox.Width, pictureBox.Height); toolStripStatusSpeed.Text = $"Скорость: {_warmlyShip.warmlyShip?.Speed}"; toolStripStatusWeight.Text = $"Вес: {_warmlyShip.warmlyShip?.Weight}"; toolStripStatusLabelBodyColor.Text = $"Цвет: {_warmlyShip.warmlyShip?.BodyColor}";