diff --git a/AircraftCarrier/AircraftCarrier/AircraftCarrier.csproj b/AircraftCarrier/AircraftCarrier/AircraftCarrier.csproj index 663fdb8..af03d74 100644 --- a/AircraftCarrier/AircraftCarrier/AircraftCarrier.csproj +++ b/AircraftCarrier/AircraftCarrier/AircraftCarrier.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/DirectionType.cs b/AircraftCarrier/AircraftCarrier/DirectionType.cs new file mode 100644 index 0000000..7492629 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/DirectionType.cs @@ -0,0 +1,9 @@ +namespace AircraftCarrier; + +public enum DirectionType +{ + Up = 1, + Down = 2, + Left = 3, + Right = 4, +} diff --git a/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs new file mode 100644 index 0000000..d84a747 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs @@ -0,0 +1,108 @@ +namespace AircraftCarrier; + +public class DrawingAircraftCarrier +{ + public EntityAircraftCarrier? EntityAircraftCarrier { get; private set; } + private int? _startPosX; + private int? _startPosY; + private int? _pictureWidth; + private int? _pictureHeight; + private readonly int _drawingCarWidth = 250; + private readonly int _drawingCarHeight = 100; + + public void Init(int speed, double weight, Color primaryColor, Color secondaryColor, + bool hasDeck, bool hasСabin) + { + EntityAircraftCarrier = new EntityAircraftCarrier(); + EntityAircraftCarrier.Init(speed, weight, primaryColor, secondaryColor, hasDeck, hasСabin); + _startPosX = null; + _startPosY = null; + _pictureWidth = null; + _pictureHeight = null; + } + + public void SetPictureSize(int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + } + + public void SetPosition(int x, int y) + { + _startPosX = x; + _startPosY = y; + } + + public bool MoveAircraftCarrier(DirectionType direction) + { + if (EntityAircraftCarrier == null || !_startPosX.HasValue || + !_startPosY.HasValue) + { + return false; + } + + switch (direction) + { + case DirectionType.Up: + if (_startPosY - EntityAircraftCarrier.Step > 0) + { + _startPosY -= (int)EntityAircraftCarrier.Step; + } + return true; + case DirectionType.Down: + if (_startPosY + EntityAircraftCarrier.Step + _drawingCarHeight < _pictureHeight) + { + _startPosY += (int)EntityAircraftCarrier.Step; + } + return true; + case DirectionType.Left: + if (_startPosX - EntityAircraftCarrier.Step > 0) + { + _startPosX -= (int)EntityAircraftCarrier.Step; + } + return true; + case DirectionType.Right: + if (_startPosX + EntityAircraftCarrier.Step + _drawingCarWidth < _pictureWidth) + { + _startPosX += (int)EntityAircraftCarrier.Step; + } + return true; + default: + return false; + } + } + + public void DrawAircraftCarrier(Graphics g) + { + if (EntityAircraftCarrier == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + + + Pen pen = new(Color.Black); + Brush brushPC = new SolidBrush(EntityAircraftCarrier.PrimaryColor); + Brush brushSC = new SolidBrush(EntityAircraftCarrier.SecondaryColor); + + Point[] point = { + new Point(_startPosX.Value, _startPosY.Value), + new Point(_startPosX.Value + 200, _startPosY.Value), + new Point(_startPosX.Value + 250, _startPosY.Value + 50), + new Point(_startPosX.Value + 200, _startPosY.Value + 100), + new Point(_startPosX.Value, _startPosY.Value + 100), + }; + g.DrawPolygon(pen, point); + + g.DrawEllipse(pen, _startPosX.Value + 175, _startPosY.Value + 35, 30, 30); + + if (EntityAircraftCarrier.HasDeck) + { + g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 40, 55, 20); + } + + if (EntityAircraftCarrier.HasСabin) + { + g.DrawRectangle(pen, _startPosX.Value + 105, _startPosY.Value + 25, 30, 50); + } + } +} diff --git a/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs new file mode 100644 index 0000000..e0ca730 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs @@ -0,0 +1,23 @@ +namespace AircraftCarrier; + +public class EntityAircraftCarrier +{ + public int Speed { get; private set; } + public double Weight { get; private set; } + public Color PrimaryColor { get; private set; } + public Color SecondaryColor { get; private set; } + public bool HasDeck { get; private set; } + public bool HasСabin { get; private set; } + public double Step => Speed * 100 / Weight; + + public void Init(int speed, double weight, Color primaryColor, Color secondaryColor, + bool hasDeck, bool hasСabin) + { + Speed = speed; + Weight = weight; + PrimaryColor = primaryColor; + SecondaryColor = secondaryColor; + HasDeck = hasDeck; + HasСabin = hasСabin; + } +} \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/Form1.Designer.cs b/AircraftCarrier/AircraftCarrier/Form1.Designer.cs deleted file mode 100644 index 1ca1bf4..0000000 --- a/AircraftCarrier/AircraftCarrier/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace AircraftCarrier -{ - 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 - } -} diff --git a/AircraftCarrier/AircraftCarrier/Form1.cs b/AircraftCarrier/AircraftCarrier/Form1.cs deleted file mode 100644 index e46c0f1..0000000 --- a/AircraftCarrier/AircraftCarrier/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AircraftCarrier -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.Designer.cs b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.Designer.cs new file mode 100644 index 0000000..643b11c --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.Designer.cs @@ -0,0 +1,139 @@ +namespace AircraftCarrier +{ + partial class FormAircraftCarrier + { + /// + /// 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() + { + pictureBoxAircraftCarrier = new PictureBox(); + buttonCreate = new Button(); + buttonLeft = new Button(); + buttonDown = new Button(); + buttonRight = new Button(); + buttonUp = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxAircraftCarrier).BeginInit(); + SuspendLayout(); + // + // pictureBoxAircraftCarrier + // + pictureBoxAircraftCarrier.BorderStyle = BorderStyle.FixedSingle; + pictureBoxAircraftCarrier.Dock = DockStyle.Fill; + pictureBoxAircraftCarrier.Location = new Point(0, 0); + pictureBoxAircraftCarrier.Name = "pictureBoxAircraftCarrier"; + pictureBoxAircraftCarrier.Size = new Size(800, 438); + pictureBoxAircraftCarrier.TabIndex = 0; + pictureBoxAircraftCarrier.TabStop = false; + // + // buttonCreate + // + buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreate.Location = new Point(20, 389); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(94, 29); + buttonCreate.TabIndex = 1; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonCreate_Click; + // + // buttonLeft + // + buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonLeft.BackgroundImage = Properties.Resources.left_arrow; + buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; + buttonLeft.Location = new Point(677, 386); + buttonLeft.Margin = new Padding(0); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(35, 35); + buttonLeft.TabIndex = 2; + buttonLeft.UseVisualStyleBackColor = true; + buttonLeft.Click += ButtonMove_Click; + // + // buttonDown + // + buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonDown.BackgroundImage = Properties.Resources.down_arrow; + buttonDown.BackgroundImageLayout = ImageLayout.Stretch; + buttonDown.Location = new Point(710, 386); + buttonDown.Margin = new Padding(0); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(35, 35); + buttonDown.TabIndex = 3; + buttonDown.UseVisualStyleBackColor = true; + buttonDown.Click += ButtonMove_Click; + // + // buttonRight + // + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackgroundImage = Properties.Resources.right_arrow; + buttonRight.BackgroundImageLayout = ImageLayout.Stretch; + buttonRight.Location = new Point(743, 386); + buttonRight.Margin = new Padding(0); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(35, 35); + buttonRight.TabIndex = 4; + buttonRight.UseVisualStyleBackColor = true; + buttonRight.Click += ButtonMove_Click; + // + // buttonUp + // + buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonUp.BackgroundImage = Properties.Resources.up_arrow; + buttonUp.BackgroundImageLayout = ImageLayout.Stretch; + buttonUp.Location = new Point(710, 353); + buttonUp.Margin = new Padding(0); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(35, 35); + buttonUp.TabIndex = 5; + buttonUp.UseVisualStyleBackColor = true; + buttonUp.Click += ButtonMove_Click; + // + // FormAircraftCarrier + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 438); + Controls.Add(buttonUp); + Controls.Add(buttonRight); + Controls.Add(buttonDown); + Controls.Add(buttonLeft); + Controls.Add(buttonCreate); + Controls.Add(pictureBoxAircraftCarrier); + Name = "FormAircraftCarrier"; + Text = "FormAircraftCarrier"; + ((System.ComponentModel.ISupportInitialize)pictureBoxAircraftCarrier).EndInit(); + ResumeLayout(false); + } + + #endregion + + private PictureBox pictureBoxAircraftCarrier; + private Button buttonCreate; + private Button buttonLeft; + private Button buttonDown; + private Button buttonRight; + private Button buttonUp; + } +} \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.cs new file mode 100644 index 0000000..01d2fb9 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.cs @@ -0,0 +1,63 @@ +using System.Security.Cryptography; + +namespace AircraftCarrier; + +public partial class FormAircraftCarrier : Form +{ + private DrawingAircraftCarrier? _drawingAircraftCarrier; + + public FormAircraftCarrier() + { + InitializeComponent(); + } + + private void Draw() + { + if (_drawingAircraftCarrier == null) return; + Bitmap bmp = new Bitmap(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height); + Graphics g = Graphics.FromImage(bmp); + _drawingAircraftCarrier.DrawAircraftCarrier(g); + pictureBoxAircraftCarrier.Image = bmp; + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + _drawingAircraftCarrier = new(); + _drawingAircraftCarrier.Init(random.Next(100, 200), random.Next(1000, 2000), + 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))); + _drawingAircraftCarrier.SetPictureSize(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height); + _drawingAircraftCarrier.SetPosition(10, 10); + + Draw(); + } + + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_drawingAircraftCarrier == null) return; + string nameButton = ((Button)sender)?.Name ?? string.Empty; + DirectionType? directionType = null; + switch (nameButton) + { + case "buttonUp": + directionType = DirectionType.Up; + break; + case "buttonDown": + directionType = DirectionType.Down; + break; + case "buttonLeft": + directionType = DirectionType.Left; + break; + case "buttonRight": + directionType = DirectionType.Right; + break; + } + + if (directionType.HasValue) { + _drawingAircraftCarrier.MoveAircraftCarrier(directionType.Value); + Draw(); + } + } +} diff --git a/AircraftCarrier/AircraftCarrier/Form1.resx b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.resx similarity index 92% rename from AircraftCarrier/AircraftCarrier/Form1.resx rename to AircraftCarrier/AircraftCarrier/FormAircraftCarrier.resx index 1af7de1..8b2ff64 100644 --- a/AircraftCarrier/AircraftCarrier/Form1.resx +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.resx @@ -1,17 +1,17 @@  - diff --git a/AircraftCarrier/AircraftCarrier/Program.cs b/AircraftCarrier/AircraftCarrier/Program.cs index 58eab96..f373679 100644 --- a/AircraftCarrier/AircraftCarrier/Program.cs +++ b/AircraftCarrier/AircraftCarrier/Program.cs @@ -11,7 +11,7 @@ namespace AircraftCarrier // 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 FormAircraftCarrier()); } } } \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/Properties/Resources.Designer.cs b/AircraftCarrier/AircraftCarrier/Properties/Resources.Designer.cs new file mode 100644 index 0000000..93919de --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace AircraftCarrier.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("AircraftCarrier.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 down_arrow { + get { + object obj = ResourceManager.GetObject("down-arrow", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap left_arrow { + get { + object obj = ResourceManager.GetObject("left-arrow", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap right_arrow { + get { + object obj = ResourceManager.GetObject("right-arrow", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap up_arrow { + get { + object obj = ResourceManager.GetObject("up-arrow", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/AircraftCarrier/AircraftCarrier/Properties/Resources.resx b/AircraftCarrier/AircraftCarrier/Properties/Resources.resx new file mode 100644 index 0000000..3eb3d03 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/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 + + + + down-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + left-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + right-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + up-arrow.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/Properties/down-arrow.png b/AircraftCarrier/AircraftCarrier/Properties/down-arrow.png new file mode 100644 index 0000000..77c9d88 Binary files /dev/null and b/AircraftCarrier/AircraftCarrier/Properties/down-arrow.png differ diff --git a/AircraftCarrier/AircraftCarrier/Properties/left-arrow.png b/AircraftCarrier/AircraftCarrier/Properties/left-arrow.png new file mode 100644 index 0000000..3ef0d95 Binary files /dev/null and b/AircraftCarrier/AircraftCarrier/Properties/left-arrow.png differ diff --git a/AircraftCarrier/AircraftCarrier/Properties/right-arrow.png b/AircraftCarrier/AircraftCarrier/Properties/right-arrow.png new file mode 100644 index 0000000..10fa05f Binary files /dev/null and b/AircraftCarrier/AircraftCarrier/Properties/right-arrow.png differ diff --git a/AircraftCarrier/AircraftCarrier/Properties/up-arrow.png b/AircraftCarrier/AircraftCarrier/Properties/up-arrow.png new file mode 100644 index 0000000..db4972b Binary files /dev/null and b/AircraftCarrier/AircraftCarrier/Properties/up-arrow.png differ