PIbd-14_Davydow_M.D._LabWork01_Simple #1

Open
Max18 wants to merge 4 commits from Laba1 into main
3 changed files with 37 additions and 31 deletions
Showing only changes of commit 5097475d5d - Show all commits

View File

@ -26,11 +26,11 @@ public class DrawingTank
/// <summary>
/// Ширина прорисовки танка
/// </summary>
private readonly int _drawningTankWidth = 150;
private readonly int _drawningTankWidth = 160;
/// <summary>
/// Высота прорисовки танка
/// </summary>
private readonly int _drawningTankHeight = 50;
private readonly int _drawningTankHeight = 60;
/// <summary>
/// Инициализация свойств
/// </summary>
@ -110,41 +110,46 @@ public class DrawingTank
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction)
{
if (EntityTank == null || !_startPosX.HasValue || !_startPosY.HasValue)
if (EntityTank == null || !_startPosX.HasValue ||
!_startPosY.HasValue)
{
return false;
}
int newX = _startPosX.Value;
int newY = _startPosY.Value;
switch (direction)
{
//влево
case DirectionType.Left:
newX -= (int)EntityTank.Step;
if (newX < 0) newX = 0;
break;
if (_startPosX.Value - EntityTank.Step > 0)
{
_startPosX -= (int)EntityTank.Step;
}
return true;
//вверх
case DirectionType.Up:
newY -= (int)EntityTank.Step;
if (newY < 0) newY = 0;
break;
if (_startPosY.Value - EntityTank.Step > 0)
{
_startPosY -= (int)EntityTank.Step;
}
return true;
// вправо
case DirectionType.Right:
newX += (int)EntityTank.Step;
if (newX + _drawningTankWidth > _pictureWidth) newX = _pictureWidth.Value - _drawningTankWidth;
break;
//TODO прописать логику сдвига в право
if (_startPosX.Value + _drawningTankWidth < _pictureWidth)
{
_startPosX += (int)EntityTank.Step;
}
return true;
//вниз
case DirectionType.Down:
newY += (int)EntityTank.Step;
if (newY + _drawningTankHeight > _pictureHeight) newY = _pictureHeight.Value - _drawningTankHeight;
break;
//TODO прописать логику сдвига в вниз
if (_startPosY.Value + _drawningTankHeight < _pictureHeight)
{
_startPosY += (int)EntityTank.Step;
}
return true;
default:
return false;
}
// Устанавливаем новые координаты
_startPosX = newX;
_startPosY = newY;
return true;
}
public void DrawTransport(Graphics g)
{
@ -157,16 +162,17 @@ public class DrawingTank
Brush additionalBrush = new SolidBrush(EntityTank.AdditionalColor);
Brush brWhite = new SolidBrush(Color.White);
Brush brBlack = new SolidBrush(Color.Black);
Brush MainBrush = new SolidBrush(EntityTank.BodyColor);
//пушка
if (EntityTank.TankTurret)
{
g.FillRectangle(brBlack, _startPosX.Value + 70, _startPosY.Value + 15, 80, 8);
g.FillRectangle(brBlack, _startPosX.Value + 140, _startPosY.Value + 14, 10, 10);
g.FillRectangle(MainBrush, _startPosX.Value + 70, _startPosY.Value + 15, 80, 8);
g.FillRectangle(MainBrush, _startPosX.Value + 140, _startPosY.Value + 14, 10, 10);
g.FillRectangle(brWhite, _startPosX.Value + 143, _startPosY.Value + 16, 5, 2);
g.FillRectangle(brWhite, _startPosX.Value + 143, _startPosY.Value + 20, 5, 2);
}
//границы танка
g.FillRectangle(brBlack, _startPosX.Value + 20, _startPosY.Value + 10, 50, 20);
g.FillRectangle(MainBrush, _startPosX.Value + 20, _startPosY.Value + 10, 50, 20);
g.DrawRectangle(pen, _startPosX.Value + 1, _startPosY.Value + 30, 100, 10);
g.DrawRectangle(pen, _startPosX.Value + 1, _startPosY.Value + 40, 100, 5);
g.DrawEllipse(pen, _startPosX.Value + 1, _startPosY.Value + 40, 10,10);
@ -174,7 +180,7 @@ public class DrawingTank
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 40, 10, 10);
g.FillRectangle(brWhite, _startPosX.Value + 2, _startPosY.Value + 31, 99, 15);
g.FillRectangle(brWhite, _startPosX.Value + 5, _startPosY.Value + 31, 91, 19);
g.FillRectangle(brBlack, _startPosX.Value + 1, _startPosY.Value + 27, 101, 7);
g.FillRectangle(MainBrush, _startPosX.Value + 1, _startPosY.Value + 27, 101, 7);
g.DrawEllipse(pen, _startPosX.Value + 3, _startPosY.Value + 35, 13, 13);
g.DrawEllipse(pen, _startPosX.Value + 86, _startPosY.Value + 35, 13, 13);
g.DrawEllipse(pen, _startPosX.Value + 25, _startPosY.Value + 37, 10, 10);

View File

@ -31,7 +31,7 @@ public class EntityTank
/// <summary>
/// Шаг перемещения танка
/// </summary>
public double Step => Speed * 100 / Weight;
public double Step => Speed * 100 / Weight; //краткая запись - это совйство у которого есть только гетер
/// <summary>
/// Инициализация полей объекта класса "танк"
/// </summary>

View File

@ -39,7 +39,7 @@ namespace Projekt
{
Random random = new();
_drawingTank = new DrawingTank();
_drawingTank.Init(random.Next(30,70), random.Next(3000, 5000),
_drawingTank.Init(random.Next(30,70), random.Next(300, 500),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));