diff --git a/GasolineTanker/GasolineTanker/DrawningGasolineTanker.cs b/GasolineTanker/GasolineTanker/DrawningGasolineTanker.cs index 0b25d5b..64b18a4 100644 --- a/GasolineTanker/GasolineTanker/DrawningGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/DrawningGasolineTanker.cs @@ -11,27 +11,40 @@ namespace GasolineTanker public EntityGasolineTanker? EntityGasolineTanker { get; private set; } public int _pictureWidth; public int _pictureHeight; - private int _startPosX; - private int _startPosY; + private int _startPosX = 0; + private int _startPosY = 0; //Ширина грузовика - private readonly int _carWidth = 110; + private readonly int _gasolineTankerWidth = 110; //Высота грузовика - private readonly int _carHeight = 60; + private readonly int _gasolineTankerHeight = 60; //Инициализация свойств public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height) { - //TODO:Придумать проверки! + + if (width <= _gasolineTankerWidth || height <= _gasolineTankerHeight) + { + return false; + } _pictureWidth = width; _pictureHeight = height; EntityGasolineTanker = new EntityGasolineTanker(); + //!!!!!! EntityGasolineTanker.Init(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine); return true; } public void SetPosition(int x, int y) { - //TODO:Изменение x, y + if (EntityGasolineTanker == null) + { + return; + } _startPosX = x; _startPosY = y; + if(x + _gasolineTankerWidth >= _pictureWidth || y + _gasolineTankerHeight >= _pictureHeight) + { + _startPosX = 1; + _startPosY = 1; + } } public void MoveTransport(Direction direction) { @@ -42,29 +55,44 @@ namespace GasolineTanker switch (direction) { case Direction.Left: - if (_startPosX - EntityGasolineTanker.Step > 0) + if (_startPosX - EntityGasolineTanker.Step >= 0) { _startPosX -= (int)EntityGasolineTanker.Step; } + else + { + _startPosX = 0; + } break; case Direction.Up: if (_startPosY - EntityGasolineTanker.Step > 0) { _startPosY -= (int)EntityGasolineTanker.Step; } + else + { + _startPosY = 0; + } break; case Direction.Right: - //TODO:Логика движения - if (_startPosX - EntityGasolineTanker.Step < 1000) + if (_startPosX + EntityGasolineTanker.Step + _gasolineTankerWidth < _pictureWidth) { _startPosX += (int)EntityGasolineTanker.Step; } - break; + else + { + _startPosX = _pictureWidth - _gasolineTankerWidth; + } + break; case Direction.Down: - if (_startPosY - EntityGasolineTanker.Step < 1000) + if (_startPosY + EntityGasolineTanker.Step + _gasolineTankerHeight < _pictureHeight) { _startPosY += (int)EntityGasolineTanker.Step; } + else + { + _startPosY = _pictureHeight - _gasolineTankerHeight; + } break; } }