diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSelfPropelledArtilleryUnit.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSelfPropelledArtilleryUnit.cs index 178122f..90570b1 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSelfPropelledArtilleryUnit.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSelfPropelledArtilleryUnit.cs @@ -33,7 +33,7 @@ public class DrawningSelfPropelledArtilleryUnit /// /// Ширина прорисовки cамоходной арт. установки /// - private readonly int _drawningSelfPropelledArtilleryUnitWidth = 143; + private readonly int _drawningSelfPropelledArtilleryUnitWidth = 135; /// /// Высота прорисовки cамоходной арт. установки @@ -68,10 +68,26 @@ public class DrawningSelfPropelledArtilleryUnit /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах public bool SetPictureSize(int width, int height) { - // TODO проверка, что объект "влезает" в размеры поля - // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена + if (_drawningSelfPropelledArtilleryUnitWidth > width || _drawningSelfPropelledArtilleryUnitHeight > height) + { + return false; + } + _pictureWidth = width; _pictureHeight = height; + if (_startPosX.HasValue || _startPosY.HasValue) + { + if (_startPosX + _drawningSelfPropelledArtilleryUnitWidth > _pictureWidth) + { + _startPosX = _pictureWidth - _drawningSelfPropelledArtilleryUnitWidth; + } + else if (_startPosX < 0) _startPosX = 0; + if (_startPosY + _drawningSelfPropelledArtilleryUnitHeight > _pictureHeight) + { + _startPosY = _pictureHeight - _drawningSelfPropelledArtilleryUnitHeight; + } + else if (_startPosY < 0) _startPosY = 0; + } return true; } @@ -89,8 +105,19 @@ public class DrawningSelfPropelledArtilleryUnit // TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы // то надо изменить координаты, чтобы он оставался в этих границах - _startPosX = x; - _startPosY = y; + if (x + _drawningSelfPropelledArtilleryUnitWidth > _pictureWidth) + { + _startPosX = _pictureWidth - _drawningSelfPropelledArtilleryUnitWidth; + } + else if (x < 0) _startPosX = 0; + else _startPosX = x; + + if (y + _drawningSelfPropelledArtilleryUnitHeight > _pictureHeight) + { + _startPosY = _pictureHeight - _drawningSelfPropelledArtilleryUnitHeight; + } + else if (y < 0) _startPosY = 0; + else _startPosY = y; } @@ -157,76 +184,76 @@ public class DrawningSelfPropelledArtilleryUnit Pen pen = new(Color.Black); Brush additionalBrush = new SolidBrush(EntitySelfPropelledArtilleryUnit.AdditionalColor); - g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 75, 30, 30); - g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 75, 30, 30); - g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 75, 90, 30); + g.DrawEllipse(pen, _startPosX.Value + 0, _startPosY.Value + 75, 30, 30); + g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 75, 30, 30); + g.DrawRectangle(pen, _startPosX.Value + 15, _startPosY.Value + 75, 90, 30); //границы ЦВЕТ Brush brOlive = new SolidBrush(Color.Olive); - g.FillRectangle(brOlive, _startPosX.Value + 35, _startPosY.Value + 40, 35, 30); - g.FillEllipse(brOlive, _startPosX.Value + 10, _startPosY.Value + 75, 30, 30); - g.FillEllipse(brOlive, _startPosX.Value + 100, _startPosY.Value + 75, 30, 30); - g.FillRectangle(brOlive, _startPosX.Value + 25, _startPosY.Value + 75, 90, 30); + g.FillRectangle(brOlive, _startPosX.Value + 25, _startPosY.Value + 40, 35, 30);//башня + g.FillEllipse(brOlive, _startPosX.Value +0, _startPosY.Value + 75, 30, 30); + g.FillEllipse(brOlive, _startPosX.Value + 90, _startPosY.Value + 75, 30, 30); + g.FillRectangle(brOlive, _startPosX.Value + 15, _startPosY.Value + 75, 90, 30); // границы арт. установки - g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 40, 35, 30); - g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 65, 120, 13); + g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 40, 35, 30); + g.DrawRectangle(pen, _startPosX.Value + 0, _startPosY.Value + 65, 120, 13);//крыша // верхние катки ЦВЕТ Brush brCadetBlue = new SolidBrush(Color.CadetBlue); - g.FillEllipse(brCadetBlue, _startPosX.Value + 40, _startPosY.Value + 70, 20, 20); - g.FillEllipse(brCadetBlue, _startPosX.Value + 60, _startPosY.Value + 70, 20, 20); - g.FillEllipse(brCadetBlue, _startPosX.Value + 80, _startPosY.Value + 70, 20, 20); + g.FillEllipse(brCadetBlue, _startPosX.Value + 30, _startPosY.Value + 70, 20, 20); + g.FillEllipse(brCadetBlue, _startPosX.Value + 50, _startPosY.Value + 70, 20, 20); + g.FillEllipse(brCadetBlue, _startPosX.Value + 70, _startPosY.Value + 70, 20, 20); // верхние катки ОТРИСОВКА - g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 70, 20, 20); - g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 70, 20, 20); - g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 70, 20, 20); + g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 70, 20, 20); + g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 70, 20, 20); + g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 70, 20, 20); //нижние катки ЦВЕТ Brush brDimGray = new SolidBrush(Color.DimGray); - g.FillEllipse(brDimGray, _startPosX.Value + 40, _startPosY.Value + 90, 15, 15); - g.FillEllipse(brDimGray, _startPosX.Value + 55, _startPosY.Value + 90, 15, 15); - g.FillEllipse(brDimGray, _startPosX.Value + 70, _startPosY.Value + 90, 15, 15); - g.FillEllipse(brDimGray, _startPosX.Value + 85, _startPosY.Value + 90, 15, 15); + g.FillEllipse(brDimGray, _startPosX.Value + 30, _startPosY.Value + 90, 15, 15); + g.FillEllipse(brDimGray, _startPosX.Value + 45, _startPosY.Value + 90, 15, 15); + g.FillEllipse(brDimGray, _startPosX.Value + 60, _startPosY.Value + 90, 15, 15); + g.FillEllipse(brDimGray, _startPosX.Value + 75, _startPosY.Value + 90, 15, 15); //нижние катки ОТРИСОВКА - g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 90, 15, 15); - g.DrawEllipse(pen, _startPosX.Value + 55, _startPosY.Value + 90, 15, 15); - g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 90, 15, 15); - g.DrawEllipse(pen, _startPosX.Value + 85, _startPosY.Value + 90, 15, 15); + g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 90, 15, 15); + g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 90, 15, 15); + g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 90, 15, 15); + g.DrawEllipse(pen, _startPosX.Value + 75, _startPosY.Value + 90, 15, 15); //Большие катки ЦВЕТ Brush brSlateGray = new SolidBrush(Color.SlateGray); - g.FillEllipse(brSlateGray, _startPosX.Value + 13, _startPosY.Value + 78, 24, 24); - g.FillEllipse(brSlateGray, _startPosX.Value + 103, _startPosY.Value + 78, 24, 24); + g.FillEllipse(brSlateGray, _startPosX.Value + 3, _startPosY.Value + 78, 24, 24); + g.FillEllipse(brSlateGray, _startPosX.Value + 93, _startPosY.Value + 78, 24, 24); //Большие катки ОТРИСОВКА - g.DrawEllipse(pen, _startPosX.Value + 13, _startPosY.Value + 78, 24, 24); - g.DrawEllipse(pen, _startPosX.Value + 103, _startPosY.Value + 78, 24, 24); + g.DrawEllipse(pen, _startPosX.Value + 3, _startPosY.Value + 78, 24, 24); + g.DrawEllipse(pen, _startPosX.Value + 93, _startPosY.Value + 78, 24, 24); - g.FillRectangle(brOlive, _startPosX.Value + 10, _startPosY.Value + 65, 120, 13); + g.FillRectangle(brOlive, _startPosX.Value + 0, _startPosY.Value + 65, 120, 13);// if (EntitySelfPropelledArtilleryUnit.TurretCannon) { - g.FillEllipse(additionalBrush, _startPosX.Value + 36, _startPosY.Value + 35, 50, 30); - g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 36, 20, 29); - g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value + 45, 60, 5); - g.FillEllipse(additionalBrush, _startPosX.Value + 123, _startPosY.Value + 42, 20, 10); + g.FillEllipse(additionalBrush, _startPosX.Value + 26, _startPosY.Value + 35, 50, 30); + g.FillRectangle(additionalBrush, _startPosX.Value + 25, _startPosY.Value + 36, 20, 29); + g.FillRectangle(additionalBrush, _startPosX.Value + 60, _startPosY.Value + 45, 60, 5); + g.FillEllipse(additionalBrush, _startPosX.Value + 113, _startPosY.Value + 42, 20, 10); } if (EntitySelfPropelledArtilleryUnit.LaunchBattery) { - g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 45, 20, 20); + g.FillRectangle(additionalBrush, _startPosX.Value + 0, _startPosY.Value + 45, 20, 20); g.FillPolygon(additionalBrush, new Point[] { - new Point(_startPosX.Value + 10, _startPosY.Value + 15), new Point(_startPosX.Value + 10, _startPosY.Value + 65), - new Point(_startPosX.Value + 30, _startPosY.Value + 65), new Point(_startPosX.Value + 30, _startPosY.Value + 45), - new Point(_startPosX.Value + 10, _startPosY.Value + 15) + new Point(_startPosX.Value + 0, _startPosY.Value + 15), new Point(_startPosX.Value + 0, _startPosY.Value + 65), + new Point(_startPosX.Value + 20, _startPosY.Value + 65), new Point(_startPosX.Value + 20, _startPosY.Value + 45), + new Point(_startPosX.Value + 0, _startPosY.Value + 15) }); - g.FillEllipse(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 5, 10, 30); - g.FillRectangle(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 15, 20, 5); - g.FillRectangle(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 25, 15, 5); + g.FillEllipse(additionalBrush, _startPosX.Value + 0, _startPosY.Value + 5, 10, 30); + g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 15, 20, 5); + g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 25, 15, 5); } } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.Designer.cs new file mode 100644 index 0000000..419aba2 --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.Designer.cs @@ -0,0 +1,39 @@ +namespace SelfPropelledArtilleryUnit +{ + partial class FormSelfPropelledArtilleryUnit + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "FormSelfPropelledArtilleryUnit"; + } + + #endregion + } +} \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.cs new file mode 100644 index 0000000..299f56c --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SelfPropelledArtilleryUnit +{ + public partial class FormSelfPropelledArtilleryUnit : Form + { + public FormSelfPropelledArtilleryUnit() + { + InitializeComponent(); + } + } +} diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.Designer.cs index 7b58321..b2f161a 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.Designer.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.Designer.cs @@ -49,9 +49,9 @@ // buttonCreate // buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(12, 446); + buttonCreate.Location = new Point(12, 438); buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(94, 35); + buttonCreate.Size = new Size(94, 43); buttonCreate.TabIndex = 1; buttonCreate.Text = "Создать"; buttonCreate.UseVisualStyleBackColor = true; diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.csproj b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.csproj index af03d74..244387d 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.csproj +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.csproj @@ -2,7 +2,7 @@ WinExe - net8.0-windows + net7.0-windows enable true enable