Коммит пятый. 100%

This commit is contained in:
Hells Hound 2022-09-11 11:03:45 +04:00
parent 714420d726
commit 7e743b4b3b
3 changed files with 85 additions and 13 deletions

View File

@ -59,13 +59,28 @@ namespace AircraftCarrier
/// <param name="height"></param>
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;
}
}
/// <summary>
/// Изменение направления пермещения
/// </summary>
@ -107,7 +122,6 @@ namespace AircraftCarrier
}
break;
}
}
/// <summary>
@ -116,7 +130,49 @@ namespace AircraftCarrier
/// <param name="g"></param>
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);
}
/// <summary>

View File

@ -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);

View File

@ -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();
}
/// <summary>
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PictureBoxWarship_Resize(object sender, EventArgs e)
{
_warship?.ChangeBorders(pictureBoxWarship.Width,pictureBoxWarship.Height);
Draw();
}
}
}