LabWork_02 #2

Closed
maxnes3 wants to merge 13 commits from LabWork_02 into LabWork_01
2 changed files with 30 additions and 3 deletions
Showing only changes of commit 5aa3e08ed0 - Show all commits

View File

@ -32,10 +32,37 @@ namespace WarmlyShip
return DrawMapWithObject();
}
private bool CanMove(Direction direction)
{
for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{
if (direction == Direction.Left && _drawningObject.GetCurrentPosition().Left - _drawningObject.Step < i * _size_x && _drawningObject.GetCurrentPosition().Left > i * _size_x + _size_x && _map[i,j] == _barrier)
{
return false;
}
else if (direction == Direction.Up && _drawningObject.GetCurrentPosition().Top - _drawningObject.Step < j * _size_y && _drawningObject.GetCurrentPosition().Top > j * _size_y + _size_y && _map[i, j] == _barrier)
{
return false;
}
else if (direction == Direction.Right && _drawningObject.GetCurrentPosition().Right < i * _size_x && _drawningObject.GetCurrentPosition().Right + _drawningObject.Step > i * _size_x + _size_x && _map[i, j] == _barrier)
{
return false;
}
else if (direction == Direction.Down && _drawningObject.GetCurrentPosition().Bottom < j * _size_y && _drawningObject.GetCurrentPosition().Bottom + _drawningObject.Step > j * _size_y + _size_y && _map[i, j] == _barrier)
{
return false;
}
}
}
return true;
}
public Bitmap MoveObject(Direction direction)
{
// TODO проверка, что объект может переместится в требуемомнаправлении
if (true)
if (CanMove(direction))
{
_drawningObject.MoveObject(direction);
}

View File

@ -14,11 +14,11 @@ namespace WarmlyShip
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, 20, 20);
g.FillRectangle(barrierColor, i * _size_x, j * _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, i * _size_x, j * _size_y, _size_x, _size_y);
}
protected override void GenerateMap()
{