diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/DrawningAircraftCarrier.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/DrawningAircraftCarrier.cs index 33480f6..6ba8b08 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/DrawningAircraftCarrier.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/DrawningAircraftCarrier.cs @@ -21,4 +21,87 @@ public class DrawningAircraftCarrier private readonly int _drawningAircraftCarrierWidth = 110; private readonly int _drawningAircraftCarrierHeight = 60; + + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool aircraftDeck, bool controlRoom) + { + EntityAircraftCarrier = new EntityAircraftCarrier(); + EntityAircraftCarrier.Init(speed, weight, bodyColor, additionalColor, aircraftDeck, controlRoom); + _pictureWidth = null; + _pictureHeight = null; + _startPosX = null; + _startPosY = null; + } + + public bool SetPictureSize(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(EntityAircraftCarrier == null || !_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return false; + } + + switch (direction) + { + case DirectionType.Left: + if (_startPosX - EntityAircraftCarrier.Step > 0) + { + _startPosX -= (int)EntityAircraftCarrier.Step; + } + return true; + case DirectionType.Up: + if (_startPosY - EntityAircraftCarrier.Step > 0) + { + _startPosY -= (int)EntityAircraftCarrier.Step; + } + return true; + case DirectionType.Right: + if (_startPosX + EntityAircraftCarrier.Step < _pictureWidth) + { + _startPosX += (int)EntityAircraftCarrier.Step; + } + return true; + case DirectionType.Down: + if (_startPosY + EntityAircraftCarrier.Step < _pictureHeight) + { + _startPosY += (int)EntityAircraftCarrier.Step; + } + return true; + default: + return false; + } + } + + public void DrawTransport(Graphics g) + { + if (EntityAircraftCarrier == null || !_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(EntityAircraftCarrier.AdditionalColor); + + //корпус авианосца + g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 10, 70, 30); + + } + } diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/ProjectAircraftCarrier.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/EntityAircraftCarrier.cs similarity index 88% rename from ProjectAircraftCarrier/ProjectAircraftCarrier/ProjectAircraftCarrier.cs rename to ProjectAircraftCarrier/ProjectAircraftCarrier/EntityAircraftCarrier.cs index caf037b..fc5acc6 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/ProjectAircraftCarrier.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/EntityAircraftCarrier.cs @@ -22,13 +22,13 @@ public class EntityAircraftCarrier public double Step => Speed * 100 / Weight; - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool aircratDeck, bool controlRoom) + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool aircraftDeck, bool controlRoom) { Speed = speed; Weight = weight; BodyColor = bodyColor; AdditionalColor = additionalColor; - AircraftDeck = aircratDeck; + AircraftDeck = aircraftDeck; ControlRoom = controlRoom; } } diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/Form1.Designer.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/Form1.Designer.cs deleted file mode 100644 index a75079b..0000000 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ProjectAircraftCarrier -{ - 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/ProjectAircraftCarrier/ProjectAircraftCarrier/Form1.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/Form1.cs deleted file mode 100644 index e51b901..0000000 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ProjectAircraftCarrier -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.Designer.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.Designer.cs new file mode 100644 index 0000000..cb771ef --- /dev/null +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.Designer.cs @@ -0,0 +1,137 @@ +namespace ProjectAircraftCarrier +{ + 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(); + buttonRight = new Button(); + buttonUp = new Button(); + buttonDown = new Button(); + buttonLeft = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxAircraftCarrier).BeginInit(); + SuspendLayout(); + // + // pictureBoxAircraftCarrier + // + pictureBoxAircraftCarrier.Dock = DockStyle.Fill; + pictureBoxAircraftCarrier.Location = new Point(0, 0); + pictureBoxAircraftCarrier.Name = "pictureBoxAircraftCarrier"; + pictureBoxAircraftCarrier.Size = new Size(803, 471); + pictureBoxAircraftCarrier.SizeMode = PictureBoxSizeMode.AutoSize; + pictureBoxAircraftCarrier.TabIndex = 0; + pictureBoxAircraftCarrier.TabStop = false; + // + // buttonCreate + // + buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreate.Location = new Point(12, 436); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(75, 23); + buttonCreate.TabIndex = 1; + buttonCreate.Text = "создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // buttonRight + // + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackgroundImage = Properties.Resources.arrowRight; + buttonRight.BackgroundImageLayout = ImageLayout.Zoom; + buttonRight.Location = new Point(761, 429); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(30, 30); + buttonRight.TabIndex = 2; + buttonRight.UseVisualStyleBackColor = true; + buttonRight.Click += buttonMove_Click; + // + // buttonUp + // + buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonUp.BackgroundImage = Properties.Resources.arrowUp; + buttonUp.BackgroundImageLayout = ImageLayout.Zoom; + buttonUp.Location = new Point(725, 393); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(30, 30); + buttonUp.TabIndex = 3; + buttonUp.UseVisualStyleBackColor = true; + buttonUp.Click += buttonMove_Click; + // + // buttonDown + // + buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonDown.BackgroundImage = Properties.Resources.arrowDown; + buttonDown.BackgroundImageLayout = ImageLayout.Zoom; + buttonDown.Location = new Point(725, 429); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(30, 30); + buttonDown.TabIndex = 4; + buttonDown.UseVisualStyleBackColor = true; + buttonDown.Click += buttonMove_Click; + // + // buttonLeft + // + buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonLeft.BackgroundImage = Properties.Resources.arrowLeft; + buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; + buttonLeft.Location = new Point(689, 429); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(30, 30); + buttonLeft.TabIndex = 5; + buttonLeft.UseVisualStyleBackColor = true; + buttonLeft.Click += buttonMove_Click; + // + // FormAircraftCarrier + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(803, 471); + Controls.Add(buttonLeft); + Controls.Add(buttonDown); + Controls.Add(buttonUp); + Controls.Add(buttonRight); + Controls.Add(buttonCreate); + Controls.Add(pictureBoxAircraftCarrier); + Name = "FormAircraftCarrier"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Авианосец"; + ((System.ComponentModel.ISupportInitialize)pictureBoxAircraftCarrier).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private PictureBox pictureBoxAircraftCarrier; + private Button buttonCreate; + private Button buttonRight; + private Button buttonUp; + private Button buttonDown; + private Button buttonLeft; + } +} \ No newline at end of file diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.cs new file mode 100644 index 0000000..b3f0311 --- /dev/null +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.cs @@ -0,0 +1,79 @@ +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 ProjectAircraftCarrier +{ + public partial class FormAircraftCarrier : Form + { + private DrawningAircraftCarrier? _drawningAircraftCarrier; + + public FormAircraftCarrier() + { + InitializeComponent(); + } + + private void Draw() + { + if (_drawningAircraftCarrier == null) + { + return; + } + + Bitmap bmp = new(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningAircraftCarrier.DrawTransport(gr); + pictureBoxAircraftCarrier.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))); + _drawningAircraftCarrier.SetPictureSize(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.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; + bool result = false; + switch (name) + { + case "buttonUp": + result = _drawningAircraftCarrier.MoveTransport(DirectionType.Up); + break; + case "buttonDown": + result = _drawningAircraftCarrier.MoveTransport(DirectionType.Down); + break; + case "buttonLeft": + result = _drawningAircraftCarrier.MoveTransport(DirectionType.Left); + break; + case "buttonRight": + result = _drawningAircraftCarrier.MoveTransport(DirectionType.Right); + break; + } + + if (result) + { + Draw(); + } + } + } +} diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.resx b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.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/ProjectAircraftCarrier/ProjectAircraftCarrier/Program.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/Program.cs index 1ba11b2..94348f3 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/Program.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/Program.cs @@ -11,7 +11,7 @@ namespace ProjectAircraftCarrier // 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/ProjectAircraftCarrier/ProjectAircraftCarrier/ProjectAircraftCarrier.csproj b/ProjectAircraftCarrier/ProjectAircraftCarrier/ProjectAircraftCarrier.csproj index e1a0735..244387d 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/ProjectAircraftCarrier.csproj +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/ProjectAircraftCarrier.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/Properties/Resources.Designer.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/Properties/Resources.Designer.cs new file mode 100644 index 0000000..267e158 --- /dev/null +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ProjectAircraftCarrier.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("ProjectAircraftCarrier.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/ProjectAircraftCarrier/ProjectAircraftCarrier/Properties/Resources.resx b/ProjectAircraftCarrier/ProjectAircraftCarrier/Properties/Resources.resx new file mode 100644 index 0000000..e293864 --- /dev/null +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/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\arrowUp.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 + + \ No newline at end of file diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/Resources/arrowDown.jpg b/ProjectAircraftCarrier/ProjectAircraftCarrier/Resources/arrowDown.jpg new file mode 100644 index 0000000..f21002e Binary files /dev/null and b/ProjectAircraftCarrier/ProjectAircraftCarrier/Resources/arrowDown.jpg differ diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/Resources/arrowLeft.jpg b/ProjectAircraftCarrier/ProjectAircraftCarrier/Resources/arrowLeft.jpg new file mode 100644 index 0000000..61b8dae Binary files /dev/null and b/ProjectAircraftCarrier/ProjectAircraftCarrier/Resources/arrowLeft.jpg differ diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/Resources/arrowRight.jpg b/ProjectAircraftCarrier/ProjectAircraftCarrier/Resources/arrowRight.jpg new file mode 100644 index 0000000..b440197 Binary files /dev/null and b/ProjectAircraftCarrier/ProjectAircraftCarrier/Resources/arrowRight.jpg differ diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/Resources/arrowUp.jpg b/ProjectAircraftCarrier/ProjectAircraftCarrier/Resources/arrowUp.jpg new file mode 100644 index 0000000..e630cea Binary files /dev/null and b/ProjectAircraftCarrier/ProjectAircraftCarrier/Resources/arrowUp.jpg differ