added cannon and rocket

This commit is contained in:
cleverman1337 2024-03-06 20:57:03 +04:00
parent 1b6b309216
commit d48cbad4a6
3 changed files with 68 additions and 43 deletions

View File

@ -56,43 +56,40 @@ public class DrawningSelfPropelledArtillery
/// <param name="additionalColor">Дополнительный цвет</param>
/// /// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public void Init(int speed, float weight, Color bodyColor)
/// /// <param name="Cannon">орудие</param>
///<param name="Rocket">залповая установка</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool cannon, bool rocket)
{
EntitySelfPropelledArtillery = new EntitySelfPropelledArtillery();
EntitySelfPropelledArtillery.Init(speed, weight,bodyColor);
EntitySelfPropelledArtillery.Init(speed, weight,bodyColor, additionalColor, cannon, rocket);
}
/// <summary>
/// Установка границ поля
/// </summary>
/// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param>
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetPictureSize(int width, int height)
{
// TODO проверка, что объект "влезает" в размеры поля
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
_pictureWidth = width;
_pictureHeight = height;
return true;
}
/// <summary>
/// Установка границ поля
/// </summary>
/// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param>
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
/// <summary>
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
public void SetPosition(int x, int y, int width, int height)
{
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
if (x < 0 || x - _SelfPropelledArtilleryWidth >= width)
{
return;
}
if (y < 0 || y - _SelfPropelledArtilleryHeight >= height)
{
return;
}
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
// то надо изменить координаты, чтобы он оставался в этих границах
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
}
/// <summary>
@ -125,14 +122,14 @@ public class DrawningSelfPropelledArtillery
return true;
// вправо
case DirectionType.Right:
if (_startPosX + EntitySelfPropelledArtillery.Step < _pictureWidth - _SelfPropelledArtilleryWidth)
if (_startPosX.Value + EntitySelfPropelledArtillery.Step + _SelfPropelledArtilleryWidth < _pictureWidth)
{
_startPosX += (int)EntitySelfPropelledArtillery.Step;
}
return true;
//вниз
case DirectionType.Down:
if (_startPosY + EntitySelfPropelledArtillery.Step < _pictureHeight - _SelfPropelledArtilleryHeight)
if (_startPosY.Value + EntitySelfPropelledArtillery.Step + _SelfPropelledArtilleryHeight < _pictureHeight)
{
_startPosY += (int)EntitySelfPropelledArtillery.Step;
}
@ -154,29 +151,50 @@ public class DrawningSelfPropelledArtillery
}
Pen pen = new(Color.Black);
Brush brush = new SolidBrush(EntitySelfPropelledArtillery?.BodyColor ?? Color.Black);
//башня
g.FillRectangle(brush, _startPosX.Value + _SelfPropelledArtilleryWidth / 16 * 2, _startPosY.Value, _SelfPropelledArtilleryWidth / 8 * 4, _SelfPropelledArtilleryWidth / 5);
g.FillRectangle(brush, _startPosX.Value, _startPosY.Value + _SelfPropelledArtilleryHeight / 3, _SelfPropelledArtilleryWidth, _SelfPropelledArtilleryHeight / 3);
g.DrawRectangle(pen, _startPosX.Value + _SelfPropelledArtilleryWidth / 16 * 2, _startPosY.Value, _SelfPropelledArtilleryWidth / 8 * 4, _SelfPropelledArtilleryWidth / 5);
//корпус
g.FillRectangle(brush, _startPosX.Value, _startPosY.Value + _SelfPropelledArtilleryHeight / 3, _SelfPropelledArtilleryWidth, _SelfPropelledArtilleryHeight / 3);
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + _SelfPropelledArtilleryHeight / 3, _SelfPropelledArtilleryWidth, _SelfPropelledArtilleryHeight / 3);
Brush blackBrush = new SolidBrush(Color.Black);
Brush grayBrush = new SolidBrush(Color.Gray);
g.DrawRectangle(pen, _startPosX.Value + 62, _startPosY.Value, _SelfPropelledArtilleryWidth / 8 * 5, _SelfPropelledArtilleryWidth / 15);
g.FillRectangle(blackBrush, _startPosX.Value + 62, _startPosY.Value, _SelfPropelledArtilleryWidth / 8 * 5, _SelfPropelledArtilleryWidth / 15);
//орудие
if (EntitySelfPropelledArtillery.Cannon)
{
g.DrawRectangle(pen, _startPosX.Value + 62, _startPosY.Value, _SelfPropelledArtilleryWidth / 8 * 5, _SelfPropelledArtilleryWidth / 15);
g.FillRectangle(blackBrush, _startPosX.Value + 62, _startPosY.Value, _SelfPropelledArtilleryWidth / 8 * 5, _SelfPropelledArtilleryWidth / 15);
}
//установка
if (EntitySelfPropelledArtillery.Rocket)
{
// g.DrawRectangle(pen, _startPosX.Value - 55, _startPosY.Value, _SelfPropelledArtilleryWidth / 2 * 5, _SelfPropelledArtilleryWidth / 10);
// g.FillRectangle(blackBrush, _startPosX.Value - 55, _startPosY.Value, _SelfPropelledArtilleryWidth / 2 * 5, _SelfPropelledArtilleryWidth / 10);
g.FillRectangle(brush, _startPosX.Value + _SelfPropelledArtilleryWidth / 100 * 2, _startPosY.Value-15, _SelfPropelledArtilleryWidth / 80 * 4, _SelfPropelledArtilleryWidth / 3);
g.DrawRectangle(pen, _startPosX.Value + _SelfPropelledArtilleryWidth / 100 * 2, _startPosY.Value-15, _SelfPropelledArtilleryWidth / 80 * 4, _SelfPropelledArtilleryWidth / 3);
g.FillRectangle(brush, _startPosX.Value + _SelfPropelledArtilleryWidth / 200 * 2, _startPosY.Value - 15, _SelfPropelledArtilleryWidth / 80 * 50, _SelfPropelledArtilleryWidth / 10);
g.DrawRectangle(pen, _startPosX.Value + _SelfPropelledArtilleryWidth / 200 * 2, _startPosY.Value - 15, _SelfPropelledArtilleryWidth / 80 * 50, _SelfPropelledArtilleryWidth / 10);
g.DrawRectangle(pen, _startPosX.Value + _SelfPropelledArtilleryWidth / 200 * 50, _startPosY.Value - 16, _SelfPropelledArtilleryWidth / 80 * 60, _SelfPropelledArtilleryWidth / 35);
g.DrawRectangle(pen, _startPosX.Value + _SelfPropelledArtilleryWidth / 200 * 50, _startPosY.Value - 11, _SelfPropelledArtilleryWidth / 80 * 60, _SelfPropelledArtilleryWidth / 35);
g.DrawRectangle(pen, _startPosX.Value + _SelfPropelledArtilleryWidth / 200 * 50, _startPosY.Value - 6, _SelfPropelledArtilleryWidth / 80 * 60, _SelfPropelledArtilleryWidth / 35);
// g.DrawRectangle(pen, _startPosX.Value + _SelfPropelledArtilleryWidth / 200 * 50, _startPosY.Value - 14, _SelfPropelledArtilleryWidth / 80 * 50, _SelfPropelledArtilleryWidth / 35);
}
//ходовая
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + _SelfPropelledArtilleryHeight * 2 / 5, _SelfPropelledArtilleryWidth, _SelfPropelledArtilleryHeight * 2 / 5);
g.FillEllipse(grayBrush, _startPosX.Value, _startPosY.Value + _SelfPropelledArtilleryHeight * 2 / 5, _SelfPropelledArtilleryWidth, _SelfPropelledArtilleryHeight * 2 / 5);
//катки
g.FillEllipse(blackBrush, _startPosX.Value+ _SelfPropelledArtilleryWidth / 20, _startPosY.Value + _SelfPropelledArtilleryHeight * 7 / 15, _SelfPropelledArtilleryWidth * 4 / 20, _SelfPropelledArtilleryHeight * 10 / 32);
g.FillEllipse(blackBrush, _startPosX.Value+ _SelfPropelledArtilleryWidth * 5 / 20, _startPosY.Value + _SelfPropelledArtilleryHeight * 9 / 16, _SelfPropelledArtilleryWidth * 3 / 20, _SelfPropelledArtilleryHeight * 8 / 32);
g.FillEllipse(blackBrush, _startPosX.Value+ _SelfPropelledArtilleryWidth * 8 / 20, _startPosY.Value + _SelfPropelledArtilleryHeight * 10 / 16, _SelfPropelledArtilleryWidth * 2 / 20, _SelfPropelledArtilleryHeight * 6 / 32);
g.FillEllipse(blackBrush, _startPosX.Value+ _SelfPropelledArtilleryWidth * 10 / 20, _startPosY.Value + _SelfPropelledArtilleryHeight * 10 / 16, _SelfPropelledArtilleryWidth * 2 / 20, _SelfPropelledArtilleryHeight * 6 / 32);
g.FillEllipse(blackBrush, _startPosX.Value+ _SelfPropelledArtilleryWidth * 12 / 20, _startPosY.Value + _SelfPropelledArtilleryHeight * 9 / 16, _SelfPropelledArtilleryWidth * 3 / 20, _SelfPropelledArtilleryHeight * 8 / 32);
g.FillEllipse(blackBrush, _startPosX.Value + _SelfPropelledArtilleryWidth * 15 / 20, _startPosY.Value + _SelfPropelledArtilleryHeight * 7 / 15, _SelfPropelledArtilleryWidth * 4 / 20, _SelfPropelledArtilleryHeight * 10 / 32);
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + _SelfPropelledArtilleryHeight * 2 / 5, _SelfPropelledArtilleryWidth, _SelfPropelledArtilleryHeight * 2 / 5);
//обводка катков
g.DrawEllipse(pen, _startPosX.Value + _SelfPropelledArtilleryWidth / 20, _startPosY.Value + _SelfPropelledArtilleryHeight * 7 / 15, _SelfPropelledArtilleryWidth * 4 / 20, _SelfPropelledArtilleryHeight * 10 / 32);
g.DrawEllipse(pen, _startPosX.Value + _SelfPropelledArtilleryWidth * 5 / 20, _startPosY.Value + _SelfPropelledArtilleryHeight * 9 / 16, _SelfPropelledArtilleryWidth * 3 / 20, _SelfPropelledArtilleryHeight * 8 / 32);
g.DrawEllipse(pen, _startPosX.Value + _SelfPropelledArtilleryWidth * 8 / 20, _startPosY.Value + _SelfPropelledArtilleryHeight * 10 / 16, _SelfPropelledArtilleryWidth * 2 / 20, _SelfPropelledArtilleryHeight * 6 / 32);
@ -205,5 +223,6 @@ public class DrawningSelfPropelledArtillery
_startPosY = _pictureHeight.Value - _SelfPropelledArtilleryHeight;
}
}
}

View File

@ -41,19 +41,22 @@ public class EntitySelfPropelledArtillery
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="Cannon">орудие</param>
///<param name="Rocket">залповая установка</param>
public bool Machine_gun { get; private set; }
//пушка
public bool Cannon { get; private set; }
public void Init(int speed, float weight, Color bodyColor)
//залповая установка
public bool Rocket { get; private set; }
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool cannon, bool rocket)
{
Random random = new();
Speed = speed <= 0 ? random.Next(50, 150) : speed;
Weight = weight <= 0 ? random.Next(40, 70) : weight;
BodyColor = bodyColor;
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
Cannon = cannon;
Rocket = rocket;
}
}

View File

@ -52,9 +52,12 @@ namespace SelfPropelledArtilleryUnit
Random random = new();
_drawningSelfPropelledArtillery = new DrawningSelfPropelledArtillery();
_drawningSelfPropelledArtillery.Init(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
_drawningSelfPropelledArtillery.SetPictureSize(pictureBoxSelfPropelledArtillery.Width, pictureBoxSelfPropelledArtillery.Height);
_drawningSelfPropelledArtillery.SetPosition(random.Next(10, 100), random.Next(10, 100));
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)));
_drawningSelfPropelledArtillery.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBoxSelfPropelledArtillery.Width, pictureBoxSelfPropelledArtillery.Height);
Draw();
}