name fix
This commit is contained in:
parent
a2feace3c1
commit
56e1256a98
@ -6,10 +6,10 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Airbus
|
||||
{
|
||||
internal class DrawningAirbus
|
||||
internal class DrawningAirplane
|
||||
{
|
||||
/// Класс-сущность
|
||||
public EntityAirbus airbus { private set; get; }
|
||||
public EntityAirplane airplane { private set; get; }
|
||||
/// Левая координата отрисовки автомобиля
|
||||
private float _startPosX;
|
||||
/// Верхняя кооридната отрисовки автомобиля
|
||||
@ -19,20 +19,20 @@ 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();
|
||||
airbus.Init(speed, weight, bodyColor);
|
||||
airplane = new EntityAirplane();
|
||||
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;
|
||||
@ -46,16 +46,16 @@ 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;
|
||||
}
|
||||
}
|
||||
@ -68,15 +68,15 @@ namespace Airbus
|
||||
}
|
||||
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)),
|
||||
@ -86,32 +86,32 @@ namespace Airbus
|
||||
});
|
||||
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 + _airbusWidth - 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 - 40, _startPosY + 30, 20, 20);
|
||||
g.DrawEllipse(new(Color.Red, 2), _startPosX + _airplaneWidth - 65, _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 + _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);
|
||||
}
|
||||
|
||||
public void ChangeBorders(int width, int height)
|
||||
{
|
||||
_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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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; } //Вес
|
@ -1,6 +1,6 @@
|
||||
namespace Airbus
|
||||
{
|
||||
partial class FormAirbus
|
||||
partial class FormAirplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
@ -140,7 +140,7 @@
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// FormAirbus
|
||||
// FormAirplane
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
@ -152,7 +152,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();
|
@ -11,11 +11,11 @@ using System.Windows.Forms;
|
||||
|
||||
namespace Airbus
|
||||
{
|
||||
public partial class FormAirbus : Form
|
||||
public partial class FormAirplane : Form
|
||||
{
|
||||
private DrawningAirbus airbus;
|
||||
private DrawningAirplane airplane;
|
||||
|
||||
public FormAirbus()
|
||||
public FormAirplane()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
@ -24,19 +24,19 @@ namespace Airbus
|
||||
{
|
||||
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}";
|
||||
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}";
|
||||
Draw();
|
||||
}
|
||||
|
||||
@ -47,16 +47,16 @@ 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();
|
||||
@ -64,7 +64,7 @@ namespace Airbus
|
||||
|
||||
private void PictureBox_Resize(object sender, EventArgs e)
|
||||
{
|
||||
airbus?.ChangeBorders(pictureBox.Width, pictureBox.Height);
|
||||
airplane?.ChangeBorders(pictureBox.Width, pictureBox.Height);
|
||||
Draw();
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user