This commit is contained in:
Daniya_Youdakova 2022-12-24 22:47:59 +04:00
parent a72f35472d
commit 6d56d78be5
2 changed files with 11 additions and 7 deletions

View File

@ -45,7 +45,6 @@ namespace AircraftCarrier
yNumOfCells = (int)Math.Ceiling(_drawningObject.Step / _size_y); yNumOfCells = (int)Math.Ceiling(_drawningObject.Step / _size_y);
xObjOffset = (int)(Left / _size_x); xObjOffset = (int)(Left / _size_x);
yObjOffset = (int)Math.Floor(Top / _size_y); yObjOffset = (int)Math.Floor(Top / _size_y);
for (int i = 0; i < yNumOfCells; i++) for (int i = 0; i < yNumOfCells; i++)
{ {
if (!roadIsClear) if (!roadIsClear)
@ -71,7 +70,6 @@ namespace AircraftCarrier
yNumOfCells = (int)Math.Ceiling(_drawningObject.Step / _size_y); yNumOfCells = (int)Math.Ceiling(_drawningObject.Step / _size_y);
xObjOffset = (int)(Left / _size_x); xObjOffset = (int)(Left / _size_x);
yObjOffset = (int)Math.Ceiling(Bottom / _size_y); yObjOffset = (int)Math.Ceiling(Bottom / _size_y);
for (int i = 0; i < yNumOfCells; i++) for (int i = 0; i < yNumOfCells; i++)
{ {
if (!roadIsClear) if (!roadIsClear)
@ -123,6 +121,7 @@ namespace AircraftCarrier
yNumOfCells = (int)Math.Ceiling((Bottom - Top) / _size_y); yNumOfCells = (int)Math.Ceiling((Bottom - Top) / _size_y);
xObjOffset = (int)(Right / _size_x); xObjOffset = (int)(Right / _size_x);
yObjOffset = (int)Math.Ceiling(Top / _size_y); yObjOffset = (int)Math.Ceiling(Top / _size_y);
for (int i = 0; i < yNumOfCells; i++) for (int i = 0; i < yNumOfCells; i++)
{ {
if (!roadIsClear) if (!roadIsClear)
@ -158,13 +157,11 @@ namespace AircraftCarrier
} }
int x = _random.Next(0, 10); int x = _random.Next(0, 10);
int y = _random.Next(50, 100); int y = _random.Next(50, 100);
(float Left, float Top, float Right, float Bottom) = _drawningObject.GetCurrentPosition(); (float Left, float Top, float Right, float Bottom) = _drawningObject.GetCurrentPosition();
int xNumOfCells = (int)Math.Ceiling(Right / _size_x) - (int)Math.Floor(Left / _size_x); int xNumOfCells = (int)Math.Ceiling(Right / _size_x) - (int)Math.Floor(Left / _size_x);
int yNumOfCells = (int)Math.Ceiling(Bottom / _size_y) - (int)Math.Floor(Top / _size_y); int yNumOfCells = (int)Math.Ceiling(Bottom / _size_y) - (int)Math.Floor(Top / _size_y);
int xObjOffset = (int)(x / _size_x); int xObjOffset = (int)(x / _size_x);
int yObjOffset = (int)(y / _size_y); int yObjOffset = (int)(y / _size_y);
while (y < _height - (Bottom - Top)) while (y < _height - (Bottom - Top))
{ {
while (x < _width - (Right - Left)) while (x < _width - (Right - Left))
@ -181,7 +178,6 @@ namespace AircraftCarrier
y += (int)_size_y; y += (int)_size_y;
yObjOffset = (int)(y / _size_y); yObjOffset = (int)(y / _size_y);
} }
return false; return false;
} }
private bool AreaIsFree(int xNumOfCells, int yNumOfCells, int xObjOffset, int yObjOffset) private bool AreaIsFree(int xNumOfCells, int yNumOfCells, int xObjOffset, int yObjOffset)

View File

@ -52,7 +52,6 @@ namespace AircraftCarrier
{ {
_startPosX = x; _startPosX = x;
_startPosY = y; _startPosY = y;
_pictureWidth = width; _pictureWidth = width;
_pictureHeigth = height; _pictureHeigth = height;
} }
@ -127,15 +126,24 @@ namespace AircraftCarrier
{ {
_startPosX = _pictureWidth.Value - _aircraftcarrierWidth; _startPosX = _pictureWidth.Value - _aircraftcarrierWidth;
} }
if (_startPosY + _aircraftcarrierHeight > _pictureHeigth) if (_startPosY + _aircraftcarrierHeight > _pictureHeigth)
{ {
_startPosY = _pictureHeigth.Value - _aircraftcarrierHeight; _startPosY = _pictureHeigth.Value - _aircraftcarrierHeight;
} }
} }
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{ {
return (_startPosX, _startPosY, _startPosX + _aircraftcarrierWidth, _startPosY + _aircraftcarrierHeight); return (_startPosX, _startPosY, _startPosX + _aircraftcarrierWidth, _startPosY + _aircraftcarrierHeight);
} }
public void ReturnColor(Color returnColor)
{
if (AircraftCarrier is not EntityModernAircraftCarrier modernAircraftCarrier)
{
return;
}
modernAircraftCarrier.DopColor = returnColor;
}
} }
} }