Compare commits

...

5 Commits

3 changed files with 7 additions and 23 deletions

View File

@ -59,27 +59,13 @@ namespace AircraftCarrier
/// <param name="height"></param> /// <param name="height"></param>
public void SetPosition(int x, int y, int width, int height) public void SetPosition(int x, int y, int width, int height)
{ {
_startPosX = x; if (width >= x + _warshipWidth && height >= y + _warshipHeight && x >= 0 && y >= 0)
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
if (width < _warshipWidth)
{ {
width = _warshipWidth; _startPosX = x;
} _startPosY = y;
if (height < _warshipHeight) _pictureWidth = width;
{ _pictureHeight = height;
height = _warshipHeight; }
}
if(x + _warshipWidth > width)
{
_startPosX -= x + _warshipWidth - width;
}
if (y + _warshipHeight > height)
{
_pictureHeight -= y + _warshipHeight - height;
}
} }
/// <summary> /// <summary>
/// Изменение направления пермещения /// Изменение направления пермещения

View File

@ -40,7 +40,5 @@ namespace AircraftCarrier
Weight = weight <= 0 ? rnd.Next(40, 70) : weight; Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
BodyColor = bodyColor; BodyColor = bodyColor;
} }
} }
} }

View File

@ -23,7 +23,7 @@ namespace AircraftCarrier
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_warship = new DrawingWarship(); _warship = new DrawingWarship();
_warship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _warship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));