Переход на конструкторы
This commit is contained in:
parent
79d879bc9f
commit
da86c334a4
@ -25,10 +25,9 @@ namespace Locomotive
|
|||||||
private readonly int _locomotiveHeight = 50;
|
private readonly int _locomotiveHeight = 50;
|
||||||
|
|
||||||
/// Инициализация свойств
|
/// Инициализация свойств
|
||||||
public void Init(int speed, float weight, Color bodyColor, EntityLocomotive entity)
|
public DrawningLocomotive(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Locomotive = entity;
|
Locomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||||||
Locomotive.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)
|
||||||
|
@ -17,7 +17,7 @@ namespace Locomotive
|
|||||||
/// Шаг перемещения локомотива
|
/// Шаг перемещения локомотива
|
||||||
public float Step => Speed * 100 / Weight;
|
public float Step => Speed * 100 / Weight;
|
||||||
|
|
||||||
public void Init(int speed, float weight, Color bodyColor)
|
public EntityLocomotive(int speed, float weight, Color bodyColor)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||||
|
@ -3,7 +3,6 @@ namespace Locomotive
|
|||||||
public partial class FormLocomotive : Form
|
public partial class FormLocomotive : Form
|
||||||
{
|
{
|
||||||
private DrawningLocomotive _locomotive;
|
private DrawningLocomotive _locomotive;
|
||||||
private EntityLocomotive _entity;
|
|
||||||
|
|
||||||
public FormLocomotive()
|
public FormLocomotive()
|
||||||
{
|
{
|
||||||
@ -22,9 +21,7 @@ namespace Locomotive
|
|||||||
private void buttonCreate_Click(object sender, EventArgs e)
|
private void buttonCreate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
_locomotive = new DrawningLocomotive();
|
_locomotive = new DrawningLocomotive(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);
|
_locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
|
||||||
toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}";
|
toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}";
|
||||||
toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}";
|
toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}";
|
||||||
|
Loading…
Reference in New Issue
Block a user