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

This commit is contained in:
Алина Батылкина 2022-10-04 19:09:23 +04:00
parent 7865c256dc
commit 59f5022d99
3 changed files with 4 additions and 6 deletions

View File

@ -12,10 +12,9 @@
private int? _pictureHeight = null;
private readonly int _shipWidth = 80;
private readonly int _shipHeight = 50;
public void Init(int speed, float weight, Color сolor)
public DrawningShip(int speed, float weight, Color сolor)
{
Ship = new EntityShip();
Ship.Init(speed, weight, сolor);
Ship = new EntityShip(speed, weight, сolor);
}
public void SetPosition(int x, int y, int width, int height)
{

View File

@ -19,7 +19,7 @@
/// </summary>
public float Step => Speed * 100 / Weight;
public void Init(int speed, float weight, Color сolor)
public EntityShip(int speed, float weight, Color сolor)
{
Random rnd = new();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;

View File

@ -17,8 +17,7 @@ namespace WarmlyShip
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
_ship = new DrawningShip();
_ship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_ship = new DrawningShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
toolStripStatusSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";
toolStripStatusWeight.Text = $"Âåñ: {_ship.Ship.Weight}";