From 93c5ba6742fc4dd2248cd9c6f453ab940c15df89 Mon Sep 17 00:00:00 2001 From: Kristina Date: Sun, 10 Dec 2023 22:18:33 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B7=D0=B0=D1=84=D0=B8=D0=BA=D1=81=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Boat_Hard/Boat_Hard.sln | 25 ++++ Boat_Hard/Boat_Hard/Boat_Hard.csproj | 26 ++++ Boat_Hard/Boat_Hard/DirectionType.cs | 16 +++ Boat_Hard/Boat_Hard/DrawningBoat.cs | 117 +++++++++++++++++ Boat_Hard/Boat_Hard/DrawningOars.cs | 88 +++++++++++++ Boat_Hard/Boat_Hard/EntityBoat.cs | 35 +++++ Boat_Hard/Boat_Hard/FormBoat.Designer.cs | 123 ++++++++++++++++++ Boat_Hard/Boat_Hard/FormBoat.cs | 61 +++++++++ Boat_Hard/Boat_Hard/FormBoat.resx | 120 +++++++++++++++++ Boat_Hard/Boat_Hard/Oars.cs | 15 +++ Boat_Hard/Boat_Hard/Program.cs | 17 +++ .../Properties/Resources.Designer.cs | 63 +++++++++ Boat_Hard/Boat_Hard/Properties/Resources.resx | 120 +++++++++++++++++ 13 files changed, 826 insertions(+) create mode 100644 Boat_Hard/Boat_Hard.sln create mode 100644 Boat_Hard/Boat_Hard/Boat_Hard.csproj create mode 100644 Boat_Hard/Boat_Hard/DirectionType.cs create mode 100644 Boat_Hard/Boat_Hard/DrawningBoat.cs create mode 100644 Boat_Hard/Boat_Hard/DrawningOars.cs create mode 100644 Boat_Hard/Boat_Hard/EntityBoat.cs create mode 100644 Boat_Hard/Boat_Hard/FormBoat.Designer.cs create mode 100644 Boat_Hard/Boat_Hard/FormBoat.cs create mode 100644 Boat_Hard/Boat_Hard/FormBoat.resx create mode 100644 Boat_Hard/Boat_Hard/Oars.cs create mode 100644 Boat_Hard/Boat_Hard/Program.cs create mode 100644 Boat_Hard/Boat_Hard/Properties/Resources.Designer.cs create mode 100644 Boat_Hard/Boat_Hard/Properties/Resources.resx diff --git a/Boat_Hard/Boat_Hard.sln b/Boat_Hard/Boat_Hard.sln new file mode 100644 index 0000000..dea72c2 --- /dev/null +++ b/Boat_Hard/Boat_Hard.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34316.72 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Boat_Hard", "Boat_Hard\Boat_Hard.csproj", "{0A0432B4-0E96-4D1B-A91A-77FB8332EB3F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0A0432B4-0E96-4D1B-A91A-77FB8332EB3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0A0432B4-0E96-4D1B-A91A-77FB8332EB3F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0A0432B4-0E96-4D1B-A91A-77FB8332EB3F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0A0432B4-0E96-4D1B-A91A-77FB8332EB3F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A6F3D5F9-6B0F-40E6-B0A1-4F6D3783D0CC} + EndGlobalSection +EndGlobal diff --git a/Boat_Hard/Boat_Hard/Boat_Hard.csproj b/Boat_Hard/Boat_Hard/Boat_Hard.csproj new file mode 100644 index 0000000..13ee123 --- /dev/null +++ b/Boat_Hard/Boat_Hard/Boat_Hard.csproj @@ -0,0 +1,26 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + \ No newline at end of file diff --git a/Boat_Hard/Boat_Hard/DirectionType.cs b/Boat_Hard/Boat_Hard/DirectionType.cs new file mode 100644 index 0000000..8486d7e --- /dev/null +++ b/Boat_Hard/Boat_Hard/DirectionType.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boat_Hard +{ + public enum DirectionType + { + Up = 1, + Down = 2, + Left = 3, + Right = 4 + } +} diff --git a/Boat_Hard/Boat_Hard/DrawningBoat.cs b/Boat_Hard/Boat_Hard/DrawningBoat.cs new file mode 100644 index 0000000..ddf97d4 --- /dev/null +++ b/Boat_Hard/Boat_Hard/DrawningBoat.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boat_Hard +{ + public class DrawningBoat + { + public EntityBoat? EntityBoat { get; private set; } + private int _pictureWidth; + private int _pictureHeight; + private int _startPosX; + private int _startPosY; + private readonly int _boatWidth = 160; + private readonly int _boatHeight = 118; + private DrawningOars drawningOars; + + public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool motor + //, bool bombs, bool fuelTanks + , int oars, int width, int height) + { + if (width < _boatWidth || height < _boatHeight) + { + return false; + } + _pictureWidth = width; + _pictureHeight = height; + EntityBoat = new EntityBoat(); + EntityBoat.Init(speed, weight, bodyColor, additionalColor, motor + //, bombs, fuelTanks + , oars); + + drawningOars = new DrawningOars(); + drawningOars.SetAmount(oars); + + return true; + } + + public void SetPosition(int x, int y) + { + if (x < 0 || x + _boatWidth > _pictureWidth) + { + x = _pictureWidth - _boatWidth; + } + + if (y < 0 || y + _boatWidth > _pictureHeight) + { + y = _pictureHeight - _boatHeight; + } + _startPosX = x; + _startPosY = y; + } + public void MoveTransport(DirectionType direction) + { + if (EntityBoat == null) + { + return; + } + switch (direction) + { + case DirectionType.Left: + if (_startPosX - EntityBoat.Step > 0) + { + _startPosX -= (int)EntityBoat.Step; + } + break; + case DirectionType.Up: + if (_startPosY - EntityBoat.Step > 0) + { + _startPosY -= (int)EntityBoat.Step; + } + break; + case DirectionType.Right: + if (_startPosX + EntityBoat.Step + _boatWidth < _pictureWidth) + { + _startPosX += (int)EntityBoat.Step; + } + break; + case DirectionType.Down: + if (_startPosY + EntityBoat.Step + _boatHeight < _pictureHeight) + { + _startPosY += (int)EntityBoat.Step; + } + break; + } + } + public void DrawBoat(Graphics g) + { + if (EntityBoat == null) + { + return; + } + + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(EntityBoat.BodyColor); + Brush mainBrush = new SolidBrush(EntityBoat.AdditionalColor); + + drawningOars.DrawOars(g, _startPosX, _startPosY); + + g.FillRectangle(mainBrush, _startPosX + 20, _startPosY + 20, 150, 90); + g.DrawEllipse(pen, _startPosX + 30, _startPosY + 30, 130, 70); + g.FillEllipse(additionalBrush, _startPosX + 30, _startPosY + 30, 130, 70); + + #region Координаты переда лодки + Point b1 = new Point(_startPosX + 170, _startPosY + 20); + Point b2 = new Point(_startPosX + 200, _startPosY + 70); + Point b3 = new Point(_startPosX + 170, _startPosY + 110); + Point[] pointsBoat = { b1, b2, b3 }; + #endregion + + g.DrawPolygon(pen, pointsBoat); + g.FillPolygon(mainBrush, pointsBoat); + } + } +} diff --git a/Boat_Hard/Boat_Hard/DrawningOars.cs b/Boat_Hard/Boat_Hard/DrawningOars.cs new file mode 100644 index 0000000..23e1cfa --- /dev/null +++ b/Boat_Hard/Boat_Hard/DrawningOars.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boat_Hard +{ + public class DrawningOars + { + private Oars amount; + public void SetAmount(int a) + { + if (a <= 1) + { + amount = Oars.One; + } + else if (a == 2) + { + amount = Oars.Two; + } + else if (a >= 3) + { + amount = Oars.Three; + } + } + public void DrawOars(Graphics g, int _startPosX, int _startPosY) + { + Brush oarsColor = new SolidBrush(Color.Black); + + g.FillPolygon(oarsColor, new Point[] // up + { + new Point(_startPosX + 31, _startPosY - 10), + new Point(_startPosX + 41, _startPosY - 10), + new Point(_startPosX + 41, _startPosY + 90), + new Point(_startPosX + 31, _startPosY + 90), + } + ); + g.FillPolygon(oarsColor, new Point[] // down + { + new Point(_startPosX + 31, _startPosY + 30), + new Point(_startPosX + 41, _startPosY + 30), + new Point(_startPosX + 41, _startPosY + 140), + new Point(_startPosX + 31, _startPosY + 140), + } + ); + + if (amount == Oars.Two || amount == Oars.Three) + { + g.FillPolygon(oarsColor, new Point[] // up + { + new Point(_startPosX + 61, _startPosY - 10), + new Point(_startPosX + 71, _startPosY - 10), + new Point(_startPosX + 71, _startPosY + 90), + new Point(_startPosX + 61, _startPosY + 90), + } + ); + g.FillPolygon(oarsColor, new Point[] // down + { + new Point(_startPosX + 61, _startPosY + 30), + new Point(_startPosX + 71, _startPosY + 30), + new Point(_startPosX + 71, _startPosY + 140), + new Point(_startPosX + 61, _startPosY + 140), + } + ); + } + if (amount == Oars.Three) + { + g.FillPolygon(oarsColor, new Point[] // up + { + new Point(_startPosX + 91, _startPosY - 10), + new Point(_startPosX + 101, _startPosY - 10), + new Point(_startPosX + 101, _startPosY + 90), + new Point(_startPosX + 91, _startPosY + 90), + } + ); + g.FillPolygon(oarsColor, new Point[] // down + { + new Point(_startPosX + 91, _startPosY + 30), + new Point(_startPosX + 101, _startPosY + 30), + new Point(_startPosX + 101, _startPosY + 140), + new Point(_startPosX + 91, _startPosY + 140), + } + ); + } + } + } +} diff --git a/Boat_Hard/Boat_Hard/EntityBoat.cs b/Boat_Hard/Boat_Hard/EntityBoat.cs new file mode 100644 index 0000000..7937c45 --- /dev/null +++ b/Boat_Hard/Boat_Hard/EntityBoat.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boat_Hard +{ + public class EntityBoat + { + 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 isMotor { get; private set; } + + //public bool Bombs { get; private set; } + //public bool FuelTanks { get; private set; } + public int Oars { get; private set; } + public double Step => (double)Speed * 100 / Weight; + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool motor + //, bool fuelTanks + , int oars) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + isMotor = motor; + //Bombs = bombs; + //FuelTanks = fuelTanks; + Oars = oars; + } + } +} diff --git a/Boat_Hard/Boat_Hard/FormBoat.Designer.cs b/Boat_Hard/Boat_Hard/FormBoat.Designer.cs new file mode 100644 index 0000000..152549e --- /dev/null +++ b/Boat_Hard/Boat_Hard/FormBoat.Designer.cs @@ -0,0 +1,123 @@ +namespace Boat_Hard +{ + partial class FormBoat + { + /// + /// 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() + { + buttonCreate = new Button(); + buttonUp = new Button(); + buttonDown = new Button(); + buttonRight = new Button(); + buttonLeft = new Button(); + pictureBoxBoat = new PictureBox(); + ((System.ComponentModel.ISupportInitialize)pictureBoxBoat).BeginInit(); + SuspendLayout(); + // + // buttonCreate + // + buttonCreate.Location = new Point(23, 573); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(112, 34); + buttonCreate.TabIndex = 0; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // buttonUp + // + buttonUp.Location = new Point(936, 525); + buttonUp.Name = "buttonUp"; + buttonUp.Size = new Size(30, 30); + buttonUp.TabIndex = 1; + buttonUp.UseVisualStyleBackColor = true; + buttonUp.Click += buttonMove_Click; + // + // buttonDown + // + buttonDown.Location = new Point(936, 577); + buttonDown.Name = "buttonDown"; + buttonDown.Size = new Size(30, 30); + buttonDown.TabIndex = 2; + buttonDown.UseVisualStyleBackColor = true; + buttonDown.Click += buttonMove_Click; + // + // buttonRight + // + buttonRight.Location = new Point(972, 550); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(30, 30); + buttonRight.TabIndex = 3; + buttonRight.UseVisualStyleBackColor = true; + buttonRight.Click += buttonMove_Click; + // + // buttonLeft + // + buttonLeft.Location = new Point(900, 550); + buttonLeft.Name = "buttonLeft"; + buttonLeft.Size = new Size(30, 30); + buttonLeft.TabIndex = 4; + buttonLeft.UseVisualStyleBackColor = true; + buttonLeft.Click += buttonMove_Click; + // + // pictureBoxBoat + // + pictureBoxBoat.Dock = DockStyle.Fill; + pictureBoxBoat.Location = new Point(0, 0); + pictureBoxBoat.Name = "pictureBoxBoat"; + pictureBoxBoat.Size = new Size(1035, 619); + pictureBoxBoat.SizeMode = PictureBoxSizeMode.AutoSize; + pictureBoxBoat.TabIndex = 5; + pictureBoxBoat.TabStop = false; + // + // FormBoat + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1035, 619); + Controls.Add(buttonLeft); + Controls.Add(buttonRight); + Controls.Add(buttonDown); + Controls.Add(buttonUp); + Controls.Add(buttonCreate); + Controls.Add(pictureBoxBoat); + Name = "FormBoat"; + Text = "FormBoat"; + ((System.ComponentModel.ISupportInitialize)pictureBoxBoat).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCreate; + private Button buttonUp; + private Button buttonDown; + private Button buttonRight; + private Button buttonLeft; + private PictureBox pictureBoxBoat; + } +} diff --git a/Boat_Hard/Boat_Hard/FormBoat.cs b/Boat_Hard/Boat_Hard/FormBoat.cs new file mode 100644 index 0000000..9b5f6ca --- /dev/null +++ b/Boat_Hard/Boat_Hard/FormBoat.cs @@ -0,0 +1,61 @@ +namespace Boat_Hard +{ + public partial class FormBoat : Form + { + private DrawningBoat? _drawningBoat; + public FormBoat() + { + InitializeComponent(); + } + + private void Draw() + { + if (_drawningBoat == null) + { + return; + } + Bitmap bmp = new(pictureBoxBoat.Width, pictureBoxBoat.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningBoat.DrawBoat(gr); + pictureBoxBoat.Image = bmp; + } + + private void buttonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningBoat = new DrawningBoat(); + _drawningBoat.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)) + ,random.Next(1, 4) * 2, pictureBoxBoat.Width, pictureBoxBoat.Height); + + _drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + } + + private void buttonMove_Click(object sender, EventArgs e) + { + if (_drawningBoat == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _drawningBoat.MoveTransport(DirectionType.Up); + break; + case "buttonDown": + _drawningBoat.MoveTransport(DirectionType.Down); + break; + case "buttonLeft": + _drawningBoat.MoveTransport(DirectionType.Left); + break; + case "buttonRight": + _drawningBoat.MoveTransport(DirectionType.Right); + break; + } + Draw(); + } + } +} diff --git a/Boat_Hard/Boat_Hard/FormBoat.resx b/Boat_Hard/Boat_Hard/FormBoat.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Boat_Hard/Boat_Hard/FormBoat.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/Boat_Hard/Boat_Hard/Oars.cs b/Boat_Hard/Boat_Hard/Oars.cs new file mode 100644 index 0000000..ce50b80 --- /dev/null +++ b/Boat_Hard/Boat_Hard/Oars.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boat_Hard +{ + public enum Oars + { + One, + Two, + Three + } +} diff --git a/Boat_Hard/Boat_Hard/Program.cs b/Boat_Hard/Boat_Hard/Program.cs new file mode 100644 index 0000000..fc83179 --- /dev/null +++ b/Boat_Hard/Boat_Hard/Program.cs @@ -0,0 +1,17 @@ +namespace Boat_Hard +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new FormBoat()); + } + } +} \ No newline at end of file diff --git a/Boat_Hard/Boat_Hard/Properties/Resources.Designer.cs b/Boat_Hard/Boat_Hard/Properties/Resources.Designer.cs new file mode 100644 index 0000000..f24dcd8 --- /dev/null +++ b/Boat_Hard/Boat_Hard/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace Boat_Hard.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("Boat_Hard.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; + } + } + } +} diff --git a/Boat_Hard/Boat_Hard/Properties/Resources.resx b/Boat_Hard/Boat_Hard/Properties/Resources.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Boat_Hard/Boat_Hard/Properties/Resources.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