diff --git a/AircraftCarrier/AircraftCarrier/DrawingWarship.cs b/AircraftCarrier/AircraftCarrier/DrawingWarship.cs
index 447fee2..e5fdddb 100644
--- a/AircraftCarrier/AircraftCarrier/DrawingWarship.cs
+++ b/AircraftCarrier/AircraftCarrier/DrawingWarship.cs
@@ -59,13 +59,28 @@ namespace AircraftCarrier
///
public void SetPosition(int x, int y, int width, int height)
{
- // TODO checks
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
- }
+ if (width < _warshipWidth)
+ {
+ width = _warshipWidth;
+ }
+ if (height < _warshipHeight)
+ {
+ height = _warshipHeight;
+ }
+ if(x + _warshipWidth > width)
+ {
+ _startPosX -= x + _warshipWidth - width;
+ }
+ if (y + _warshipHeight > height)
+ {
+ _pictureHeight -= y + _warshipHeight - height;
+ }
+ }
///
/// Изменение направления пермещения
///
@@ -107,7 +122,6 @@ namespace AircraftCarrier
}
break;
}
-
}
///
@@ -116,7 +130,49 @@ namespace AircraftCarrier
///
public void DrawTransport(Graphics g)
{
+ if (_startPosX < 0 || _startPosY < 0
+ || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
+ {
+ return;
+ }
+ Pen pen = new(Color.Black);
+ //границы военного корабля
+ PointF point1 = new PointF(_startPosX, _startPosY);
+ PointF point2 = new PointF(_startPosX + 74, _startPosY);
+ PointF point3 = new PointF(_startPosX + 94, _startPosY + 20);
+ PointF point4 = new PointF(_startPosX + 74, _startPosY + 40);
+ PointF point5 = new PointF(_startPosX, _startPosY + 40);
+
+ PointF[] curvePoints =
+ {
+ point1, point2, point3, point4, point5
+ };
+ g.DrawPolygon(pen, curvePoints);
+
+ //главная палуба
+ Brush br = new SolidBrush(Warship?.BodyColor ?? Color.White);
+ g.FillPolygon(br, curvePoints);
+
+ //мачта
+ Brush brWhite = new SolidBrush(Color.White);
+ g.FillEllipse(brWhite, _startPosX + 59, _startPosY + 13, 15, 15);
+
+ //границы мачты
+ g.DrawEllipse(pen, _startPosX + 59, _startPosY + 13, 15, 15);
+
+ //палуба
+ g.FillRectangle(brWhite, _startPosX + 44, _startPosY + 10, 10, 20);
+ g.FillRectangle(brWhite, _startPosX + 24, _startPosY + 15, 20, 10);
+
+ //границы палуба
+ g.DrawRectangle(pen, _startPosX + 44, _startPosY + 10, 10, 20);
+ g.DrawRectangle(pen, _startPosX + 24, _startPosY + 15, 20, 10);
+
+ //двигатели
+ Brush brBlack = new SolidBrush(Color.Black);
+ g.FillRectangle(brBlack, _startPosX, _startPosY + 5, 4, 10);
+ g.FillRectangle(brBlack, _startPosX, _startPosY + 23, 4, 10);
}
///
diff --git a/AircraftCarrier/AircraftCarrier/FormWarship.Designer.cs b/AircraftCarrier/AircraftCarrier/FormWarship.Designer.cs
index 16e926d..4e7f9f8 100644
--- a/AircraftCarrier/AircraftCarrier/FormWarship.Designer.cs
+++ b/AircraftCarrier/AircraftCarrier/FormWarship.Designer.cs
@@ -47,10 +47,11 @@
this.pictureBoxWarship.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxWarship.Location = new System.Drawing.Point(0, 0);
this.pictureBoxWarship.Name = "pictureBoxWarship";
- this.pictureBoxWarship.Size = new System.Drawing.Size(1058, 498);
+ this.pictureBoxWarship.Size = new System.Drawing.Size(510, 426);
this.pictureBoxWarship.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxWarship.TabIndex = 0;
this.pictureBoxWarship.TabStop = false;
+ this.pictureBoxWarship.Resize += new System.EventHandler(this.PictureBoxWarship_Resize);
//
// statusStrip
//
@@ -58,9 +59,9 @@
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor});
- this.statusStrip.Location = new System.Drawing.Point(0, 498);
+ this.statusStrip.Location = new System.Drawing.Point(0, 426);
this.statusStrip.Name = "statusStrip";
- this.statusStrip.Size = new System.Drawing.Size(1058, 22);
+ this.statusStrip.Size = new System.Drawing.Size(510, 22);
this.statusStrip.TabIndex = 1;
//
// toolStripStatusLabelSpeed
@@ -83,7 +84,8 @@
//
// buttonCreate
//
- this.buttonCreate.Location = new System.Drawing.Point(12, 457);
+ this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonCreate.Location = new System.Drawing.Point(12, 393);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.TabIndex = 2;
@@ -93,9 +95,10 @@
//
// buttonDown
//
+ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonDown.Location = new System.Drawing.Point(980, 450);
+ this.buttonDown.Location = new System.Drawing.Point(428, 386);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 3;
@@ -105,9 +108,10 @@
//
// buttonUp
//
+ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonUp.Location = new System.Drawing.Point(980, 414);
+ this.buttonUp.Location = new System.Drawing.Point(428, 350);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 4;
@@ -117,9 +121,10 @@
//
// buttonLeft
//
+ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonLeft.Location = new System.Drawing.Point(944, 450);
+ this.buttonLeft.Location = new System.Drawing.Point(392, 386);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 5;
@@ -129,9 +134,10 @@
//
// buttonRight
//
+ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonRight.Location = new System.Drawing.Point(1016, 450);
+ this.buttonRight.Location = new System.Drawing.Point(464, 386);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 6;
@@ -143,7 +149,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(1058, 520);
+ this.ClientSize = new System.Drawing.Size(510, 448);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonUp);
diff --git a/AircraftCarrier/AircraftCarrier/FormWarship.cs b/AircraftCarrier/AircraftCarrier/FormWarship.cs
index 9c075a6..3866bc7 100644
--- a/AircraftCarrier/AircraftCarrier/FormWarship.cs
+++ b/AircraftCarrier/AircraftCarrier/FormWarship.cs
@@ -33,7 +33,7 @@ namespace AircraftCarrier
toolStripStatusLabelBodyColor.Text = $": {_warship.Warship.BodyColor.Name}";
Draw();
}
-
+
private void ButtonMove_Click(object sender, EventArgs e)
{
string name = ((Button)sender)?.Name ?? string.Empty;
@@ -54,5 +54,15 @@ namespace AircraftCarrier
}
Draw();
}
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void PictureBoxWarship_Resize(object sender, EventArgs e)
+ {
+ _warship?.ChangeBorders(pictureBoxWarship.Width,pictureBoxWarship.Height);
+ Draw();
+ }
}
}
\ No newline at end of file