Фикс2 Лабораторная работа 1

This commit is contained in:
ivans 2024-02-14 15:03:05 +04:00
parent dcb0b44290
commit 4fbee86189
4 changed files with 62 additions and 68 deletions

View File

@ -51,7 +51,7 @@ public class DrawingSeaplane
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool landingGear, bool radar) public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool landingGear, bool radar)
{ {
EntitySeaplane = new EntitySeaplane(); EntitySeaplane = new EntitySeaplane();
EntitySeaplane.Init(speed, weight, bodyColor, additionalColor, landingGear, radar); EntitySeaplane.Init(speed, weight, bodyColor, additionalColor, landingGear, radar);
_pictureWidth = null; _pictureWidth = null;
_pictureHeight = null; _pictureHeight = null;
_startPosX = null; _startPosX = null;
@ -69,16 +69,35 @@ public class DrawingSeaplane
// TODO проверка, что объект "влезает" в размеры поля // TODO проверка, что объект "влезает" в размеры поля
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
if (_drawningSeaplaneWidth < width && _drawningSeaplaneHeight < height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_startPosX != null && _startPosY != null)
{
if (_startPosX + _drawningSeaplaneWidth > width)
{
_startPosX = width - (_drawningSeaplaneWidth + 1);
}
if (_startPosY + _drawningSeaplaneWidth > height)
{
_startPosY = height - (_drawningSeaplaneHeight + 1);
}
}
_pictureWidth = width;
_pictureHeight = height;
if (_drawningSeaplaneWidth < width && _drawningSeaplaneHeight < height) {
return true; return true;
} }
else { return false; }
return false;
} }
/// <summary> /// <summary>
@ -98,13 +117,21 @@ public class DrawingSeaplane
_startPosX = x; _startPosX = x;
_startPosY = y; _startPosY = y;
if (_drawningSeaplaneWidth - _startPosX < 0) if (_startPosX < 0)
{ {
_startPosX += _drawningSeaplaneWidth; _startPosX = 0;
} }
if (_drawningSeaplaneHeight - _startPosY < 0) if (_startPosY < 0)
{ {
_startPosY += _drawningSeaplaneHeight; _startPosY = 0;
}
if (_startPosX + _drawningSeaplaneWidth > _pictureWidth)
{
_startPosX = _pictureWidth - _drawningSeaplaneWidth;
}
if (_startPosY - _drawningSeaplaneHeight > _pictureHeight)
{
_startPosY = _pictureHeight - _drawningSeaplaneHeight;
} }
} }
@ -119,7 +146,7 @@ public class DrawingSeaplane
{ {
return false; return false;
} }
switch (direction) switch (direction)
{ {
//влево //влево
@ -138,7 +165,7 @@ public class DrawingSeaplane
return true; return true;
// вправо // вправо
case DirectionType.Right: case DirectionType.Right:
if (_startPosX + (int)EntitySeaplane.Step < _pictureWidth - _drawningSeaplaneWidth) if (_startPosX + (int)EntitySeaplane.Step < _pictureWidth - _drawningSeaplaneWidth)
{ {
_startPosX += (int)EntitySeaplane.Step; _startPosX += (int)EntitySeaplane.Step;
@ -146,7 +173,7 @@ public class DrawingSeaplane
return true; return true;
//вниз //вниз
case DirectionType.Down: case DirectionType.Down:
if (_startPosY + (int)EntitySeaplane.Step < _pictureHeight - _drawningSeaplaneHeight) if (_startPosY + (int)EntitySeaplane.Step < _pictureHeight - _drawningSeaplaneHeight)
{ {
_startPosY += (int)EntitySeaplane.Step; _startPosY += (int)EntitySeaplane.Step;
@ -180,7 +207,7 @@ public class DrawingSeaplane
//Полигон для хвоста //Полигон для хвоста
Point point1 = new Point(_startPosX.Value, _startPosY.Value); Point point1 = new Point(_startPosX.Value, _startPosY.Value);
Point point2 = new Point(_startPosX.Value + 35, _startPosY.Value + 35); Point point2 = new Point(_startPosX.Value + 35, _startPosY.Value + 35);
Point point3 = new Point(_startPosX.Value, _startPosY.Value+35); Point point3 = new Point(_startPosX.Value, _startPosY.Value + 35);
Point point4 = new Point(_startPosX.Value, _startPosY.Value); Point point4 = new Point(_startPosX.Value, _startPosY.Value);
Point[] Hvost = Point[] Hvost =
{ {
@ -202,13 +229,13 @@ public class DrawingSeaplane
//Хвост //Хвост
g.FillPolygon(brBody, Hvost); g.FillPolygon(brBody, Hvost);
//Тело //Тело
g.FillRectangle(brBody, _startPosX.Value + 30, _startPosY.Value + 30, 85, 25); g.FillRectangle(brBody, _startPosX.Value + 30, _startPosY.Value + 30, 85, 25);
g.FillEllipse(brBody, _startPosX.Value + 45, _startPosY.Value + 30, 110, 24); g.FillEllipse(brBody, _startPosX.Value + 45, _startPosY.Value + 30, 110, 24);
g.FillEllipse(brBody, _startPosX.Value - 5, _startPosY.Value + 30, 100, 24); g.FillEllipse(brBody, _startPosX.Value - 5, _startPosY.Value + 30, 100, 24);
g.DrawEllipse(penKraya, _startPosX.Value, _startPosY.Value + 27, 17, 6); g.DrawEllipse(penKraya, _startPosX.Value, _startPosY.Value + 27, 17, 6);
@ -220,13 +247,13 @@ public class DrawingSeaplane
g.FillEllipse(brAdditional, _startPosX.Value + 45, _startPosY.Value + 43, 50, 7); g.FillEllipse(brAdditional, _startPosX.Value + 45, _startPosY.Value + 43, 50, 7);
//Иллюминаторы //Иллюминаторы
for (int i = 0; i < 80; i += 10) for (int i = 0; i < 80; i += 10)
{ {
g.FillEllipse(brWhity, _startPosX.Value + 30 + i, _startPosY.Value + 34, 6, 6); g.FillEllipse(brWhity, _startPosX.Value + 30 + i, _startPosY.Value + 34, 6, 6);
} }
@ -251,48 +278,14 @@ public class DrawingSeaplane
g.FillEllipse(brAdditional, _startPosX.Value + 30, _startPosY.Value + 12, 40, 15); g.FillEllipse(brAdditional, _startPosX.Value + 30, _startPosY.Value + 12, 40, 15);
g.FillPolygon(brAdditional, Radar); g.FillPolygon(brAdditional, Radar);
} }
else { else
{
} }
//Пилоты //Пилоты
g.FillEllipse(brWhity, _startPosX.Value + 115, _startPosY.Value + 34, 20, 8); g.FillEllipse(brWhity, _startPosX.Value + 115, _startPosY.Value + 34, 20, 8);
//границы автомобиля
//g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 5, 20, 20);
//g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20);
//g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 5, 20, 20);
//g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 35, 20, 20);
//g.DrawRectangle(pen, _startPosX.Value + 9, _startPosY.Value + 15, 10, 30);
//g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 15, 10, 30);
//g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 4, 70, 52);
////задние фары
//Brush brRed = new SolidBrush(Color.Red);
//g.FillEllipse(brRed, _startPosX.Value + 10, _startPosY.Value + 5, 20, 20);
//g.FillEllipse(brRed, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20);
////передние фары
//Brush brYellow = new SolidBrush(Color.Yellow);
//g.FillEllipse(brYellow, _startPosX.Value + 80, _startPosY.Value + 5, 20, 20);
//g.FillEllipse(brYellow, _startPosX.Value + 80, _startPosY.Value + 35, 20, 20);
////кузов
//Brush br = new SolidBrush(EntitySeaplane.BodyColor);
//g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 15, 10, 30);
//g.FillRectangle(br, _startPosX.Value + 90, _startPosY.Value + 15, 10, 30);
//g.FillRectangle(br, _startPosX.Value + 20, _startPosY.Value + 5, 70, 50);
////стекла
//Brush brBlue = new SolidBrush(Color.LightBlue);
//g.FillRectangle(brBlue, _startPosX.Value + 70, _startPosY.Value + 10, 5, 40);
//g.FillRectangle(brBlue, _startPosX.Value + 30, _startPosY.Value + 10, 5, 40);
//g.FillRectangle(brBlue, _startPosX.Value + 35, _startPosY.Value + 8, 35, 2);
//g.FillRectangle(brBlue, _startPosX.Value + 35, _startPosY.Value + 51, 35, 2);
////выделяем рамкой крышу
//g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 10, 35, 40);
//g.DrawRectangle(pen, _startPosX.Value + 75, _startPosY.Value + 15, 25, 30);
//g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 15, 15, 30);

View File

@ -40,7 +40,7 @@ public class EntitySeaplane
/// <param name="bodyColor">Основной цвет</param> /// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param> /// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="landingGear">Тип "шасси"</param> /// <param name="landingGear">Тип "шасси"</param>
/// <param name="radar">Тип двигателя</param> /// <param name="radar">При</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool landingGear, bool radar) public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool landingGear, bool radar)
{ {
Speed = speed; Speed = speed;

View File

@ -42,15 +42,14 @@
pictureBoxSeaplane.Dock = DockStyle.Fill; pictureBoxSeaplane.Dock = DockStyle.Fill;
pictureBoxSeaplane.Location = new Point(0, 0); pictureBoxSeaplane.Location = new Point(0, 0);
pictureBoxSeaplane.Name = "pictureBoxSeaplane"; pictureBoxSeaplane.Name = "pictureBoxSeaplane";
pictureBoxSeaplane.Size = new Size(776, 531); pictureBoxSeaplane.Size = new Size(590, 379);
pictureBoxSeaplane.TabIndex = 0; pictureBoxSeaplane.TabIndex = 0;
pictureBoxSeaplane.TabStop = false; pictureBoxSeaplane.TabStop = false;
// //
// buttonCreate // buttonCreate
// //
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 501); buttonCreate.Location = new Point(12, 349);
buttonCreate.Name = "buttonCreate"; buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(75, 23); buttonCreate.Size = new Size(75, 23);
buttonCreate.TabIndex = 1; buttonCreate.TabIndex = 1;
@ -64,7 +63,7 @@
buttonLeft.BackColor = Color.Snow; buttonLeft.BackColor = Color.Snow;
buttonLeft.BackgroundImage = Properties.Resources.arrow11; buttonLeft.BackgroundImage = Properties.Resources.arrow11;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(651, 489); buttonLeft.Location = new Point(465, 337);
buttonLeft.Name = "buttonLeft"; buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(35, 35); buttonLeft.Size = new Size(35, 35);
buttonLeft.TabIndex = 2; buttonLeft.TabIndex = 2;
@ -77,7 +76,7 @@
buttonDown.BackColor = Color.Snow; buttonDown.BackColor = Color.Snow;
buttonDown.BackgroundImage = Properties.Resources.arrow4; buttonDown.BackgroundImage = Properties.Resources.arrow4;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch; buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(692, 489); buttonDown.Location = new Point(506, 337);
buttonDown.Name = "buttonDown"; buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(35, 35); buttonDown.Size = new Size(35, 35);
buttonDown.TabIndex = 4; buttonDown.TabIndex = 4;
@ -90,7 +89,7 @@
buttonUp.BackColor = Color.Snow; buttonUp.BackColor = Color.Snow;
buttonUp.BackgroundImage = Properties.Resources.arrow2; buttonUp.BackgroundImage = Properties.Resources.arrow2;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch; buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(692, 449); buttonUp.Location = new Point(506, 297);
buttonUp.Name = "buttonUp"; buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(35, 35); buttonUp.Size = new Size(35, 35);
buttonUp.TabIndex = 5; buttonUp.TabIndex = 5;
@ -103,7 +102,7 @@
buttonRight.BackColor = Color.Snow; buttonRight.BackColor = Color.Snow;
buttonRight.BackgroundImage = Properties.Resources.arrow3; buttonRight.BackgroundImage = Properties.Resources.arrow3;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch; buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(733, 489); buttonRight.Location = new Point(547, 337);
buttonRight.Name = "buttonRight"; buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(35, 35); buttonRight.Size = new Size(35, 35);
buttonRight.TabIndex = 7; buttonRight.TabIndex = 7;
@ -114,7 +113,7 @@
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(776, 531); ClientSize = new Size(590, 379);
Controls.Add(buttonRight); Controls.Add(buttonRight);
Controls.Add(buttonUp); Controls.Add(buttonUp);
Controls.Add(buttonDown); Controls.Add(buttonDown);

View File

@ -84,5 +84,7 @@
Draw(); Draw();
} }
} }
} }
} }