Переход на конструкторы

This commit is contained in:
Катя Ихонкина 2022-10-02 12:09:49 +04:00
parent ff46937040
commit 36c2bf68a1
6 changed files with 12 additions and 14 deletions

View File

@ -7,9 +7,9 @@ using System.Threading.Tasks;
namespace MotorBoat
{
class DrawningMotorBoat
class DrawningBoat
{
public EntityMotorBoat Boat { get; private set; }
public EntityBoat Boat { get; private set; }
private float _startPosX;
private float _startPosY;
@ -19,10 +19,9 @@ namespace MotorBoat
private readonly int _boatWidth = 70;
private readonly int _boatHeight = 40;
public void Init(int speed, float weight, Color bodyColor)
public DrawningBoat(int speed, float weight, Color bodyColor)
{
Boat = new EntityMotorBoat();
Boat.Init(speed, weight, bodyColor);
Boat = new EntityBoat(speed, weight, bodyColor);
}
public void SetPosition(int x, int y, int width, int height)
{

View File

@ -7,13 +7,13 @@ using System.Threading.Tasks;
namespace MotorBoat
{
class EntityMotorBoat
class EntityBoat
{
public int Speed { get; private set; }
public float Weight { get; private set; }
public Color BodyColor { get; private set; }
public float Step => Speed * 100 / Weight;
public void Init(int speed, float weight, Color bodyColor)
public EntityBoat(int speed, float weight, Color bodyColor)
{
Random rnd = new Random();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;

View File

@ -1,6 +1,6 @@
namespace MotorBoat
{
partial class FormMotorBoat
partial class FormBoat
{
/// <summary>
/// Required designer variable.

View File

@ -8,10 +8,10 @@ using System.Windows.Forms;
namespace MotorBoat
{
public partial class FormMotorBoat : Form
public partial class FormBoat : Form
{
private DrawningMotorBoat _boat;
public FormMotorBoat()
private DrawningBoat _boat;
public FormBoat()
{
InitializeComponent();
}
@ -19,8 +19,7 @@ namespace MotorBoat
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new Random();
_boat = new DrawningMotorBoat();
_boat.Init(rnd.Next(50, 150), rnd.Next(100, 200), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_boat = new DrawningBoat(rnd.Next(50, 150), rnd.Next(100, 200), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_boat.SetPosition(rnd.Next(10, 100), rnd.Next(0,100), pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_boat.Boat.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_boat.Boat.Weight}";

View File

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