Фиксация

This commit is contained in:
Макс Бондаренко 2022-10-05 00:41:14 +04:00
parent 64eab1b261
commit 5aa3e08ed0
2 changed files with 30 additions and 3 deletions

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()
{