PIbd-13_Grishina_A.S._6_LabWork01_Simple #1
@ -1,4 +1,6 @@
|
||||
namespace ProjectTank;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
|
||||
|
||||
namespace ProjectTank;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
@ -27,11 +29,11 @@ public class DrawningTank
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningTankWidth = 110;
|
||||
private readonly int _drawningTankWidth = 180;
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningTankHeight = 60;
|
||||
private readonly int _drawningTankHeight = 75;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
@ -39,15 +41,12 @@ public class DrawningTank
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||||
additionalColor, bool body, bool tower, bool wheel, bool colorwheel, bool gun)
|
||||
{
|
||||
EntityTank = new EntityTank();
|
||||
EntityTank.Init(speed, weight, bodyColor, additionalColor,
|
||||
bodyKit, wing, sportLine);
|
||||
EntityTank.Init(speed, weight, bodyColor, additionalColor, body, tower, wheel, colorwheel, gun);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
@ -78,10 +77,30 @@ public class DrawningTank
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
if (x < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
else if (x + _drawningTankWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth.Value - _drawningTankWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
else if (y + _drawningTankHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight.Value - _drawningTankHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
@ -114,11 +133,17 @@ public class DrawningTank
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
//TODO прописать логику сдвига в право
|
||||
if (_startPosX.Value - EntityTank.Step > 0)
|
||||
{
|
||||
_startPosX += (int)EntityTank.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
//TODO прописать логику сдвига в вниз
|
||||
if (_startPosY.Value - EntityTank.Step > 0)
|
||||
{
|
||||
_startPosY += (int)EntityTank.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@ -137,8 +162,50 @@ public class DrawningTank
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityTank.AdditionalColor);
|
||||
Brush bodyColor = new SolidBrush(EntityTank.BodyColor);
|
||||
|
||||
// основание
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 45, 100, 30);
|
||||
g.FillRectangle(bodyColor, _startPosX.Value + 80, _startPosY.Value + 45, 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);
|
||||
|
||||
// башня
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
// башня c пушкой
|
||||
if (EntityTank.Tower)
|
||||
{
|
||||
if (EntityTank.Tower)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX.Value + 150, _startPosY.Value + 20, 40, 5);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 110, _startPosY.Value + 15, 40, 30);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// прямоугольник
|
||||
g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value +40, 15, 15);
|
||||
}
|
||||
}
|
||||
|
@ -20,42 +20,56 @@ public class EntityTank
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия обвеса
|
||||
/// </summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия антикрыла
|
||||
/// </summary>
|
||||
public bool Wing { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия гоночной полосы
|
||||
/// </summary>
|
||||
public bool SportLine { get; private set; }
|
||||
/// <summary>
|
||||
/// Основание
|
||||
/// </summary>
|
||||
public bool Body { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия башни
|
||||
/// </summary>
|
||||
public bool Tower { get; private set; }
|
||||
/// <summary>
|
||||
/// гусеница
|
||||
/// </summary>
|
||||
public bool Wheel { get; private set; }
|
||||
/// <summary>
|
||||
/// закрашенная гусеница
|
||||
/// </summary>
|
||||
public bool ColorWheel { get; private set; }
|
||||
/// <summary>
|
||||
/// пушка
|
||||
/// </summary>
|
||||
public bool Gun { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
|
||||
public double Step => Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="weight">Вес танка</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="wing">Признак наличия антикрыла</param>
|
||||
/// <param name="sportLine">Признак наличия гоночной полосы</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||||
/// <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)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Wing = wing;
|
||||
SportLine = sportLine;
|
||||
Body = body;
|
||||
Tower = tower;
|
||||
Wheel = wheel;
|
||||
ColorWheel = colorwheel;
|
||||
Gun = gun;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,10 +28,10 @@ public partial class FormTank : Form
|
||||
{
|
||||
Random random = new();
|
||||
_drawningTank = new DrawningTank();
|
||||
_drawningTank.Init(random.Next(100, 300), random.Next(1000,3000),
|
||||
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)));
|
||||
_drawningTank.Init(random.Next(100, 300), random.Next(1000, 3000),
|
||||
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.SetPosition(random.Next(10, 100), random.Next(10,100));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user