diff --git a/ProjectMotorBoat/ProjectMotorBoat/DirectionType.cs b/ProjectMotorBoat/ProjectMotorBoat/DirectionType.cs new file mode 100644 index 0000000..af7b6d7 --- /dev/null +++ b/ProjectMotorBoat/ProjectMotorBoat/DirectionType.cs @@ -0,0 +1,24 @@ +namespace ProjectMotorBoat; + +/// +/// Направление перемещения +/// +public enum DirectionType +{ + /// + /// Вверх + /// + Up = 1, + /// + /// Вниз + /// + Down = 2, + /// + /// Влево + /// + Left = 3, + /// + /// Вправо + /// + Right = 4 +} \ No newline at end of file diff --git a/ProjectMotorBoat/ProjectMotorBoat/DrawingMotorBoat.cs b/ProjectMotorBoat/ProjectMotorBoat/DrawingMotorBoat.cs new file mode 100644 index 0000000..6345e59 --- /dev/null +++ b/ProjectMotorBoat/ProjectMotorBoat/DrawingMotorBoat.cs @@ -0,0 +1,158 @@ +namespace ProjectMotorBoat; + +/// +/// Класс, отвечающий за прорисовку и перемещение объекта-сущности +/// +public class DrawingMotorBoat +{ + /// + /// Класс-сущность + /// + public EntityMotorBoat? EntityMotorBoat { get; private set; } + + /// + /// Ширина окна + /// + private int? _pictureWidth; + + /// + /// Высота окна + /// + private int? _pictureHeight; + + /// + /// Левая координата прорисовки катера + /// + private int? _startPosX; + + /// + /// Верхняя кооридната прорисовки катера + /// + private int? _startPosY; + + + /// + /// Ширина прорисовки катера + /// + private readonly int _drawningBoatWidth = 110; + + /// + /// Высота прорисовки катера + /// + private readonly int _drawningBoatHeight = 60; + + /// + /// Инициализация свойств + /// + /// + /// + /// + /// + /// + /// + /// + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool inboardEngine, bool paddle, bool protectiveGlass) + { + EntityMotorBoat = new EntityMotorBoat(); + EntityMotorBoat.Init(speed, weight, bodyColor, additionalColor, inboardEngine, paddle, protectiveGlass); + _pictureWidth = null; + _pictureHeight = null; + _startPosX = null; + _startPosY = null; + } + + /// + /// Установка границ поля + /// + /// Ширина поля + /// Высота поля + /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах + public bool SetPictureSize(int width, int height) + { + // TODO проверка, что объект "влезает" в размеры поля + // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена + _pictureWidth = width; + _pictureHeight = height; + return true; + } + + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + // TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы + // то надо изменить координаты, чтобы он оставался в этих границах + _startPosX = x; + _startPosY = y; + } + + /// + /// Изменение направления перемещения + /// + /// Направление + /// true - перемещене выполнено, false - перемещение невозможно + public bool MoveTransport(DirectionType direction) + { + if (EntityMotorBoat == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return false; + } + + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX.Value - EntityMotorBoat.Step > 0) + { + _startPosX -= (int)EntityMotorBoat.Step; + } + return true; + //вверх + case DirectionType.Up: + if (_startPosY.Value - EntityMotorBoat.Step > 0) + { + _startPosY -= (int)EntityMotorBoat.Step; + } + return true; + // вправо + case DirectionType.Right: + //TODO прописать логику сдвига в право + + //if (_startPosX.Value + EntityMotorBoat.Step < _pictureWidth) + //{ + // _startPosX += (int)EntityMotorBoat.Step; + //} + return true; + //вниз + case DirectionType.Down: + //TODO прописать логику сдвига в низ + + //if (_startPosY.Value + EntityMotorBoat.Step < _pictureHeight) + //{ + // _startPosY += (int)EntityMotorBoat.Step; + //} + return true; + default: + return false; + } + } + + /// + /// Прорисовка объекта + /// + /// + public void DrawTransport(Graphics g) + { + if (EntityMotorBoat == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + } +} \ No newline at end of file diff --git a/ProjectMotorBoat/ProjectMotorBoat/EntityMotorBoat.cs b/ProjectMotorBoat/ProjectMotorBoat/EntityMotorBoat.cs new file mode 100644 index 0000000..9d238ad --- /dev/null +++ b/ProjectMotorBoat/ProjectMotorBoat/EntityMotorBoat.cs @@ -0,0 +1,68 @@ +namespace ProjectMotorBoat; + +/// +/// Класс-сущность "Катер" +/// +public class EntityMotorBoat +{ + /// + /// Скорость + /// + public int Speed { get; private set; } + + /// + /// Вес + /// + public double Weight { get; private set; } + + /// + /// Основной цвет + /// + public Color BodyColor { get; private set; } + + /// + /// Дополнительный цвет (для опциональных элементов) + /// + public Color AdditionalColor { get; private set; } + + /// + /// Признак (опция) наличия внутреннего двигателя + /// + public bool InboardEngine { get; private set; } + + /// + /// Признак (опция) наличия вёсел + /// + public bool Paddle { get; private set; } + + /// + /// Возможность глиссирования + /// + public bool ProtectiveGlass { get; private set; } + + /// + /// Шаг перемещения катера + /// + public double Step => Speed * 100 / Weight; + + /// + /// Инициализация полей объекта-класса катера + /// + /// + /// + /// + /// + /// + /// + /// + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool inboardEngine, bool paddle, bool protectiveGlass) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + InboardEngine = inboardEngine; + Paddle = paddle; + ProtectiveGlass = protectiveGlass; + } +} \ No newline at end of file diff --git a/ProjectMotorBoat/ProjectMotorBoat/Form1.Designer.cs b/ProjectMotorBoat/ProjectMotorBoat/Form1.Designer.cs deleted file mode 100644 index 0bbb677..0000000 --- a/ProjectMotorBoat/ProjectMotorBoat/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ProjectMotorBoat -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/ProjectMotorBoat/ProjectMotorBoat/Form1.cs b/ProjectMotorBoat/ProjectMotorBoat/Form1.cs deleted file mode 100644 index 3c8c336..0000000 --- a/ProjectMotorBoat/ProjectMotorBoat/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ProjectMotorBoat -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/ProjectMotorBoat/ProjectMotorBoat/FormMotorBoat.Designer.cs b/ProjectMotorBoat/ProjectMotorBoat/FormMotorBoat.Designer.cs new file mode 100644 index 0000000..55dd971 --- /dev/null +++ b/ProjectMotorBoat/ProjectMotorBoat/FormMotorBoat.Designer.cs @@ -0,0 +1,132 @@ +namespace ProjectMotorBoat +{ + partial class FormMotorBoat + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + pictureBoxMotorBoat = new PictureBox(); + buttonCreate = new Button(); + buttonLeft = new Button(); + buttonUp = new Button(); + buttonRight = new Button(); + buttonDown = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxMotorBoat).BeginInit(); + SuspendLayout(); + // + // pictureBoxMotorBoat + // + pictureBoxMotorBoat.Dock = DockStyle.Fill; + pictureBoxMotorBoat.Location = new Point(0, 0); + pictureBoxMotorBoat.Name = "pictureBoxMotorBoat"; + pictureBoxMotorBoat.Size = new Size(956, 483); + pictureBoxMotorBoat.SizeMode = PictureBoxSizeMode.AutoSize; + pictureBoxMotorBoat.TabIndex = 0; + pictureBoxMotorBoat.TabStop = false; + // + // buttonCreate + // + buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreate.Location = new Point(12, 448); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(75, 23); + buttonCreate.TabIndex = 1; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonCreate_Click; + // + // buttonLeft + // + buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonLeft.BackgroundImage = Properties.Resources.arrowLeft; + buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; + buttonLeft.Location = new Point(814, 436); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(35, 35); + buttonLeft.TabIndex = 2; + buttonLeft.UseVisualStyleBackColor = true; + // + // buttonUp + // + buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonUp.BackgroundImage = Properties.Resources.arrowUp; + buttonUp.BackgroundImageLayout = ImageLayout.Stretch; + buttonUp.Location = new Point(855, 395); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(35, 35); + buttonUp.TabIndex = 3; + buttonUp.UseVisualStyleBackColor = true; + // + // buttonRight + // + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackgroundImage = Properties.Resources.arrowRight; + buttonRight.BackgroundImageLayout = ImageLayout.Stretch; + buttonRight.Location = new Point(896, 436); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(35, 35); + buttonRight.TabIndex = 4; + buttonRight.UseVisualStyleBackColor = true; + // + // buttonDown + // + buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonDown.BackgroundImage = Properties.Resources.arrowDown; + buttonDown.BackgroundImageLayout = ImageLayout.Stretch; + buttonDown.Location = new Point(855, 436); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(35, 35); + buttonDown.TabIndex = 5; + buttonDown.UseVisualStyleBackColor = true; + // + // FormMotorBoat + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(956, 483); + Controls.Add(buttonDown); + Controls.Add(buttonRight); + Controls.Add(buttonUp); + Controls.Add(buttonLeft); + Controls.Add(buttonCreate); + Controls.Add(pictureBoxMotorBoat); + Name = "FormMotorBoat"; + Text = "Катер"; + ((System.ComponentModel.ISupportInitialize)pictureBoxMotorBoat).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private PictureBox pictureBoxMotorBoat; + private Button buttonCreate; + private Button buttonLeft; + private Button buttonUp; + private Button buttonRight; + private Button buttonDown; + } +} \ No newline at end of file diff --git a/ProjectMotorBoat/ProjectMotorBoat/FormMotorBoat.cs b/ProjectMotorBoat/ProjectMotorBoat/FormMotorBoat.cs new file mode 100644 index 0000000..b5d45a2 --- /dev/null +++ b/ProjectMotorBoat/ProjectMotorBoat/FormMotorBoat.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectMotorBoat +{ + public partial class FormMotorBoat : Form + { + private DrawingMotorBoat? _drawingMotorBoat; + + public FormMotorBoat() + { + InitializeComponent(); + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + _drawingMotorBoat = new DrawingMotorBoat(); + _drawingMotorBoat.Init(random.Next(100, 300), random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), + Convert.ToBoolean(random.Next(0, 2))); + _drawingMotorBoat.SetPictureSize(pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height); + _drawingMotorBoat.SetPosition(random.Next(10, 100), random.Next(10, 100)); + + Bitmap bmp = new(pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawingMotorBoat.DrawTransport(gr); + pictureBoxMotorBoat.Image = bmp; + + } + } +} diff --git a/ProjectMotorBoat/ProjectMotorBoat/FormMotorBoat.resx b/ProjectMotorBoat/ProjectMotorBoat/FormMotorBoat.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectMotorBoat/ProjectMotorBoat/FormMotorBoat.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectMotorBoat/ProjectMotorBoat/Program.cs b/ProjectMotorBoat/ProjectMotorBoat/Program.cs index 4c389e9..30a5090 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/Program.cs +++ b/ProjectMotorBoat/ProjectMotorBoat/Program.cs @@ -11,7 +11,7 @@ namespace ProjectMotorBoat // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new FormMotorBoat()); } } } \ No newline at end of file diff --git a/ProjectMotorBoat/ProjectMotorBoat/ProjectMotorBoat.csproj b/ProjectMotorBoat/ProjectMotorBoat/ProjectMotorBoat.csproj index e1a0735..244387d 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/ProjectMotorBoat.csproj +++ b/ProjectMotorBoat/ProjectMotorBoat/ProjectMotorBoat.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/ProjectMotorBoat/ProjectMotorBoat/Properties/Resources.Designer.cs b/ProjectMotorBoat/ProjectMotorBoat/Properties/Resources.Designer.cs new file mode 100644 index 0000000..3ba38a4 --- /dev/null +++ b/ProjectMotorBoat/ProjectMotorBoat/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ProjectMotorBoat.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectMotorBoat.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowDown { + get { + object obj = ResourceManager.GetObject("arrowDown", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowLeft { + get { + object obj = ResourceManager.GetObject("arrowLeft", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowRight { + get { + object obj = ResourceManager.GetObject("arrowRight", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap arrowUp { + get { + object obj = ResourceManager.GetObject("arrowUp", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/ProjectMotorBoat/ProjectMotorBoat/Properties/Resources.resx b/ProjectMotorBoat/ProjectMotorBoat/Properties/Resources.resx new file mode 100644 index 0000000..293419e --- /dev/null +++ b/ProjectMotorBoat/ProjectMotorBoat/Properties/Resources.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\arrowDown.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrowLeft.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrowRight.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\arrowUp.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/ProjectMotorBoat/ProjectMotorBoat/Resources/arrowDown.jpg b/ProjectMotorBoat/ProjectMotorBoat/Resources/arrowDown.jpg new file mode 100644 index 0000000..f21002e Binary files /dev/null and b/ProjectMotorBoat/ProjectMotorBoat/Resources/arrowDown.jpg differ diff --git a/ProjectMotorBoat/ProjectMotorBoat/Resources/arrowLeft.jpg b/ProjectMotorBoat/ProjectMotorBoat/Resources/arrowLeft.jpg new file mode 100644 index 0000000..61b8dae Binary files /dev/null and b/ProjectMotorBoat/ProjectMotorBoat/Resources/arrowLeft.jpg differ diff --git a/ProjectMotorBoat/ProjectMotorBoat/Resources/arrowRight.jpg b/ProjectMotorBoat/ProjectMotorBoat/Resources/arrowRight.jpg new file mode 100644 index 0000000..b440197 Binary files /dev/null and b/ProjectMotorBoat/ProjectMotorBoat/Resources/arrowRight.jpg differ diff --git a/ProjectMotorBoat/ProjectMotorBoat/Resources/arrowUp.jpg b/ProjectMotorBoat/ProjectMotorBoat/Resources/arrowUp.jpg new file mode 100644 index 0000000..e630cea Binary files /dev/null and b/ProjectMotorBoat/ProjectMotorBoat/Resources/arrowUp.jpg differ