diff --git a/ProjectCruiser/ProjectCruiser/DirectionType.cs b/ProjectCruiser/ProjectCruiser/DirectionType.cs new file mode 100644 index 0000000..4cdd1e9 --- /dev/null +++ b/ProjectCruiser/ProjectCruiser/DirectionType.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCruiser; + +/// +/// Направление перемещения +/// + public enum DirectionType + { + /// + /// Вверх + /// + Up = 1, + /// + /// Вниз + /// + Down = 2, + /// + /// Влева + /// + Left = 3, + /// + /// Вправо + /// + Right = 4 + } + diff --git a/ProjectCruiser/ProjectCruiser/DrawingCruiser.cs b/ProjectCruiser/ProjectCruiser/DrawingCruiser.cs new file mode 100644 index 0000000..a1fb426 --- /dev/null +++ b/ProjectCruiser/ProjectCruiser/DrawingCruiser.cs @@ -0,0 +1,154 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCruiser; + +public class DrawingCruiser +{ + /// + /// Класс-сущность + /// + public EntityCruiser? EntityCruiser { get; private set; } + /// + /// Ширина окна + /// + private int? _pictureWidth; + /// + /// Высота окна + /// + private int? _pictureHeight; + /// + /// Левая координата прорисовки крейсера + /// + private int? _startPosX; + /// + /// Верхняя координата прорисовки крейсера + /// + private int? _startPosY; + + /// + /// Ширина прорисовки крейсера + /// + private readonly int _drawningCruiserWidth = 110; + /// + /// Высота прорисовки крейсера + /// + private readonly int _drawingCruiserHeight = 60; + + /// + /// Инициализация полей объекта класса крейсера + /// + /// Скорость + /// Вес крейсера + /// Скорость + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия брони + /// Признак наличия оружия + public void Init(int speed, double weigth, Color bodyColor, Color additionalColor, bool bodyKit, bool armor, bool weapon) + { + EntityCruiser = new EntityCruiser(); + EntityCruiser.Init(speed, weigth, bodyColor, additionalColor, bodyKit, armor, weapon); + _pictureWidth = null; + _pictureHeight = null; + _startPosX = null; + _startPosY = null; + } + + public bool SetPictireSize(int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + return true; + } + + public void SetPosition(int x, int y) + { + if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + + _startPosX = x; + _startPosY = y; + } + + public bool MoveTransport(DirectionType direction) + { + if (EntityCruiser == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return false; + } + + switch (direction) + { + case DirectionType.Left: + if (_startPosX.Value - EntityCruiser.Step > 0) + { + _startPosX -= (int)EntityCruiser.Step; + } + return true; + + case DirectionType.Up: + if (_startPosY.Value - EntityCruiser.Step > 0) + { + _startPosY -= (int)EntityCruiser.Step; + } + return true; + case DirectionType.Right: + if (_startPosX.Value - EntityCruiser.Step > 0) + { + _startPosX += (int)EntityCruiser.Step; + } + return true; + case DirectionType.Down: + if (_startPosY.Value - EntityCruiser.Step > 0) + { + _startPosY += (int)EntityCruiser.Step; + } + return true; + default: + return false; + } + } + + public void DrawTransport(Graphics g) + { + if (EntityCruiser == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + + Pen pen = new(Color.Black); + + Brush additionalBrush = new SolidBrush(EntityCruiser.AdditionalColor); + + //Границы крейсера + g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 5, 20, 20); + g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 35, 20, 20); + g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 5, 20, 20); + g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 35, 20, 20); + g.DrawRectangle(pen, _startPosX.Value + 9, _startPosY.Value + 15, 10, 30); + g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 15, 10, 30); + g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 4, 70, 52); + + //кузов крейсера + Brush br = new SolidBrush(EntityCruiser.BodyColor); + g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 15, 10, 30); + g.FillRectangle(br, _startPosX.Value + 90, _startPosY.Value + 15, 10, 30); + g.FillRectangle(br, _startPosX.Value + 20, _startPosY.Value + 5, 70, 50); + + // оружие крейсера + if (EntityCruiser.Weapon) + { + g.FillRectangle(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 23, 25, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 23, 35, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 23, 20, 15); + + } + + } +} diff --git a/ProjectCruiser/ProjectCruiser/EntityCruiser.cs b/ProjectCruiser/ProjectCruiser/EntityCruiser.cs new file mode 100644 index 0000000..8fdcd5d --- /dev/null +++ b/ProjectCruiser/ProjectCruiser/EntityCruiser.cs @@ -0,0 +1,69 @@ +namespace ProjectCruiser +{ + /// + /// Класс-сущность "Крейсер" Вариант 18 + /// + public class EntityCruiser + { + /// + /// Скорость + /// + public int Speed { get; private set; } + + /// + /// Вес + /// + public double Weigth { get; private set; } + + /// + /// Основной цвет + /// + public Color BodyColor { get; private set; } + + /// + /// Дополнительный цвет (для опциональных элементов) + /// + public Color AdditionalColor { get; private set; } + + /// + /// Признак (опция) наличие обвеса + /// + public bool BodyKit { get; private set; } + + /// + /// Признак (опция) брони + /// + public bool Armor { get; private set; } + + /// + /// Признак (опция) оружия + /// + public bool Weapon { get; private set; } + + /// + /// Шаг перемещения крейсера + /// + public double Step => Speed * 100 / Weigth; + + /// + /// Инициализация полей объекта класса крейсера + /// + /// Скорость + /// Вес крейсера + /// Скорость + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия брони + /// Признак наличия оружия + public void Init(int speed, double weigth, Color bodyColor, Color additionalColor, bool bodyKit, bool armor, bool weapon) + { + Speed = speed; + Weigth = weigth; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + BodyKit = bodyKit; + Armor = armor; + Weapon = weapon; + } + } +} diff --git a/ProjectCruiser/ProjectCruiser/Form1.Designer.cs b/ProjectCruiser/ProjectCruiser/Form1.Designer.cs deleted file mode 100644 index a813ab1..0000000 --- a/ProjectCruiser/ProjectCruiser/Form1.Designer.cs +++ /dev/null @@ -1,45 +0,0 @@ -namespace ProjectCruiser -{ - 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() - { - SuspendLayout(); - // - // Form1 - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Name = "Form1"; - Text = "Form1"; - ResumeLayout(false); - } - - #endregion - } -} diff --git a/ProjectCruiser/ProjectCruiser/Form1.cs b/ProjectCruiser/ProjectCruiser/Form1.cs deleted file mode 100644 index 99d4497..0000000 --- a/ProjectCruiser/ProjectCruiser/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ProjectCruiser -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/ProjectCruiser/ProjectCruiser/FormCruiser.Designer.cs b/ProjectCruiser/ProjectCruiser/FormCruiser.Designer.cs new file mode 100644 index 0000000..69e341a --- /dev/null +++ b/ProjectCruiser/ProjectCruiser/FormCruiser.Designer.cs @@ -0,0 +1,134 @@ +namespace ProjectCruiser +{ + partial class FormCruiser + { + /// + /// 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() + { + pictureBoxCruiser = new PictureBox(); + buttonCreateCruiser = new Button(); + buttonDown = new Button(); + buttonUp = new Button(); + buttonRight = new Button(); + buttonLeft = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCruiser).BeginInit(); + SuspendLayout(); + // + // pictureBoxCruiser + // + pictureBoxCruiser.Dock = DockStyle.Fill; + pictureBoxCruiser.Location = new Point(0, 0); + pictureBoxCruiser.Name = "pictureBoxCruiser"; + pictureBoxCruiser.Size = new Size(800, 450); + pictureBoxCruiser.TabIndex = 0; + pictureBoxCruiser.TabStop = false; + // + // buttonCreateCruiser + // + buttonCreateCruiser.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateCruiser.Location = new Point(12, 409); + buttonCreateCruiser.Name = "buttonCreateCruiser"; + buttonCreateCruiser.Size = new Size(94, 29); + buttonCreateCruiser.TabIndex = 1; + buttonCreateCruiser.Text = "Создать"; + buttonCreateCruiser.UseVisualStyleBackColor = true; + buttonCreateCruiser.Click += ButtonCreateCruiser_Click; + // + // buttonDown + // + buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonDown.BackgroundImage = Properties.Resources.arrowDown; + buttonDown.BackgroundImageLayout = ImageLayout.Stretch; + buttonDown.Location = new Point(682, 392); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(35, 35); + buttonDown.TabIndex = 2; + buttonDown.UseVisualStyleBackColor = true; + buttonDown.Click += ButtonMove_Click; + // + // buttonUp + // + buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonUp.BackgroundImage = Properties.Resources.arrowUp; + buttonUp.BackgroundImageLayout = ImageLayout.Stretch; + buttonUp.Location = new Point(682, 351); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(35, 35); + buttonUp.TabIndex = 3; + buttonUp.UseVisualStyleBackColor = true; + buttonUp.Click += ButtonMove_Click; + // + // buttonRight + // + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackgroundImage = Properties.Resources.arrowRight; + buttonRight.BackgroundImageLayout = ImageLayout.Stretch; + buttonRight.Location = new Point(723, 392); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(35, 35); + buttonRight.TabIndex = 4; + buttonRight.UseVisualStyleBackColor = true; + buttonRight.Click += ButtonMove_Click; + // + // buttonLeft + // + buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonLeft.BackgroundImage = Properties.Resources.arrowLeft; + buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; + buttonLeft.Location = new Point(641, 392); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(35, 35); + buttonLeft.TabIndex = 5; + buttonLeft.UseVisualStyleBackColor = true; + buttonLeft.Click += ButtonMove_Click; + // + // FormCruiser + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonLeft); + Controls.Add(buttonRight); + Controls.Add(buttonUp); + Controls.Add(buttonDown); + Controls.Add(buttonCreateCruiser); + Controls.Add(pictureBoxCruiser); + Name = "FormCruiser"; + Text = "Крейсер"; + ((System.ComponentModel.ISupportInitialize)pictureBoxCruiser).EndInit(); + ResumeLayout(false); + } + + #endregion + + private PictureBox pictureBoxCruiser; + private Button buttonCreateCruiser; + private Button buttonDown; + private Button buttonUp; + private Button buttonRight; + private Button buttonLeft; + } +} \ No newline at end of file diff --git a/ProjectCruiser/ProjectCruiser/FormCruiser.cs b/ProjectCruiser/ProjectCruiser/FormCruiser.cs new file mode 100644 index 0000000..b12c168 --- /dev/null +++ b/ProjectCruiser/ProjectCruiser/FormCruiser.cs @@ -0,0 +1,73 @@ +namespace ProjectCruiser +{ + public partial class FormCruiser : Form + { + + private DrawingCruiser? _drawingCruiser; + public FormCruiser() + { + InitializeComponent(); + } + + private void Draw() + { + if (_drawingCruiser == null) + { + return; + } + + Bitmap bmp = new(pictureBoxCruiser.Width, pictureBoxCruiser.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawingCruiser.DrawTransport(gr); + pictureBoxCruiser.Image = bmp; + } + + private void ButtonCreateCruiser_Click(object sender, EventArgs e) + { + Random random = new(); + _drawingCruiser = new DrawingCruiser(); + _drawingCruiser.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))); + + _drawingCruiser.SetPictireSize(pictureBoxCruiser.Width, pictureBoxCruiser.Height); + _drawingCruiser.SetPosition(random.Next(10, 100), random.Next(10, 100)); + + Draw(); + } + + private void ButtonMove_Click(object sender, EventArgs e) + { + if(_drawingCruiser == null) + { + return; + } + + string name = ((Button)sender)?.Name ?? string.Empty; + bool result = false; + switch(name) { + case "buttonUp": + result = _drawingCruiser.MoveTransport(DirectionType.Up); + break; + case "buttonDown": + result = _drawingCruiser.MoveTransport(DirectionType.Down); + break; + case "buttonLeft": + result = _drawingCruiser.MoveTransport(DirectionType.Left); + break; + case "buttonRight": + result = _drawingCruiser.MoveTransport(DirectionType.Right); + break; + } + + if (result) { + Draw(); + } + } + } +} diff --git a/ProjectCruiser/ProjectCruiser/Form1.resx b/ProjectCruiser/ProjectCruiser/FormCruiser.resx similarity index 100% rename from ProjectCruiser/ProjectCruiser/Form1.resx rename to ProjectCruiser/ProjectCruiser/FormCruiser.resx diff --git a/ProjectCruiser/ProjectCruiser/Program.cs b/ProjectCruiser/ProjectCruiser/Program.cs index 2ddf3fc..4e00cd8 100644 --- a/ProjectCruiser/ProjectCruiser/Program.cs +++ b/ProjectCruiser/ProjectCruiser/Program.cs @@ -11,7 +11,7 @@ namespace ProjectCruiser // 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 FormCruiser()); } } } \ No newline at end of file diff --git a/ProjectCruiser/ProjectCruiser/ProjectCruiser.csproj b/ProjectCruiser/ProjectCruiser/ProjectCruiser.csproj index 663fdb8..af03d74 100644 --- a/ProjectCruiser/ProjectCruiser/ProjectCruiser.csproj +++ b/ProjectCruiser/ProjectCruiser/ProjectCruiser.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/ProjectCruiser/ProjectCruiser/Properties/Resources.Designer.cs b/ProjectCruiser/ProjectCruiser/Properties/Resources.Designer.cs new file mode 100644 index 0000000..724a88c --- /dev/null +++ b/ProjectCruiser/ProjectCruiser/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ProjectCruiser.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("ProjectCruiser.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/ProjectCruiser/ProjectCruiser/Properties/Resources.resx b/ProjectCruiser/ProjectCruiser/Properties/Resources.resx new file mode 100644 index 0000000..b4f1385 --- /dev/null +++ b/ProjectCruiser/ProjectCruiser/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.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + Resources\arrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + Resources\arrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + Resources\arrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/ProjectCruiser/ProjectCruiser/Properties/Resources/arrowDown.png b/ProjectCruiser/ProjectCruiser/Properties/Resources/arrowDown.png new file mode 100644 index 0000000..fec3972 Binary files /dev/null and b/ProjectCruiser/ProjectCruiser/Properties/Resources/arrowDown.png differ diff --git a/ProjectCruiser/ProjectCruiser/Properties/Resources/arrowLeft.png b/ProjectCruiser/ProjectCruiser/Properties/Resources/arrowLeft.png new file mode 100644 index 0000000..0a1d82c Binary files /dev/null and b/ProjectCruiser/ProjectCruiser/Properties/Resources/arrowLeft.png differ diff --git a/ProjectCruiser/ProjectCruiser/Properties/Resources/arrowRight.png b/ProjectCruiser/ProjectCruiser/Properties/Resources/arrowRight.png new file mode 100644 index 0000000..eecf7b0 Binary files /dev/null and b/ProjectCruiser/ProjectCruiser/Properties/Resources/arrowRight.png differ diff --git a/ProjectCruiser/ProjectCruiser/Properties/Resources/arrowUp.png b/ProjectCruiser/ProjectCruiser/Properties/Resources/arrowUp.png new file mode 100644 index 0000000..e2a4a93 Binary files /dev/null and b/ProjectCruiser/ProjectCruiser/Properties/Resources/arrowUp.png differ