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

This commit is contained in:
Никита Чернышов 2022-10-07 16:52:02 +04:00
parent 32e7d7fd5f
commit 8ad0fe65dc
9 changed files with 17 additions and 19 deletions

View File

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.3.32901.215 VisualStudioVersion = 17.3.32901.215
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Warship", "Warship\Warship.csproj", "{9CFF4FD7-9721-45C9-84DC-020B509D6024}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AircraftCarrier", "Warship\AircraftCarrier.csproj", "{9CFF4FD7-9721-45C9-84DC-020B509D6024}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Warship namespace AircraftCarrier
{ {
/// <summary> /// <summary>
/// Направление перемещения /// Направление перемещения

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Warship namespace AircraftCarrier
{ {
/// <summary> /// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности /// Класс, отвечающий за прорисовку и перемещение объекта-сущности
@ -45,10 +45,9 @@ namespace Warship
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
/// <param name="weight">Вес корабля</param> /// <param name="weight">Вес корабля</param>
/// <param name="bodyColor">Цвет</param> /// <param name="bodyColor">Цвет</param>
public void Init(int speed, float weight, Color bodyColor) public DrawingWarship(int speed, float weight, Color bodyColor)
{ {
Ship = new EntityWarship(); Ship = new EntityWarship(speed, weight, bodyColor);
Ship.Init(speed, weight, bodyColor);
} }
/// <summary> /// <summary>
/// Установка позиции корабля /// Установка позиции корабля

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Warship namespace AircraftCarrier
{ {
/// <summary> /// <summary>
/// Класс-сущность "Военный корабль" /// Класс-сущность "Военный корабль"
@ -34,7 +34,7 @@ namespace Warship
/// <param name="weight"></param> /// <param name="weight"></param>
/// <param name="bodyColor"></param> /// <param name="bodyColor"></param>
/// <returns></returns> /// <returns></returns>
public void Init(int speed, float weight, Color bodyColor) public EntityWarship(int speed, float weight, Color bodyColor)
{ {
Random rnd = new Random(); Random rnd = new Random();
Speed = speed <= 0 ? rnd.Next(50, 100) : speed; Speed = speed <= 0 ? rnd.Next(50, 100) : speed;

View File

@ -1,4 +1,4 @@
namespace Warship namespace AircraftCarrier
{ {
partial class FormShip partial class FormShip
{ {
@ -96,7 +96,7 @@
// buttonLeft // buttonLeft
// //
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::Warship.Properties.Resources.стрелка; this.buttonLeft.BackgroundImage = global::AircraftCarrier.Properties.Resources.стрелка;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(657, 375); this.buttonLeft.Location = new System.Drawing.Point(657, 375);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
@ -108,7 +108,7 @@
// buttonDown // buttonDown
// //
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Warship.Properties.Resources.стрелкаbott; this.buttonDown.BackgroundImage = global::AircraftCarrier.Properties.Resources.стрелкаbott;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(693, 375); this.buttonDown.Location = new System.Drawing.Point(693, 375);
this.buttonDown.Name = "buttonDown"; this.buttonDown.Name = "buttonDown";
@ -120,7 +120,7 @@
// buttonUp // buttonUp
// //
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::Warship.Properties.Resources.стрелкаtop; this.buttonUp.BackgroundImage = global::AircraftCarrier.Properties.Resources.стрелкаtop;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(693, 339); this.buttonUp.Location = new System.Drawing.Point(693, 339);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
@ -132,7 +132,7 @@
// buttonRight // buttonRight
// //
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Warship.Properties.Resources.стрелкаright; this.buttonRight.BackgroundImage = global::AircraftCarrier.Properties.Resources.стрелкаright;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(729, 375); this.buttonRight.Location = new System.Drawing.Point(729, 375);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";

View File

@ -1,4 +1,4 @@
namespace Warship namespace AircraftCarrier
{ {
public partial class FormShip : Form public partial class FormShip : Form
{ {
@ -25,8 +25,7 @@ namespace Warship
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_ship = new DrawingWarship(); _ship = new DrawingWarship(rnd.Next(50, 100), rnd.Next(20000, 30000),
_ship.Init(rnd.Next(50, 100), rnd.Next(20000, 30000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), _ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
pictureBoxShip.Width, pictureBoxShip.Height); pictureBoxShip.Width, pictureBoxShip.Height);

View File

@ -1,4 +1,4 @@
namespace Warship namespace AircraftCarrier
{ {
internal static class Program internal static class Program
{ {

View File

@ -8,7 +8,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Warship.Properties { namespace AircraftCarrier.Properties {
using System; using System;
@ -39,7 +39,7 @@ namespace Warship.Properties {
internal static global::System.Resources.ResourceManager ResourceManager { internal static global::System.Resources.ResourceManager ResourceManager {
get { get {
if (object.ReferenceEquals(resourceMan, null)) { if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Warship.Properties.Resources", typeof(Resources).Assembly); global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AircraftCarrier.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp; resourceMan = temp;
} }
return resourceMan; return resourceMan;