diff --git a/ProjectExcavator/ProjectExcavator/DrawningExcavarorBodyKits.cs b/ProjectExcavator/ProjectExcavator/DrawningExcavarorBodyKits.cs index 79f4a78..5e47dad 100644 --- a/ProjectExcavator/ProjectExcavator/DrawningExcavarorBodyKits.cs +++ b/ProjectExcavator/ProjectExcavator/DrawningExcavarorBodyKits.cs @@ -24,7 +24,7 @@ namespace ProjectExcavator.DrawningObjects Color bodyColor, Color additionalColor, bool bodyKit, bool bucket, int width, int height) : - base(speed, weight, bodyColor, width, height, 110, 60) + base(speed, weight, bodyColor, width, height, 170, 100) { if(EntityExcavator != null) { @@ -43,7 +43,8 @@ namespace ProjectExcavator.DrawningObjects //ыспомогательные опоры if (excavator.BodyKit) { - g.FillRectangle(additionalBrush, _startPosX + 20, _startPosY + 100, 110, 10); + g.FillRectangle(additionalBrush, _startPosX + 20, _startPosY + 50, 110, 10); + g.DrawRectangle(pen, _startPosX + 20, _startPosY + 50, 110, 10); } //отрисовка базы экскаватора base.DrawTransport(g); @@ -51,9 +52,9 @@ namespace ProjectExcavator.DrawningObjects if (excavator.Bucket) { Point[] pointsBacket = { - new Point(_startPosX + 150, _startPosY + 75), - new Point(_startPosX + 150, _startPosY + 135), - new Point(_startPosX + 195, _startPosY + 135), + new Point(_startPosX + 150, _startPosY + 25), + new Point(_startPosX + 150, _startPosY + 85), + new Point(_startPosX + 195, _startPosY + 85), }; g.FillPolygon(additionalBrush, pointsBacket); g.DrawPolygon(pen, pointsBacket); diff --git a/ProjectExcavator/ProjectExcavator/DrawningExcavator.cs b/ProjectExcavator/ProjectExcavator/DrawningExcavator.cs index 76870f1..f5c74f8 100644 --- a/ProjectExcavator/ProjectExcavator/DrawningExcavator.cs +++ b/ProjectExcavator/ProjectExcavator/DrawningExcavator.cs @@ -32,11 +32,11 @@ namespace ProjectExcavator.DrawningObjects /// /// Ширина прорисовки автомобиля /// - protected readonly int _excavatorWidth = 150; + protected readonly int _excavatorWidth = 135; /// /// Высота прорисовки автомобиля /// - protected readonly int _excavatorHeight = 155; + protected readonly int _excavatorHeight = 80; /// /// Координата X объекта /// @@ -83,11 +83,14 @@ namespace ProjectExcavator.DrawningObjects int width, int height, int excavatorWidth, int excavatorHeight) { - // TODO: Продумать проверки _pictureWidth = width; _pictureHeight = height; _excavatorWidth = excavatorWidth; _excavatorHeight = excavatorHeight; + if (_pictureHeight < _excavatorHeight || _pictureWidth < _excavatorWidth) + { + return; + } EntityExcavator = new EntityExcavator(speed, weight, bodyColor); } /// @@ -97,9 +100,8 @@ namespace ProjectExcavator.DrawningObjects /// Координата Y public void SetPosition(int x, int y) { - // TODO: Изменение x, y - _startPosX = x; - _startPosY = y; + _startPosX = Math.Min(x,_pictureWidth - _excavatorWidth); + _startPosY = Math.Min(y,_pictureHeight - _excavatorHeight); } /// /// Проверка, что объект может переместится по указанному направлению @@ -117,7 +119,7 @@ namespace ProjectExcavator.DrawningObjects //влево DirectionType.Left => _startPosX - EntityExcavator.Step >0, //вверх - DirectionType.Up => _startPosY - EntityExcavator.Step > -50, + DirectionType.Up => _startPosY - EntityExcavator.Step > 0, //вправо DirectionType.Right => _startPosX + EntityExcavator.Step < _pictureWidth - _excavatorWidth, //вниз @@ -168,29 +170,29 @@ namespace ProjectExcavator.DrawningObjects Pen pen = new(Color.Black); //корпус Brush bodyBrush = new SolidBrush(Color.Red); - g.FillRectangle(bodyBrush, _startPosX + 20, _startPosY + 110, 130, 20); - g.FillRectangle(bodyBrush, _startPosX + 100, _startPosY + 70, 30, 40); - g.FillRectangle(bodyBrush, _startPosX + 30, _startPosY + 90, 10, 20); - g.DrawRectangle(pen, _startPosX + 20, _startPosY + 110, 130, 20); - g.DrawRectangle(pen, _startPosX + 100, _startPosY + 70, 30, 40); - g.DrawRectangle(pen, _startPosX + 30, _startPosY + 90, 10, 20); + g.FillRectangle(bodyBrush, _startPosX + 20, _startPosY + 60, 130, 20); + g.FillRectangle(bodyBrush, _startPosX + 100, _startPosY + 20, 30, 40); + g.FillRectangle(bodyBrush, _startPosX + 30, _startPosY + 40, 10, 20); + g.DrawRectangle(pen, _startPosX + 20, _startPosY + 60, 130, 20); + g.DrawRectangle(pen, _startPosX + 100, _startPosY + 20, 30, 40); + g.DrawRectangle(pen, _startPosX + 30, _startPosY + 40, 10, 20); //гусеница Point[] points = { - new Point(_startPosX + 20, _startPosY + 130), - new Point(_startPosX + 15, _startPosY+ 135), - new Point(_startPosX + 15, _startPosY + 145), - new Point(_startPosX + 20, _startPosY + 150), - new Point(_startPosX + 145, _startPosY + 150), - new Point(_startPosX + 150, _startPosY + 145), - new Point(_startPosX + 150, _startPosY + 135), - new Point(_startPosX + 145, _startPosY + 130)}; + new Point(_startPosX + 20, _startPosY + 80), + new Point(_startPosX + 15, _startPosY+ 85), + new Point(_startPosX + 15, _startPosY + 95), + new Point(_startPosX + 20, _startPosY + 100), + new Point(_startPosX + 145, _startPosY + 100), + new Point(_startPosX + 150, _startPosY + 95), + new Point(_startPosX + 150, _startPosY + 85), + new Point(_startPosX + 145, _startPosY + 80)}; g.DrawPolygon(pen, points); - g.DrawEllipse(pen, _startPosX + 20, _startPosY + 130, 20, 20); - g.DrawEllipse(pen, _startPosX + 40, _startPosY + 130, 20, 20); - g.DrawEllipse(pen, _startPosX + 60, _startPosY + 130, 20, 20); - g.DrawEllipse(pen, _startPosX + 80, _startPosY + 130, 20, 20); - g.DrawEllipse(pen, _startPosX + 100, _startPosY + 130, 20, 20); - g.DrawEllipse(pen, _startPosX + 120, _startPosY + 130, 20, 20); + g.DrawEllipse(pen, _startPosX + 20, _startPosY + 80, 20, 20); + g.DrawEllipse(pen, _startPosX + 40, _startPosY + 80, 20, 20); + g.DrawEllipse(pen, _startPosX + 60, _startPosY + 80, 20, 20); + g.DrawEllipse(pen, _startPosX + 80, _startPosY + 80, 20, 20); + g.DrawEllipse(pen, _startPosX + 100, _startPosY + 80, 20, 20); + g.DrawEllipse(pen, _startPosX + 120, _startPosY + 80, 20, 20); } } diff --git a/ProjectExcavator/ProjectExcavator/ExcavatorForm.Designer.cs b/ProjectExcavator/ProjectExcavator/ExcavatorForm.Designer.cs index 39c5858..6352b5c 100644 --- a/ProjectExcavator/ProjectExcavator/ExcavatorForm.Designer.cs +++ b/ProjectExcavator/ProjectExcavator/ExcavatorForm.Designer.cs @@ -44,8 +44,9 @@ // pictureBoxExcavator.Dock = DockStyle.Fill; pictureBoxExcavator.Location = new Point(0, 0); + pictureBoxExcavator.Margin = new Padding(3, 4, 3, 4); pictureBoxExcavator.Name = "pictureBoxExcavator"; - pictureBoxExcavator.Size = new Size(800, 450); + pictureBoxExcavator.Size = new Size(914, 600); pictureBoxExcavator.SizeMode = PictureBoxSizeMode.AutoSize; pictureBoxExcavator.TabIndex = 0; pictureBoxExcavator.TabStop = false; @@ -53,9 +54,10 @@ // buttonCreate // buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(12, 397); + buttonCreate.Location = new Point(14, 529); + buttonCreate.Margin = new Padding(3, 4, 3, 4); buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(155, 41); + buttonCreate.Size = new Size(177, 55); buttonCreate.TabIndex = 1; buttonCreate.Text = "Создать простой экскаватор"; buttonCreate.UseVisualStyleBackColor = true; @@ -66,9 +68,10 @@ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.BackgroundImage = Properties.Resources.down; buttonDown.BackgroundImageLayout = ImageLayout.Zoom; - buttonDown.Location = new Point(722, 415); + buttonDown.Location = new Point(825, 553); + buttonDown.Margin = new Padding(3, 4, 3, 4); buttonDown.Name = "buttonDown"; - buttonDown.Size = new Size(30, 30); + buttonDown.Size = new Size(34, 40); buttonDown.TabIndex = 2; buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += buttonMove_Click; @@ -78,9 +81,10 @@ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.BackgroundImage = Properties.Resources.up; buttonUp.BackgroundImageLayout = ImageLayout.Zoom; - buttonUp.Location = new Point(722, 379); + buttonUp.Location = new Point(825, 505); + buttonUp.Margin = new Padding(3, 4, 3, 4); buttonUp.Name = "buttonUp"; - buttonUp.Size = new Size(30, 30); + buttonUp.Size = new Size(34, 40); buttonUp.TabIndex = 3; buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += buttonMove_Click; @@ -90,9 +94,10 @@ buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.BackgroundImage = Properties.Resources.left; buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; - buttonLeft.Location = new Point(686, 415); + buttonLeft.Location = new Point(784, 553); + buttonLeft.Margin = new Padding(3, 4, 3, 4); buttonLeft.Name = "buttonLeft"; - buttonLeft.Size = new Size(30, 30); + buttonLeft.Size = new Size(34, 40); buttonLeft.TabIndex = 4; buttonLeft.UseVisualStyleBackColor = true; buttonLeft.Click += buttonMove_Click; @@ -102,9 +107,10 @@ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.BackgroundImage = Properties.Resources.right; buttonRight.BackgroundImageLayout = ImageLayout.Zoom; - buttonRight.Location = new Point(758, 415); + buttonRight.Location = new Point(866, 553); + buttonRight.Margin = new Padding(3, 4, 3, 4); buttonRight.Name = "buttonRight"; - buttonRight.Size = new Size(30, 30); + buttonRight.Size = new Size(34, 40); buttonRight.TabIndex = 5; buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += buttonMove_Click; @@ -113,17 +119,19 @@ // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.FormattingEnabled = true; - comboBoxStrategy.Items.AddRange(new object[] { "0", "1" }); - comboBoxStrategy.Location = new Point(667, 12); + comboBoxStrategy.Items.AddRange(new object[] { "Двигаться в центр", "Двигаться к краю экрана" }); + comboBoxStrategy.Location = new Point(762, 16); + comboBoxStrategy.Margin = new Padding(3, 4, 3, 4); comboBoxStrategy.Name = "comboBoxStrategy"; - comboBoxStrategy.Size = new Size(121, 23); + comboBoxStrategy.Size = new Size(138, 28); comboBoxStrategy.TabIndex = 6; // // buttonCreateExcavatorBodyKits // - buttonCreateExcavatorBodyKits.Location = new Point(173, 397); + buttonCreateExcavatorBodyKits.Location = new Point(198, 529); + buttonCreateExcavatorBodyKits.Margin = new Padding(3, 4, 3, 4); buttonCreateExcavatorBodyKits.Name = "buttonCreateExcavatorBodyKits"; - buttonCreateExcavatorBodyKits.Size = new Size(145, 41); + buttonCreateExcavatorBodyKits.Size = new Size(166, 55); buttonCreateExcavatorBodyKits.TabIndex = 7; buttonCreateExcavatorBodyKits.Text = "Создать Экскаватор с обвесами"; buttonCreateExcavatorBodyKits.UseVisualStyleBackColor = true; @@ -131,9 +139,10 @@ // // buttonStep // - buttonStep.Location = new Point(713, 41); + buttonStep.Location = new Point(815, 55); + buttonStep.Margin = new Padding(3, 4, 3, 4); buttonStep.Name = "buttonStep"; - buttonStep.Size = new Size(75, 23); + buttonStep.Size = new Size(86, 31); buttonStep.TabIndex = 8; buttonStep.Text = "Шаг"; buttonStep.UseVisualStyleBackColor = true; @@ -141,9 +150,9 @@ // // ExcavatorForm // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(914, 600); Controls.Add(buttonStep); Controls.Add(buttonCreateExcavatorBodyKits); Controls.Add(comboBoxStrategy); @@ -153,6 +162,7 @@ Controls.Add(buttonDown); Controls.Add(buttonCreate); Controls.Add(pictureBoxExcavator); + Margin = new Padding(3, 4, 3, 4); Name = "ExcavatorForm"; Text = "Excavator"; Click += buttonMove_Click; diff --git a/ProjectExcavator/ProjectExcavator/MoveToCenter.cs b/ProjectExcavator/ProjectExcavator/MoveToCenter.cs index 8c32d3f..92af0d0 100644 --- a/ProjectExcavator/ProjectExcavator/MoveToCenter.cs +++ b/ProjectExcavator/ProjectExcavator/MoveToCenter.cs @@ -28,7 +28,7 @@ namespace ProjectExcavator.MovementStrategy { return; } - var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2; + var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2 ; if (Math.Abs(diffX) > GetStep()) { if (diffX > 0) @@ -40,7 +40,7 @@ namespace ProjectExcavator.MovementStrategy MoveRight(); } } - var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2; + var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2 ; if (Math.Abs(diffY) > GetStep()) { if (diffY > 0)