Фикс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

@ -51,7 +51,7 @@ public class DrawingSeaplane
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool landingGear, bool radar)
{
EntitySeaplane = new EntitySeaplane();
EntitySeaplane.Init(speed, weight, bodyColor, additionalColor, landingGear, radar);
EntitySeaplane.Init(speed, weight, bodyColor, additionalColor, landingGear, radar);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
@ -69,16 +69,35 @@ public class DrawingSeaplane
// 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;
}
else { return false; }
return false;
}
/// <summary>
@ -98,13 +117,21 @@ public class DrawingSeaplane
_startPosX = x;
_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;
}
switch (direction)
{
//влево
@ -138,7 +165,7 @@ public class DrawingSeaplane
return true;
// вправо
case DirectionType.Right:
if (_startPosX + (int)EntitySeaplane.Step < _pictureWidth - _drawningSeaplaneWidth)
{
_startPosX += (int)EntitySeaplane.Step;
@ -146,7 +173,7 @@ public class DrawingSeaplane
return true;
//вниз
case DirectionType.Down:
if (_startPosY + (int)EntitySeaplane.Step < _pictureHeight - _drawningSeaplaneHeight)
{
_startPosY += (int)EntitySeaplane.Step;
@ -180,7 +207,7 @@ public class DrawingSeaplane
//Полигон для хвоста
Point point1 = new Point(_startPosX.Value, _startPosY.Value);
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[] Hvost =
{
@ -202,13 +229,13 @@ public class DrawingSeaplane
//Хвост
g.FillPolygon(brBody, Hvost);
//Тело
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 - 5, _startPosY.Value + 30, 100, 24);
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);
//Иллюминаторы
for (int i = 0; i < 80; i += 10)
{
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.FillPolygon(brAdditional, Radar);
}
else {
else
{
}
//Пилоты
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);

@ -40,7 +40,7 @@ public class EntitySeaplane
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</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)
{
Speed = speed;

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

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