Оформленная работа

This commit is contained in:
Данила Мочалов 2022-09-13 17:13:08 +04:00
parent 4f70dc343c
commit 79d879bc9f
3 changed files with 10 additions and 9 deletions

View File

@ -25,9 +25,9 @@ namespace Locomotive
private readonly int _locomotiveHeight = 50;
/// Инициализация свойств
public void Init(int speed, float weight, Color bodyColor)
public void Init(int speed, float weight, Color bodyColor, EntityLocomotive entity)
{
Locomotive = new EntityLocomotive();
Locomotive = entity;
Locomotive.Init(speed, weight, bodyColor);
}
/// Установка позиции локомотива
@ -101,9 +101,9 @@ namespace Locomotive
//тело
g.DrawRectangle(pen, _startPosX , _startPosY, _locomotiveWidth - 10, _locomotiveHeight - 10);
//окна
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 10, 10, 10);
g.DrawRectangle(pen, _startPosX + 30, _startPosY + 10, 10, 10);
g.DrawRectangle(pen, _startPosX + 80, _startPosY + 10, 10, 10);
g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 10, _startPosY + 10, 10, 10);
g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 30, _startPosY + 10, 10, 10);
g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 80, _startPosY + 10, 10, 10);
//дверь
g.DrawRectangle(pen, _startPosX + 50, _startPosY + 10, 10, 20);
//колеса
@ -112,7 +112,7 @@ namespace Locomotive
g.DrawEllipse(pen, _startPosX + 70, _startPosY + 40, 10, 10);
g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 10, 10);
//черный прямоугольник
g.FillRectangle(new SolidBrush(Color.Black), _startPosX + 100, _startPosY + 10, 10, 30);
g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 100, _startPosY + 10, 10, 30);
}
public void ChangeBorders(int width, int height)

View File

@ -51,7 +51,7 @@
this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxLocomotive.TabIndex = 0;
this.pictureBoxLocomotive.TabStop = false;
//this.pictureBoxLocomotive.Click += new System.EventHandler(this.pictureBoxLocomotive_Click);
this.pictureBoxLocomotive.Resize += new System.EventHandler(this.pictureBoxLocomotive_Resize);
//
// statusStrip1

View File

@ -3,6 +3,7 @@ namespace Locomotive
public partial class FormLocomotive : Form
{
private DrawningLocomotive _locomotive;
private EntityLocomotive _entity;
public FormLocomotive()
{
@ -22,7 +23,8 @@ namespace Locomotive
{
Random rnd = new();
_locomotive = new DrawningLocomotive();
_locomotive.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_entity = new EntityLocomotive();
_locomotive.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), _entity);
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}";
toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}";
@ -52,7 +54,6 @@ namespace Locomotive
Draw();
}
private void pictureBoxLocomotive_Click() { }
private void pictureBoxLocomotive_Resize(object sender, EventArgs e)
{
_locomotive?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);