PIbd-13_Grishina_A.S._6_LabWork01_Simple #1

Open
grankwwq wants to merge 3 commits from LabWork01 into main
2 changed files with 45 additions and 34 deletions
Showing only changes of commit ebd403f54f - Show all commits

View File

@ -29,11 +29,11 @@ public class DrawningTank
/// <summary>
/// Ширина прорисовки автомобиля
/// </summary>
private readonly int _drawningTankWidth = 180;
private readonly int _drawningTankWidth = 140;
/// <summary>
/// Высота прорисовки автомобиля
/// </summary>
private readonly int _drawningTankHeight = 75;
private readonly int _drawningTankHeight = 85;
/// <summary>
/// Инициализация свойств
/// </summary>
@ -41,7 +41,12 @@ public class DrawningTank
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="body">Основание</param>
/// <param name="tower">Башня</param>
/// <param name="wheel">Гусеница</param>
/// <param name="colorwheel">Закрашенная Гусеница</param>
/// <param name="gun">пушка</param>
public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool body, bool tower, bool wheel, bool colorwheel, bool gun)
{
@ -58,14 +63,16 @@ public class DrawningTank
/// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param>
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetPictureSize(int width, int height)
public void SetPictureSize(int width, int height)
{
// TODO проверка, что объект "влезает" в размеры поля
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
if (_drawningTankHeight > height || _drawningTankWidth > width) return;
_pictureWidth = width;
_pictureHeight = height;
return true;
}
/// <summary>
/// Установка позиции
/// </summary>
@ -75,13 +82,15 @@ public class DrawningTank
{
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
return; // Размеры формы не установлены
}
// Проверяем, чтобы объект не выходил за границы формы по оси X
if (x < 0)
{
_startPosX = 0;
}
else if (x + _drawningTankWidth > _pictureWidth)
else if (x + _drawningTankHeight > _pictureWidth)
{
_startPosX = _pictureWidth.Value - _drawningTankWidth;
}
@ -89,6 +98,7 @@ public class DrawningTank
{
_startPosX = x;
}
// Проверяем, чтобы объект не выходил за границы формы по оси Y
if (y < 0)
{
_startPosY = 0;
@ -101,7 +111,6 @@ public class DrawningTank
{
_startPosY = y;
}
}
/// <summary>
/// Изменение направления перемещения
@ -133,14 +142,14 @@ public class DrawningTank
return true;
// вправо
case DirectionType.Right:
if (_startPosX.Value - EntityTank.Step > 0)
if (_startPosX.Value - EntityTank.Step < _pictureWidth)
{
_startPosX += (int)EntityTank.Step;
}
return true;
//вниз
case DirectionType.Down:
if (_startPosY.Value - EntityTank.Step > 0)
if (_startPosY.Value - EntityTank.Step < _pictureHeight)
{
_startPosY += (int)EntityTank.Step;
}
@ -166,43 +175,45 @@ public class DrawningTank
// основание
g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 45, 100, 30);
g.FillRectangle(bodyColor, _startPosX.Value + 80, _startPosY.Value + 45, 100, 30);
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 35, 100, 30);
g.FillRectangle(bodyColor, _startPosX.Value + 20, _startPosY.Value + 35, 100, 30);
// гусеница
g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 75, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 75, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 75, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 120, _startPosY.Value + 75, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 140, _startPosY.Value + 75, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 160, _startPosY.Value + 75, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 180, _startPosY.Value + 75, 20, 20);
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 65, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 65, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 65, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 65, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 65, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 65, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 120, _startPosY.Value + 65, 20, 20);
// башня
if (EntityTank.Tower)
{
g.DrawRectangle(pen, _startPosX.Value + 110, _startPosY.Value + 15, 40, 30);
g.FillRectangle(additionalBrush, _startPosX.Value + 110, _startPosY.Value + 15, 40, 30);
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 5, 40, 30);
g.FillRectangle(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 5, 40, 30);
}
if (EntityTank.ColorWheel)
{
g.FillEllipse(additionalBrush, _startPosX.Value + 60, _startPosY.Value + 75, 20, 20);
g.FillEllipse(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 75, 20, 20);
g.FillEllipse(additionalBrush, _startPosX.Value + 100, _startPosY.Value + 75, 20, 20);
g.FillEllipse(additionalBrush, _startPosX.Value + 120, _startPosY.Value + 75, 20, 20);
g.FillEllipse(additionalBrush, _startPosX.Value + 140, _startPosY.Value + 75, 20, 20);
g.FillEllipse(additionalBrush, _startPosX.Value + 160, _startPosY.Value + 75, 20, 20);
g.FillEllipse(additionalBrush, _startPosX.Value + 180, _startPosY.Value + 75, 20, 20);
g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value + 65, 20, 20);
g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 65, 20, 20);
g.FillEllipse(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 65, 20, 20);
g.FillEllipse(additionalBrush, _startPosX.Value + 60, _startPosY.Value + 65, 20, 20);
g.FillEllipse(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 65, 20, 20);
g.FillEllipse(additionalBrush, _startPosX.Value + 100, _startPosY.Value + 65, 20, 20);
g.FillEllipse(additionalBrush, _startPosX.Value + 120, _startPosY.Value + 65, 20, 20);
}
// башня c пушкой
if (EntityTank.Tower)
{
if (EntityTank.Tower)
if (EntityTank.Gun)
{
g.DrawRectangle(pen, _startPosX.Value + 150, _startPosY.Value + 20, 40, 5);
g.FillRectangle(additionalBrush, _startPosX.Value + 110, _startPosY.Value + 15, 40, 30);
g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 5, 40, 5);
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 5, 40, 5);
}
}

View File

@ -32,7 +32,7 @@ public partial class FormTank : Form
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)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
_drawningTank.SetPictureSize(pictureBoxTank.Width, pictureBoxTank.Height);
_drawningTank.SetPictureSize(pictureBoxTank.Width-170, pictureBoxTank.Height-115);
_drawningTank.SetPosition(random.Next(10, 100), random.Next(10,100));
Draw();