Лабораторная работа№1

This commit is contained in:
nezui1 2024-02-27 13:51:18 +03:00
parent 18baaa5880
commit 71156a3ec2
4 changed files with 59 additions and 36 deletions

View File

@ -36,7 +36,7 @@ public class DrawningAirFighter
/// <summary> /// <summary>
/// Ширина прорисовки истребителя /// Ширина прорисовки истребителя
/// </summary> /// </summary>
private int? _drawningAirFlighterWidth = 130; private int? _drawningAirFlighterWidth = 120;
/// <summary> /// <summary>
/// Высота прорисовки истребителя /// Высота прорисовки истребителя
@ -53,10 +53,11 @@ public class DrawningAirFighter
/// <param name="bodyKit">Признак наличия корпуса</param> /// <param name="bodyKit">Признак наличия корпуса</param>
/// <param name="rocket">Признак наличия рокет</param> /// <param name="rocket">Признак наличия рокет</param>
/// <param name="additionalWing">Признак наличия дополнительных крыльев</param> /// <param name="additionalWing">Признак наличия дополнительных крыльев</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool rocket, bool additionalWing) //public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool additionalWing)
public void Init(EntityAirFighter entityAirFighter)
{ {
EntityAirFighter = new EntityAirFighter(); EntityAirFighter = entityAirFighter;
EntityAirFighter.Init(speed, weight, bodyColor, additionalColor, bodyKit, rocket, additionalWing); //EntityAirFighter.Init(speed, weight, bodyColor, additionalColor, rocket, additionalWing);
_pictureHeight = null; _pictureHeight = null;
_pictureWidth = null; _pictureWidth = null;
_startPosX = null; _startPosX = null;
@ -78,8 +79,14 @@ public class DrawningAirFighter
_pictureHeight = height; _pictureHeight = height;
if (_startPosX != null && _startPosY != null) if (_startPosX != null && _startPosY != null)
{ {
if (_startPosX.Value < 0) _startPosX = 0; if (_startPosX.Value < 0)
if (_startPosY.Value < 0) _startPosY = 0; {
_startPosX = 0;
}
if (_startPosY.Value < 0)
{
_startPosY = 0;
}
if (_startPosX.Value + _drawningAirFlighterWidth > _pictureWidth) if (_startPosX.Value + _drawningAirFlighterWidth > _pictureWidth)
{ {
_startPosX = _pictureWidth - _drawningAirFlighterWidth; _startPosX = _pictureWidth - _drawningAirFlighterWidth;
@ -111,13 +118,19 @@ public class DrawningAirFighter
{ {
_startPosX = x; _startPosX = x;
_startPosY = y; _startPosY = y;
if (_startPosX.Value < 0) _startPosX = 0; if (_startPosX.Value < 0)
if (_startPosY.Value < 0) _startPosY = 0; {
if (_startPosX.Value + _drawningAirFlighterWidth > _pictureWidth) _startPosX = 0;
}
if (_startPosY.Value < 0)
{
_startPosY = 0;
}
if (_startPosX + _drawningAirFlighterWidth > _pictureWidth)
{ {
_startPosX = _pictureWidth - _drawningAirFlighterWidth; _startPosX = _pictureWidth - _drawningAirFlighterWidth;
} }
if (_startPosY.Value + _drawningAirFlighterHeight > _pictureHeight) if (_startPosY + _drawningAirFlighterHeight > _pictureHeight)
{ {
_startPosY = _pictureHeight - _drawningAirFlighterHeight; _startPosY = _pictureHeight - _drawningAirFlighterHeight;
} }
@ -203,9 +216,9 @@ public class DrawningAirFighter
} }
//корпус //корпус
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 60, 100, 20); g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 60, 100, 20);
Point[] body = { new Point(_startPosX.Value + 110, _startPosY.Value + 80), Point[] body = { new Point(_startPosX.Value + 100, _startPosY.Value + 80),
new Point(_startPosX.Value + 130, _startPosY.Value + 70), new Point(_startPosX.Value + 110, _startPosY.Value + 60) }; new Point(_startPosX.Value + 120, _startPosY.Value + 70), new Point(_startPosX.Value + 100, _startPosY.Value + 60) };
g.DrawPolygon(pen, body); g.DrawPolygon(pen, body);
//нижнее крыло //нижнее крыло
Point[] wingUpper = { new Point(_startPosX.Value + 80, _startPosY.Value + 80), Point[] wingUpper = { new Point(_startPosX.Value + 80, _startPosY.Value + 80),
@ -218,12 +231,12 @@ public class DrawningAirFighter
g.DrawPolygon(pen, wingLower); g.DrawPolygon(pen, wingLower);
//задние крылья //задние крылья
//верхнее //верхнее
Point[] rearWingUpper = { new Point(_startPosX.Value + 10, _startPosY.Value + 60), new Point(_startPosX.Value + 10, _startPosY.Value + 30), Point[] rearWingUpper = { new Point(_startPosX.Value, _startPosY.Value + 60), new Point(_startPosX.Value, _startPosY.Value + 30),
new Point(_startPosX.Value + 25, _startPosY.Value + 50), new Point(_startPosX.Value + 25, _startPosY.Value + 60)}; new Point(_startPosX.Value + 25, _startPosY.Value + 50), new Point(_startPosX.Value + 25, _startPosY.Value + 60)};
g.DrawPolygon(pen, rearWingUpper); g.DrawPolygon(pen, rearWingUpper);
//нижнее //нижнее
Point[] rearWingLower = { new Point(_startPosX.Value + 10, _startPosY.Value + 80), Point[] rearWingLower = { new Point(_startPosX.Value, _startPosY.Value + 80),
new Point(_startPosX.Value + 10, _startPosY.Value + 110),new Point(_startPosX.Value + 25, _startPosY.Value + 90), new Point(_startPosX.Value, _startPosY.Value + 110),new Point(_startPosX.Value + 25, _startPosY.Value + 90),
new Point(_startPosX.Value + 25, _startPosY.Value + 80) }; new Point(_startPosX.Value + 25, _startPosY.Value + 80) };
g.DrawPolygon(pen, rearWingLower); g.DrawPolygon(pen, rearWingLower);
@ -233,7 +246,7 @@ public class DrawningAirFighter
//залив корпуса //залив корпуса
Brush br = new SolidBrush(EntityAirFighter.BodyColor); Brush br = new SolidBrush(EntityAirFighter.BodyColor);
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 60, 100, 20); g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 60, 100, 20);
g.FillPolygon(br, wingLower); g.FillPolygon(br, wingLower);
g.FillPolygon(br, wingUpper); g.FillPolygon(br, wingUpper);

View File

@ -46,10 +46,9 @@ public class EntityAirFighter
/// <param name="weight">Вес</param> /// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param> /// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param> /// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия корпуса</param>
/// <param name="rocket">Признак наличия рокет</param> /// <param name="rocket">Признак наличия рокет</param>
/// <param name="additionalWing">Признак наличия дополнительных крыльев</param> /// <param name="additionalWing">Признак наличия дополнительных крыльев</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool rocket, bool additionalWing) public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool rocket, bool additionalWing)
{ {
Speed = speed; Speed = speed;
Weight = weight; Weight = weight;

View File

@ -41,16 +41,20 @@
// //
pictureBoxAirFighter.Dock = DockStyle.Fill; pictureBoxAirFighter.Dock = DockStyle.Fill;
pictureBoxAirFighter.Location = new Point(0, 0); pictureBoxAirFighter.Location = new Point(0, 0);
pictureBoxAirFighter.Margin = new Padding(3, 4, 3, 4);
pictureBoxAirFighter.Name = "pictureBoxAirFighter"; pictureBoxAirFighter.Name = "pictureBoxAirFighter";
pictureBoxAirFighter.Size = new Size(924, 557); pictureBoxAirFighter.Size = new Size(1056, 743);
pictureBoxAirFighter.TabIndex = 0; pictureBoxAirFighter.TabIndex = 0;
pictureBoxAirFighter.TabStop = false; pictureBoxAirFighter.TabStop = false;
// //
// buttonCreate // buttonCreate
// //
buttonCreate.Location = new Point(12, 476); buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(14, 635);
buttonCreate.Margin = new Padding(3, 4, 3, 4);
buttonCreate.Name = "buttonCreate"; buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(75, 23); buttonCreate.Size = new Size(86, 31);
buttonCreate.TabIndex = 1; buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать"; buttonCreate.Text = "Создать";
buttonCreate.UseVisualStyleBackColor = true; buttonCreate.UseVisualStyleBackColor = true;
@ -61,9 +65,10 @@
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.left; buttonLeft.BackgroundImage = Properties.Resources.left;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(785, 510); buttonLeft.Location = new Point(897, 680);
buttonLeft.Margin = new Padding(3, 4, 3, 4);
buttonLeft.Name = "buttonLeft"; buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(35, 35); buttonLeft.Size = new Size(40, 47);
buttonLeft.TabIndex = 2; buttonLeft.TabIndex = 2;
buttonLeft.UseVisualStyleBackColor = true; buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.ClientSizeChanged += FormAirFighter_SizeChanged; buttonLeft.ClientSizeChanged += FormAirFighter_SizeChanged;
@ -74,9 +79,10 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.up; buttonUp.BackgroundImage = Properties.Resources.up;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch; buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(828, 469); buttonUp.Location = new Point(946, 625);
buttonUp.Margin = new Padding(3, 4, 3, 4);
buttonUp.Name = "buttonUp"; buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(35, 35); buttonUp.Size = new Size(40, 47);
buttonUp.TabIndex = 3; buttonUp.TabIndex = 3;
buttonUp.UseVisualStyleBackColor = true; buttonUp.UseVisualStyleBackColor = true;
buttonUp.ClientSizeChanged += FormAirFighter_SizeChanged; buttonUp.ClientSizeChanged += FormAirFighter_SizeChanged;
@ -87,9 +93,10 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.down; buttonDown.BackgroundImage = Properties.Resources.down;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch; buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(828, 510); buttonDown.Location = new Point(946, 680);
buttonDown.Margin = new Padding(3, 4, 3, 4);
buttonDown.Name = "buttonDown"; buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(35, 35); buttonDown.Size = new Size(40, 47);
buttonDown.TabIndex = 4; buttonDown.TabIndex = 4;
buttonDown.UseVisualStyleBackColor = true; buttonDown.UseVisualStyleBackColor = true;
buttonDown.ClientSizeChanged += FormAirFighter_SizeChanged; buttonDown.ClientSizeChanged += FormAirFighter_SizeChanged;
@ -100,9 +107,10 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.right; buttonRight.BackgroundImage = Properties.Resources.right;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch; buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(869, 510); buttonRight.Location = new Point(993, 680);
buttonRight.Margin = new Padding(3, 4, 3, 4);
buttonRight.Name = "buttonRight"; buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(35, 35); buttonRight.Size = new Size(40, 47);
buttonRight.TabIndex = 5; buttonRight.TabIndex = 5;
buttonRight.UseVisualStyleBackColor = true; buttonRight.UseVisualStyleBackColor = true;
buttonRight.ClientSizeChanged += FormAirFighter_SizeChanged; buttonRight.ClientSizeChanged += FormAirFighter_SizeChanged;
@ -110,15 +118,16 @@
// //
// FormAirFighter // FormAirFighter
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(924, 557); ClientSize = new Size(1056, 743);
Controls.Add(buttonRight); Controls.Add(buttonRight);
Controls.Add(buttonDown); Controls.Add(buttonDown);
Controls.Add(buttonUp); Controls.Add(buttonUp);
Controls.Add(buttonLeft); Controls.Add(buttonLeft);
Controls.Add(buttonCreate); Controls.Add(buttonCreate);
Controls.Add(pictureBoxAirFighter); Controls.Add(pictureBoxAirFighter);
Margin = new Padding(3, 4, 3, 4);
Name = "FormAirFighter"; Name = "FormAirFighter";
Text = "Истребитель"; Text = "Истребитель";
SizeChanged += FormAirFighter_SizeChanged; SizeChanged += FormAirFighter_SizeChanged;

View File

@ -11,6 +11,8 @@ using System.Windows.Forms;
namespace ProjectAirFighter namespace ProjectAirFighter
{ {
public partial class FormAirFighter : Form public partial class FormAirFighter : Form
{ {
private DrawningAirFighter? _drawningAirFighter; private DrawningAirFighter? _drawningAirFighter;
@ -35,13 +37,13 @@ namespace ProjectAirFighter
_drawningAirFighter = new DrawningAirFighter(); _drawningAirFighter = new DrawningAirFighter();
_entityAirFighter = new EntityAirFighter(); _entityAirFighter = new EntityAirFighter();
_drawningAirFighter.Init(random.Next(100, 300), random.Next(1000, 3000), _entityAirFighter.Init(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
_drawningAirFighter.Init(_entityAirFighter);
_drawningAirFighter.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); _drawningAirFighter.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
_drawningAirFighter.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); _drawningAirFighter.SetPosition(random.Next(40, 100), random.Next(40, 100));
_drawningAirFighter.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw(); Draw();
} }