Aleikin A.M. LabWork02 #2

Merged
eegov merged 9 commits from LabWork02 into LabWork01 2022-10-28 09:12:52 +04:00
3 changed files with 63 additions and 6 deletions
Showing only changes of commit 9d01e9ae66 - Show all commits

View File

@ -32,12 +32,69 @@ namespace AirBomber
return DrawMapWithObject();
}
private bool CanMove(Direction direction, (float Left, float Right, float Top, float Bottom) position)
{
if (direction == Direction.Left)
{
for (int i = (int)((position.Left - _drawningObject.Step) / _size_y); i <= (int)(position.Left / _size_y); ++i)
{
for (int j = (int)(position.Top / _size_x); j <= (int)(position.Bottom / _size_x); ++j)
{
if (i >= 0 && _map[i,j] == _barrier)
{
return false;
}
}
}
}
else if (direction == Direction.Right)
{
for (int i = (int)(position.Right / _size_y); i <= (int)((position.Right + _drawningObject.Step) / _size_y); ++i)
{
for (int j = (int)(position.Top / _size_x); j <= (int)(position.Bottom / _size_x); ++j)
{
if (i <= _map.GetLength(0) && _map[i, j] == _barrier)
{
return false;
}
}
}
}
else if (direction == Direction.Up)
{
for (int i = (int)(position.Left / _size_y); i <= (int)(position.Right / _size_y); ++i)
{
for (int j = (int)((position.Top - _drawningObject.Step) / _size_x); j <= (int)(position.Top / _size_x); ++j)
{
if (j >= 0 && _map[i, j] == _barrier)
{
return false;
}
}
}
}
else if (direction == Direction.Down)
{
for (int i = (int)(position.Left / _size_y); i <= (int)(position.Right / _size_y); ++i)
{
for (int j = (int)(position.Bottom / _size_x); j <= (int)((position.Bottom + _drawningObject.Step) / _size_x); ++j)
{
if (j <= _map.GetLength(1) && _map[i, j] == _barrier)
{
return false;
}
}
}
}
return true;
}
public Bitmap MoveObject(Direction direction)
{
//TODO
if (true)
{
if (CanMove(direction, _drawningObject.GetCurrentPosition()))
{
_drawningObject.MoveObject(direction);
}
return DrawMapWithObject();
}

View File

@ -133,7 +133,7 @@ namespace AirBomber
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosY, _startPosX + _airBomberWidth, _airBomberHeight);
return (_startPosX, _startPosX + _airBomberWidth, _startPosY, _startPosY + _airBomberHeight);
}
}
}

View File

@ -13,12 +13,12 @@ namespace AirBomber
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, 20, 20);
g.FillRectangle(barrierColor, j * _size_x, i * _size_y, _size_x, _size_y);
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, i * _size_x, j * _size_y, 20, 20);
g.FillRectangle(roadColor, j * _size_x, i * _size_y, _size_x, _size_y);
}
protected override void GenerateMap()