Последняя подготовка перед очередным развалом формы

This commit is contained in:
Itos 2023-11-28 00:27:15 +04:00
parent 5fee344048
commit 1996b36bc2

View File

@ -11,27 +11,40 @@ namespace GasolineTanker
public EntityGasolineTanker? EntityGasolineTanker { get; private set; } public EntityGasolineTanker? EntityGasolineTanker { get; private set; }
public int _pictureWidth; public int _pictureWidth;
public int _pictureHeight; public int _pictureHeight;
private int _startPosX; private int _startPosX = 0;
private int _startPosY; 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) 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; _pictureWidth = width;
_pictureHeight = height; _pictureHeight = height;
EntityGasolineTanker = new EntityGasolineTanker(); EntityGasolineTanker = new EntityGasolineTanker();
//!!!!!!
EntityGasolineTanker.Init(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine); EntityGasolineTanker.Init(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine);
return true; return true;
} }
public void SetPosition(int x, int y) public void SetPosition(int x, int y)
{ {
//TODO:Изменение x, y if (EntityGasolineTanker == null)
{
return;
}
_startPosX = x; _startPosX = x;
_startPosY = y; _startPosY = y;
if(x + _gasolineTankerWidth >= _pictureWidth || y + _gasolineTankerHeight >= _pictureHeight)
{
_startPosX = 1;
_startPosY = 1;
}
} }
public void MoveTransport(Direction direction) public void MoveTransport(Direction direction)
{ {
@ -42,29 +55,44 @@ namespace GasolineTanker
switch (direction) switch (direction)
{ {
case Direction.Left: case Direction.Left:
if (_startPosX - EntityGasolineTanker.Step > 0) if (_startPosX - EntityGasolineTanker.Step >= 0)
{ {
_startPosX -= (int)EntityGasolineTanker.Step; _startPosX -= (int)EntityGasolineTanker.Step;
} }
else
{
_startPosX = 0;
}
break; break;
case Direction.Up: case Direction.Up:
if (_startPosY - EntityGasolineTanker.Step > 0) if (_startPosY - EntityGasolineTanker.Step > 0)
{ {
_startPosY -= (int)EntityGasolineTanker.Step; _startPosY -= (int)EntityGasolineTanker.Step;
} }
else
{
_startPosY = 0;
}
break; break;
case Direction.Right: case Direction.Right:
//TODO:Логика движения if (_startPosX + EntityGasolineTanker.Step + _gasolineTankerWidth < _pictureWidth)
if (_startPosX - EntityGasolineTanker.Step < 1000)
{ {
_startPosX += (int)EntityGasolineTanker.Step; _startPosX += (int)EntityGasolineTanker.Step;
}
else
{
_startPosX = _pictureWidth - _gasolineTankerWidth;
} }
break; break;
case Direction.Down: case Direction.Down:
if (_startPosY - EntityGasolineTanker.Step < 1000) if (_startPosY + EntityGasolineTanker.Step + _gasolineTankerHeight < _pictureHeight)
{ {
_startPosY += (int)EntityGasolineTanker.Step; _startPosY += (int)EntityGasolineTanker.Step;
} }
else
{
_startPosY = _pictureHeight - _gasolineTankerHeight;
}
break; break;
} }
} }