diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSelfPropelledArtillery.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSelfPropelledArtillery.cs index ecc95ba..d107eec 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSelfPropelledArtillery.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSelfPropelledArtillery.cs @@ -56,43 +56,40 @@ public class DrawningSelfPropelledArtillery /// Дополнительный цвет /// /// Ширина картинки /// Высота картинки - public void Init(int speed, float weight, Color bodyColor) + /// /// орудие + ///залповая установка + 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); } - /// - /// Установка границ поля - /// - /// Ширина поля - /// Высота поля - /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах - public bool SetPictureSize(int width, int height) - { - // TODO проверка, что объект "влезает" в размеры поля - // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена - _pictureWidth = width; - _pictureHeight = height; - return true; - } + /// + /// Установка границ поля + /// + /// Ширина поля + /// Высота поля + /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах /// /// Установка позиции /// /// Координата X /// Координата Y - 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; } /// @@ -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; } } + } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntitySelfPropelledArtillery.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntitySelfPropelledArtillery.cs index 160b0c6..8d9f695 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntitySelfPropelledArtillery.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntitySelfPropelledArtillery.cs @@ -41,19 +41,22 @@ public class EntitySelfPropelledArtillery /// Вес автомобиля /// Основной цвет /// Дополнительный цвет + /// орудие + ///залповая установка - 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; } } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtillery.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtillery.cs index 113c738..b5f69da 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtillery.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtillery.cs @@ -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(); }