This commit is contained in:
NikGapon 2022-11-05 14:21:44 +04:00
parent a2feace3c1
commit 56e1256a98
6 changed files with 50 additions and 50 deletions

View File

@ -6,10 +6,10 @@ using System.Threading.Tasks;
namespace Airbus namespace Airbus
{ {
internal class DrawningAirbus internal class DrawningAirplane
{ {
/// Класс-сущность /// Класс-сущность
public EntityAirbus airbus { private set; get; } public EntityAirplane airplane { private set; get; }
/// Левая координата отрисовки автомобиля /// Левая координата отрисовки автомобиля
private float _startPosX; private float _startPosX;
/// Верхняя кооридната отрисовки автомобиля /// Верхняя кооридната отрисовки автомобиля
@ -19,20 +19,20 @@ namespace Airbus
/// Высота окна отрисовки /// Высота окна отрисовки
private int? _pictureHeight = null; private int? _pictureHeight = null;
/// Ширина отрисовки автомобиля /// Ширина отрисовки автомобиля
private readonly int _airbusWidth = 150; //Ширина отрисовки корабля private readonly int _airplaneWidth = 150; //Ширина отрисовки корабля
private readonly int _airbusHeight = 30; //Высота отрисовки корабля private readonly int _airplaneHeight = 30; //Высота отрисовки корабля
public void Init(int speed, float weight, Color bodyColor) public void Init(int speed, float weight, Color bodyColor)
{ {
airbus = new EntityAirbus(); airplane = new EntityAirplane();
airbus.Init(speed, weight, bodyColor); airplane.Init(speed, weight, bodyColor);
} }
public void SetPosition(int x, int y, int width, int height) public void SetPosition(int x, int y, int width, int height)
{ {
if (width < _airbusWidth || height < _airbusHeight) return; if (width < _airplaneWidth || height < _airplaneHeight) return;
Random random = new Random(); Random random = new Random();
_startPosX = x < 0 || x + _airbusWidth > width ? random.Next(0, width - _airbusWidth) : x; _startPosX = x < 0 || x + _airplaneWidth > width ? random.Next(0, width - _airplaneWidth) : x;
_startPosY = y < 0 || y + _airbusHeight > height ? random.Next(0, height - _airbusHeight) : y; _startPosY = y < 0 || y + _airplaneHeight > height ? random.Next(0, height - _airplaneHeight) : y;
_startPosX = x; _startPosX = x;
_startPosY = y; _startPosY = y;
_pictureWidth = width; _pictureWidth = width;
@ -46,16 +46,16 @@ namespace Airbus
{ {
case Direction.Left: //Влево case Direction.Left: //Влево
if (_startPosX - airbus.Step > 0) _startPosX -= airbus.Step; if (_startPosX - airplane.Step > 0) _startPosX -= airplane.Step;
break; break;
case Direction.Up: //Вверх case Direction.Up: //Вверх
if (_startPosY - airbus.Step > 0) _startPosY -= airbus.Step; if (_startPosY - airplane.Step > 0) _startPosY -= airplane.Step;
break; break;
case Direction.Right: //Вправо case Direction.Right: //Вправо
if (_startPosX + _airbusWidth + airbus.Step - 6 < _pictureWidth) _startPosX += airbus.Step; if (_startPosX + _airplaneWidth + airplane.Step - 6 < _pictureWidth) _startPosX += airplane.Step;
break; break;
case Direction.Down: //Вниз case Direction.Down: //Вниз
if (_startPosY + _airbusHeight + airbus.Step + 25 < _pictureHeight) _startPosY += airbus.Step; if (_startPosY + _airplaneHeight + airplane.Step + 25 < _pictureHeight) _startPosY += airplane.Step;
break; break;
} }
} }
@ -68,15 +68,15 @@ namespace Airbus
} }
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
SolidBrush brush = new SolidBrush(airbus?.BodyColor ?? Color.White); SolidBrush brush = new SolidBrush(airplane?.BodyColor ?? Color.White);
g.FillPolygon(brush, new[] g.FillPolygon(brush, new[]
{ {
new Point((int)(_startPosX + _airbusWidth - 25), (int)(_startPosY + 25)), new Point((int)(_startPosX + _airplaneWidth - 25), (int)(_startPosY + 25)),
new Point((int)(_startPosX + _airbusWidth), (int)(_startPosY + 40)), new Point((int)(_startPosX + _airplaneWidth), (int)(_startPosY + 40)),
new Point((int)(_startPosX + _airbusWidth - 25), (int)(_startPosY + 55)), new Point((int)(_startPosX + _airplaneWidth - 25), (int)(_startPosY + 55)),
new Point((int)(_startPosX + _airbusWidth - 25), (int)(_startPosY + 15)), new Point((int)(_startPosX + _airplaneWidth - 25), (int)(_startPosY + 15)),
}); });
g.FillRectangle(brush, _startPosX, _startPosY + 25, _airbusWidth - 25, _airbusHeight ); g.FillRectangle(brush, _startPosX, _startPosY + 25, _airplaneWidth - 25, _airplaneHeight);
g.DrawPolygon(pen, new[] g.DrawPolygon(pen, new[]
{ {
new Point((int)(_startPosX), (int)(_startPosY)), new Point((int)(_startPosX), (int)(_startPosY)),
@ -86,32 +86,32 @@ namespace Airbus
}); });
g.DrawEllipse(new(Color.Blue, 2), _startPosX, _startPosY + 15, 25, 5); g.DrawEllipse(new(Color.Blue, 2), _startPosX, _startPosY + 15, 25, 5);
g.DrawEllipse(new(Color.Red, 2), _startPosX + _airbusWidth - 40, _startPosY + 30, 20, 20); g.DrawEllipse(new(Color.Red, 2), _startPosX + _airplaneWidth - 40, _startPosY + 30, 20, 20);
g.DrawEllipse(new(Color.Red, 2), _startPosX + _airbusWidth - 65, _startPosY + 30, 20, 20); g.DrawEllipse(new(Color.Red, 2), _startPosX + _airplaneWidth - 65, _startPosY + 30, 20, 20);
g.DrawEllipse(new(Color.Red, 2), _startPosX + _airbusWidth - 90, _startPosY + 30, 20, 20); g.DrawEllipse(new(Color.Red, 2), _startPosX + _airplaneWidth - 90, _startPosY + 30, 20, 20);
g.DrawEllipse(new(Color.Black, 2), _startPosX + _airbusWidth - 30, _startPosY + _airbusHeight + 25, 4, 4); g.DrawEllipse(new(Color.Black, 2), _startPosX + _airplaneWidth - 30, _startPosY + _airplaneHeight + 25, 4, 4);
g.DrawEllipse(new(Color.Black, 2), _startPosX + _airbusWidth - 35, _startPosY + _airbusHeight + 25, 4, 4); g.DrawEllipse(new(Color.Black, 2), _startPosX + _airplaneWidth - 35, _startPosY + _airplaneHeight + 25, 4, 4);
g.DrawEllipse(new(Color.Black, 2), _startPosX , _startPosY + _airbusHeight + 25, 4, 4); g.DrawEllipse(new(Color.Black, 2), _startPosX , _startPosY + _airplaneHeight + 25, 4, 4);
} }
public void ChangeBorders(int width, int height) public void ChangeBorders(int width, int height)
{ {
_pictureWidth = width; _pictureWidth = width;
_pictureHeight = height; _pictureHeight = height;
if (_pictureWidth <= _airbusWidth || _pictureHeight <= _airbusHeight) if (_pictureWidth <= _airplaneWidth || _pictureHeight <= _airplaneHeight)
{ {
_pictureWidth = null; _pictureWidth = null;
_pictureHeight = null; _pictureHeight = null;
return; return;
} }
if (_startPosX + _airbusWidth > _pictureWidth) if (_startPosX + _airplaneWidth > _pictureWidth)
{ {
_startPosX = _pictureWidth.Value - _airbusWidth; _startPosX = _pictureWidth.Value - _airplaneWidth;
} }
if (_startPosY + _airbusHeight > _pictureHeight) if (_startPosY + _airplaneHeight > _pictureHeight)
{ {
_startPosY = _pictureHeight.Value - _airbusHeight; _startPosY = _pictureHeight.Value - _airplaneHeight;
} }
} }
} }

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Airbus namespace Airbus
{ {
internal class EntityAirbus internal class EntityAirplane
{ {
public int Speed { get; private set; } //Скорость public int Speed { get; private set; } //Скорость
public float Weight { get; private set; } //Вес public float Weight { get; private set; } //Вес

View File

@ -1,6 +1,6 @@
namespace Airbus namespace Airbus
{ {
partial class FormAirbus partial class FormAirplane
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
@ -140,7 +140,7 @@
this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// FormAirbus // FormAirplane
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
@ -152,7 +152,7 @@
this.Controls.Add(this.buttonCreate); this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.statusStrip1); this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.pictureBox); this.Controls.Add(this.pictureBox);
this.Name = "FormAirbus"; this.Name = "FormAirplane";
this.Text = "Airbus"; this.Text = "Airbus";
this.statusStrip1.ResumeLayout(false); this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout(); this.statusStrip1.PerformLayout();

View File

@ -11,11 +11,11 @@ using System.Windows.Forms;
namespace Airbus namespace Airbus
{ {
public partial class FormAirbus : Form public partial class FormAirplane : Form
{ {
private DrawningAirbus airbus; private DrawningAirplane airplane;
public FormAirbus() public FormAirplane()
{ {
InitializeComponent(); InitializeComponent();
} }
@ -24,19 +24,19 @@ namespace Airbus
{ {
Bitmap bmp = new(pictureBox.Width, pictureBox.Height); Bitmap bmp = new(pictureBox.Width, pictureBox.Height);
Graphics g = Graphics.FromImage(bmp); Graphics g = Graphics.FromImage(bmp);
airbus.DrawTransport(g); airplane.DrawTransport(g);
pictureBox.Image = bmp; pictureBox.Image = bmp;
} }
private void buttonCreate_Click(object sender, EventArgs e) private void buttonCreate_Click(object sender, EventArgs e)
{ {
Random random = new Random(); Random random = new Random();
airbus = new DrawningAirbus(); airplane = new DrawningAirplane();
airbus.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); airplane.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
airbus.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBox.Width, pictureBox.Height); airplane.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBox.Width, pictureBox.Height);
toolStripStatusLabelSpeed.Text = $"Скорость: {airbus.airbus?.Speed}"; toolStripStatusLabelSpeed.Text = $"Скорость: {airplane.airplane?.Speed}";
toolStripStatusLabelWight.Text = $"Вес: {airbus.airbus?.Weight}"; toolStripStatusLabelWight.Text = $"Вес: {airplane.airplane?.Weight}";
toolStripStatusLabelColor.Text = $" : {airbus.airbus?.BodyColor}"; toolStripStatusLabelColor.Text = $" : {airplane.airplane?.BodyColor}";
Draw(); Draw();
} }
@ -47,16 +47,16 @@ namespace Airbus
{ {
case "buttonLeft": case "buttonLeft":
Console.WriteLine(""); Console.WriteLine("");
airbus?.MoveTransport(Direction.Left); airplane?.MoveTransport(Direction.Left);
break; break;
case "buttonUp": case "buttonUp":
airbus?.MoveTransport(Direction.Up); airplane?.MoveTransport(Direction.Up);
break; break;
case "buttonRight": case "buttonRight":
airbus?.MoveTransport(Direction.Right); airplane?.MoveTransport(Direction.Right);
break; break;
case "buttonDown": case "buttonDown":
airbus?.MoveTransport(Direction.Down); airplane?.MoveTransport(Direction.Down);
break; break;
} }
Draw(); Draw();
@ -64,7 +64,7 @@ namespace Airbus
private void PictureBox_Resize(object sender, EventArgs e) private void PictureBox_Resize(object sender, EventArgs e)
{ {
airbus?.ChangeBorders(pictureBox.Width, pictureBox.Height); airplane?.ChangeBorders(pictureBox.Width, pictureBox.Height);
Draw(); Draw();
} }
} }

View File

@ -11,7 +11,7 @@ namespace Airbus
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormAirbus()); Application.Run(new FormAirplane());
} }
} }
} }