diff --git a/AircraftCarrier/AircraftCarrier/AircraftCarrier.csproj b/AircraftCarrier/AircraftCarrier/AircraftCarrier.csproj index b57c89e..13ee123 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/Direction.cs b/AircraftCarrier/AircraftCarrier/Direction.cs new file mode 100644 index 0000000..5042925 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/Direction.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +namespace AircraftCarrier +{ + public enum Direction + { + /// + /// Вверх + /// + Up = 1, + /// + /// Вниз + /// + Down = 2, + /// + /// Влево + /// + Left = 3, + /// + /// Вправо + /// + Right = 4 + } +} diff --git a/AircraftCarrier/AircraftCarrier/DrawningAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/DrawningAircraftCarrier.cs new file mode 100644 index 0000000..6230099 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/DrawningAircraftCarrier.cs @@ -0,0 +1,113 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +namespace AircraftCarrier +{ + internal class DrawningAircraftCarrier + { + public EntityAircraftCarrier? EntityAircraftCarrier { get; private set; } + private int _pictureWidth; + private int _pictureHeight; + private int _startPosX; + private int _startPosY; + private readonly int _AircraftCarrierWidth = 164; + private readonly int _AircraftCarrierHeight = 40; + public bool Init(int speed, double weight, Color bodyColor, Color + additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + if(_AircraftCarrierWidth <_pictureWidth || _AircraftCarrierHeight <_pictureHeight) + { + EntityAircraftCarrier = new EntityAircraftCarrier(); + EntityAircraftCarrier.Init(speed, weight, bodyColor, additionalColor, + bodyKit, wing, sportLine); + return true; + } + return false; + } + public void SetPosition(int x, int y) + { + _startPosX = x; + _startPosY = y; + if (_startPosX < 0 || _startPosY < 0 || _startPosX > (_pictureWidth - _AircraftCarrierWidth) || _startPosY>(_pictureHeight - _AircraftCarrierHeight)) + { + _startPosX = 50; + _startPosY = 50; + } + } + public void MoveTransport(Direction direction) + { + if (EntityAircraftCarrier == null) + { + return; + } + switch (direction) + { + //влево + case Direction.Left: + if (_startPosX - EntityAircraftCarrier.Step > 0) + { + _startPosX -= (int)EntityAircraftCarrier.Step; + } + break; + //вверх + case Direction.Up: + if (_startPosY - EntityAircraftCarrier.Step > 0) + { + _startPosY -= (int)EntityAircraftCarrier.Step; + } + break; + // вправо + case Direction.Right: + if (_startPosX + EntityAircraftCarrier.Step + _AircraftCarrierWidth < _pictureWidth) + { + _startPosX += (int)EntityAircraftCarrier.Step; + } + break; + //вниз + case Direction.Down: + if(_startPosY + EntityAircraftCarrier.Step + _AircraftCarrierHeight < _pictureHeight) + { + _startPosY += (int)EntityAircraftCarrier.Step; + } + break; + } + } + public void DrawTransport(Graphics g) + { + if (EntityAircraftCarrier == null) + { + return; + } + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(EntityAircraftCarrier.AdditionalColor); + g.DrawLine(pen, _startPosX+4, _startPosY, _startPosX + 124, _startPosY); + g.DrawLine(pen, _startPosX+124, _startPosY, _startPosX + 164, _startPosY+20); + g.DrawLine(pen, _startPosX + 164, _startPosY+20, _startPosX + 124, _startPosY + 40); + g.DrawLine(pen, _startPosX + 164, _startPosY + 20, _startPosX + 124, _startPosY + 40); + g.DrawLine(pen, _startPosX + 124, _startPosY + 40, _startPosX + 4, _startPosY + 40); + g.DrawLine(pen, _startPosX+4, _startPosY + 40, _startPosX + 4, _startPosY); + g.FillRectangle(additionalBrush, _startPosX, _startPosY + 6, 4, 12); + g.FillRectangle(additionalBrush, _startPosX, _startPosY + 24, 4, 12); + g.DrawEllipse(pen, _startPosX + 115, _startPosY + 13, 14, 14); + g.DrawRectangle(pen, _startPosX + 63, _startPosY + 13, 27, 14); + g.DrawRectangle(pen, _startPosX + 90, _startPosY + 9, 14, 22); + Pen penWhite = new(Color.White); + if (EntityAircraftCarrier.BodyKit) + { + g.FillRectangle(additionalBrush, _startPosX + 4, _startPosY + 13, 59, 14); + g.DrawLine(penWhite, _startPosX + 62, _startPosY + 19, _startPosX + 52, _startPosY + 19); + g.DrawLine(penWhite, _startPosX + 47, _startPosY + 19, _startPosX + 37, _startPosY + 19); + g.DrawLine(penWhite, _startPosX + 32, _startPosY + 19, _startPosX + 22, _startPosY + 19); + g.DrawLine(penWhite, _startPosX + 17, _startPosY + 19, _startPosX + 7, _startPosY + 19); + } + if (EntityAircraftCarrier.Wing) + { + g.FillRectangle(additionalBrush, _startPosX + 90, _startPosY, 15, 9); + } + } + } +} diff --git a/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs new file mode 100644 index 0000000..eac481b --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftCarrier +{ + public class EntityAircraftCarrier + { + /// + /// Скорость + /// + 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 BodyKit { get; private set; } + /// + /// Признак (опция) наличия антикрыла + /// + public bool Wing { get; private set; } + /// + /// Признак (опция) наличия гоночной полосы + /// + public bool SportLine { get; private set; } + /// + /// Шаг перемещения автомобиля + /// + public double Step => (double)Speed * 100 / Weight; + public void Init(int speed, double weight, Color bodyColor, Color + additionalColor, bool bodyKit, bool wing, bool sportLine) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + BodyKit = bodyKit; + Wing = wing; + SportLine = sportLine; + } + } +} \ 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 d531f87..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 - } -} \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/Form1.cs b/AircraftCarrier/AircraftCarrier/Form1.cs deleted file mode 100644 index 1c6b704..0000000 --- a/AircraftCarrier/AircraftCarrier/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AircraftCarrier -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.Designer.cs b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.Designer.cs new file mode 100644 index 0000000..bd09e0b --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.Designer.cs @@ -0,0 +1,138 @@ +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() + { + pictureBox = new PictureBox(); + buttonCreate = new Button(); + buttonUp = new Button(); + buttonLeft = new Button(); + buttonDown = new Button(); + buttonRight = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(882, 453); + pictureBox.SizeMode = PictureBoxSizeMode.AutoSize; + pictureBox.TabIndex = 0; + pictureBox.TabStop = false; + pictureBox.Click += buttonMove_Click; + // + // buttonCreate + // + buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreate.Location = new Point(23, 403); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(94, 29); + buttonCreate.TabIndex = 1; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // buttonUp + // + buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonUp.BackgroundImage = Properties.Resources.Icon_Up; + buttonUp.BackgroundImageLayout = ImageLayout.Zoom; + buttonUp.Location = new Point(791, 366); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(30, 30); + buttonUp.TabIndex = 2; + buttonUp.UseVisualStyleBackColor = true; + buttonUp.Click += buttonMove_Click; + // + // buttonLeft + // + buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonLeft.BackgroundImage = Properties.Resources.Icon_Left; + buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; + buttonLeft.Location = new Point(755, 402); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(30, 30); + buttonLeft.TabIndex = 3; + buttonLeft.UseVisualStyleBackColor = true; + buttonLeft.Click += buttonMove_Click; + // + // buttonDown + // + buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonDown.BackgroundImage = Properties.Resources.Icon_Down; + buttonDown.BackgroundImageLayout = ImageLayout.Zoom; + buttonDown.Location = new Point(791, 402); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(30, 30); + buttonDown.TabIndex = 4; + buttonDown.UseVisualStyleBackColor = true; + buttonDown.Click += buttonMove_Click; + // + // buttonRight + // + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackgroundImage = Properties.Resources.Icon_Right; + buttonRight.BackgroundImageLayout = ImageLayout.Zoom; + buttonRight.Location = new Point(827, 402); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(30, 30); + buttonRight.TabIndex = 5; + buttonRight.UseVisualStyleBackColor = true; + buttonRight.Click += buttonMove_Click; + // + // FormAircraftCarrier + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(882, 453); + Controls.Add(buttonRight); + Controls.Add(buttonDown); + Controls.Add(buttonLeft); + Controls.Add(buttonUp); + Controls.Add(buttonCreate); + Controls.Add(pictureBox); + Name = "FormAircraftCarrier"; + StartPosition = FormStartPosition.CenterScreen; + Text = "AircraftCarrier"; + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private PictureBox pictureBox; + private Button buttonCreate; + private Button buttonUp; + private Button buttonLeft; + private Button buttonDown; + private Button buttonRight; + } +} \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.cs new file mode 100644 index 0000000..f9cf77b --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.cs @@ -0,0 +1,63 @@ +namespace AircraftCarrier +{ + public partial class FormAircraftCarrier : System.Windows.Forms.Form + { + private DrawningAircraftCarrier? _drawningAircraftCarrier; + public FormAircraftCarrier() + { + InitializeComponent(); + } + private void Draw() + { + if (_drawningAircraftCarrier == null) + { + return; + } + Bitmap bmp = new(pictureBox.Width, pictureBox.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningAircraftCarrier.DrawTransport(gr); + pictureBox.Image = bmp; + } + private void buttonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningAircraftCarrier = new DrawningAircraftCarrier(); + _drawningAircraftCarrier.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)), + pictureBox.Width, pictureBox.Height); + _drawningAircraftCarrier.SetPosition(random.Next(10, 100), + random.Next(10, 100)); + Draw(); + } + private void buttonMove_Click(object sender, EventArgs e) + { + if (_drawningAircraftCarrier == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _drawningAircraftCarrier.MoveTransport(Direction.Up); + break; + case "buttonDown": + _drawningAircraftCarrier.MoveTransport(Direction.Down); + break; + case "buttonLeft": + _drawningAircraftCarrier.MoveTransport(Direction.Left); + break; + case "buttonRight": + _drawningAircraftCarrier.MoveTransport(Direction.Right); + break; + } + Draw(); + } + } +} \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/Form1.resx b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.resx similarity index 93% rename from AircraftCarrier/AircraftCarrier/Form1.resx rename to AircraftCarrier/AircraftCarrier/FormAircraftCarrier.resx index 1af7de1..af32865 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..9d3f211 --- /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 Icon_Down { + get { + object obj = ResourceManager.GetObject("Icon_Down", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Icon_Left { + get { + object obj = ResourceManager.GetObject("Icon_Left", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Icon_Right { + get { + object obj = ResourceManager.GetObject("Icon_Right", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Icon_Up { + get { + object obj = ResourceManager.GetObject("Icon_Up", 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..538913c --- /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 + + + + ..\Resources\Icon_Down.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Icon_Left.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Icon_Right.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Icon_Up.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/Resources/Icon_Down.png b/AircraftCarrier/AircraftCarrier/Resources/Icon_Down.png new file mode 100644 index 0000000..7ad371f Binary files /dev/null and b/AircraftCarrier/AircraftCarrier/Resources/Icon_Down.png differ diff --git a/AircraftCarrier/AircraftCarrier/Resources/Icon_Left.png b/AircraftCarrier/AircraftCarrier/Resources/Icon_Left.png new file mode 100644 index 0000000..a7e79ae Binary files /dev/null and b/AircraftCarrier/AircraftCarrier/Resources/Icon_Left.png differ diff --git a/AircraftCarrier/AircraftCarrier/Resources/Icon_Right.png b/AircraftCarrier/AircraftCarrier/Resources/Icon_Right.png new file mode 100644 index 0000000..caa700f Binary files /dev/null and b/AircraftCarrier/AircraftCarrier/Resources/Icon_Right.png differ diff --git a/AircraftCarrier/AircraftCarrier/Resources/Icon_Up.png b/AircraftCarrier/AircraftCarrier/Resources/Icon_Up.png new file mode 100644 index 0000000..518147e Binary files /dev/null and b/AircraftCarrier/AircraftCarrier/Resources/Icon_Up.png differ