ISEbd-21 Nikolay Gapon LabWork01 HARD #1

Closed
NikGapon wants to merge 8 commits from LabWork01 into master
5 changed files with 76 additions and 75 deletions
Showing only changes of commit 7b9ea10ad1 - Show all commits

View File

@ -6,10 +6,11 @@ using System.Threading.Tasks;
namespace Airbus
{
internal class DrawningAirbus
internal class DrawningAirplane
{
/// Класс-сущность
public EntityAirbus airbus { private set; get; }
public EntityAirplane airplane { private set; get; }
public DrawningPorthole porthole { private set; get; }
/// Левая координата отрисовки автомобиля
private float _startPosX;
@ -20,21 +21,21 @@ namespace Airbus
/// Высота окна отрисовки
private int? _pictureHeight = null;
/// Ширина отрисовки автомобиля
private readonly int _airbusWidth = 150; //Ширина отрисовки корабля
private readonly int _airbusHeight = 30; //Высота отрисовки корабля
private readonly int _airplaneWidth = 150; //Ширина отрисовки корабля
private readonly int _airplaneHeight = 30; //Высота отрисовки корабля
public void Init(int speed, float weight, Color bodyColor)
{
airbus = new EntityAirbus();
airplane = new EntityAirplane();
porthole = new DrawningPorthole();
airbus.Init(speed, weight, bodyColor);
airplane.Init(speed, weight, bodyColor);
}
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();
_startPosX = x < 0 || x + _airbusWidth > width ? random.Next(0, width - _airbusWidth) : x;
_startPosY = y < 0 || y + _airbusHeight > height ? random.Next(0, height - _airbusHeight) : y;
_startPosX = x < 0 || x + _airplaneWidth > width ? random.Next(0, width - _airplaneWidth) : x;
_startPosY = y < 0 || y + _airplaneHeight > height ? random.Next(0, height - _airplaneHeight) : y;
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
@ -51,38 +52,37 @@ namespace Airbus
{
case Direction.Left: //Влево
if (_startPosX - airbus.Step > 0) _startPosX -= airbus.Step;
if (_startPosX - airplane.Step > 0) _startPosX -= airplane.Step;
break;
case Direction.Up: //Вверх
if (_startPosY - airbus.Step > 0) _startPosY -= airbus.Step;
if (_startPosY - airplane.Step > 0) _startPosY -= airplane.Step;
break;
case Direction.Right: //Вправо
if (_startPosX + _airbusWidth + airbus.Step - 6 < _pictureWidth) _startPosX += airbus.Step;
if (_startPosX + _airplaneWidth + airplane.Step - 6 < _pictureWidth) _startPosX += airplane.Step;
break;
case Direction.Down: //Вниз
if (_startPosY + _airbusHeight + airbus.Step + 25 < _pictureHeight) _startPosY += airbus.Step;
if (_startPosY + _airplaneHeight + airplane.Step + 25 < _pictureHeight) _startPosY += airplane.Step;
break;
}
}
public void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
return;
}
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[]
{
new Point((int)(_startPosX + _airbusWidth - 25), (int)(_startPosY + 25)),
new Point((int)(_startPosX + _airbusWidth), (int)(_startPosY + 40)),
new Point((int)(_startPosX + _airbusWidth - 25), (int)(_startPosY + 55)),
new Point((int)(_startPosX + _airbusWidth - 25), (int)(_startPosY + 15)),
new Point((int)(_startPosX + _airplaneWidth - 25), (int)(_startPosY + 25)),
new Point((int)(_startPosX + _airplaneWidth), (int)(_startPosY + 40)),
new Point((int)(_startPosX + _airplaneWidth - 25), (int)(_startPosY + 55)),
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[]
{
new Point((int)(_startPosX), (int)(_startPosY)),
@ -91,10 +91,9 @@ namespace Airbus
new Point((int)(_startPosX), (int)(_startPosY)),
});
g.DrawEllipse(new(Color.Blue, 2), _startPosX, _startPosY + 15, 25, 5);
g.DrawEllipse(new(Color.Black, 2), _startPosX + _airbusWidth - 30, _startPosY + _airbusHeight + 25, 4, 4);
g.DrawEllipse(new(Color.Black, 2), _startPosX + _airbusWidth - 35, _startPosY + _airbusHeight + 25, 4, 4);
g.DrawEllipse(new(Color.Black, 2), _startPosX , _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 + _airplaneWidth - 35, _startPosY + _airplaneHeight + 25, 4, 4);
g.DrawEllipse(new(Color.Black, 2), _startPosX , _startPosY + _airplaneHeight + 25, 4, 4);
porthole.DrawPorthole(g, Color.Red, _startPosX, _startPosY);
}
@ -102,21 +101,20 @@ namespace Airbus
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _airbusWidth || _pictureHeight <= _airbusHeight)
if (_pictureWidth <= _airplaneWidth || _pictureHeight <= _airplaneHeight)
{
_pictureWidth = null;
_pictureHeight = null;
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
{
internal class EntityAirbus
internal class EntityAirplane
{
public int Speed { get; private set; } //Скорость
public float Weight { get; private set; } //Вес

View File

@ -1,6 +1,6 @@
namespace Airbus
{
partial class FormAirbus
partial class FormAirplane
{
/// <summary>
/// Required designer variable.
@ -129,18 +129,6 @@
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.v4;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(719, 390);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(35, 35);
this.buttonDown.TabIndex = 6;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// comboBoxPortholeSer
//
this.comboBoxPortholeSer.FormattingEnabled = true;
@ -155,7 +143,20 @@
this.comboBoxPortholeSer.Text = "Кол-во Иллюминаторов";
this.comboBoxPortholeSer.SelectedIndexChanged += new System.EventHandler(this.comboBoxPortholeSer_SelectedIndexChanged);
//
// FormAirbus
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.v4;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(719, 390);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(35, 35);
this.buttonDown.TabIndex = 6;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// FormAirplane
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
@ -168,7 +169,7 @@
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.pictureBox);
this.Name = "FormAirbus";
this.Name = "FormAirplane";
this.Text = "Airbus";
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
@ -190,4 +191,4 @@
private Button buttonDown;
private ComboBox comboBoxPortholeSer;
}
}
}

View File

@ -8,36 +8,36 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Airbus
{
public partial class FormAirbus : Form
public partial class FormAirplane : Form
{
private DrawningAirbus airbus;
public FormAirbus()
private DrawningAirplane airplane;
public FormAirplane()
{
InitializeComponent();
}
private void Draw()
{
Bitmap bmp = new(pictureBox.Width, pictureBox.Height);
Graphics g = Graphics.FromImage(bmp);
airbus.DrawTransport(g);
airplane.DrawTransport(g);
pictureBox.Image = bmp;
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new Random();
airbus = new DrawningAirbus();
airbus.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);
toolStripStatusLabelSpeed.Text = $"Скорость: {airbus.airbus?.Speed}";
toolStripStatusLabelWight.Text = $"Вес: {airbus.airbus?.Weight}";
toolStripStatusLabelColor.Text = $" : {airbus.airbus?.BodyColor}";
airbus.Upd_count_Porthole(count_porthole);
airplane = new DrawningAirplane();
airplane.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
airplane.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBox.Width, pictureBox.Height);
toolStripStatusLabelSpeed.Text = $"Скорость: {airplane.airplane?.Speed}";
toolStripStatusLabelWight.Text = $"Вес: {airplane.airplane?.Weight}";
toolStripStatusLabelColor.Text = $" : {airplane.airplane?.BodyColor}";
airplane.Upd_count_Porthole(count_porthole);
Draw();
}
@ -48,30 +48,24 @@ namespace Airbus
{
case "buttonLeft":
Console.WriteLine("");
airbus?.MoveTransport(Direction.Left);
airplane?.MoveTransport(Direction.Left);
break;
case "buttonUp":
airbus?.MoveTransport(Direction.Up);
airplane?.MoveTransport(Direction.Up);
break;
case "buttonRight":
airbus?.MoveTransport(Direction.Right);
airplane?.MoveTransport(Direction.Right);
break;
case "buttonDown":
airbus?.MoveTransport(Direction.Down);
airplane?.MoveTransport(Direction.Down);
break;
}
Draw();
}
private void PictureBox_Resize(object sender, EventArgs e)
{
airbus?.ChangeBorders(pictureBox.Width, pictureBox.Height);
Draw();
}
CountPorthole count_porthole = CountPorthole.Ten;
private void comboBoxPortholeSer_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxPortholeSer.Text)
{
@ -85,9 +79,17 @@ namespace Airbus
case "30":
count_porthole = CountPorthole.Thirty;
break;
}
airbus.Upd_count_Porthole(count_porthole);
if (airplane != null)
{
airplane.Upd_count_Porthole(count_porthole);
Draw();
}
}
private void PictureBox_Resize(object sender, EventArgs e)
{
airplane?.ChangeBorders(pictureBox.Width, pictureBox.Height);
Draw();
}
}

View File

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