Фиксы

This commit is contained in:
Володя 2022-10-10 10:29:50 +03:00
parent ee7a0def18
commit bc3f888f2f
3 changed files with 73 additions and 8 deletions

View File

@ -32,12 +32,66 @@ namespace AirPlaneWithRadar
}
public Bitmap MoveObject(Direction direction)
{
// TODO проверка, что объект может переместится в требуемом направлении
if (true)
switch (direction)
{
_drawningObject.MoveObject(direction);
}
case Direction.Up:
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] == _barrier && ((_drawningObject.GetCurrentPosition().Left < i * _size_x && _drawningObject.GetCurrentPosition().Top > i * _size_x) ||
(_drawningObject.GetCurrentPosition().Left < i * (_size_x + 1) && _drawningObject.GetCurrentPosition().Top > i * (_size_x + 1))) &&
j * (_size_y + 1) < _drawningObject.GetCurrentPosition().Right && _drawningObject.GetCurrentPosition().Right - j * (_size_y + 1) <= _drawningObject.Step)
return DrawMapWithObject();
}
}
break;
case Direction.Down:
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] == _barrier && ((_drawningObject.GetCurrentPosition().Left < i * _size_x && _drawningObject.GetCurrentPosition().Top > i * _size_x) ||
(_drawningObject.GetCurrentPosition().Left < i * (_size_x + 1) && _drawningObject.GetCurrentPosition().Top > i * (_size_x + 1))) &&
j * _size_y > _drawningObject.GetCurrentPosition().Bottom && j * _size_y - _drawningObject.GetCurrentPosition().Bottom <= _drawningObject.Step)
return DrawMapWithObject();
}
}
break;
case Direction.Left:
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] == _barrier && ((_drawningObject.GetCurrentPosition().Right < j * _size_y && _drawningObject.GetCurrentPosition().Bottom > j * _size_y) ||
(_drawningObject.GetCurrentPosition().Right < j * (_size_y + 1) && _drawningObject.GetCurrentPosition().Bottom > j * (_size_y + 1))) &&
i * (_size_x + 1) < _drawningObject.GetCurrentPosition().Left && _drawningObject.GetCurrentPosition().Left - i * (_size_x + 1) <= _drawningObject.Step)
return DrawMapWithObject();
}
}
break;
case Direction.Right:
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] == _barrier && ((_drawningObject.GetCurrentPosition().Right < j * _size_y && _drawningObject.GetCurrentPosition().Bottom > j * _size_y) ||
(_drawningObject.GetCurrentPosition().Right < j * (_size_y + 1) && _drawningObject.GetCurrentPosition().Bottom > j * (_size_y + 1))) &&
i * (_size_x) > _drawningObject.GetCurrentPosition().Top && i * (_size_x) - _drawningObject.GetCurrentPosition().Top <= _drawningObject.Step)
return DrawMapWithObject();
}
}
break;
}
_drawningObject.MoveObject(direction);
return DrawMapWithObject();
}
private bool SetObjectOnMap()
{
@ -48,7 +102,18 @@ namespace AirPlaneWithRadar
int x = _random.Next(0, 10);
int y = _random.Next(0, 10);
_drawningObject.SetObject(x, y, _width, _height);
// TODO првоерка, что объект не "накладывается" на закрытые участки
if (_drawningObject is DrawingObjectPlane)
{
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] == _barrier && _drawningObject.GetCurrentPosition().Left < i * _size_x && _drawningObject.GetCurrentPosition().Right < j * _size_y && _drawningObject.GetCurrentPosition().Top > i * _size_x && _drawningObject.GetCurrentPosition().Bottom > j * _size_y)
return false;
}
}
}
return true;
}
private Bitmap DrawMapWithObject()

View File

@ -6,11 +6,11 @@ using System.Threading.Tasks;
namespace AirPlaneWithRadar
{
internal class DrawingObject : IDrawingObject
internal class DrawingObjectPlane : IDrawingObject
{
private DrawingPlain _plain;
public DrawingObject(DrawingPlain plain)
public DrawingObjectPlane(DrawingPlain plain)
{
_plain = plain;
}
@ -19,7 +19,7 @@ namespace AirPlaneWithRadar
public void DrawningObject(Graphics g)
{
//TODO
_plain?.DrawTransoprt(g);
}
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()

View File

@ -23,7 +23,7 @@ namespace AirPlaneWithRadar
toolStripStatusLabelSpeed.Text = $"Скорость: {plain.Plain.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {plain.Plain.Weight}";
toolStripStatusLabelColor.Text = $"Цвет: {plain.Plain.BodyColor.Name}";
pictureBoxPlain.Image = _abstractMap.CreateMap(pictureBoxPlain.Width, pictureBoxPlain.Height,new DrawingObject(plain)) ;
pictureBoxPlain.Image = _abstractMap.CreateMap(pictureBoxPlain.Width, pictureBoxPlain.Height,new DrawingObjectPlane(plain)) ;
}
private void ButtonCreate_Click(object sender, EventArgs e)
{