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

This commit is contained in:
Hells Hound 2022-09-17 11:17:47 +04:00
parent 7e743b4b3b
commit 629f4919c0
4 changed files with 11 additions and 13 deletions

View File

@ -45,10 +45,9 @@ namespace AircraftCarrier
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес военного корабля</param>
/// <param name="bodyColor">Цвет главной палубы</param>
public void Init(int speed, float weight, Color bodyColor)
public DrawingWarship(int speed, float weight, Color bodyColor)
{
Warship = new EntityWarship();
Warship.Init(speed, weight, bodyColor);
Warship = new EntityWarship(speed, weight, bodyColor);
}
/// <summary>
/// Установка позиции военного корабля

View File

@ -33,7 +33,7 @@ namespace AircraftCarrier
/// <param name="speed"></param>
/// <param name="weight"></param>
/// <param name="bodyColor"></param>
public void Init(int speed, float weight, Color bodyColor)
public EntityWarship(int speed, float weight, Color bodyColor)
{
Random rnd = new();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;

View File

@ -47,7 +47,7 @@
this.pictureBoxWarship.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxWarship.Location = new System.Drawing.Point(0, 0);
this.pictureBoxWarship.Name = "pictureBoxWarship";
this.pictureBoxWarship.Size = new System.Drawing.Size(510, 426);
this.pictureBoxWarship.Size = new System.Drawing.Size(768, 426);
this.pictureBoxWarship.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxWarship.TabIndex = 0;
this.pictureBoxWarship.TabStop = false;
@ -61,7 +61,7 @@
this.toolStripStatusLabelBodyColor});
this.statusStrip.Location = new System.Drawing.Point(0, 426);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(510, 22);
this.statusStrip.Size = new System.Drawing.Size(768, 22);
this.statusStrip.TabIndex = 1;
//
// toolStripStatusLabelSpeed
@ -98,7 +98,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(428, 386);
this.buttonDown.Location = new System.Drawing.Point(686, 386);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 3;
@ -111,7 +111,7 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(428, 350);
this.buttonUp.Location = new System.Drawing.Point(686, 350);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 4;
@ -124,7 +124,7 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(392, 386);
this.buttonLeft.Location = new System.Drawing.Point(650, 386);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 5;
@ -137,7 +137,7 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(464, 386);
this.buttonRight.Location = new System.Drawing.Point(722, 386);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 6;
@ -149,7 +149,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(510, 448);
this.ClientSize = new System.Drawing.Size(768, 448);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonUp);

View File

@ -25,8 +25,7 @@ namespace AircraftCarrier
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
_warship = new DrawingWarship();
_warship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_warship = new DrawingWarship(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_warship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxWarship.Width, pictureBoxWarship.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_warship.Warship.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_warship.Warship.Weight}";