diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base.git/AbstractMap.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base.git/AbstractMap.cs index c29ea9e..db52a5e 100644 --- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base.git/AbstractMap.cs +++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base.git/AbstractMap.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -32,7 +33,23 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base public Bitmap MoveObject(Direction direction) { // TODO проверка, что объект может переместится в требуемом направлении - if (true) + bool enoughPlace = false; + switch (direction) + { + case Direction.Up: + enoughPlace = CheckEnoughPlace(0, _drawningObject.Step * -1); + break; + case Direction.Down: + enoughPlace = CheckEnoughPlace(0, _drawningObject.Step); + break; + case Direction.Left: + enoughPlace = CheckEnoughPlace(_drawningObject.Step * -1, 0); + break; + case Direction.Right: + enoughPlace = CheckEnoughPlace(_drawningObject.Step, 0); + break; + } + if (enoughPlace) { _drawningObject.MoveObject(direction); } @@ -48,24 +65,30 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base int y = _random.Next(0, 10); _drawningObject.SetObject(x, y, _width, _height); // TODO првоерка, что объект не "накладывается" на закрытые участки - while (!CheckEnoughPlace()) + while (!CheckEnoughPlace(0, 0)) { x += 10; if (x >= _width) { - y += 10; - x = 0; + if (y <= _height) + { + y += 10; + x = 0; + } else + { + return false; + } } _drawningObject.SetObject(x, y, _width, _height); } return true; } - private bool CheckEnoughPlace() + private bool CheckEnoughPlace(float x, float y) { - int right = Convert.ToInt32(_drawningObject.GetCurrentPosition().Right / _size_x); - int left = Convert.ToInt32(_drawningObject.GetCurrentPosition().Left / _size_x); - int up = Convert.ToInt32(_drawningObject.GetCurrentPosition().Top / _size_y); - int down = Convert.ToInt32(_drawningObject.GetCurrentPosition().Bottom / _size_y); + int right = Convert.ToInt32((_drawningObject.GetCurrentPosition().Right + x) / _size_x) > 0 ? Convert.ToInt32((_drawningObject.GetCurrentPosition().Right + x) / _size_x) : 0; + int left = Convert.ToInt32((_drawningObject.GetCurrentPosition().Left + x) / _size_x) > 0 ? Convert.ToInt32((_drawningObject.GetCurrentPosition().Left + x) / _size_x) : 0; + int up = Convert.ToInt32((_drawningObject.GetCurrentPosition().Top + y) / _size_y) > 0 ? Convert.ToInt32((_drawningObject.GetCurrentPosition().Top + y) / _size_y) : 0; + int down = Convert.ToInt32((_drawningObject.GetCurrentPosition().Bottom + y) / _size_y) > 0 ? Convert.ToInt32((_drawningObject.GetCurrentPosition().Bottom + y) / _size_y) : 0; for (int i = left; i <= right; i++) { for (int j = up; j <= down; j++) diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base.git/DrawningSportBoat.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base.git/DrawningSportBoat.cs index b610506..cae3fca 100644 --- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base.git/DrawningSportBoat.cs +++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base.git/DrawningSportBoat.cs @@ -19,7 +19,7 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base /// Признак наличия антикрыла /// Признак наличия гоночной полосы public DrawningSportBoat(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : - base(speed, weight, bodyColor, 195, 60) + base(speed, weight, bodyColor, 195, 80) { Boat = new EntitySportBoat(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine); }