From 87fd13d60addc3f741fd9f5d5855858cc86eea06 Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Fri, 8 Sep 2023 12:23:15 +0400 Subject: [PATCH 01/15] New Class EnityTank --- ProjectTank/ProjectTank/EnityTank.cs | 74 ++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 ProjectTank/ProjectTank/EnityTank.cs diff --git a/ProjectTank/ProjectTank/EnityTank.cs b/ProjectTank/ProjectTank/EnityTank.cs new file mode 100644 index 0000000..b34bebd --- /dev/null +++ b/ProjectTank/ProjectTank/EnityTank.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectTank +{ + internal class EnityTank + { + /// + /// Скорость + /// + public int Speed { get; private set; } + + /// + /// Вес + /// + public double Weight { get; private set; } + + /// + /// Башня + /// + public bool Tower { get; private set; } + + /// + /// Пушка + /// + public bool Gun { get; private set; } + + /// + /// Пулемет + /// + public bool MachineGun { get; private set; } + + /// + /// Основной цвет + /// + public Color BodyColor { get; private set; } + + /// + /// Дополнительный цвет (для опциональных элементов) + /// + public Color AdditionalColor { get; private set; } + + /// + /// Расчет шага по карте + /// + public double Step => (double)Speed * 100 / Weight; + + /// + /// Инициализация полей объекта-класса спортивного автомобиля + /// + /// Скорость + /// Вес автомобиля + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия башни + /// Признак наличия пушки + /// Признак наличия пулемета + /// + public void Init(int speed, double weight, bool tower, bool gun, bool machineGun, Color bodyColor, Color + additionalColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + Tower = tower; + Gun = gun; + MachineGun = machineGun; + } + } +} -- 2.25.1 From 47a0a325e908d60ca0e5a021439259dd611c3078 Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Fri, 8 Sep 2023 12:27:58 +0400 Subject: [PATCH 02/15] New Class Direction --- ProjectTank/ProjectTank/Direction.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ProjectTank/ProjectTank/Direction.cs diff --git a/ProjectTank/ProjectTank/Direction.cs b/ProjectTank/ProjectTank/Direction.cs new file mode 100644 index 0000000..7e6a2b7 --- /dev/null +++ b/ProjectTank/ProjectTank/Direction.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectTank +{ + public enum DirectionType + { + /// + /// Вверх + /// + Up = 1, + /// + /// Вниз + /// + Down = 2, + /// + /// Влево + /// + Left = 3, + /// + /// Вправо + /// + Right = 4 + } +} -- 2.25.1 From 63a9eb093e6dc56eb41396d40c19dd383d772383 Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Thu, 21 Sep 2023 22:32:58 +0400 Subject: [PATCH 03/15] lab1 is done --- .DS_Store | Bin 0 -> 6148 bytes ProjectTank/.DS_Store | Bin 0 -> 6148 bytes ProjectTank/ProjectTank/DrawningTank.cs | 200 ++++++++++++++++++ .../{EnityTank.cs => EntityTank.cs} | 12 +- ProjectTank/ProjectTank/Form1.Designer.cs | 39 ---- ProjectTank/ProjectTank/Form1.cs | 10 - ProjectTank/ProjectTank/Program.cs | 9 +- ProjectTank/ProjectTank/ProjectTank.csproj | 15 ++ .../Properties/Resources.Designer.cs | 103 +++++++++ .../{Form1.resx => Properties/Resources.resx} | 13 ++ ProjectTank/ProjectTank/Resources/btnDown.png | Bin 0 -> 333 bytes ProjectTank/ProjectTank/Resources/btnLeft.png | Bin 0 -> 328 bytes .../ProjectTank/Resources/btnRight.png | Bin 0 -> 335 bytes ProjectTank/ProjectTank/Resources/btnUp.png | Bin 0 -> 333 bytes ProjectTank/ProjectTank/TankForm.Designer.cs | 148 +++++++++++++ ProjectTank/ProjectTank/TankForm.cs | 84 ++++++++ ProjectTank/ProjectTank/TankForm.resx | 60 ++++++ images/btnDown.png | Bin 0 -> 333 bytes images/btnLeft.png | Bin 0 -> 328 bytes images/btnRight.png | Bin 0 -> 335 bytes images/btnUp.png | Bin 0 -> 333 bytes 21 files changed, 630 insertions(+), 63 deletions(-) create mode 100644 .DS_Store create mode 100644 ProjectTank/.DS_Store create mode 100644 ProjectTank/ProjectTank/DrawningTank.cs rename ProjectTank/ProjectTank/{EnityTank.cs => EntityTank.cs} (83%) delete mode 100644 ProjectTank/ProjectTank/Form1.Designer.cs delete mode 100644 ProjectTank/ProjectTank/Form1.cs create mode 100644 ProjectTank/ProjectTank/Properties/Resources.Designer.cs rename ProjectTank/ProjectTank/{Form1.resx => Properties/Resources.resx} (83%) create mode 100644 ProjectTank/ProjectTank/Resources/btnDown.png create mode 100644 ProjectTank/ProjectTank/Resources/btnLeft.png create mode 100644 ProjectTank/ProjectTank/Resources/btnRight.png create mode 100644 ProjectTank/ProjectTank/Resources/btnUp.png create mode 100644 ProjectTank/ProjectTank/TankForm.Designer.cs create mode 100644 ProjectTank/ProjectTank/TankForm.cs create mode 100644 ProjectTank/ProjectTank/TankForm.resx create mode 100644 images/btnDown.png create mode 100644 images/btnLeft.png create mode 100644 images/btnRight.png create mode 100644 images/btnUp.png diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..65b000cd43cfc78c06da3fba22e05f3e40646349 GIT binary patch literal 6148 zcmeHKOHRWu5Pj1|(9%tpY>;w-NZcT;(gh17L^%NTqX-CzR7%&`a~RIY3f|bJQeBW( zAwV*FmQ8dR{)y!vAGvinjn*4qS z^xY-MP~sNr=>3g2m%TZ08#(&$qi=~C4OUo2F)vX}moXbW?s~~{! zW55{ra}4N-N9hebT5Aj#1IECX0X-j5s$w3n_2`ZcHm(F9CNw)?-~IX%Q#BCtfUQSb zDB?qjK2$=9A)#^*AI|wa__rQ?IK-{YJYi)C6^ewyLsI7s$vs+Y3>X8u40Qc)sQ3Tm z>-v8;$VSG1G4QV#kffLvV{R$jt$Ul(yEdg>Q&rTj^|%dT$6dwr)vNfJ>V)=GJH$L- S>yZ|U{RlW3tT6_Dl!15i;$Xx8 literal 0 HcmV?d00001 diff --git a/ProjectTank/.DS_Store b/ProjectTank/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..4daa337b619a76d0b2fb526e100d33398ff65203 GIT binary patch literal 6148 zcmeHK%}N6?5dOyYQ0T!Py$E@Nf^QH@J$Mu918A!Vy6i%$J?D*lMEzza3S0Nklc3B% z@+Fy{WIxzU27oNy9xi|xfC-zT=wLu}c~EsyjmJdM7~N*wbZgEu+}{vA`v`OFvAb@1 z=f9+8{$XODGQ|zH=>jg z4^BgZfnXpQ2nK?IqZ!c5Lzzq+qYnmxfnea90lgm*n_{k59PR30XC(kppV1~9+vA^@ zbb**F7Duj7#9fK*Dz(IrT04llQ=hASaddZx?aVlJ=da>LYUv@#%put^`d}a!=rb_# z=}hzg6@R6{BERnvvtS??_-72rc)40G_)#^t{`fr2wTbPHO-1dB4k#R3DkfSg=0xw2 eGgG=g>6rRlu{dfJT{m}PJOqr8=z@V?VBiz=yFEkz literal 0 HcmV?d00001 diff --git a/ProjectTank/ProjectTank/DrawningTank.cs b/ProjectTank/ProjectTank/DrawningTank.cs new file mode 100644 index 0000000..eba26d2 --- /dev/null +++ b/ProjectTank/ProjectTank/DrawningTank.cs @@ -0,0 +1,200 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectTank +{ + public class DrawningTank + { + /// + /// Класс-сущность + /// + public EntityTank? _EntityTank { get; private set; } + /// + /// Ширина окна + /// + private int _pictureWidth; + /// + /// Высота окна + /// + private int _pictureHeight; + + /// + /// Левая координата прорисовки танка + /// + private int _startPosX; + /// + /// Верхняя кооридната прорисовки танка + /// + private int _startPosY; + /// + /// Левая координата прорисовки танка + /// + // private int _endPosX; + /// + /// Верхняя кооридната прорисовки танка + /// + // private int _endPosY; + /// + /// Ширина прорисовки танка + /// + private readonly int _tankWidth = 200; + /// + /// Высота прорисовки танка + /// + private readonly int _tankHeight = 80; + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес + /// Цвет кузова + /// Дополнительный цвет + /// Ширина картинки + /// Высота картинки + /// true - объект создан, false - проверка не пройдена,нельзя создать объект в этих размерах + + public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool gun, bool machineGun, int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + _EntityTank = new EntityTank(); + _EntityTank.Init(speed, weight, gun, machineGun, bodyColor, additionalColor); + return true; + } + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + // TODO: Изменение x, y + _startPosX = x; + _startPosY = y; + + _pictureWidth= x + _tankWidth; + _pictureHeight= y + _tankHeight; + } + /// + /// Изменение направления перемещения + /// + /// Направление + public void MoveTransport(DirectionType direction) + { + if (_EntityTank == null) + { + return; + } + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX - _EntityTank.Step > 0) + { + _startPosX -= (int)_EntityTank.Step; + } + break; + //вверх + case DirectionType.Up: + if (_startPosY - _EntityTank.Step > 0) + { + _startPosY -= (int)_EntityTank.Step; + } + break; + // вправо + case DirectionType.Right: + if (_startPosX + _pictureWidth + _EntityTank.Step < TankForm.ActiveForm.ClientSize.Width) + { + _startPosX += (int)_EntityTank.Step; + } + break; + //вниз + case DirectionType.Down: + if (_startPosY + _pictureHeight + _EntityTank.Step < TankForm.ActiveForm.ClientSize.Height) + { + _startPosY += (int)_EntityTank.Step; + } + break; + } + } + /// + /// Прорисовка объекта + /// + /// + public void DrawTransport(Graphics g) + { + if (_EntityTank == null) + { + return; + } + Pen pen = new(Color.Black, 3); + Pen penGray = new(Color.Gray, 4); + Brush grayColorBrush = new SolidBrush(Color.Gray); + Brush blackColorBrush = new SolidBrush(Color.Black); + Brush additionalBrush = new SolidBrush(_EntityTank.AdditionalColor); + Brush bodyBrush = new SolidBrush(_EntityTank.BodyColor); + + // Границы автомобиля + // гусеницы + g.DrawEllipse(pen, _startPosX+14, _startPosY+44, 151, 31); + g.FillEllipse(blackColorBrush, _startPosX + 15, _startPosY + 45, 150, 30); + g.DrawEllipse(penGray, _startPosX + 24, _startPosY + 54, 10, 10); + g.DrawEllipse(penGray, _startPosX + 144, _startPosY + 54, 10, 10); + g.DrawEllipse(penGray, _startPosX + 44, _startPosY + 59, 10, 10); + g.DrawEllipse(penGray, _startPosX + 124, _startPosY + 59, 10, 10); + g.DrawEllipse(penGray, _startPosX + 64, _startPosY + 61, 10, 10); + g.DrawEllipse(penGray, _startPosX + 104, _startPosY + 61, 10, 10); + g.DrawEllipse(penGray, _startPosX + 84, _startPosY + 62, 10, 10); + // Кузов + g.DrawRectangle(pen, _startPosX + 19, _startPosY + 34, 141, 21); + g.FillRectangle(bodyBrush, _startPosX+20, _startPosY+35, 140, 20); + + // Башня + g.FillRectangle(blackColorBrush, _startPosX + 75, _startPosY + 10, 25, 5); + g.DrawRectangle(pen, _startPosX + 64, _startPosY + 14, 66, 21); + g.FillRectangle(additionalBrush, _startPosX + 65, _startPosY + 15, 65, 20); + + Point point1 = new Point(_startPosX + 18, _startPosY + 35); + Point point2 = new Point(_startPosX + 18, _startPosY + 55); + Point point3 = new Point(_startPosX+0, _startPosY+55); + Point point4 = new Point(_startPosX + 162, _startPosY + 35); + Point point5 = new Point(_startPosX + 185, _startPosY + 55); + Point point6 = new Point(_startPosX + 162, _startPosY + 55); + + // Задняя часть + Point[] curvePoints = { point1, point2, point3 }; + g.DrawPolygon(pen, curvePoints); + g.FillPolygon(bodyBrush, curvePoints); + // Передняя часть + Point[] curvePoints2 ={point4,point5,point6}; + g.DrawPolygon(pen, curvePoints2); + g.FillPolygon(bodyBrush, curvePoints2); + + // пушка + if (_EntityTank.Gun) + { + g.DrawRectangle(pen, _startPosX + 129, _startPosY + 19, 56, 6); + g.FillRectangle(additionalBrush, _startPosX + 130, _startPosY + 20, 55, 5); + g.DrawRectangle(pen, _startPosX + 184, _startPosY + 17, 16, 11); + g.FillRectangle(blackColorBrush, _startPosX + 185, _startPosY + 18, 15, 10); + } + // пулемет + if (_EntityTank.MachineGun) + { + g.DrawRectangle(pen, _startPosX + 104, _startPosY + 9, 16, 6); + g.FillRectangle(additionalBrush, _startPosX + 105, _startPosY + 10, 15, 5); + g.DrawRectangle(pen, _startPosX + 111, _startPosY, 4, 6); + g.FillRectangle(additionalBrush, _startPosX + 112, _startPosY + 1, 4, 7); + g.FillRectangle(blackColorBrush, _startPosX + 98, _startPosY, 7, 7); + g.DrawRectangle(pen, _startPosX + 104, _startPosY + 2, 30, 3); + g.FillRectangle(additionalBrush, _startPosX + 105, _startPosY + 3, 29, 3); + g.FillRectangle(blackColorBrush, _startPosX + 135, _startPosY, 15, 8); + + } + } + } +} diff --git a/ProjectTank/ProjectTank/EnityTank.cs b/ProjectTank/ProjectTank/EntityTank.cs similarity index 83% rename from ProjectTank/ProjectTank/EnityTank.cs rename to ProjectTank/ProjectTank/EntityTank.cs index b34bebd..d9103aa 100644 --- a/ProjectTank/ProjectTank/EnityTank.cs +++ b/ProjectTank/ProjectTank/EntityTank.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ProjectTank { - internal class EnityTank + public class EntityTank { /// /// Скорость @@ -18,11 +18,6 @@ namespace ProjectTank /// public double Weight { get; private set; } - /// - /// Башня - /// - public bool Tower { get; private set; } - /// /// Пушка /// @@ -55,18 +50,15 @@ namespace ProjectTank /// Вес автомобиля /// Основной цвет /// Дополнительный цвет - /// Признак наличия башни /// Признак наличия пушки /// Признак наличия пулемета /// - public void Init(int speed, double weight, bool tower, bool gun, bool machineGun, Color bodyColor, Color - additionalColor) + public void Init(int speed, double weight, bool gun, bool machineGun, Color bodyColor, Color additionalColor) { Speed = speed; Weight = weight; BodyColor = bodyColor; AdditionalColor = additionalColor; - Tower = tower; Gun = gun; MachineGun = machineGun; } diff --git a/ProjectTank/ProjectTank/Form1.Designer.cs b/ProjectTank/ProjectTank/Form1.Designer.cs deleted file mode 100644 index 6b0ceb0..0000000 --- a/ProjectTank/ProjectTank/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ProjectTank -{ - 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/ProjectTank/ProjectTank/Form1.cs b/ProjectTank/ProjectTank/Form1.cs deleted file mode 100644 index 5ad885c..0000000 --- a/ProjectTank/ProjectTank/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ProjectTank -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/ProjectTank/ProjectTank/Program.cs b/ProjectTank/ProjectTank/Program.cs index e967a59..149fdd8 100644 --- a/ProjectTank/ProjectTank/Program.cs +++ b/ProjectTank/ProjectTank/Program.cs @@ -1,17 +1,18 @@ +using System.Drawing; + namespace ProjectTank { internal static class Program { /// - /// The main entry point for the application. + /// 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 Form1()); + Application.Run(new TankForm()); } } } \ No newline at end of file diff --git a/ProjectTank/ProjectTank/ProjectTank.csproj b/ProjectTank/ProjectTank/ProjectTank.csproj index b57c89e..13ee123 100644 --- a/ProjectTank/ProjectTank/ProjectTank.csproj +++ b/ProjectTank/ProjectTank/ProjectTank.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/ProjectTank/ProjectTank/Properties/Resources.Designer.cs b/ProjectTank/ProjectTank/Properties/Resources.Designer.cs new file mode 100644 index 0000000..c600bc6 --- /dev/null +++ b/ProjectTank/ProjectTank/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ProjectTank.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("ProjectTank.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 btnDown { + get { + object obj = ResourceManager.GetObject("btnDown", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap btnLeft { + get { + object obj = ResourceManager.GetObject("btnLeft", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap btnRight { + get { + object obj = ResourceManager.GetObject("btnRight", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap btnUp { + get { + object obj = ResourceManager.GetObject("btnUp", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/ProjectTank/ProjectTank/Form1.resx b/ProjectTank/ProjectTank/Properties/Resources.resx similarity index 83% rename from ProjectTank/ProjectTank/Form1.resx rename to ProjectTank/ProjectTank/Properties/Resources.resx index 1af7de1..4be9f4a 100644 --- a/ProjectTank/ProjectTank/Form1.resx +++ b/ProjectTank/ProjectTank/Properties/Resources.resx @@ -117,4 +117,17 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\btnDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\btnLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\btnRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\btnUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/ProjectTank/ProjectTank/Resources/btnDown.png b/ProjectTank/ProjectTank/Resources/btnDown.png new file mode 100644 index 0000000000000000000000000000000000000000..51559f1b8b8eb6510faeb32648652cba810d57e9 GIT binary patch literal 333 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3oCO|{#S9GG!XV7ZFl&wkP>``W z$lZxy-8q?;Kn_c~qpu?a!^VE@KZ&eB{v%Hp$B+ufw^I-DHXHD`&RxZ9z?5@HBZonn zVX^^}vH{mk1?43_EkpLIY@EAl?-Nf!g#-H2{)j$i{=zP|B;kI!(Xk_~zvp-EcN8`+ z1fkC#Ir|KwIK?MiyH=e5-~ zk^9qjrFI_NmYef&*Sa~AY&I6_@p->>=sfzs=KQK3D~>9N>+hMYAoTpvQAv%h5;~_B zb@^|VX#OUt&ogC9w1S;V(-f!c@1IxB(>&qX)tRd;(WV&ZynV?-PcNsE6H(q#S7fh$ aV%l`X{$klhp;JKLGI+ZBxvX``W z$lZxy-8q?;Kn_c~qpu?a!^VE@KZ&eB{#{QO$B+ufx6>{PHY@NrB(G<-Xj*L1rM#nY zSEJtoX&~nW+XhFjEnhBFZ3*bK-?O{sS)88YMIO}xM)MsVDt<}omrWcEBo1uSiI}F! zwk&&((e=`!t5$8f;1Xi^T;}$+qc-QwFRge~Id7vz7k{G3MqBsrIcj0KYhV9b{UQG2 z-MWXd*B$SFS7>R7547B8;`>=Aa_d#o4Rv$hmJV VTlHn7s4LK;44$rjF6*2UngIKKf|LLN literal 0 HcmV?d00001 diff --git a/ProjectTank/ProjectTank/Resources/btnRight.png b/ProjectTank/ProjectTank/Resources/btnRight.png new file mode 100644 index 0000000000000000000000000000000000000000..5d43457866fe03ad7f97835e026d24b8f9852704 GIT binary patch literal 335 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3oCO|{#S9GG!XV7ZFl&wkP>``W z$lZxy-8q?;Kn_c~qpu?a!^VE@KZ&eB{u56Z$B+ufx6|J8x*CYI_0P6$;FUP4VV1z` z)5O_xK+VnIQ1xxKqWuB3p?@!{TYhxDXLB~wzf(bh-{yp{qs)=rUuyls8ajKHWp-80 zJ9yA*PuRTY$GCU6=xFyPUn#A%<5%1NXlu&v-RmwtKbYdbCu~}3``dE0Yj6Jt&wH~h z^MvT4wM#_;DE6wUt548Ag3+LFV zbGly6r^Lz9@3Fv3(5q?Db360@d%XB|v2#am^bG;c-Ry_X d#|c``W z$lZxy-8q?;Kn_c~qpu?a!^VE@KZ&eB{v%Hp$B+ufx6=>uwkQa=7HV%`d3z*C=b(_z zLB1u-UJZU4jY4UX!aX;242)AYi^qL>?D*8v$o>eU(kuQwQv}v-Ejp*E*<5n`vrT;X z`@KSpOnr|J^zYsD-r6If`!QeQtYy(QeabBY4cyUt*1gvCy}6Bd$A%+2Zu@6;ZJoAR z#D9;DcUaH&IwiaF#@fDy#{#A=?w-#)mD|o))?|`|cJSn)*P)`19THPlB-M!B&lIa) z?XUa8Z}N_i`B7P4wYoH!Ro8}x`K{Y- literal 0 HcmV?d00001 diff --git a/ProjectTank/ProjectTank/TankForm.Designer.cs b/ProjectTank/ProjectTank/TankForm.Designer.cs new file mode 100644 index 0000000..c8abd55 --- /dev/null +++ b/ProjectTank/ProjectTank/TankForm.Designer.cs @@ -0,0 +1,148 @@ +namespace ProjectTank +{ + partial class TankForm + { + /// + /// 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.pictureBoxTanks = new System.Windows.Forms.PictureBox(); + this.ButtonCreateTank = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTanks)).BeginInit(); + this.SuspendLayout(); + // + // pictureBoxTanks + // + this.pictureBoxTanks.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxTanks.Location = new System.Drawing.Point(0, 0); + this.pictureBoxTanks.Name = "pictureBoxTanks"; + this.pictureBoxTanks.Size = new System.Drawing.Size(778, 413); + this.pictureBoxTanks.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxTanks.TabIndex = 0; + this.pictureBoxTanks.TabStop = false; + // + // ButtonCreateTank + // + this.ButtonCreateTank.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.ButtonCreateTank.Location = new System.Drawing.Point(12, 378); + this.ButtonCreateTank.Name = "ButtonCreateTank"; + this.ButtonCreateTank.Size = new System.Drawing.Size(75, 23); + this.ButtonCreateTank.TabIndex = 1; + this.ButtonCreateTank.Text = "Создать"; + this.ButtonCreateTank.UseVisualStyleBackColor = true; + this.ButtonCreateTank.Click += new System.EventHandler(this.ButtonCreateTank_Click); + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::ProjectTank.Properties.Resources.btnUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonUp.Location = new System.Drawing.Point(700, 342); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 2; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::ProjectTank.Properties.Resources.btnRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonRight.Location = new System.Drawing.Point(736, 378); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 3; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonLeft + // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft.BackgroundImage = global::ProjectTank.Properties.Resources.btnLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonLeft.Location = new System.Drawing.Point(664, 378); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 4; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::ProjectTank.Properties.Resources.btnDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonDown.Location = new System.Drawing.Point(700, 378); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 5; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(631, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(0, 15); + this.label1.TabIndex = 6; + // + // TankForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(778, 413); + this.Controls.Add(this.label1); + this.Controls.Add(this.buttonDown); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.buttonUp); + this.Controls.Add(this.ButtonCreateTank); + this.Controls.Add(this.pictureBoxTanks); + this.Name = "TankForm"; + this.Text = "Tank"; + this.Load += new System.EventHandler(this.TankForm_Load); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTanks)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private Button ButtonCreateTank; + private Button buttonUp; + private Button buttonRight; + private Button buttonLeft; + private Button buttonDown; + public PictureBox pictureBoxTanks; + private Label label1; + } +} \ No newline at end of file diff --git a/ProjectTank/ProjectTank/TankForm.cs b/ProjectTank/ProjectTank/TankForm.cs new file mode 100644 index 0000000..c05b907 --- /dev/null +++ b/ProjectTank/ProjectTank/TankForm.cs @@ -0,0 +1,84 @@ +using System.Reflection.Emit; + +namespace ProjectTank +{ + /// + /// "" + /// + public partial class TankForm : Form + { + private void TankForm_Load(object sender, EventArgs e) + { + + } + + + /// + /// - + /// + private DrawningTank? _drawningTank; + /// + /// + /// + public TankForm() + { + InitializeComponent(); + } + /// + /// + /// + private void Draw() + { + if (_drawningTank == null) + { + return; + } + Bitmap bmp = new(pictureBoxTanks.Width, pictureBoxTanks.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningTank.DrawTransport(gr); + pictureBoxTanks.Image = bmp; + } + /// + /// "" + /// + /// + /// + private void ButtonCreateTank_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningTank = new DrawningTank(); + _drawningTank.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)), pictureBoxTanks.Width, pictureBoxTanks.Height); + _drawningTank.SetPosition(0,0); + Draw(); + } + /// + /// + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_drawningTank == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _drawningTank.MoveTransport(DirectionType.Up); + break; + case "buttonDown": + _drawningTank.MoveTransport(DirectionType.Down); + break; + case "buttonLeft": + _drawningTank.MoveTransport(DirectionType.Left); + break; + case "buttonRight": + _drawningTank.MoveTransport(DirectionType.Right); + break; + } + Draw(); + } + } +} \ No newline at end of file diff --git a/ProjectTank/ProjectTank/TankForm.resx b/ProjectTank/ProjectTank/TankForm.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ProjectTank/ProjectTank/TankForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/images/btnDown.png b/images/btnDown.png new file mode 100644 index 0000000000000000000000000000000000000000..51559f1b8b8eb6510faeb32648652cba810d57e9 GIT binary patch literal 333 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3oCO|{#S9GG!XV7ZFl&wkP>``W z$lZxy-8q?;Kn_c~qpu?a!^VE@KZ&eB{v%Hp$B+ufw^I-DHXHD`&RxZ9z?5@HBZonn zVX^^}vH{mk1?43_EkpLIY@EAl?-Nf!g#-H2{)j$i{=zP|B;kI!(Xk_~zvp-EcN8`+ z1fkC#Ir|KwIK?MiyH=e5-~ zk^9qjrFI_NmYef&*Sa~AY&I6_@p->>=sfzs=KQK3D~>9N>+hMYAoTpvQAv%h5;~_B zb@^|VX#OUt&ogC9w1S;V(-f!c@1IxB(>&qX)tRd;(WV&ZynV?-PcNsE6H(q#S7fh$ aV%l`X{$klhp;JKLGI+ZBxvX``W z$lZxy-8q?;Kn_c~qpu?a!^VE@KZ&eB{#{QO$B+ufx6>{PHY@NrB(G<-Xj*L1rM#nY zSEJtoX&~nW+XhFjEnhBFZ3*bK-?O{sS)88YMIO}xM)MsVDt<}omrWcEBo1uSiI}F! zwk&&((e=`!t5$8f;1Xi^T;}$+qc-QwFRge~Id7vz7k{G3MqBsrIcj0KYhV9b{UQG2 z-MWXd*B$SFS7>R7547B8;`>=Aa_d#o4Rv$hmJV VTlHn7s4LK;44$rjF6*2UngIKKf|LLN literal 0 HcmV?d00001 diff --git a/images/btnRight.png b/images/btnRight.png new file mode 100644 index 0000000000000000000000000000000000000000..5d43457866fe03ad7f97835e026d24b8f9852704 GIT binary patch literal 335 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3oCO|{#S9GG!XV7ZFl&wkP>``W z$lZxy-8q?;Kn_c~qpu?a!^VE@KZ&eB{u56Z$B+ufx6|J8x*CYI_0P6$;FUP4VV1z` z)5O_xK+VnIQ1xxKqWuB3p?@!{TYhxDXLB~wzf(bh-{yp{qs)=rUuyls8ajKHWp-80 zJ9yA*PuRTY$GCU6=xFyPUn#A%<5%1NXlu&v-RmwtKbYdbCu~}3``dE0Yj6Jt&wH~h z^MvT4wM#_;DE6wUt548Ag3+LFV zbGly6r^Lz9@3Fv3(5q?Db360@d%XB|v2#am^bG;c-Ry_X d#|c``W z$lZxy-8q?;Kn_c~qpu?a!^VE@KZ&eB{v%Hp$B+ufx6=>uwkQa=7HV%`d3z*C=b(_z zLB1u-UJZU4jY4UX!aX;242)AYi^qL>?D*8v$o>eU(kuQwQv}v-Ejp*E*<5n`vrT;X z`@KSpOnr|J^zYsD-r6If`!QeQtYy(QeabBY4cyUt*1gvCy}6Bd$A%+2Zu@6;ZJoAR z#D9;DcUaH&IwiaF#@fDy#{#A=?w-#)mD|o))?|`|cJSn)*P)`19THPlB-M!B&lIa) z?XUa8Z}N_i`B7P4wYoH!Ro8}x`K{Y- literal 0 HcmV?d00001 -- 2.25.1 From 4c5992cd4a2190e837a5af9cb86c46bc5fb7bfa8 Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Thu, 21 Sep 2023 23:07:00 +0400 Subject: [PATCH 04/15] rm ds_store --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 800 +++++++++++++++++++++--------------------- ProjectTank/.DS_Store | Bin 6148 -> 0 bytes 3 files changed, 400 insertions(+), 400 deletions(-) delete mode 100644 .DS_Store delete mode 100644 ProjectTank/.DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 65b000cd43cfc78c06da3fba22e05f3e40646349..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKOHRWu5Pj1|(9%tpY>;w-NZcT;(gh17L^%NTqX-CzR7%&`a~RIY3f|bJQeBW( zAwV*FmQ8dR{)y!vAGvinjn*4qS z^xY-MP~sNr=>3g2m%TZ08#(&$qi=~C4OUo2F)vX}moXbW?s~~{! zW55{ra}4N-N9hebT5Aj#1IECX0X-j5s$w3n_2`ZcHm(F9CNw)?-~IX%Q#BCtfUQSb zDB?qjK2$=9A)#^*AI|wa__rQ?IK-{YJYi)C6^ewyLsI7s$vs+Y3>X8u40Qc)sQ3Tm z>-v8;$VSG1G4QV#kffLvV{R$jt$Ul(yEdg>Q&rTj^|%dT$6dwr)vNfJ>V)=GJH$L- S>yZ|U{RlW3tT6_Dl!15i;$Xx8 diff --git a/.gitignore b/.gitignore index ca1c7a3..d4b088d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,400 +1,400 @@ -# ---> VisualStudio -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore - -# User-specific files -*.rsuser -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Mono auto generated files -mono_crash.* - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -[Ww][Ii][Nn]32/ -[Aa][Rr][Mm]/ -[Aa][Rr][Mm]64/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ -[Ll]ogs/ - -# Visual Studio 2015/2017 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# Visual Studio 2017 auto generated files -Generated\ Files/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUnit -*.VisualState.xml -TestResult.xml -nunit-*.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# Benchmark Results -BenchmarkDotNet.Artifacts/ - -# .NET Core -project.lock.json -project.fragment.lock.json -artifacts/ - -# ASP.NET Scaffolding -ScaffoldingReadMe.txt - -# StyleCop -StyleCopReport.xml - -# Files built by Visual Studio -*_i.c -*_p.c -*_h.h -*.ilk -*.meta -*.obj -*.iobj -*.pch -*.pdb -*.ipdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*_wpftmp.csproj -*.log -*.tlog -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# Visual Studio Trace Files -*.e2e - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# AxoCover is a Code Coverage Tool -.axoCover/* -!.axoCover/settings.json - -# Coverlet is a free, cross platform Code Coverage Tool -coverage*.json -coverage*.xml -coverage*.info - -# Visual Studio code coverage results -*.coverage -*.coveragexml - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# Note: Comment the next line if you want to checkin your web deploy settings, -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# NuGet Symbol Packages -*.snupkg -# The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* -# except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/[Pp]ackages/repositories.config -# NuGet v3's project.json files produces more ignorable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt -*.appx -*.appxbundle -*.appxupload - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!?*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -orleans.codegen.cs - -# Including strong name files can present a security risk -# (https://github.com/github/gitignore/pull/2483#issue-259490424) -#*.snk - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm -ServiceFabricBackup/ -*.rptproj.bak - -# SQL Server files -*.mdf -*.ldf -*.ndf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings -*.rptproj.rsuser -*- [Bb]ackup.rdl -*- [Bb]ackup ([0-9]).rdl -*- [Bb]ackup ([0-9][0-9]).rdl - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat -node_modules/ - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - -# Visual Studio 6 auto-generated project file (contains which files were open etc.) -*.vbp - -# Visual Studio 6 workspace and project file (working project files containing files to include in project) -*.dsw -*.dsp - -# Visual Studio 6 technical files -*.ncb -*.aps - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# CodeRush personal settings -.cr/personal - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Tabs Studio -*.tss - -# Telerik's JustMock configuration file -*.jmconfig - -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs - -# OpenCover UI analysis results -OpenCover/ - -# Azure Stream Analytics local run output -ASALocalRun/ - -# MSBuild Binary and Structured Log -*.binlog - -# NVidia Nsight GPU debugger configuration file -*.nvuser - -# MFractors (Xamarin productivity tool) working folder -.mfractor/ - -# Local History for Visual Studio -.localhistory/ - -# Visual Studio History (VSHistory) files -.vshistory/ - -# BeatPulse healthcheck temp database -healthchecksdb - -# Backup folder for Package Reference Convert tool in Visual Studio 2017 -MigrationBackup/ - -# Ionide (cross platform F# VS Code tools) working folder -.ionide/ - -# Fody - auto-generated XML schema -FodyWeavers.xsd - -# VS Code files for those working on multiple tools -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -*.code-workspace - -# Local History for Visual Studio Code -.history/ - -# Windows Installer files from build outputs -*.cab -*.msi -*.msix -*.msm -*.msp - -# JetBrains Rider -*.sln.iml - +# ---> VisualStudio +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + diff --git a/ProjectTank/.DS_Store b/ProjectTank/.DS_Store deleted file mode 100644 index 4daa337b619a76d0b2fb526e100d33398ff65203..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}N6?5dOyYQ0T!Py$E@Nf^QH@J$Mu918A!Vy6i%$J?D*lMEzza3S0Nklc3B% z@+Fy{WIxzU27oNy9xi|xfC-zT=wLu}c~EsyjmJdM7~N*wbZgEu+}{vA`v`OFvAb@1 z=f9+8{$XODGQ|zH=>jg z4^BgZfnXpQ2nK?IqZ!c5Lzzq+qYnmxfnea90lgm*n_{k59PR30XC(kppV1~9+vA^@ zbb**F7Duj7#9fK*Dz(IrT04llQ=hASaddZx?aVlJ=da>LYUv@#%put^`d}a!=rb_# z=}hzg6@R6{BERnvvtS??_-72rc)40G_)#^t{`fr2wTbPHO-1dB4k#R3DkfSg=0xw2 eGgG=g>6rRlu{dfJT{m}PJOqr8=z@V?VBiz=yFEkz -- 2.25.1 From 2a26a6d074b7f931ca8c478cd9bf7049685fb323 Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Thu, 21 Sep 2023 23:09:14 +0400 Subject: [PATCH 05/15] rm ds_store --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index d4b088d..b6ef7b3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ ## ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore +#mac file +.DS_Store + # User-specific files *.rsuser *.suo -- 2.25.1 From d1179ba86480ab2fb6964b57bb59c5796189c9db Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Fri, 22 Sep 2023 13:06:04 +0400 Subject: [PATCH 06/15] edit lab1 --- ProjectTank/ProjectTank.sln | 50 +-- ProjectTank/ProjectTank/Direction.cs | 56 +-- ProjectTank/ProjectTank/DrawningTank.cs | 404 +++++++++--------- ProjectTank/ProjectTank/EntityTank.cs | 132 +++--- ProjectTank/ProjectTank/Program.cs | 34 +- ProjectTank/ProjectTank/ProjectTank.csproj | 50 +-- .../Properties/Resources.Designer.cs | 206 ++++----- .../ProjectTank/Properties/Resources.resx | 264 ++++++------ ProjectTank/ProjectTank/TankForm.Designer.cs | 301 ++++++------- ProjectTank/ProjectTank/TankForm.cs | 163 ++++--- ProjectTank/ProjectTank/TankForm.resx | 118 ++--- README.md | 4 +- 12 files changed, 895 insertions(+), 887 deletions(-) diff --git a/ProjectTank/ProjectTank.sln b/ProjectTank/ProjectTank.sln index e6a4d03..31b235f 100644 --- a/ProjectTank/ProjectTank.sln +++ b/ProjectTank/ProjectTank.sln @@ -1,25 +1,25 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.4.33103.184 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectTank", "ProjectTank\ProjectTank.csproj", "{5365A6E1-3D16-42DB-80AE-69880B9C560C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {5365A6E1-3D16-42DB-80AE-69880B9C560C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5365A6E1-3D16-42DB-80AE-69880B9C560C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5365A6E1-3D16-42DB-80AE-69880B9C560C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5365A6E1-3D16-42DB-80AE-69880B9C560C}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {52BC5146-F9AB-4977-AA7D-3C2F3D505B4C} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33103.184 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectTank", "ProjectTank\ProjectTank.csproj", "{5365A6E1-3D16-42DB-80AE-69880B9C560C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5365A6E1-3D16-42DB-80AE-69880B9C560C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5365A6E1-3D16-42DB-80AE-69880B9C560C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5365A6E1-3D16-42DB-80AE-69880B9C560C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5365A6E1-3D16-42DB-80AE-69880B9C560C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {52BC5146-F9AB-4977-AA7D-3C2F3D505B4C} + EndGlobalSection +EndGlobal diff --git a/ProjectTank/ProjectTank/Direction.cs b/ProjectTank/ProjectTank/Direction.cs index 7e6a2b7..303cf57 100644 --- a/ProjectTank/ProjectTank/Direction.cs +++ b/ProjectTank/ProjectTank/Direction.cs @@ -1,28 +1,28 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectTank -{ - public enum DirectionType - { - /// - /// Вверх - /// - Up = 1, - /// - /// Вниз - /// - Down = 2, - /// - /// Влево - /// - Left = 3, - /// - /// Вправо - /// - Right = 4 - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectTank +{ + public enum DirectionType + { + /// + /// Вверх + /// + Up = 1, + /// + /// Вниз + /// + Down = 2, + /// + /// Влево + /// + Left = 3, + /// + /// Вправо + /// + Right = 4 + } +} diff --git a/ProjectTank/ProjectTank/DrawningTank.cs b/ProjectTank/ProjectTank/DrawningTank.cs index eba26d2..0d6b3af 100644 --- a/ProjectTank/ProjectTank/DrawningTank.cs +++ b/ProjectTank/ProjectTank/DrawningTank.cs @@ -1,200 +1,204 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace ProjectTank -{ - public class DrawningTank - { - /// - /// Класс-сущность - /// - public EntityTank? _EntityTank { get; private set; } - /// - /// Ширина окна - /// - private int _pictureWidth; - /// - /// Высота окна - /// - private int _pictureHeight; - - /// - /// Левая координата прорисовки танка - /// - private int _startPosX; - /// - /// Верхняя кооридната прорисовки танка - /// - private int _startPosY; - /// - /// Левая координата прорисовки танка - /// - // private int _endPosX; - /// - /// Верхняя кооридната прорисовки танка - /// - // private int _endPosY; - /// - /// Ширина прорисовки танка - /// - private readonly int _tankWidth = 200; - /// - /// Высота прорисовки танка - /// - private readonly int _tankHeight = 80; - /// - /// Инициализация свойств - /// - /// Скорость - /// Вес - /// Цвет кузова - /// Дополнительный цвет - /// Ширина картинки - /// Высота картинки - /// true - объект создан, false - проверка не пройдена,нельзя создать объект в этих размерах - - public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool gun, bool machineGun, int width, int height) - { - _pictureWidth = width; - _pictureHeight = height; - _EntityTank = new EntityTank(); - _EntityTank.Init(speed, weight, gun, machineGun, bodyColor, additionalColor); - return true; - } - /// - /// Установка позиции - /// - /// Координата X - /// Координата Y - public void SetPosition(int x, int y) - { - // TODO: Изменение x, y - _startPosX = x; - _startPosY = y; - - _pictureWidth= x + _tankWidth; - _pictureHeight= y + _tankHeight; - } - /// - /// Изменение направления перемещения - /// - /// Направление - public void MoveTransport(DirectionType direction) - { - if (_EntityTank == null) - { - return; - } - switch (direction) - { - //влево - case DirectionType.Left: - if (_startPosX - _EntityTank.Step > 0) - { - _startPosX -= (int)_EntityTank.Step; - } - break; - //вверх - case DirectionType.Up: - if (_startPosY - _EntityTank.Step > 0) - { - _startPosY -= (int)_EntityTank.Step; - } - break; - // вправо - case DirectionType.Right: - if (_startPosX + _pictureWidth + _EntityTank.Step < TankForm.ActiveForm.ClientSize.Width) - { - _startPosX += (int)_EntityTank.Step; - } - break; - //вниз - case DirectionType.Down: - if (_startPosY + _pictureHeight + _EntityTank.Step < TankForm.ActiveForm.ClientSize.Height) - { - _startPosY += (int)_EntityTank.Step; - } - break; - } - } - /// - /// Прорисовка объекта - /// - /// - public void DrawTransport(Graphics g) - { - if (_EntityTank == null) - { - return; - } - Pen pen = new(Color.Black, 3); - Pen penGray = new(Color.Gray, 4); - Brush grayColorBrush = new SolidBrush(Color.Gray); - Brush blackColorBrush = new SolidBrush(Color.Black); - Brush additionalBrush = new SolidBrush(_EntityTank.AdditionalColor); - Brush bodyBrush = new SolidBrush(_EntityTank.BodyColor); - - // Границы автомобиля - // гусеницы - g.DrawEllipse(pen, _startPosX+14, _startPosY+44, 151, 31); - g.FillEllipse(blackColorBrush, _startPosX + 15, _startPosY + 45, 150, 30); - g.DrawEllipse(penGray, _startPosX + 24, _startPosY + 54, 10, 10); - g.DrawEllipse(penGray, _startPosX + 144, _startPosY + 54, 10, 10); - g.DrawEllipse(penGray, _startPosX + 44, _startPosY + 59, 10, 10); - g.DrawEllipse(penGray, _startPosX + 124, _startPosY + 59, 10, 10); - g.DrawEllipse(penGray, _startPosX + 64, _startPosY + 61, 10, 10); - g.DrawEllipse(penGray, _startPosX + 104, _startPosY + 61, 10, 10); - g.DrawEllipse(penGray, _startPosX + 84, _startPosY + 62, 10, 10); - // Кузов - g.DrawRectangle(pen, _startPosX + 19, _startPosY + 34, 141, 21); - g.FillRectangle(bodyBrush, _startPosX+20, _startPosY+35, 140, 20); - - // Башня - g.FillRectangle(blackColorBrush, _startPosX + 75, _startPosY + 10, 25, 5); - g.DrawRectangle(pen, _startPosX + 64, _startPosY + 14, 66, 21); - g.FillRectangle(additionalBrush, _startPosX + 65, _startPosY + 15, 65, 20); - - Point point1 = new Point(_startPosX + 18, _startPosY + 35); - Point point2 = new Point(_startPosX + 18, _startPosY + 55); - Point point3 = new Point(_startPosX+0, _startPosY+55); - Point point4 = new Point(_startPosX + 162, _startPosY + 35); - Point point5 = new Point(_startPosX + 185, _startPosY + 55); - Point point6 = new Point(_startPosX + 162, _startPosY + 55); - - // Задняя часть - Point[] curvePoints = { point1, point2, point3 }; - g.DrawPolygon(pen, curvePoints); - g.FillPolygon(bodyBrush, curvePoints); - // Передняя часть - Point[] curvePoints2 ={point4,point5,point6}; - g.DrawPolygon(pen, curvePoints2); - g.FillPolygon(bodyBrush, curvePoints2); - - // пушка - if (_EntityTank.Gun) - { - g.DrawRectangle(pen, _startPosX + 129, _startPosY + 19, 56, 6); - g.FillRectangle(additionalBrush, _startPosX + 130, _startPosY + 20, 55, 5); - g.DrawRectangle(pen, _startPosX + 184, _startPosY + 17, 16, 11); - g.FillRectangle(blackColorBrush, _startPosX + 185, _startPosY + 18, 15, 10); - } - // пулемет - if (_EntityTank.MachineGun) - { - g.DrawRectangle(pen, _startPosX + 104, _startPosY + 9, 16, 6); - g.FillRectangle(additionalBrush, _startPosX + 105, _startPosY + 10, 15, 5); - g.DrawRectangle(pen, _startPosX + 111, _startPosY, 4, 6); - g.FillRectangle(additionalBrush, _startPosX + 112, _startPosY + 1, 4, 7); - g.FillRectangle(blackColorBrush, _startPosX + 98, _startPosY, 7, 7); - g.DrawRectangle(pen, _startPosX + 104, _startPosY + 2, 30, 3); - g.FillRectangle(additionalBrush, _startPosX + 105, _startPosY + 3, 29, 3); - g.FillRectangle(blackColorBrush, _startPosX + 135, _startPosY, 15, 8); - - } - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectTank +{ + public class DrawningTank + { + /// + /// Класс-сущность + /// + public EntityTank? _EntityTank { get; private set; } + /// + /// Ширина окна + /// + private int _pictureWidth; + /// + /// Высота окна + /// + private int _pictureHeight; + + /// + /// Левая координата прорисовки танка + /// + private int _startPosX; + /// + /// Верхняя кооридната прорисовки танка + /// + private int _startPosY; + /// + /// Левая координата прорисовки танка + /// + // private int _endPosX; + /// + /// Верхняя кооридната прорисовки танка + /// + // private int _endPosY; + /// + /// Ширина прорисовки танка + /// + private readonly int _tankWidth = 200; + /// + /// Высота прорисовки танка + /// + private readonly int _tankHeight = 80; + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес + /// Цвет кузова + /// Дополнительный цвет + /// Ширина картинки + /// Высота картинки + /// true - объект создан, false - проверка не пройдена,нельзя создать объект в этих размерах + + public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool gun, bool machineGun, int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + _EntityTank = new EntityTank(); + _EntityTank.Init(speed, weight, gun, machineGun, bodyColor, additionalColor); + return true; + } + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + if ((x < 0 || y < 0) || (x + _tankWidth > TankForm.ActiveForm.ClientSize.Width || y + _tankHeight > TankForm.ActiveForm.ClientSize.Height)) + { + _startPosX = 0; + _startPosY = 0; + } + else + { + _startPosX = x; + _startPosY = y; + } + } + /// + /// Изменение направления перемещения + /// + /// Направление + public void MoveTransport(DirectionType direction) + { + if (_EntityTank == null) + { + return; + } + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX - _EntityTank.Step > 0) + { + _startPosX -= (int)_EntityTank.Step; + } + break; + //вверх + case DirectionType.Up: + if (_startPosY - _EntityTank.Step > 0) + { + _startPosY -= (int)_EntityTank.Step; + } + break; + // вправо + case DirectionType.Right: + if (_startPosX + _tankWidth + _EntityTank.Step < TankForm.ActiveForm.ClientSize.Width) + { + _startPosX += (int)_EntityTank.Step; + } + break; + //вниз + case DirectionType.Down: + if (_startPosY + _tankHeight + _EntityTank.Step < TankForm.ActiveForm.ClientSize.Height) + { + _startPosY += (int)_EntityTank.Step; + } + break; + } + } + /// + /// Прорисовка объекта + /// + /// + public void DrawTransport(Graphics g) + { + if (_EntityTank == null) + { + return; + } + Pen pen = new(Color.Black, 3); + Pen penGray = new(Color.Gray, 4); + Brush grayColorBrush = new SolidBrush(Color.Gray); + Brush blackColorBrush = new SolidBrush(Color.Black); + Brush additionalBrush = new SolidBrush(_EntityTank.AdditionalColor); + Brush bodyBrush = new SolidBrush(_EntityTank.BodyColor); + + // Границы автомобиля + // гусеницы + g.DrawEllipse(pen, _startPosX+14, _startPosY+44, 151, 31); + g.FillEllipse(blackColorBrush, _startPosX + 15, _startPosY + 45, 150, 30); + g.DrawEllipse(penGray, _startPosX + 24, _startPosY + 54, 10, 10); + g.DrawEllipse(penGray, _startPosX + 144, _startPosY + 54, 10, 10); + g.DrawEllipse(penGray, _startPosX + 44, _startPosY + 59, 10, 10); + g.DrawEllipse(penGray, _startPosX + 124, _startPosY + 59, 10, 10); + g.DrawEllipse(penGray, _startPosX + 64, _startPosY + 61, 10, 10); + g.DrawEllipse(penGray, _startPosX + 104, _startPosY + 61, 10, 10); + g.DrawEllipse(penGray, _startPosX + 84, _startPosY + 62, 10, 10); + // Кузов + g.DrawRectangle(pen, _startPosX + 19, _startPosY + 34, 141, 21); + g.FillRectangle(bodyBrush, _startPosX+20, _startPosY+35, 140, 20); + + // Башня + g.FillRectangle(blackColorBrush, _startPosX + 75, _startPosY + 10, 25, 5); + g.DrawRectangle(pen, _startPosX + 64, _startPosY + 14, 66, 21); + g.FillRectangle(additionalBrush, _startPosX + 65, _startPosY + 15, 65, 20); + + Point point1 = new Point(_startPosX + 18, _startPosY + 35); + Point point2 = new Point(_startPosX + 18, _startPosY + 55); + Point point3 = new Point(_startPosX+0, _startPosY+55); + Point point4 = new Point(_startPosX + 162, _startPosY + 35); + Point point5 = new Point(_startPosX + 185, _startPosY + 55); + Point point6 = new Point(_startPosX + 162, _startPosY + 55); + + // Задняя часть + Point[] curvePoints = { point1, point2, point3 }; + g.DrawPolygon(pen, curvePoints); + g.FillPolygon(bodyBrush, curvePoints); + // Передняя часть + Point[] curvePoints2 ={point4,point5,point6}; + g.DrawPolygon(pen, curvePoints2); + g.FillPolygon(bodyBrush, curvePoints2); + + // пушка + if (_EntityTank.Gun) + { + g.DrawRectangle(pen, _startPosX + 129, _startPosY + 19, 56, 6); + g.FillRectangle(additionalBrush, _startPosX + 130, _startPosY + 20, 55, 5); + g.DrawRectangle(pen, _startPosX + 184, _startPosY + 17, 16, 11); + g.FillRectangle(blackColorBrush, _startPosX + 185, _startPosY + 18, 15, 10); + } + // пулемет + if (_EntityTank.MachineGun) + { + g.DrawRectangle(pen, _startPosX + 104, _startPosY + 9, 16, 6); + g.FillRectangle(additionalBrush, _startPosX + 105, _startPosY + 10, 15, 5); + g.DrawRectangle(pen, _startPosX + 111, _startPosY, 4, 6); + g.FillRectangle(additionalBrush, _startPosX + 112, _startPosY + 1, 4, 7); + g.FillRectangle(blackColorBrush, _startPosX + 98, _startPosY, 7, 7); + g.DrawRectangle(pen, _startPosX + 104, _startPosY + 2, 30, 3); + g.FillRectangle(additionalBrush, _startPosX + 105, _startPosY + 3, 29, 3); + g.FillRectangle(blackColorBrush, _startPosX + 135, _startPosY, 15, 8); + } + g.DrawString("ZOV", new Font("Courier New", 10.0F), blackColorBrush, new Point(_startPosX + 70, _startPosY + 11)); + } + } +} diff --git a/ProjectTank/ProjectTank/EntityTank.cs b/ProjectTank/ProjectTank/EntityTank.cs index d9103aa..eb99e6b 100644 --- a/ProjectTank/ProjectTank/EntityTank.cs +++ b/ProjectTank/ProjectTank/EntityTank.cs @@ -1,66 +1,66 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectTank -{ - public class EntityTank - { - /// - /// Скорость - /// - public int Speed { get; private set; } - - /// - /// Вес - /// - public double Weight { get; private set; } - - /// - /// Пушка - /// - public bool Gun { get; private set; } - - /// - /// Пулемет - /// - public bool MachineGun { get; private set; } - - /// - /// Основной цвет - /// - public Color BodyColor { get; private set; } - - /// - /// Дополнительный цвет (для опциональных элементов) - /// - public Color AdditionalColor { get; private set; } - - /// - /// Расчет шага по карте - /// - public double Step => (double)Speed * 100 / Weight; - - /// - /// Инициализация полей объекта-класса спортивного автомобиля - /// - /// Скорость - /// Вес автомобиля - /// Основной цвет - /// Дополнительный цвет - /// Признак наличия пушки - /// Признак наличия пулемета - /// - public void Init(int speed, double weight, bool gun, bool machineGun, Color bodyColor, Color additionalColor) - { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; - AdditionalColor = additionalColor; - Gun = gun; - MachineGun = machineGun; - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectTank +{ + public class EntityTank + { + /// + /// Скорость + /// + public int Speed { get; private set; } + + /// + /// Вес + /// + public double Weight { get; private set; } + + /// + /// Пушка + /// + public bool Gun { get; private set; } + + /// + /// Пулемет + /// + public bool MachineGun { get; private set; } + + /// + /// Основной цвет + /// + public Color BodyColor { get; private set; } + + /// + /// Дополнительный цвет (для опциональных элементов) + /// + public Color AdditionalColor { get; private set; } + + /// + /// Расчет шага по карте + /// + public double Step => (double)Speed * 100 / Weight; + + /// + /// Инициализация полей объекта-класса спортивного автомобиля + /// + /// Скорость + /// Вес автомобиля + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия пушки + /// Признак наличия пулемета + /// + public void Init(int speed, double weight, bool gun, bool machineGun, Color bodyColor, Color additionalColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + Gun = gun; + MachineGun = machineGun; + } + } +} diff --git a/ProjectTank/ProjectTank/Program.cs b/ProjectTank/ProjectTank/Program.cs index 149fdd8..8621987 100644 --- a/ProjectTank/ProjectTank/Program.cs +++ b/ProjectTank/ProjectTank/Program.cs @@ -1,18 +1,18 @@ -using System.Drawing; - -namespace ProjectTank -{ - internal static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - - ApplicationConfiguration.Initialize(); - Application.Run(new TankForm()); - } - } +using System.Drawing; + +namespace ProjectTank +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + + ApplicationConfiguration.Initialize(); + Application.Run(new TankForm()); + } + } } \ No newline at end of file diff --git a/ProjectTank/ProjectTank/ProjectTank.csproj b/ProjectTank/ProjectTank/ProjectTank.csproj index 13ee123..714c472 100644 --- a/ProjectTank/ProjectTank/ProjectTank.csproj +++ b/ProjectTank/ProjectTank/ProjectTank.csproj @@ -1,26 +1,26 @@ - - - - WinExe - net6.0-windows - enable - true - enable - - - - - True - True - Resources.resx - - - - - - ResXFileCodeGenerator - Resources.Designer.cs - - - + + + + WinExe + net6.0-windows + enable + true + enable + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/ProjectTank/ProjectTank/Properties/Resources.Designer.cs b/ProjectTank/ProjectTank/Properties/Resources.Designer.cs index c600bc6..a8b608a 100644 --- a/ProjectTank/ProjectTank/Properties/Resources.Designer.cs +++ b/ProjectTank/ProjectTank/Properties/Resources.Designer.cs @@ -1,103 +1,103 @@ -//------------------------------------------------------------------------------ -// -// Этот код создан программой. -// Исполняемая версия:4.0.30319.42000 -// -// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае -// повторной генерации кода. -// -//------------------------------------------------------------------------------ - -namespace ProjectTank.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("ProjectTank.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 btnDown { - get { - object obj = ResourceManager.GetObject("btnDown", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Поиск локализованного ресурса типа System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap btnLeft { - get { - object obj = ResourceManager.GetObject("btnLeft", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Поиск локализованного ресурса типа System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap btnRight { - get { - object obj = ResourceManager.GetObject("btnRight", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Поиск локализованного ресурса типа System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap btnUp { - get { - object obj = ResourceManager.GetObject("btnUp", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - } -} +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ProjectTank.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("ProjectTank.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 btnDown { + get { + object obj = ResourceManager.GetObject("btnDown", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap btnLeft { + get { + object obj = ResourceManager.GetObject("btnLeft", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap btnRight { + get { + object obj = ResourceManager.GetObject("btnRight", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap btnUp { + get { + object obj = ResourceManager.GetObject("btnUp", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/ProjectTank/ProjectTank/Properties/Resources.resx b/ProjectTank/ProjectTank/Properties/Resources.resx index 4be9f4a..47d8a25 100644 --- a/ProjectTank/ProjectTank/Properties/Resources.resx +++ b/ProjectTank/ProjectTank/Properties/Resources.resx @@ -1,133 +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\btnDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\btnLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\btnRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Resources\btnUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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\btnDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\btnLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\btnRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\btnUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/ProjectTank/ProjectTank/TankForm.Designer.cs b/ProjectTank/ProjectTank/TankForm.Designer.cs index c8abd55..9340b66 100644 --- a/ProjectTank/ProjectTank/TankForm.Designer.cs +++ b/ProjectTank/ProjectTank/TankForm.Designer.cs @@ -1,148 +1,155 @@ -namespace ProjectTank -{ - partial class TankForm - { - /// - /// 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.pictureBoxTanks = new System.Windows.Forms.PictureBox(); - this.ButtonCreateTank = new System.Windows.Forms.Button(); - this.buttonUp = new System.Windows.Forms.Button(); - this.buttonRight = new System.Windows.Forms.Button(); - this.buttonLeft = new System.Windows.Forms.Button(); - this.buttonDown = new System.Windows.Forms.Button(); - this.label1 = new System.Windows.Forms.Label(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTanks)).BeginInit(); - this.SuspendLayout(); - // - // pictureBoxTanks - // - this.pictureBoxTanks.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBoxTanks.Location = new System.Drawing.Point(0, 0); - this.pictureBoxTanks.Name = "pictureBoxTanks"; - this.pictureBoxTanks.Size = new System.Drawing.Size(778, 413); - this.pictureBoxTanks.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.pictureBoxTanks.TabIndex = 0; - this.pictureBoxTanks.TabStop = false; - // - // ButtonCreateTank - // - this.ButtonCreateTank.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.ButtonCreateTank.Location = new System.Drawing.Point(12, 378); - this.ButtonCreateTank.Name = "ButtonCreateTank"; - this.ButtonCreateTank.Size = new System.Drawing.Size(75, 23); - this.ButtonCreateTank.TabIndex = 1; - this.ButtonCreateTank.Text = "Создать"; - this.ButtonCreateTank.UseVisualStyleBackColor = true; - this.ButtonCreateTank.Click += new System.EventHandler(this.ButtonCreateTank_Click); - // - // buttonUp - // - this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUp.BackgroundImage = global::ProjectTank.Properties.Resources.btnUp; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonUp.Location = new System.Drawing.Point(700, 342); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(30, 30); - this.buttonUp.TabIndex = 2; - this.buttonUp.UseVisualStyleBackColor = true; - this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonRight - // - this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.BackgroundImage = global::ProjectTank.Properties.Resources.btnRight; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonRight.Location = new System.Drawing.Point(736, 378); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(30, 30); - this.buttonRight.TabIndex = 3; - this.buttonRight.UseVisualStyleBackColor = true; - this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonLeft - // - this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonLeft.BackgroundImage = global::ProjectTank.Properties.Resources.btnLeft; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonLeft.Location = new System.Drawing.Point(664, 378); - this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(30, 30); - this.buttonLeft.TabIndex = 4; - this.buttonLeft.UseVisualStyleBackColor = true; - this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonDown - // - this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonDown.BackgroundImage = global::ProjectTank.Properties.Resources.btnDown; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonDown.Location = new System.Drawing.Point(700, 378); - this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(30, 30); - this.buttonDown.TabIndex = 5; - this.buttonDown.UseVisualStyleBackColor = true; - this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(631, 0); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(0, 15); - this.label1.TabIndex = 6; - // - // TankForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(778, 413); - this.Controls.Add(this.label1); - this.Controls.Add(this.buttonDown); - this.Controls.Add(this.buttonLeft); - this.Controls.Add(this.buttonRight); - this.Controls.Add(this.buttonUp); - this.Controls.Add(this.ButtonCreateTank); - this.Controls.Add(this.pictureBoxTanks); - this.Name = "TankForm"; - this.Text = "Tank"; - this.Load += new System.EventHandler(this.TankForm_Load); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTanks)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - private Button ButtonCreateTank; - private Button buttonUp; - private Button buttonRight; - private Button buttonLeft; - private Button buttonDown; - public PictureBox pictureBoxTanks; - private Label label1; - } +namespace ProjectTank +{ + partial class TankForm + { + /// + /// 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.pictureBoxTanks = new System.Windows.Forms.PictureBox(); + this.ButtonCreateTank = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTanks)).BeginInit(); + this.SuspendLayout(); + // + // pictureBoxTanks + // + this.pictureBoxTanks.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxTanks.Location = new System.Drawing.Point(0, 0); + this.pictureBoxTanks.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.pictureBoxTanks.Name = "pictureBoxTanks"; + this.pictureBoxTanks.Size = new System.Drawing.Size(1445, 881); + this.pictureBoxTanks.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxTanks.TabIndex = 0; + this.pictureBoxTanks.TabStop = false; + // + // ButtonCreateTank + // + this.ButtonCreateTank.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.ButtonCreateTank.Location = new System.Drawing.Point(22, 806); + this.ButtonCreateTank.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.ButtonCreateTank.Name = "ButtonCreateTank"; + this.ButtonCreateTank.Size = new System.Drawing.Size(139, 49); + this.ButtonCreateTank.TabIndex = 1; + this.ButtonCreateTank.Text = "Создать"; + this.ButtonCreateTank.UseVisualStyleBackColor = true; + this.ButtonCreateTank.Click += new System.EventHandler(this.ButtonCreateTank_Click); + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::ProjectTank.Properties.Resources.btnUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonUp.Location = new System.Drawing.Point(1300, 730); + this.buttonUp.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(56, 64); + this.buttonUp.TabIndex = 2; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::ProjectTank.Properties.Resources.btnRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonRight.Location = new System.Drawing.Point(1367, 806); + this.buttonRight.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(56, 64); + this.buttonRight.TabIndex = 3; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonLeft + // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft.BackgroundImage = global::ProjectTank.Properties.Resources.btnLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonLeft.Location = new System.Drawing.Point(1233, 806); + this.buttonLeft.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(56, 64); + this.buttonLeft.TabIndex = 4; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::ProjectTank.Properties.Resources.btnDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonDown.Location = new System.Drawing.Point(1300, 806); + this.buttonDown.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(56, 64); + this.buttonDown.TabIndex = 5; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(1172, 0); + this.label1.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(0, 32); + this.label1.TabIndex = 6; + // + // TankForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1445, 881); + this.Controls.Add(this.label1); + this.Controls.Add(this.buttonDown); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.buttonUp); + this.Controls.Add(this.ButtonCreateTank); + this.Controls.Add(this.pictureBoxTanks); + this.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.Name = "TankForm"; + this.Text = "Tank"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTanks)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private Button ButtonCreateTank; + private Button buttonUp; + private Button buttonRight; + private Button buttonLeft; + private Button buttonDown; + public PictureBox pictureBoxTanks; + private Label label1; + } } \ No newline at end of file diff --git a/ProjectTank/ProjectTank/TankForm.cs b/ProjectTank/ProjectTank/TankForm.cs index c05b907..550480d 100644 --- a/ProjectTank/ProjectTank/TankForm.cs +++ b/ProjectTank/ProjectTank/TankForm.cs @@ -1,84 +1,81 @@ -using System.Reflection.Emit; - -namespace ProjectTank -{ - /// - /// "" - /// - public partial class TankForm : Form - { - private void TankForm_Load(object sender, EventArgs e) - { - - } - - - /// - /// - - /// - private DrawningTank? _drawningTank; - /// - /// - /// - public TankForm() - { - InitializeComponent(); - } - /// - /// - /// - private void Draw() - { - if (_drawningTank == null) - { - return; - } - Bitmap bmp = new(pictureBoxTanks.Width, pictureBoxTanks.Height); - Graphics gr = Graphics.FromImage(bmp); - _drawningTank.DrawTransport(gr); - pictureBoxTanks.Image = bmp; - } - /// - /// "" - /// - /// - /// - private void ButtonCreateTank_Click(object sender, EventArgs e) - { - Random random = new(); - _drawningTank = new DrawningTank(); - _drawningTank.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)), pictureBoxTanks.Width, pictureBoxTanks.Height); - _drawningTank.SetPosition(0,0); - Draw(); - } - /// - /// - /// - /// - /// - private void ButtonMove_Click(object sender, EventArgs e) - { - if (_drawningTank == null) - { - return; - } - string name = ((Button)sender)?.Name ?? string.Empty; - switch (name) - { - case "buttonUp": - _drawningTank.MoveTransport(DirectionType.Up); - break; - case "buttonDown": - _drawningTank.MoveTransport(DirectionType.Down); - break; - case "buttonLeft": - _drawningTank.MoveTransport(DirectionType.Left); - break; - case "buttonRight": - _drawningTank.MoveTransport(DirectionType.Right); - break; - } - Draw(); - } - } +using System.Reflection.Emit; + +namespace ProjectTank +{ + /// + /// "" + /// + public partial class TankForm : Form + { + /// + /// - + /// + private DrawningTank? _drawningTank; + /// + /// + /// + public TankForm() + { + InitializeComponent(); + } + /// + /// + /// + private void Draw() + { + if (_drawningTank == null) + { + return; + } + Bitmap bmp = new(pictureBoxTanks.Width, pictureBoxTanks.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawningTank.DrawTransport(gr); + pictureBoxTanks.Image = bmp; + } + /// + /// "" + /// + /// + /// + private void ButtonCreateTank_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningTank = new DrawningTank(); + _drawningTank.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)), + pictureBoxTanks.Width, pictureBoxTanks.Height); + _drawningTank.SetPosition(random.Next(0, 100), random.Next(0, 100)); + Draw(); + } + /// + /// + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_drawningTank == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _drawningTank.MoveTransport(DirectionType.Up); + break; + case "buttonDown": + _drawningTank.MoveTransport(DirectionType.Down); + break; + case "buttonLeft": + _drawningTank.MoveTransport(DirectionType.Left); + break; + case "buttonRight": + _drawningTank.MoveTransport(DirectionType.Right); + break; + } + Draw(); + } + } } \ No newline at end of file diff --git a/ProjectTank/ProjectTank/TankForm.resx b/ProjectTank/ProjectTank/TankForm.resx index f298a7b..b5ae26c 100644 --- a/ProjectTank/ProjectTank/TankForm.resx +++ b/ProjectTank/ProjectTank/TankForm.resx @@ -1,60 +1,60 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/README.md b/README.md index f1dab67..5de01fd 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# ISEbd-21_Zinovev_V.V._Tank_Basic - +# ISEbd-21_Zinovev_V.V._Tank_Basic + ИСэбд-21 Зиновьев В.В. Танк Базовое задание. \ No newline at end of file -- 2.25.1 From 46c4250eeb68a921ceb53086c6d39fb7b1d9a9a2 Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Fri, 22 Sep 2023 13:13:44 +0400 Subject: [PATCH 07/15] edit lab1 --- ProjectTank/ProjectTank/DrawningTank.cs | 7 +++---- ProjectTank/ProjectTank/TankForm.cs | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/ProjectTank/ProjectTank/DrawningTank.cs b/ProjectTank/ProjectTank/DrawningTank.cs index 0d6b3af..144c8a7 100644 --- a/ProjectTank/ProjectTank/DrawningTank.cs +++ b/ProjectTank/ProjectTank/DrawningTank.cs @@ -72,7 +72,7 @@ namespace ProjectTank /// Координата Y public void SetPosition(int x, int y) { - if ((x < 0 || y < 0) || (x + _tankWidth > TankForm.ActiveForm.ClientSize.Width || y + _tankHeight > TankForm.ActiveForm.ClientSize.Height)) + if ((x < 0 || y < 0) || (x + _tankWidth > _pictureWidth || y + _tankHeight > _pictureHeight)) { _startPosX = 0; _startPosY = 0; @@ -111,14 +111,14 @@ namespace ProjectTank break; // вправо case DirectionType.Right: - if (_startPosX + _tankWidth + _EntityTank.Step < TankForm.ActiveForm.ClientSize.Width) + if (_startPosX + _tankWidth + _EntityTank.Step < _pictureWidth) { _startPosX += (int)_EntityTank.Step; } break; //вниз case DirectionType.Down: - if (_startPosY + _tankHeight + _EntityTank.Step < TankForm.ActiveForm.ClientSize.Height) + if (_startPosY + _tankHeight + _EntityTank.Step < _pictureHeight) { _startPosY += (int)_EntityTank.Step; } @@ -198,7 +198,6 @@ namespace ProjectTank g.FillRectangle(additionalBrush, _startPosX + 105, _startPosY + 3, 29, 3); g.FillRectangle(blackColorBrush, _startPosX + 135, _startPosY, 15, 8); } - g.DrawString("ZOV", new Font("Courier New", 10.0F), blackColorBrush, new Point(_startPosX + 70, _startPosY + 11)); } } } diff --git a/ProjectTank/ProjectTank/TankForm.cs b/ProjectTank/ProjectTank/TankForm.cs index 550480d..50e5e2b 100644 --- a/ProjectTank/ProjectTank/TankForm.cs +++ b/ProjectTank/ProjectTank/TankForm.cs @@ -42,9 +42,9 @@ namespace ProjectTank Random random = new(); _drawningTank = new DrawningTank(); _drawningTank.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)), - pictureBoxTanks.Width, pictureBoxTanks.Height); + 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)), + pictureBoxTanks.Width, pictureBoxTanks.Height); _drawningTank.SetPosition(random.Next(0, 100), random.Next(0, 100)); Draw(); } -- 2.25.1 From f69cd91c1dc61cb8928c5c3f1d345fd17816df3c Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Fri, 22 Sep 2023 13:52:05 +0400 Subject: [PATCH 08/15] lab1 done --- ProjectTank/ProjectTank/DrawningTank.cs | 14 +++++--------- ProjectTank/ProjectTank/Program.cs | 1 - 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/ProjectTank/ProjectTank/DrawningTank.cs b/ProjectTank/ProjectTank/DrawningTank.cs index 144c8a7..3d24ece 100644 --- a/ProjectTank/ProjectTank/DrawningTank.cs +++ b/ProjectTank/ProjectTank/DrawningTank.cs @@ -21,7 +21,6 @@ namespace ProjectTank /// Высота окна /// private int _pictureHeight; - /// /// Левая координата прорисовки танка /// @@ -30,14 +29,6 @@ namespace ProjectTank /// Верхняя кооридната прорисовки танка /// private int _startPosY; - /// - /// Левая координата прорисовки танка - /// - // private int _endPosX; - /// - /// Верхняя кооридната прорисовки танка - /// - // private int _endPosY; /// /// Ширина прорисовки танка /// @@ -61,6 +52,11 @@ namespace ProjectTank { _pictureWidth = width; _pictureHeight = height; + + if ((_pictureHeight < _tankHeight) || (_pictureWidth < _tankWidth)) + { + return false; + } _EntityTank = new EntityTank(); _EntityTank.Init(speed, weight, gun, machineGun, bodyColor, additionalColor); return true; diff --git a/ProjectTank/ProjectTank/Program.cs b/ProjectTank/ProjectTank/Program.cs index 8621987..10b63f7 100644 --- a/ProjectTank/ProjectTank/Program.cs +++ b/ProjectTank/ProjectTank/Program.cs @@ -10,7 +10,6 @@ namespace ProjectTank [STAThread] static void Main() { - ApplicationConfiguration.Initialize(); Application.Run(new TankForm()); } -- 2.25.1 From 00834f629dceee61304befc7a0baa4b3b9bb7228 Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Tue, 3 Oct 2023 20:02:47 +0400 Subject: [PATCH 09/15] lab. is done --- ProjectTank/ProjectTank/DrawningTank.cs | 30 +++++++++++++------------ ProjectTank/ProjectTank/EntityTank.cs | 5 +++-- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/ProjectTank/ProjectTank/DrawningTank.cs b/ProjectTank/ProjectTank/DrawningTank.cs index 3d24ece..c1e48fc 100644 --- a/ProjectTank/ProjectTank/DrawningTank.cs +++ b/ProjectTank/ProjectTank/DrawningTank.cs @@ -48,7 +48,8 @@ namespace ProjectTank /// Высота картинки /// true - объект создан, false - проверка не пройдена,нельзя создать объект в этих размерах - public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool gun, bool machineGun, int width, int height) + public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, + bool gun, bool machineGun, int width, int height) { _pictureWidth = width; _pictureHeight = height; @@ -105,7 +106,7 @@ namespace ProjectTank _startPosY -= (int)_EntityTank.Step; } break; - // вправо + //вправо case DirectionType.Right: if (_startPosX + _tankWidth + _EntityTank.Step < _pictureWidth) { @@ -158,21 +159,22 @@ namespace ProjectTank g.DrawRectangle(pen, _startPosX + 64, _startPosY + 14, 66, 21); g.FillRectangle(additionalBrush, _startPosX + 65, _startPosY + 15, 65, 20); - Point point1 = new Point(_startPosX + 18, _startPosY + 35); - Point point2 = new Point(_startPosX + 18, _startPosY + 55); - Point point3 = new Point(_startPosX+0, _startPosY+55); - Point point4 = new Point(_startPosX + 162, _startPosY + 35); - Point point5 = new Point(_startPosX + 185, _startPosY + 55); - Point point6 = new Point(_startPosX + 162, _startPosY + 55); + //Точки для отрисовки передней и задней части + Point pointFirstBackSide = new Point(_startPosX + 18, _startPosY + 35); + Point pointSecondBackSide = new Point(_startPosX + 18, _startPosY + 55); + Point pointThirdBackSide = new Point(_startPosX+0, _startPosY+55); + Point pointFirstFrontSide = new Point(_startPosX + 162, _startPosY + 35); + Point pointSecondFrontSide = new Point(_startPosX + 185, _startPosY + 55); + Point pointThirdFrontSide = new Point(_startPosX + 162, _startPosY + 55); // Задняя часть - Point[] curvePoints = { point1, point2, point3 }; - g.DrawPolygon(pen, curvePoints); - g.FillPolygon(bodyBrush, curvePoints); + Point[] backSide = { pointFirstBackSide, pointSecondBackSide, pointThirdBackSide }; + g.DrawPolygon(pen, backSide); + g.FillPolygon(bodyBrush, backSide); // Передняя часть - Point[] curvePoints2 ={point4,point5,point6}; - g.DrawPolygon(pen, curvePoints2); - g.FillPolygon(bodyBrush, curvePoints2); + Point[] frontSide ={ pointFirstFrontSide, pointSecondFrontSide, pointThirdFrontSide }; + g.DrawPolygon(pen, frontSide); + g.FillPolygon(bodyBrush, frontSide); // пушка if (_EntityTank.Gun) diff --git a/ProjectTank/ProjectTank/EntityTank.cs b/ProjectTank/ProjectTank/EntityTank.cs index eb99e6b..3834940 100644 --- a/ProjectTank/ProjectTank/EntityTank.cs +++ b/ProjectTank/ProjectTank/EntityTank.cs @@ -52,8 +52,9 @@ namespace ProjectTank /// Дополнительный цвет /// Признак наличия пушки /// Признак наличия пулемета - /// - public void Init(int speed, double weight, bool gun, bool machineGun, Color bodyColor, Color additionalColor) + /// + public void Init(int speed, double weight, bool gun, + bool machineGun, Color bodyColor, Color additionalColor) { Speed = speed; Weight = weight; -- 2.25.1 From a552939e52b96fb1dafbe322d5f790e57e8b4daf Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Tue, 3 Oct 2023 20:24:32 +0400 Subject: [PATCH 10/15] lab. is done --- ProjectTank/ProjectTank/DrawningTank.cs | 1 - ProjectTank/ProjectTank/TankForm.cs | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ProjectTank/ProjectTank/DrawningTank.cs b/ProjectTank/ProjectTank/DrawningTank.cs index c1e48fc..aa1d415 100644 --- a/ProjectTank/ProjectTank/DrawningTank.cs +++ b/ProjectTank/ProjectTank/DrawningTank.cs @@ -47,7 +47,6 @@ namespace ProjectTank /// Ширина картинки /// Высота картинки /// true - объект создан, false - проверка не пройдена,нельзя создать объект в этих размерах - public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool gun, bool machineGun, int width, int height) { diff --git a/ProjectTank/ProjectTank/TankForm.cs b/ProjectTank/ProjectTank/TankForm.cs index 50e5e2b..72273a3 100644 --- a/ProjectTank/ProjectTank/TankForm.cs +++ b/ProjectTank/ProjectTank/TankForm.cs @@ -14,10 +14,10 @@ namespace ProjectTank /// /// /// - public TankForm() - { - InitializeComponent(); - } + public TankForm() + { + InitializeComponent(); + } /// /// /// -- 2.25.1 From de4231767ba4d59db448617702fc518d20225fa1 Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Fri, 6 Oct 2023 10:43:19 +0400 Subject: [PATCH 11/15] lab2 is done --- ProjectTank/ProjectTank/AbstractStrategy.cs | 134 +++++++++++ .../ProjectTank/DrawningArmoredTransport.cs | 226 ++++++++++++++++++ .../DrawningObjectArmoredTransport.cs | 37 +++ ProjectTank/ProjectTank/DrawningTank.cs | 176 ++------------ .../ProjectTank/EntityArmoredTransport.cs | 43 ++++ ProjectTank/ProjectTank/EntityTank.cs | 42 +--- ProjectTank/ProjectTank/IMoveableObject.cs | 35 +++ ProjectTank/ProjectTank/MoveToBorder.cs | 45 ++++ ProjectTank/ProjectTank/MoveToCenter.cs | 59 +++++ ProjectTank/ProjectTank/ObjectParameters.cs | 57 +++++ ProjectTank/ProjectTank/Status.cs | 18 ++ ProjectTank/ProjectTank/TankForm.Designer.cs | 64 ++++- ProjectTank/ProjectTank/TankForm.cs | 89 +++++-- 13 files changed, 818 insertions(+), 207 deletions(-) create mode 100644 ProjectTank/ProjectTank/AbstractStrategy.cs create mode 100644 ProjectTank/ProjectTank/DrawningArmoredTransport.cs create mode 100644 ProjectTank/ProjectTank/DrawningObjectArmoredTransport.cs create mode 100644 ProjectTank/ProjectTank/EntityArmoredTransport.cs create mode 100644 ProjectTank/ProjectTank/IMoveableObject.cs create mode 100644 ProjectTank/ProjectTank/MoveToBorder.cs create mode 100644 ProjectTank/ProjectTank/MoveToCenter.cs create mode 100644 ProjectTank/ProjectTank/ObjectParameters.cs create mode 100644 ProjectTank/ProjectTank/Status.cs diff --git a/ProjectTank/ProjectTank/AbstractStrategy.cs b/ProjectTank/ProjectTank/AbstractStrategy.cs new file mode 100644 index 0000000..15c9d35 --- /dev/null +++ b/ProjectTank/ProjectTank/AbstractStrategy.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectTank.DrawningObjects; + +namespace ProjectTank.MovementStrategy +{ + /// + /// Класс-стратегия перемещения объекта + /// + public abstract class AbstractStrategy + { + /// + /// Перемещаемый объект + /// + private IMoveableObject? _moveableObject; + /// + /// Статус перемещения + /// + private Status _state = Status.NotInit; + /// + /// Ширина поля + /// + protected int FieldWidth { get; private set; } + /// + /// Высота поля + /// + protected int FieldHeight { get; private set; } + /// + /// Статус перемещения + /// + public Status GetStatus() { return _state; } + /// + /// Установка данных + /// + /// Перемещаемый объект + /// Ширина поля + /// Высота поля + public void SetData(IMoveableObject moveableObject, int width, int + height) + { + if (moveableObject == null) + { + _state = Status.NotInit; + return; + } + _state = Status.InProgress; + _moveableObject = moveableObject; + FieldWidth = width; + FieldHeight = height; + } + /// + /// Шаг перемещения + /// + public void MakeStep() + { + if (_state != Status.InProgress) + { + return; + } + if (IsTargetDestinaion()) + { + _state = Status.Finish; + return; + } + MoveToTarget(); + } + /// + /// Перемещение влево + /// + /// Результат перемещения (true - удалось переместиться, false -неудача) + protected bool MoveLeft() => MoveTo(DirectionType.Left); + /// + /// Перемещение вправо + /// + /// Результат перемещения (true - удалось переместиться,false - неудача) + protected bool MoveRight() => MoveTo(DirectionType.Right); + /// + /// Перемещение вверх + /// + /// Результат перемещения (true - удалось переместиться,false - неудача) + protected bool MoveUp() => MoveTo(DirectionType.Up); + /// + /// Перемещение вниз + /// + /// Результат перемещения (true - удалось переместиться,false - неудача) + protected bool MoveDown() => MoveTo(DirectionType.Down); + /// + /// Параметры объекта + /// + protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition; + /// + /// Шаг объекта + /// + /// + protected int? GetStep() + { + if (_state != Status.InProgress) + { + return null; + } + return _moveableObject?.GetStep; + } + /// + /// Перемещение к цели + /// + protected abstract void MoveToTarget(); + /// + /// Достигнута ли цель + /// + /// + protected abstract bool IsTargetDestinaion(); + /// + /// Попытка перемещения в требуемом направлении + /// + /// Направление + /// Результат попытки (true - удалось переместиться, false - неудача) + private bool MoveTo(DirectionType directionType) + { + if (_state != Status.InProgress) + { + return false; + } + if (_moveableObject?.CheckCanMove(directionType) ?? false) + { + _moveableObject.MoveObject(directionType); + return true; + } + return false; + } + } +} diff --git a/ProjectTank/ProjectTank/DrawningArmoredTransport.cs b/ProjectTank/ProjectTank/DrawningArmoredTransport.cs new file mode 100644 index 0000000..4394b3d --- /dev/null +++ b/ProjectTank/ProjectTank/DrawningArmoredTransport.cs @@ -0,0 +1,226 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectTank.Entities; + +namespace ProjectTank.DrawningObjects +{ + /// + /// Класс, отвечающий за прорисовку и перемещение объекта-сущности + /// + public class DrawningArmoredTransport + { + /// + /// Класс-сущность + /// + public EntityArmoredTransport? EntityArmoredTransport { get; protected set; } + /// + /// Ширина окна + /// + private int _pictureWidth; + /// + /// Высота окна + /// + private int _pictureHeight; + /// + /// Левая координата прорисовки автомобиля + /// + protected int _startPosX; + /// + /// Верхняя кооридната прорисовки автомобиля + /// + protected int _startPosY; + /// + /// Ширина прорисовки автомобиля + /// + protected readonly int _transportWidth = 200; + /// + /// Высота прорисовки автомобиля + /// + protected readonly int _transportHeight = 80; + /// + /// Координата X объекта + /// + public int GetPosX => _startPosX; + /// + /// Координата Y объекта + /// + public int GetPosY => _startPosY; + /// + /// Ширина объекта + /// + public int GetWidth => _transportWidth; + /// + /// Высота объекта + /// + public int GetHeight => _transportHeight; + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Ширина картинки + /// Высота картинки + public DrawningArmoredTransport(int speed, double weight, Color bodyColor, int + width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + if ((_pictureHeight > _transportHeight) && (_pictureWidth > _transportWidth)) + { + EntityArmoredTransport = new EntityArmoredTransport(speed, weight, bodyColor); + } + } + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Ширина картинки + /// Высота картинки + /// Ширина прорисовки автомобиля + /// Высота прорисовки автомобиля + protected DrawningArmoredTransport(int speed, double weight, Color bodyColor, int + width, int height, int transportWidth, int transportHeight) + { + _pictureWidth = width; + _pictureHeight = height; + _transportWidth = transportWidth; + _transportHeight = transportHeight; + if ((_pictureHeight > _transportHeight) && (_pictureWidth > _transportWidth)) + { + EntityArmoredTransport = new EntityArmoredTransport(speed, weight, bodyColor); + } + } + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + if ((x < 0 || y < 0) || (x + _transportWidth > _pictureWidth || y + _transportHeight > _pictureHeight)) + { + _startPosX = 0; + _startPosY = 0; + } + else + { + _startPosX = x; + _startPosY = y; + } + } + /// + /// Прорисовка объекта + /// + /// + public virtual void DrawTransport(Graphics g) + { + if (EntityArmoredTransport == null) + { + return; + } + Pen pen = new(Color.Black, 3); + Pen penGray = new(Color.Gray, 4); + Brush grayColorBrush = new SolidBrush(Color.Gray); + Brush blackColorBrush = new SolidBrush(Color.Black); + Brush bodyBrush = new SolidBrush(EntityArmoredTransport.BodyColor); + + + // Границы автомобиля + // гусеницы + g.DrawEllipse(pen, _startPosX + 14, _startPosY + 44, 151, 31); + g.FillEllipse(blackColorBrush, _startPosX + 15, _startPosY + 45, 150, 30); + g.DrawEllipse(penGray, _startPosX + 24, _startPosY + 54, 10, 10); + g.DrawEllipse(penGray, _startPosX + 144, _startPosY + 54, 10, 10); + g.DrawEllipse(penGray, _startPosX + 44, _startPosY + 59, 10, 10); + g.DrawEllipse(penGray, _startPosX + 124, _startPosY + 59, 10, 10); + g.DrawEllipse(penGray, _startPosX + 64, _startPosY + 61, 10, 10); + g.DrawEllipse(penGray, _startPosX + 104, _startPosY + 61, 10, 10); + g.DrawEllipse(penGray, _startPosX + 84, _startPosY + 62, 10, 10); + // Кузов + g.DrawRectangle(pen, _startPosX + 19, _startPosY + 34, 141, 21); + g.FillRectangle(bodyBrush, _startPosX + 20, _startPosY + 35, 140, 20); + + // Башня + g.FillRectangle(blackColorBrush, _startPosX + 75, _startPosY + 10, 25, 5); + g.DrawRectangle(pen, _startPosX + 64, _startPosY + 14, 66, 21); + g.FillRectangle(bodyBrush, _startPosX + 65, _startPosY + 15, 65, 20); //*** -> bodyBrush <- additionalBrush + + //Точки для отрисовки передней и задней части + Point pointFirstBackSide = new Point(_startPosX + 18, _startPosY + 35); + Point pointSecondBackSide = new Point(_startPosX + 18, _startPosY + 55); + Point pointThirdBackSide = new Point(_startPosX + 0, _startPosY + 55); + Point pointFirstFrontSide = new Point(_startPosX + 162, _startPosY + 35); + Point pointSecondFrontSide = new Point(_startPosX + 185, _startPosY + 55); + Point pointThirdFrontSide = new Point(_startPosX + 162, _startPosY + 55); + + // Задняя часть + Point[] backSide = { pointFirstBackSide, pointSecondBackSide, pointThirdBackSide }; + g.DrawPolygon(pen, backSide); + g.FillPolygon(bodyBrush, backSide); + // Передняя часть + Point[] frontSide = { pointFirstFrontSide, pointSecondFrontSide, pointThirdFrontSide }; + g.DrawPolygon(pen, frontSide); + g.FillPolygon(bodyBrush, frontSide); + } + /// + /// Проверка, что объект может переместится по указанному направлению + /// + /// Направление + /// true - можно переместится по указанномунаправлению + public bool CanMove(DirectionType direction) + { + if (EntityArmoredTransport == null) + { + return false; + } + return direction switch + { + //влево + DirectionType.Left => _startPosX - EntityArmoredTransport.Step > 0, + //вверх + DirectionType.Up => _startPosY - EntityArmoredTransport.Step > 0, + // вправо + DirectionType.Right => _startPosX + _transportWidth + EntityArmoredTransport.Step < _pictureWidth, + //вниз + DirectionType.Down => _startPosY + _transportHeight + EntityArmoredTransport.Step < _pictureHeight, + _ => false, + }; + } + /// + /// Изменение направления перемещения + /// + /// Направление + public void MoveTransport(DirectionType direction) + { + if (!CanMove(direction) || EntityArmoredTransport == null) + { + return; + } + switch (direction) + { + //влево + case DirectionType.Left: + _startPosX -= (int)EntityArmoredTransport.Step; + break; + //вверх + case DirectionType.Up: + _startPosY -= (int)EntityArmoredTransport.Step; + break; + // вправо + case DirectionType.Right: + _startPosX += (int)EntityArmoredTransport.Step; + break; + //вниз + case DirectionType.Down: + _startPosY += (int)EntityArmoredTransport.Step; + break; + } + } + } +} diff --git a/ProjectTank/ProjectTank/DrawningObjectArmoredTransport.cs b/ProjectTank/ProjectTank/DrawningObjectArmoredTransport.cs new file mode 100644 index 0000000..fe3b14d --- /dev/null +++ b/ProjectTank/ProjectTank/DrawningObjectArmoredTransport.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectTank.DrawningObjects; + +namespace ProjectTank.MovementStrategy +{ + /// + /// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar(паттерн Adapter) +/// + public class DrawningObjectArmoredTransport : IMoveableObject + { + private readonly DrawningArmoredTransport? _drawningArmoredTransport = null; + public DrawningObjectArmoredTransport(DrawningArmoredTransport drawningArmoredTransport) + { + _drawningArmoredTransport = drawningArmoredTransport; + } + public ObjectParameters? GetObjectPosition + { + get + { + if (_drawningArmoredTransport == null || _drawningArmoredTransport.EntityArmoredTransport == + null) + { + return null; + } + return new ObjectParameters(_drawningArmoredTransport.GetPosX, + _drawningArmoredTransport.GetPosY, _drawningArmoredTransport.GetWidth, _drawningArmoredTransport.GetHeight); + } + } + public int GetStep => (int)(_drawningArmoredTransport?.EntityArmoredTransport?.Step ?? 0); + public bool CheckCanMove(DirectionType direction) =>_drawningArmoredTransport?.CanMove(direction) ?? false; + public void MoveObject(DirectionType direction) =>_drawningArmoredTransport?.MoveTransport(direction); + } +} \ No newline at end of file diff --git a/ProjectTank/ProjectTank/DrawningTank.cs b/ProjectTank/ProjectTank/DrawningTank.cs index aa1d415..f3e90cf 100644 --- a/ProjectTank/ProjectTank/DrawningTank.cs +++ b/ProjectTank/ProjectTank/DrawningTank.cs @@ -1,182 +1,51 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using ProjectTank.Entities; -namespace ProjectTank +namespace ProjectTank.DrawningObjects { - public class DrawningTank + /// + /// Класс, отвечающий за прорисовку и перемещение объекта-сущности + /// + public class DrawningTank : DrawningArmoredTransport { /// - /// Класс-сущность - /// - public EntityTank? _EntityTank { get; private set; } - /// - /// Ширина окна - /// - private int _pictureWidth; - /// - /// Высота окна - /// - private int _pictureHeight; - /// - /// Левая координата прорисовки танка - /// - private int _startPosX; - /// - /// Верхняя кооридната прорисовки танка - /// - private int _startPosY; - /// - /// Ширина прорисовки танка - /// - private readonly int _tankWidth = 200; - /// - /// Высота прорисовки танка - /// - private readonly int _tankHeight = 80; - /// - /// Инициализация свойств + /// Конструктор /// /// Скорость /// Вес - /// Цвет кузова + /// Основной цвет /// Дополнительный цвет + /// Пушка + /// Пулемет /// Ширина картинки /// Высота картинки - /// true - объект создан, false - проверка не пройдена,нельзя создать объект в этих размерах - public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, - bool gun, bool machineGun, int width, int height) + public DrawningTank(int speed, double weight, Color bodyColor, Color + additionalColor, bool gun, bool machineGun, int width, int height) : + base(speed, weight, bodyColor, width, height, 200, 80) { - _pictureWidth = width; - _pictureHeight = height; - - if ((_pictureHeight < _tankHeight) || (_pictureWidth < _tankWidth)) + if (EntityArmoredTransport != null) { - return false; - } - _EntityTank = new EntityTank(); - _EntityTank.Init(speed, weight, gun, machineGun, bodyColor, additionalColor); - return true; - } - /// - /// Установка позиции - /// - /// Координата X - /// Координата Y - public void SetPosition(int x, int y) - { - if ((x < 0 || y < 0) || (x + _tankWidth > _pictureWidth || y + _tankHeight > _pictureHeight)) - { - _startPosX = 0; - _startPosY = 0; - } - else - { - _startPosX = x; - _startPosY = y; + EntityArmoredTransport = new EntityTank(speed, weight, bodyColor, + additionalColor, gun, machineGun); } } - /// - /// Изменение направления перемещения - /// - /// Направление - public void MoveTransport(DirectionType direction) + public override void DrawTransport(Graphics g) { - if (_EntityTank == null) - { - return; - } - switch (direction) - { - //влево - case DirectionType.Left: - if (_startPosX - _EntityTank.Step > 0) - { - _startPosX -= (int)_EntityTank.Step; - } - break; - //вверх - case DirectionType.Up: - if (_startPosY - _EntityTank.Step > 0) - { - _startPosY -= (int)_EntityTank.Step; - } - break; - //вправо - case DirectionType.Right: - if (_startPosX + _tankWidth + _EntityTank.Step < _pictureWidth) - { - _startPosX += (int)_EntityTank.Step; - } - break; - //вниз - case DirectionType.Down: - if (_startPosY + _tankHeight + _EntityTank.Step < _pictureHeight) - { - _startPosY += (int)_EntityTank.Step; - } - break; - } - } - /// - /// Прорисовка объекта - /// - /// - public void DrawTransport(Graphics g) - { - if (_EntityTank == null) + if (EntityArmoredTransport is not EntityTank tank) { return; } Pen pen = new(Color.Black, 3); - Pen penGray = new(Color.Gray, 4); - Brush grayColorBrush = new SolidBrush(Color.Gray); Brush blackColorBrush = new SolidBrush(Color.Black); - Brush additionalBrush = new SolidBrush(_EntityTank.AdditionalColor); - Brush bodyBrush = new SolidBrush(_EntityTank.BodyColor); - - // Границы автомобиля - // гусеницы - g.DrawEllipse(pen, _startPosX+14, _startPosY+44, 151, 31); - g.FillEllipse(blackColorBrush, _startPosX + 15, _startPosY + 45, 150, 30); - g.DrawEllipse(penGray, _startPosX + 24, _startPosY + 54, 10, 10); - g.DrawEllipse(penGray, _startPosX + 144, _startPosY + 54, 10, 10); - g.DrawEllipse(penGray, _startPosX + 44, _startPosY + 59, 10, 10); - g.DrawEllipse(penGray, _startPosX + 124, _startPosY + 59, 10, 10); - g.DrawEllipse(penGray, _startPosX + 64, _startPosY + 61, 10, 10); - g.DrawEllipse(penGray, _startPosX + 104, _startPosY + 61, 10, 10); - g.DrawEllipse(penGray, _startPosX + 84, _startPosY + 62, 10, 10); - // Кузов - g.DrawRectangle(pen, _startPosX + 19, _startPosY + 34, 141, 21); - g.FillRectangle(bodyBrush, _startPosX+20, _startPosY+35, 140, 20); - - // Башня - g.FillRectangle(blackColorBrush, _startPosX + 75, _startPosY + 10, 25, 5); - g.DrawRectangle(pen, _startPosX + 64, _startPosY + 14, 66, 21); - g.FillRectangle(additionalBrush, _startPosX + 65, _startPosY + 15, 65, 20); - - //Точки для отрисовки передней и задней части - Point pointFirstBackSide = new Point(_startPosX + 18, _startPosY + 35); - Point pointSecondBackSide = new Point(_startPosX + 18, _startPosY + 55); - Point pointThirdBackSide = new Point(_startPosX+0, _startPosY+55); - Point pointFirstFrontSide = new Point(_startPosX + 162, _startPosY + 35); - Point pointSecondFrontSide = new Point(_startPosX + 185, _startPosY + 55); - Point pointThirdFrontSide = new Point(_startPosX + 162, _startPosY + 55); - - // Задняя часть - Point[] backSide = { pointFirstBackSide, pointSecondBackSide, pointThirdBackSide }; - g.DrawPolygon(pen, backSide); - g.FillPolygon(bodyBrush, backSide); - // Передняя часть - Point[] frontSide ={ pointFirstFrontSide, pointSecondFrontSide, pointThirdFrontSide }; - g.DrawPolygon(pen, frontSide); - g.FillPolygon(bodyBrush, frontSide); - + Brush additionalBrush = new SolidBrush(tank.AdditionalColor); // пушка - if (_EntityTank.Gun) + if (tank.Gun) { g.DrawRectangle(pen, _startPosX + 129, _startPosY + 19, 56, 6); g.FillRectangle(additionalBrush, _startPosX + 130, _startPosY + 20, 55, 5); @@ -184,7 +53,7 @@ namespace ProjectTank g.FillRectangle(blackColorBrush, _startPosX + 185, _startPosY + 18, 15, 10); } // пулемет - if (_EntityTank.MachineGun) + if (tank.MachineGun) { g.DrawRectangle(pen, _startPosX + 104, _startPosY + 9, 16, 6); g.FillRectangle(additionalBrush, _startPosX + 105, _startPosY + 10, 15, 5); @@ -195,6 +64,7 @@ namespace ProjectTank g.FillRectangle(additionalBrush, _startPosX + 105, _startPosY + 3, 29, 3); g.FillRectangle(blackColorBrush, _startPosX + 135, _startPosY, 15, 8); } + base.DrawTransport(g); } } } diff --git a/ProjectTank/ProjectTank/EntityArmoredTransport.cs b/ProjectTank/ProjectTank/EntityArmoredTransport.cs new file mode 100644 index 0000000..bf3b54a --- /dev/null +++ b/ProjectTank/ProjectTank/EntityArmoredTransport.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectTank.Entities +{ + /// + /// Класс-сущность "Бронирванный транспорт" + /// + public class EntityArmoredTransport + { + /// + /// Скорость + /// + public int Speed { get; private set; } + /// + /// Вес + /// + public double Weight { get; private set; } + /// + /// Основной цвет + /// + public Color BodyColor { get; private set; } + /// + /// Шаг перемещения автомобиля + /// + public double Step => (double)Speed * 100 / Weight; + /// + /// Конструктор с параметрами + /// + /// Скорость + /// Вес автомобиля + /// Основной цвет + public EntityArmoredTransport(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } + } +} diff --git a/ProjectTank/ProjectTank/EntityTank.cs b/ProjectTank/ProjectTank/EntityTank.cs index 3834940..fcde423 100644 --- a/ProjectTank/ProjectTank/EntityTank.cs +++ b/ProjectTank/ProjectTank/EntityTank.cs @@ -1,22 +1,21 @@ -using System; +using ProjectTank.Entities; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ProjectTank +namespace ProjectTank.Entities { - public class EntityTank + /// + /// Класс-сущность "Танк" + /// + public class EntityTank : EntityArmoredTransport { /// - /// Скорость + /// Дополнительный цвет (для опциональных элементов) /// - public int Speed { get; private set; } - - /// - /// Вес - /// - public double Weight { get; private set; } + public Color AdditionalColor { get; private set; } /// /// Пушка @@ -28,21 +27,6 @@ namespace ProjectTank /// public bool MachineGun { get; private set; } - /// - /// Основной цвет - /// - public Color BodyColor { get; private set; } - - /// - /// Дополнительный цвет (для опциональных элементов) - /// - public Color AdditionalColor { get; private set; } - - /// - /// Расчет шага по карте - /// - public double Step => (double)Speed * 100 / Weight; - /// /// Инициализация полей объекта-класса спортивного автомобиля /// @@ -52,13 +36,9 @@ namespace ProjectTank /// Дополнительный цвет /// Признак наличия пушки /// Признак наличия пулемета - /// - public void Init(int speed, double weight, bool gun, - bool machineGun, Color bodyColor, Color additionalColor) + public EntityTank(int speed, double weight, Color bodyColor, Color additionalColor, bool gun, + bool machineGun) : base(speed, weight, bodyColor) { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; AdditionalColor = additionalColor; Gun = gun; MachineGun = machineGun; diff --git a/ProjectTank/ProjectTank/IMoveableObject.cs b/ProjectTank/ProjectTank/IMoveableObject.cs new file mode 100644 index 0000000..8403d7a --- /dev/null +++ b/ProjectTank/ProjectTank/IMoveableObject.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectTank.DrawningObjects; + +namespace ProjectTank.MovementStrategy +{ + /// + /// Интерфейс для работы с перемещаемым объектом + /// + public interface IMoveableObject + { + /// + /// Получение координаты X объекта + /// + ObjectParameters? GetObjectPosition { get; } + /// + /// Шаг объекта + /// + int GetStep { get; } + /// + /// Проверка, можно ли переместиться по нужному направлению + /// + /// + /// + bool CheckCanMove(DirectionType direction); + /// + /// Изменение направления пермещения объекта + /// + /// Направление + void MoveObject(DirectionType direction); + } +} diff --git a/ProjectTank/ProjectTank/MoveToBorder.cs b/ProjectTank/ProjectTank/MoveToBorder.cs new file mode 100644 index 0000000..9079642 --- /dev/null +++ b/ProjectTank/ProjectTank/MoveToBorder.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectTank.MovementStrategy +{ + /// + /// Стратегия перемещения объекта в центр экрана + /// + public class MoveToBorder : AbstractStrategy + { + protected override bool IsTargetDestinaion() + { + var objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + return objParams.RightBorder <= FieldWidth && + objParams.RightBorder + GetStep() >= FieldWidth && + objParams.DownBorder <= FieldHeight && + objParams.DownBorder + GetStep() >= FieldHeight; + } + protected override void MoveToTarget() + { + var objParams = GetObjectParameters; + if (objParams == null) + { + return; + } + var diffX = objParams.RightBorder - FieldWidth; + if (Math.Abs(diffX) > GetStep()) + { + MoveRight(); + } + var diffY = objParams.DownBorder - FieldHeight; + if (Math.Abs(diffY) > GetStep()) + { + MoveDown(); + } + } + } +} diff --git a/ProjectTank/ProjectTank/MoveToCenter.cs b/ProjectTank/ProjectTank/MoveToCenter.cs new file mode 100644 index 0000000..32a10cc --- /dev/null +++ b/ProjectTank/ProjectTank/MoveToCenter.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectTank.MovementStrategy +{ + /// + /// Стратегия перемещения объекта в центр экрана + /// + public class MoveToCenter : AbstractStrategy + { + protected override bool IsTargetDestinaion() + { + var objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 && + objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 && + objParams.ObjectMiddleVertical <= FieldHeight / 2 && + objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2; + } + protected override void MoveToTarget() + { + var objParams = GetObjectParameters; + if (objParams == null) + { + return; + } + var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2; + if (Math.Abs(diffX) > GetStep()) + { + if (diffX > 0) + { + MoveLeft(); + } + else + { + MoveRight(); + } + } + var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2; + if (Math.Abs(diffY) > GetStep()) + { + if (diffY > 0) + { + MoveUp(); + } + else + { + MoveDown(); + } + } + } + } +} diff --git a/ProjectTank/ProjectTank/ObjectParameters.cs b/ProjectTank/ProjectTank/ObjectParameters.cs new file mode 100644 index 0000000..14e4f3d --- /dev/null +++ b/ProjectTank/ProjectTank/ObjectParameters.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectTank.MovementStrategy +{ + /// + /// Параметры-координаты объекта + /// + public class ObjectParameters + { + private readonly int _x; + private readonly int _y; + private readonly int _width; + private readonly int _height; + /// + /// Левая граница + /// + public int LeftBorder => _x; + /// + /// Верхняя граница + /// + public int TopBorder => _y; + /// + /// Правая граница + /// + public int RightBorder => _x + _width; + /// + /// Нижняя граница + /// + public int DownBorder => _y + _height; + /// + /// Середина объекта + /// + public int ObjectMiddleHorizontal => _x + _width / 2; + /// + /// Середина объекта + /// + public int ObjectMiddleVertical => _y + _height / 2; + /// + /// Конструктор + /// + /// Координата X + /// Координата Y + /// Ширина + /// Высота + public ObjectParameters(int x, int y, int width, int height) + { + _x = x; + _y = y; + _width = width; + _height = height; + } + } +} diff --git a/ProjectTank/ProjectTank/Status.cs b/ProjectTank/ProjectTank/Status.cs new file mode 100644 index 0000000..346c4dc --- /dev/null +++ b/ProjectTank/ProjectTank/Status.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectTank.MovementStrategy +{ + /// + /// Статус выполнения операции перемещения + /// + public enum Status + { + NotInit, + InProgress, + Finish + } +} diff --git a/ProjectTank/ProjectTank/TankForm.Designer.cs b/ProjectTank/ProjectTank/TankForm.Designer.cs index 9340b66..dcc809e 100644 --- a/ProjectTank/ProjectTank/TankForm.Designer.cs +++ b/ProjectTank/ProjectTank/TankForm.Designer.cs @@ -35,6 +35,9 @@ this.buttonLeft = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); + this.comboBoxStrategy = new System.Windows.Forms.ComboBox(); + this.ButtonCreateArmoredTransport = new System.Windows.Forms.Button(); + this.ButtonStep = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTanks)).BeginInit(); this.SuspendLayout(); // @@ -42,7 +45,7 @@ // this.pictureBoxTanks.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBoxTanks.Location = new System.Drawing.Point(0, 0); - this.pictureBoxTanks.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.pictureBoxTanks.Margin = new System.Windows.Forms.Padding(6); this.pictureBoxTanks.Name = "pictureBoxTanks"; this.pictureBoxTanks.Size = new System.Drawing.Size(1445, 881); this.pictureBoxTanks.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; @@ -53,11 +56,11 @@ // this.ButtonCreateTank.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.ButtonCreateTank.Location = new System.Drawing.Point(22, 806); - this.ButtonCreateTank.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.ButtonCreateTank.Margin = new System.Windows.Forms.Padding(6); this.ButtonCreateTank.Name = "ButtonCreateTank"; - this.ButtonCreateTank.Size = new System.Drawing.Size(139, 49); + this.ButtonCreateTank.Size = new System.Drawing.Size(192, 49); this.ButtonCreateTank.TabIndex = 1; - this.ButtonCreateTank.Text = "Создать"; + this.ButtonCreateTank.Text = "Создать Танк"; this.ButtonCreateTank.UseVisualStyleBackColor = true; this.ButtonCreateTank.Click += new System.EventHandler(this.ButtonCreateTank_Click); // @@ -67,7 +70,7 @@ this.buttonUp.BackgroundImage = global::ProjectTank.Properties.Resources.btnUp; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonUp.Location = new System.Drawing.Point(1300, 730); - this.buttonUp.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.buttonUp.Margin = new System.Windows.Forms.Padding(6); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(56, 64); this.buttonUp.TabIndex = 2; @@ -80,7 +83,7 @@ this.buttonRight.BackgroundImage = global::ProjectTank.Properties.Resources.btnRight; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonRight.Location = new System.Drawing.Point(1367, 806); - this.buttonRight.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.buttonRight.Margin = new System.Windows.Forms.Padding(6); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(56, 64); this.buttonRight.TabIndex = 3; @@ -93,7 +96,7 @@ this.buttonLeft.BackgroundImage = global::ProjectTank.Properties.Resources.btnLeft; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonLeft.Location = new System.Drawing.Point(1233, 806); - this.buttonLeft.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.buttonLeft.Margin = new System.Windows.Forms.Padding(6); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(56, 64); this.buttonLeft.TabIndex = 4; @@ -106,7 +109,7 @@ this.buttonDown.BackgroundImage = global::ProjectTank.Properties.Resources.btnDown; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonDown.Location = new System.Drawing.Point(1300, 806); - this.buttonDown.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.buttonDown.Margin = new System.Windows.Forms.Padding(6); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(56, 64); this.buttonDown.TabIndex = 5; @@ -122,11 +125,51 @@ this.label1.Size = new System.Drawing.Size(0, 32); this.label1.TabIndex = 6; // + // comboBoxStrategy + // + this.comboBoxStrategy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxStrategy.FormattingEnabled = true; + this.comboBoxStrategy.Items.AddRange(new object[] { + "0", + "1"}); + this.comboBoxStrategy.Location = new System.Drawing.Point(1181, 12); + this.comboBoxStrategy.Name = "comboBoxStrategy"; + this.comboBoxStrategy.Size = new System.Drawing.Size(242, 40); + this.comboBoxStrategy.TabIndex = 7; + // + // ButtonCreateArmoredTransport + // + this.ButtonCreateArmoredTransport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.ButtonCreateArmoredTransport.Location = new System.Drawing.Point(241, 806); + this.ButtonCreateArmoredTransport.Margin = new System.Windows.Forms.Padding(6); + this.ButtonCreateArmoredTransport.Name = "ButtonCreateArmoredTransport"; + this.ButtonCreateArmoredTransport.Size = new System.Drawing.Size(401, 49); + this.ButtonCreateArmoredTransport.TabIndex = 8; + this.ButtonCreateArmoredTransport.Text = "Создать Бронированную машину"; + this.ButtonCreateArmoredTransport.UseVisualStyleBackColor = true; + this.ButtonCreateArmoredTransport.Click += new System.EventHandler(this.ButtonCreateArmoredTransport_Click); + // + // ButtonStep + // + this.ButtonStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonStep.Location = new System.Drawing.Point(1263, 61); + this.ButtonStep.Margin = new System.Windows.Forms.Padding(6); + this.ButtonStep.Name = "ButtonStep"; + this.ButtonStep.Size = new System.Drawing.Size(160, 49); + this.ButtonStep.TabIndex = 9; + this.ButtonStep.Text = "Шаг"; + this.ButtonStep.UseVisualStyleBackColor = true; + this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click); + // // TankForm // this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1445, 881); + this.Controls.Add(this.ButtonStep); + this.Controls.Add(this.ButtonCreateArmoredTransport); + this.Controls.Add(this.comboBoxStrategy); this.Controls.Add(this.label1); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonLeft); @@ -134,7 +177,7 @@ this.Controls.Add(this.buttonUp); this.Controls.Add(this.ButtonCreateTank); this.Controls.Add(this.pictureBoxTanks); - this.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.Margin = new System.Windows.Forms.Padding(6); this.Name = "TankForm"; this.Text = "Tank"; ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTanks)).EndInit(); @@ -151,5 +194,8 @@ private Button buttonDown; public PictureBox pictureBoxTanks; private Label label1; + private ComboBox comboBoxStrategy; + private Button ButtonCreateArmoredTransport; + private Button ButtonStep; } } \ No newline at end of file diff --git a/ProjectTank/ProjectTank/TankForm.cs b/ProjectTank/ProjectTank/TankForm.cs index 72273a3..c4bfa90 100644 --- a/ProjectTank/ProjectTank/TankForm.cs +++ b/ProjectTank/ProjectTank/TankForm.cs @@ -1,4 +1,6 @@ using System.Reflection.Emit; +using ProjectTank.DrawningObjects; +using ProjectTank.MovementStrategy; namespace ProjectTank { @@ -10,7 +12,11 @@ namespace ProjectTank /// /// - /// - private DrawningTank? _drawningTank; + private DrawningArmoredTransport? _drawningArmoredTransport; + /// + /// + /// + private AbstractStrategy? _abstractStrategy; /// /// /// @@ -23,13 +29,13 @@ namespace ProjectTank /// private void Draw() { - if (_drawningTank == null) + if (_drawningArmoredTransport == null) { return; } Bitmap bmp = new(pictureBoxTanks.Width, pictureBoxTanks.Height); Graphics gr = Graphics.FromImage(bmp); - _drawningTank.DrawTransport(gr); + _drawningArmoredTransport.DrawTransport(gr); pictureBoxTanks.Image = bmp; } /// @@ -40,12 +46,27 @@ namespace ProjectTank private void ButtonCreateTank_Click(object sender, EventArgs e) { Random random = new(); - _drawningTank = new DrawningTank(); - _drawningTank.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)), - pictureBoxTanks.Width, pictureBoxTanks.Height); - _drawningTank.SetPosition(random.Next(0, 100), random.Next(0, 100)); + _drawningArmoredTransport = new DrawningTank(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)), + pictureBoxTanks.Width, pictureBoxTanks.Height); + _drawningArmoredTransport.SetPosition(random.Next(0, 100), random.Next(0, 100)); + Draw(); + } + /// + /// " " + /// + /// + /// + private void ButtonCreateArmoredTransport_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningArmoredTransport = new DrawningArmoredTransport(random.Next(100, 300),random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), + random.Next(0, 256)), + pictureBoxTanks.Width, pictureBoxTanks.Height); + _drawningArmoredTransport.SetPosition(random.Next(10, 100), random.Next(10,100)); Draw(); } /// @@ -55,7 +76,7 @@ namespace ProjectTank /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawningTank == null) + if (_drawningArmoredTransport == null) { return; } @@ -63,19 +84,59 @@ namespace ProjectTank switch (name) { case "buttonUp": - _drawningTank.MoveTransport(DirectionType.Up); + _drawningArmoredTransport.MoveTransport(DirectionType.Up); break; case "buttonDown": - _drawningTank.MoveTransport(DirectionType.Down); + _drawningArmoredTransport.MoveTransport(DirectionType.Down); break; case "buttonLeft": - _drawningTank.MoveTransport(DirectionType.Left); + _drawningArmoredTransport.MoveTransport(DirectionType.Left); break; case "buttonRight": - _drawningTank.MoveTransport(DirectionType.Right); + _drawningArmoredTransport.MoveTransport(DirectionType.Right); break; } Draw(); } + /// + /// "" + /// + /// + /// + private void ButtonStep_Click(object sender, EventArgs e) + { + if (_drawningArmoredTransport == null) + { + return; + } + if (comboBoxStrategy.Enabled) + { + _abstractStrategy = comboBoxStrategy.SelectedIndex + switch + { + 0 => new MoveToCenter(), + 1 => new MoveToBorder(), + _ => null, + }; + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.SetData(new DrawningObjectArmoredTransport(_drawningArmoredTransport), + pictureBoxTanks.Width, pictureBoxTanks.Height); + comboBoxStrategy.Enabled = false; + } + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.MakeStep(); + Draw(); + if (_abstractStrategy.GetStatus() == Status.Finish) + { + comboBoxStrategy.Enabled = true; + _abstractStrategy = null; + } + } } } \ No newline at end of file -- 2.25.1 From 7e28d26868a674c2dc0ce9febebaedaf470cb356 Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Fri, 6 Oct 2023 11:52:16 +0400 Subject: [PATCH 12/15] lab2 is done with amendment --- ProjectTank/ProjectTank/DrawningArmoredTransport.cs | 5 +---- ProjectTank/ProjectTank/DrawningObjectArmoredTransport.cs | 2 +- ProjectTank/ProjectTank/DrawningTank.cs | 5 ++--- ProjectTank/ProjectTank/EntityTank.cs | 3 --- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/ProjectTank/ProjectTank/DrawningArmoredTransport.cs b/ProjectTank/ProjectTank/DrawningArmoredTransport.cs index 4394b3d..3effdab 100644 --- a/ProjectTank/ProjectTank/DrawningArmoredTransport.cs +++ b/ProjectTank/ProjectTank/DrawningArmoredTransport.cs @@ -130,7 +130,6 @@ namespace ProjectTank.DrawningObjects Brush blackColorBrush = new SolidBrush(Color.Black); Brush bodyBrush = new SolidBrush(EntityArmoredTransport.BodyColor); - // Границы автомобиля // гусеницы g.DrawEllipse(pen, _startPosX + 14, _startPosY + 44, 151, 31); @@ -145,11 +144,10 @@ namespace ProjectTank.DrawningObjects // Кузов g.DrawRectangle(pen, _startPosX + 19, _startPosY + 34, 141, 21); g.FillRectangle(bodyBrush, _startPosX + 20, _startPosY + 35, 140, 20); - // Башня g.FillRectangle(blackColorBrush, _startPosX + 75, _startPosY + 10, 25, 5); g.DrawRectangle(pen, _startPosX + 64, _startPosY + 14, 66, 21); - g.FillRectangle(bodyBrush, _startPosX + 65, _startPosY + 15, 65, 20); //*** -> bodyBrush <- additionalBrush + g.FillRectangle(bodyBrush, _startPosX + 65, _startPosY + 15, 65, 20); //Точки для отрисовки передней и задней части Point pointFirstBackSide = new Point(_startPosX + 18, _startPosY + 35); @@ -158,7 +156,6 @@ namespace ProjectTank.DrawningObjects Point pointFirstFrontSide = new Point(_startPosX + 162, _startPosY + 35); Point pointSecondFrontSide = new Point(_startPosX + 185, _startPosY + 55); Point pointThirdFrontSide = new Point(_startPosX + 162, _startPosY + 55); - // Задняя часть Point[] backSide = { pointFirstBackSide, pointSecondBackSide, pointThirdBackSide }; g.DrawPolygon(pen, backSide); diff --git a/ProjectTank/ProjectTank/DrawningObjectArmoredTransport.cs b/ProjectTank/ProjectTank/DrawningObjectArmoredTransport.cs index fe3b14d..f8198ab 100644 --- a/ProjectTank/ProjectTank/DrawningObjectArmoredTransport.cs +++ b/ProjectTank/ProjectTank/DrawningObjectArmoredTransport.cs @@ -9,7 +9,7 @@ namespace ProjectTank.MovementStrategy { /// /// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar(паттерн Adapter) -/// + /// public class DrawningObjectArmoredTransport : IMoveableObject { private readonly DrawningArmoredTransport? _drawningArmoredTransport = null; diff --git a/ProjectTank/ProjectTank/DrawningTank.cs b/ProjectTank/ProjectTank/DrawningTank.cs index f3e90cf..2b85acc 100644 --- a/ProjectTank/ProjectTank/DrawningTank.cs +++ b/ProjectTank/ProjectTank/DrawningTank.cs @@ -26,13 +26,12 @@ namespace ProjectTank.DrawningObjects /// Ширина картинки /// Высота картинки public DrawningTank(int speed, double weight, Color bodyColor, Color - additionalColor, bool gun, bool machineGun, int width, int height) : - base(speed, weight, bodyColor, width, height, 200, 80) + additionalColor, bool gun, bool machineGun, int width, int height) : base(speed,weight, bodyColor, width, height, 200, 80) { if (EntityArmoredTransport != null) { EntityArmoredTransport = new EntityTank(speed, weight, bodyColor, - additionalColor, gun, machineGun); + additionalColor, gun, machineGun); } } public override void DrawTransport(Graphics g) diff --git a/ProjectTank/ProjectTank/EntityTank.cs b/ProjectTank/ProjectTank/EntityTank.cs index fcde423..136aca2 100644 --- a/ProjectTank/ProjectTank/EntityTank.cs +++ b/ProjectTank/ProjectTank/EntityTank.cs @@ -16,17 +16,14 @@ namespace ProjectTank.Entities /// Дополнительный цвет (для опциональных элементов) /// public Color AdditionalColor { get; private set; } - /// /// Пушка /// public bool Gun { get; private set; } - /// /// Пулемет /// public bool MachineGun { get; private set; } - /// /// Инициализация полей объекта-класса спортивного автомобиля /// -- 2.25.1 From 66f19085b971d7d68b9ed84af2f83a8ace5ef65b Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Thu, 19 Oct 2023 20:58:56 +0400 Subject: [PATCH 13/15] Edited from first lab --- .../{Direction.cs => DirectionType.cs} | 56 +++++++++---------- .../ProjectTank/DrawningArmoredTransport.cs | 32 +++++------ .../DrawningObjectArmoredTransport.cs | 7 +-- 3 files changed, 47 insertions(+), 48 deletions(-) rename ProjectTank/ProjectTank/{Direction.cs => DirectionType.cs} (94%) diff --git a/ProjectTank/ProjectTank/Direction.cs b/ProjectTank/ProjectTank/DirectionType.cs similarity index 94% rename from ProjectTank/ProjectTank/Direction.cs rename to ProjectTank/ProjectTank/DirectionType.cs index 303cf57..7e6a2b7 100644 --- a/ProjectTank/ProjectTank/Direction.cs +++ b/ProjectTank/ProjectTank/DirectionType.cs @@ -1,28 +1,28 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectTank -{ - public enum DirectionType - { - /// - /// Вверх - /// - Up = 1, - /// - /// Вниз - /// - Down = 2, - /// - /// Влево - /// - Left = 3, - /// - /// Вправо - /// - Right = 4 - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectTank +{ + public enum DirectionType + { + /// + /// Вверх + /// + Up = 1, + /// + /// Вниз + /// + Down = 2, + /// + /// Влево + /// + Left = 3, + /// + /// Вправо + /// + Right = 4 + } +} diff --git a/ProjectTank/ProjectTank/DrawningArmoredTransport.cs b/ProjectTank/ProjectTank/DrawningArmoredTransport.cs index 3effdab..ac81c1e 100644 --- a/ProjectTank/ProjectTank/DrawningArmoredTransport.cs +++ b/ProjectTank/ProjectTank/DrawningArmoredTransport.cs @@ -25,19 +25,19 @@ namespace ProjectTank.DrawningObjects /// private int _pictureHeight; /// - /// Левая координата прорисовки автомобиля + /// Левая координата прорисовки транспорта /// protected int _startPosX; /// - /// Верхняя кооридната прорисовки автомобиля + /// Верхняя кооридната прорисовки транспорта /// protected int _startPosY; /// - /// Ширина прорисовки автомобиля + /// Ширина прорисовки транспорта /// protected readonly int _transportWidth = 200; /// - /// Высота прорисовки автомобиля + /// Высота прорисовки транспорта /// protected readonly int _transportHeight = 80; /// @@ -65,14 +65,14 @@ namespace ProjectTank.DrawningObjects /// Ширина картинки /// Высота картинки public DrawningArmoredTransport(int speed, double weight, Color bodyColor, int - width, int height) + width, int height) { - _pictureWidth = width; - _pictureHeight = height; - if ((_pictureHeight > _transportHeight) && (_pictureWidth > _transportWidth)) + if ((height > _transportHeight) && (width > _transportWidth)) { EntityArmoredTransport = new EntityArmoredTransport(speed, weight, bodyColor); } + _pictureWidth = width; + _pictureHeight = height; } /// /// Конструктор @@ -82,19 +82,19 @@ namespace ProjectTank.DrawningObjects /// Основной цвет /// Ширина картинки /// Высота картинки - /// Ширина прорисовки автомобиля - /// Высота прорисовки автомобиля + /// Ширина прорисовки транспорта + /// Высота прорисовки транспорта protected DrawningArmoredTransport(int speed, double weight, Color bodyColor, int - width, int height, int transportWidth, int transportHeight) + width, int height, int transportWidth, int transportHeight) { + if ((height > transportHeight) && (width > transportWidth)) + { + EntityArmoredTransport = new EntityArmoredTransport(speed, weight, bodyColor); + } _pictureWidth = width; _pictureHeight = height; _transportWidth = transportWidth; _transportHeight = transportHeight; - if ((_pictureHeight > _transportHeight) && (_pictureWidth > _transportWidth)) - { - EntityArmoredTransport = new EntityArmoredTransport(speed, weight, bodyColor); - } } /// /// Установка позиции @@ -130,7 +130,7 @@ namespace ProjectTank.DrawningObjects Brush blackColorBrush = new SolidBrush(Color.Black); Brush bodyBrush = new SolidBrush(EntityArmoredTransport.BodyColor); - // Границы автомобиля + // Границы транспорта // гусеницы g.DrawEllipse(pen, _startPosX + 14, _startPosY + 44, 151, 31); g.FillEllipse(blackColorBrush, _startPosX + 15, _startPosY + 45, 150, 30); diff --git a/ProjectTank/ProjectTank/DrawningObjectArmoredTransport.cs b/ProjectTank/ProjectTank/DrawningObjectArmoredTransport.cs index f8198ab..e7a51c9 100644 --- a/ProjectTank/ProjectTank/DrawningObjectArmoredTransport.cs +++ b/ProjectTank/ProjectTank/DrawningObjectArmoredTransport.cs @@ -21,13 +21,12 @@ namespace ProjectTank.MovementStrategy { get { - if (_drawningArmoredTransport == null || _drawningArmoredTransport.EntityArmoredTransport == - null) + if (_drawningArmoredTransport == null || _drawningArmoredTransport.EntityArmoredTransport == null) { return null; } - return new ObjectParameters(_drawningArmoredTransport.GetPosX, - _drawningArmoredTransport.GetPosY, _drawningArmoredTransport.GetWidth, _drawningArmoredTransport.GetHeight); + return new ObjectParameters(_drawningArmoredTransport.GetPosX, _drawningArmoredTransport.GetPosY, + _drawningArmoredTransport.GetWidth, _drawningArmoredTransport.GetHeight); } } public int GetStep => (int)(_drawningArmoredTransport?.EntityArmoredTransport?.Step ?? 0); -- 2.25.1 From ce904c50056143f0d15a87aa091df793826978cd Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Thu, 19 Oct 2023 22:25:30 +0400 Subject: [PATCH 14/15] code dubbed --- ...ArmoredTransportCollectionForm.Designer.cs | 143 ++++++++++++++++++ .../ArmoredTransportCollectionForm.cs | 93 ++++++++++++ .../ArmoredTransportCollectionForm.resx | 63 ++++++++ .../ArmoredTransportsGenericCollection.cs | 138 +++++++++++++++++ .../ProjectTank/DrawningArmoredTransport.cs | 5 + ProjectTank/ProjectTank/Program.cs | 4 +- ProjectTank/ProjectTank/SetGeneric.cs | 80 ++++++++++ ProjectTank/ProjectTank/TankForm.cs | 35 ++++- 8 files changed, 552 insertions(+), 9 deletions(-) create mode 100644 ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs create mode 100644 ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs create mode 100644 ProjectTank/ProjectTank/ArmoredTransportCollectionForm.resx create mode 100644 ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs create mode 100644 ProjectTank/ProjectTank/SetGeneric.cs diff --git a/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs new file mode 100644 index 0000000..b8e9ce8 --- /dev/null +++ b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs @@ -0,0 +1,143 @@ +namespace ProjectTank +{ + partial class ArmoredTransportCollectionForm + { + /// + /// 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.ArmoredTransportCollectionFormToolsGroup = new System.Windows.Forms.GroupBox(); + this.ButtonRefreshCollection = new System.Windows.Forms.Button(); + this.ButtonRemoveArmoredTransport = new System.Windows.Forms.Button(); + this.maskedTextBoxNumber = new System.Windows.Forms.TextBox(); + this.ButtonAddArmoredTransport = new System.Windows.Forms.Button(); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.pictureBoxCollection = new System.Windows.Forms.PictureBox(); + this.ArmoredTransportCollectionFormToolsGroup.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); + this.SuspendLayout(); + // + // ArmoredTransportCollectionFormToolsGroup + // + this.ArmoredTransportCollectionFormToolsGroup.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Right))); + this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.ButtonRefreshCollection); + this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.ButtonRemoveArmoredTransport); + this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.maskedTextBoxNumber); + this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.ButtonAddArmoredTransport); + this.ArmoredTransportCollectionFormToolsGroup.Location = new System.Drawing.Point(1057, -4); + this.ArmoredTransportCollectionFormToolsGroup.Name = "ArmoredTransportCollectionFormToolsGroup"; + this.ArmoredTransportCollectionFormToolsGroup.Size = new System.Drawing.Size(431, 865); + this.ArmoredTransportCollectionFormToolsGroup.TabIndex = 0; + this.ArmoredTransportCollectionFormToolsGroup.TabStop = false; + this.ArmoredTransportCollectionFormToolsGroup.Text = "Инструменты"; + // + // ButtonRefreshCollection + // + this.ButtonRefreshCollection.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonRefreshCollection.Location = new System.Drawing.Point(22, 394); + this.ButtonRefreshCollection.Name = "ButtonRefreshCollection"; + this.ButtonRefreshCollection.Size = new System.Drawing.Size(391, 47); + this.ButtonRefreshCollection.TabIndex = 3; + this.ButtonRefreshCollection.Text = "Обновить коллекцию"; + this.ButtonRefreshCollection.UseVisualStyleBackColor = true; + this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click); + // + // ButtonRemoveArmoredTransport + // + this.ButtonRemoveArmoredTransport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonRemoveArmoredTransport.Location = new System.Drawing.Point(22, 251); + this.ButtonRemoveArmoredTransport.Name = "ButtonRemoveArmoredTransport"; + this.ButtonRemoveArmoredTransport.Size = new System.Drawing.Size(391, 82); + this.ButtonRemoveArmoredTransport.TabIndex = 2; + this.ButtonRemoveArmoredTransport.Text = "Удалить бронированный транспорт"; + this.ButtonRemoveArmoredTransport.UseVisualStyleBackColor = true; + this.ButtonRemoveArmoredTransport.Click += new System.EventHandler(this.ButtonRemoveArmoredTransport_Click); + // + // maskedTextBoxNumber + // + this.maskedTextBoxNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.maskedTextBoxNumber.Location = new System.Drawing.Point(71, 188); + this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + this.maskedTextBoxNumber.Size = new System.Drawing.Size(275, 39); + this.maskedTextBoxNumber.TabIndex = 1; + this.maskedTextBoxNumber.TextChanged += new System.EventHandler(this.maskedTextBoxNumber_TextChanged); + // + // ButtonAddArmoredTransport + // + this.ButtonAddArmoredTransport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ButtonAddArmoredTransport.Location = new System.Drawing.Point(22, 88); + this.ButtonAddArmoredTransport.Name = "ButtonAddArmoredTransport"; + this.ButtonAddArmoredTransport.Size = new System.Drawing.Size(391, 82); + this.ButtonAddArmoredTransport.TabIndex = 0; + this.ButtonAddArmoredTransport.Text = "Добавить бронированный транспорт"; + this.ButtonAddArmoredTransport.UseVisualStyleBackColor = true; + this.ButtonAddArmoredTransport.Click += new System.EventHandler(this.ButtonAddArmoredTransport_Click); + // + // contextMenuStrip1 + // + this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(32, 32); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4); + // + // pictureBoxCollection + // + this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0); + this.pictureBoxCollection.Name = "pictureBoxCollection"; + this.pictureBoxCollection.Size = new System.Drawing.Size(1492, 873); + this.pictureBoxCollection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxCollection.TabIndex = 2; + this.pictureBoxCollection.TabStop = false; + // + // ArmoredTransportCollectionForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1492, 873); + this.Controls.Add(this.ArmoredTransportCollectionFormToolsGroup); + this.Controls.Add(this.pictureBoxCollection); + this.Name = "ArmoredTransportCollectionForm"; + this.Text = "ArmoredTransportCollectionForm"; + this.ArmoredTransportCollectionFormToolsGroup.ResumeLayout(false); + this.ArmoredTransportCollectionFormToolsGroup.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private GroupBox ArmoredTransportCollectionFormToolsGroup; + private Button ButtonRefreshCollection; + private Button ButtonRemoveArmoredTransport; + private TextBox maskedTextBoxNumber; + private Button ButtonAddArmoredTransport; + private ContextMenuStrip contextMenuStrip1; + private PictureBox pictureBoxCollection; + } +} \ No newline at end of file diff --git a/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs new file mode 100644 index 0000000..e3255e7 --- /dev/null +++ b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs @@ -0,0 +1,93 @@ +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; +using ProjectTank.DrawningObjects; +using ProjectTank.Generics; +using ProjectTank.MovementStrategy; + +namespace ProjectTank +{ + /// + /// Форма для работы с набором объектов класса DrawningCar + /// + public partial class ArmoredTransportCollectionForm : Form + { + /// + /// Набор объектов + /// + private readonly ArmoredTransportsGenericCollection _armoredTransports; + /// + /// Конструктор + /// + public ArmoredTransportCollectionForm() + { + InitializeComponent(); + _armoredTransports = new ArmoredTransportsGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + } + /// + /// Добавление объекта в набор + /// + /// + /// + private void ButtonAddArmoredTransport_Click(object sender, EventArgs e) + { + TankForm form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_armoredTransports + form.SelectedArmoredTransport) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + /// + /// Удаление объекта из набора + /// + /// + /// + private void ButtonRemoveArmoredTransport_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxNumber.Text); + if (_armoredTransports - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Обновление рисунка по набору + /// + /// + /// + private void ButtonRefreshCollection_Click(object sender, EventArgs + e) + { + pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports(); + } + + private void maskedTextBoxNumber_TextChanged(object sender, EventArgs e) + { + + } + } +} diff --git a/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.resx b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.resx new file mode 100644 index 0000000..2a349cc --- /dev/null +++ b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs b/ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs new file mode 100644 index 0000000..7e213ed --- /dev/null +++ b/ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectTank.DrawningObjects; +using ProjectTank.MovementStrategy; + +namespace ProjectTank.Generics +{ + /// + /// Параметризованный класс для набора объектов DrawningArmoredTransport + /// + /// + /// + internal class ArmoredTransportsGenericCollection + where T : DrawningArmoredTransport + where U : IMoveableObject + { + /// + /// Ширина окна прорисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна прорисовки + /// + private readonly int _pictureHeight; + /// + /// Размер занимаемого объектом места (ширина) + /// + private readonly int _placeSizeWidth = 200; + /// + /// Размер занимаемого объектом места (высота) + /// + private readonly int _placeSizeHeight = 80; + /// + /// Набор объектов + /// + private readonly SetGeneric _collection; + /// + /// Конструктор + /// + /// + /// + public ArmoredTransportsGenericCollection(int picWidth, int picHeight) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = new SetGeneric(width * height); + } + /// + /// Перегрузка оператора сложения + /// + /// + /// + /// + public static bool operator +(ArmoredTransportsGenericCollection collect, T? obj) + { + if (obj == null) + { + return false; + } + return collect?._collection.Insert(obj) ?? false; + } + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static T? operator -(ArmoredTransportsGenericCollection collect, int + pos) + { + T? obj = collect._collection.Get(pos); + if (obj != null) + { + collect._collection.Remove(pos); + } + return obj; + } + /// + /// Получение объекта IMoveableObject + /// + /// + /// + public U? GetU(int pos) + { + return (U?)_collection.Get(pos)?.GetMoveableObject; + } + /// + /// Вывод всего набора объектов + /// + /// + public Bitmap ShowArmoredTransports() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawObjects(gr); + return bmp; + } + /// + /// Метод отрисовки фона + /// + /// + private void DrawBackground(Graphics g) + { + Pen pen = new(Color.Black, 3); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + + 1; ++j) + { + //линия рамзетки места + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, + i * _placeSizeWidth + _placeSizeWidth / 2, j *_placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, + _pictureHeight / _placeSizeHeight * _placeSizeHeight); + } + } + /// + /// Метод прорисовки объектов + /// + /// + private void DrawObjects(Graphics g) + { + for (int i = 0; i < _collection.Count; i++) + { + // TODO получение объекта + // TODO установка позиции + // TODO прорисовка объекта + } + } + } +} diff --git a/ProjectTank/ProjectTank/DrawningArmoredTransport.cs b/ProjectTank/ProjectTank/DrawningArmoredTransport.cs index ac81c1e..39fd477 100644 --- a/ProjectTank/ProjectTank/DrawningArmoredTransport.cs +++ b/ProjectTank/ProjectTank/DrawningArmoredTransport.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using ProjectTank.Entities; +using ProjectTank.MovementStrategy; namespace ProjectTank.DrawningObjects { @@ -57,6 +58,10 @@ namespace ProjectTank.DrawningObjects /// public int GetHeight => _transportHeight; /// + /// Получение объекта IMoveableObject из объекта DrawningArmoredTransport + /// + public IMoveableObject GetMoveableObject => new DrawningObjectArmoredTransport(this); + /// /// Конструктор /// /// Скорость diff --git a/ProjectTank/ProjectTank/Program.cs b/ProjectTank/ProjectTank/Program.cs index 10b63f7..23b598f 100644 --- a/ProjectTank/ProjectTank/Program.cs +++ b/ProjectTank/ProjectTank/Program.cs @@ -10,8 +10,10 @@ namespace ProjectTank [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 TankForm()); + Application.Run(new ArmoredTransportCollectionForm()); } } } \ No newline at end of file diff --git a/ProjectTank/ProjectTank/SetGeneric.cs b/ProjectTank/ProjectTank/SetGeneric.cs new file mode 100644 index 0000000..2fcdd84 --- /dev/null +++ b/ProjectTank/ProjectTank/SetGeneric.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectTank.Generics +{ + /// + /// Параметризованный набор объектов + /// + /// + internal class SetGeneric + where T : class + { + /// + /// Массив объектов, которые храним + /// + private readonly T?[] _places; + /// + /// Количество объектов в массиве + /// + public int Count => _places.Length; + /// + /// Конструктор + /// + /// + public SetGeneric(int count) + { + _places = new T?[count]; + } + /// + /// Добавление объекта в набор + /// + /// Добавляемый автомобиль + /// + public bool Insert(T car) + { + // TODO вставка в начало набора + return true; + } + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемый автомобиль + /// Позиция + /// + public bool Insert(T car, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // проверка, что после вставляемого элемента в массиве есть пустой элемент + // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента + // TODO вставка по позиции + _places[position] = car; + return true; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присвоив элементу массива значение null + return true; + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T? Get(int position) + { + // TODO проверка позиции + return _places[position]; + } + } +} diff --git a/ProjectTank/ProjectTank/TankForm.cs b/ProjectTank/ProjectTank/TankForm.cs index c4bfa90..4402c9e 100644 --- a/ProjectTank/ProjectTank/TankForm.cs +++ b/ProjectTank/ProjectTank/TankForm.cs @@ -18,11 +18,17 @@ namespace ProjectTank /// private AbstractStrategy? _abstractStrategy; /// + /// + /// + public DrawningArmoredTransport? SelectedArmoredTransport { get; private set; } + /// /// /// public TankForm() { InitializeComponent(); + _abstractStrategy = null; + SelectedArmoredTransport = null; } /// /// @@ -46,10 +52,13 @@ namespace ProjectTank private void ButtonCreateTank_Click(object sender, EventArgs e) { Random random = new(); + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + //TODO + Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + //TODO _drawningArmoredTransport = new DrawningTank(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)), + color, dopColor,Convert.ToBoolean(random.Next(0, 2)), + Convert.ToBoolean(random.Next(0, 2)), pictureBoxTanks.Width, pictureBoxTanks.Height); _drawningArmoredTransport.SetPosition(random.Next(0, 100), random.Next(0, 100)); Draw(); @@ -62,9 +71,9 @@ namespace ProjectTank private void ButtonCreateArmoredTransport_Click(object sender, EventArgs e) { Random random = new(); - _drawningArmoredTransport = new DrawningArmoredTransport(random.Next(100, 300),random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + //TODO + _drawningArmoredTransport = new DrawningArmoredTransport(random.Next(100, 300),random.Next(1000, 3000), color, pictureBoxTanks.Width, pictureBoxTanks.Height); _drawningArmoredTransport.SetPosition(random.Next(10, 100), random.Next(10,100)); Draw(); @@ -122,14 +131,14 @@ namespace ProjectTank { return; } - _abstractStrategy.SetData(new DrawningObjectArmoredTransport(_drawningArmoredTransport), + _abstractStrategy.SetData(_drawningArmoredTransport.GetMoveableObject, pictureBoxTanks.Width, pictureBoxTanks.Height); - comboBoxStrategy.Enabled = false; } if (_abstractStrategy == null) { return; } + comboBoxStrategy.Enabled = false; _abstractStrategy.MakeStep(); Draw(); if (_abstractStrategy.GetStatus() == Status.Finish) @@ -138,5 +147,15 @@ namespace ProjectTank _abstractStrategy = null; } } + /// + /// + /// + /// + /// + private void ButtonSelectCar_Click(object sender, EventArgs e) + { + SelectedArmoredTransport = _drawningArmoredTransport; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file -- 2.25.1 From 5419c0c52d5875ed6f5a1a3472eb9d40ac45c5ad Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Thu, 2 Nov 2023 20:50:20 +0400 Subject: [PATCH 15/15] laba3 is done --- ...ArmoredTransportCollectionForm.Designer.cs | 1 - .../ArmoredTransportCollectionForm.cs | 7 +-- .../ArmoredTransportsGenericCollection.cs | 48 ++++++++++------- ProjectTank/ProjectTank/SetGeneric.cs | 51 +++++++++++++------ ProjectTank/ProjectTank/TankForm.Designer.cs | 15 ++++++ ProjectTank/ProjectTank/TankForm.cs | 19 +++++-- 6 files changed, 97 insertions(+), 44 deletions(-) diff --git a/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs index b8e9ce8..d99b1e8 100644 --- a/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs +++ b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs @@ -84,7 +84,6 @@ this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; this.maskedTextBoxNumber.Size = new System.Drawing.Size(275, 39); this.maskedTextBoxNumber.TabIndex = 1; - this.maskedTextBoxNumber.TextChanged += new System.EventHandler(this.maskedTextBoxNumber_TextChanged); // // ButtonAddArmoredTransport // diff --git a/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs index e3255e7..826e20c 100644 --- a/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs +++ b/ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs @@ -40,7 +40,7 @@ namespace ProjectTank TankForm form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (_armoredTransports + form.SelectedArmoredTransport) + if (_armoredTransports + form.SelectedArmoredTransport != null) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports(); @@ -84,10 +84,5 @@ namespace ProjectTank { pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports(); } - - private void maskedTextBoxNumber_TextChanged(object sender, EventArgs e) - { - - } } } diff --git a/ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs b/ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs index 7e213ed..ff3f105 100644 --- a/ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs +++ b/ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs @@ -17,6 +17,10 @@ namespace ProjectTank.Generics where T : DrawningArmoredTransport where U : IMoveableObject { + /// + /// Коэффициент изменения ширины парковки + /// + readonly int koefWidth = 2; /// /// Ширина окна прорисовки /// @@ -32,7 +36,7 @@ namespace ProjectTank.Generics /// /// Размер занимаемого объектом места (высота) /// - private readonly int _placeSizeHeight = 80; + private readonly int _placeSizeHeight = 90; /// /// Набор объектов /// @@ -56,13 +60,13 @@ namespace ProjectTank.Generics /// /// /// - public static bool operator +(ArmoredTransportsGenericCollection collect, T? obj) + public static int operator +(ArmoredTransportsGenericCollection collect, T? obj) { - if (obj == null) + if (obj == null || collect == null) { - return false; + return -1; } - return collect?._collection.Insert(obj) ?? false; + return collect._collection.Insert(obj); } /// /// Перегрузка оператора вычитания @@ -70,15 +74,14 @@ namespace ProjectTank.Generics /// /// /// - public static T? operator -(ArmoredTransportsGenericCollection collect, int - pos) + public static bool operator -(ArmoredTransportsGenericCollection collect, int pos) { - T? obj = collect._collection.Get(pos); - if (obj != null) + T? obj = collect?._collection.Get(pos); + if (obj != null && collect != null) { - collect._collection.Remove(pos); + return collect._collection.Remove(pos); } - return obj; + return false; } /// /// Получение объекта IMoveableObject @@ -108,17 +111,19 @@ namespace ProjectTank.Generics private void DrawBackground(Graphics g) { Pen pen = new(Color.Black, 3); - for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + for (int i = 0; i < (_pictureWidth / _placeSizeWidth)/koefWidth; i++) //изменение ширины парковки { - for (int j = 0; j < _pictureHeight / _placeSizeHeight + - 1; ++j) + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) { //линия рамзетки места - g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *_placeSizeHeight); + g.DrawString("P", new Font("Courier New", 30.0F), new SolidBrush(Color.Blue), + new Point(i * _placeSizeWidth, (j-1) * _placeSizeHeight)); } g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); + } } /// @@ -127,11 +132,18 @@ namespace ProjectTank.Generics /// private void DrawObjects(Graphics g) { + int width = (_pictureWidth / _placeSizeWidth)/koefWidth; //изменение ширины парковки + int height = _pictureHeight / _placeSizeHeight; for (int i = 0; i < _collection.Count; i++) { - // TODO получение объекта - // TODO установка позиции - // TODO прорисовка объекта + DrawningArmoredTransport? armoredTransport = _collection.Get(i); + if (armoredTransport != null) + { + int row = height - 1 - (i / width); + int col = width - 1 - (i % width); + armoredTransport.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight); + armoredTransport.DrawTransport(g); + } } } } diff --git a/ProjectTank/ProjectTank/SetGeneric.cs b/ProjectTank/ProjectTank/SetGeneric.cs index 2fcdd84..63a2874 100644 --- a/ProjectTank/ProjectTank/SetGeneric.cs +++ b/ProjectTank/ProjectTank/SetGeneric.cs @@ -32,12 +32,18 @@ namespace ProjectTank.Generics /// /// Добавление объекта в набор /// - /// Добавляемый автомобиль + /// Добавляемый автомобиль /// - public bool Insert(T car) + public int Insert(T armoredTransport) { - // TODO вставка в начало набора - return true; + if (_places[Count - 1] != null) + { + return -1; + } + else + { + return Insert(armoredTransport,0); + } } /// /// Добавление объекта в набор на конкретную позицию @@ -45,15 +51,22 @@ namespace ProjectTank.Generics /// Добавляемый автомобиль /// Позиция /// - public bool Insert(T car, int position) + public int Insert(T armoredTransport, int position) { - // TODO проверка позиции - // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // проверка, что после вставляемого элемента в массиве есть пустой элемент - // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента - // TODO вставка по позиции - _places[position] = car; - return true; + if (!(position >= 0 && position < Count)) + return -1; + if (_places[position] != null) + { + int ind = position; + while (ind < Count && _places[ind] != null) + ind++; + if (ind == Count) + return -1; + for (int i = ind - 1; i >= position; i--) + _places[i + 1] = _places[i]; + } + _places[position] = armoredTransport; + return position; } /// /// Удаление объекта из набора с конкретной позиции @@ -62,9 +75,12 @@ namespace ProjectTank.Generics /// public bool Remove(int position) { - // TODO проверка позиции - // TODO удаление объекта из массива, присвоив элементу массива значение null - return true; + if (!(position >= 0 && position < Count) || _places[position] == null) + { + return false; + } + _places[position] = null; + return true; } /// /// Получение объекта из набора по позиции @@ -73,7 +89,10 @@ namespace ProjectTank.Generics /// public T? Get(int position) { - // TODO проверка позиции + if (!(position >= 0 && position < Count)) + { + return null; + } return _places[position]; } } diff --git a/ProjectTank/ProjectTank/TankForm.Designer.cs b/ProjectTank/ProjectTank/TankForm.Designer.cs index dcc809e..e4d9053 100644 --- a/ProjectTank/ProjectTank/TankForm.Designer.cs +++ b/ProjectTank/ProjectTank/TankForm.Designer.cs @@ -38,6 +38,7 @@ this.comboBoxStrategy = new System.Windows.Forms.ComboBox(); this.ButtonCreateArmoredTransport = new System.Windows.Forms.Button(); this.ButtonStep = new System.Windows.Forms.Button(); + this.ButtonSelectArmoredTransport = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTanks)).BeginInit(); this.SuspendLayout(); // @@ -162,11 +163,24 @@ this.ButtonStep.UseVisualStyleBackColor = true; this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click); // + // ButtonSelectArmoredTransport + // + this.ButtonSelectArmoredTransport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.ButtonSelectArmoredTransport.Location = new System.Drawing.Point(664, 806); + this.ButtonSelectArmoredTransport.Margin = new System.Windows.Forms.Padding(6); + this.ButtonSelectArmoredTransport.Name = "ButtonSelectArmoredTransport"; + this.ButtonSelectArmoredTransport.Size = new System.Drawing.Size(227, 49); + this.ButtonSelectArmoredTransport.TabIndex = 10; + this.ButtonSelectArmoredTransport.Text = "Выбор"; + this.ButtonSelectArmoredTransport.UseVisualStyleBackColor = true; + this.ButtonSelectArmoredTransport.Click += new System.EventHandler(this.ButtonSelectArmoredTransport_Click); + // // TankForm // this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1445, 881); + this.Controls.Add(this.ButtonSelectArmoredTransport); this.Controls.Add(this.ButtonStep); this.Controls.Add(this.ButtonCreateArmoredTransport); this.Controls.Add(this.comboBoxStrategy); @@ -197,5 +211,6 @@ private ComboBox comboBoxStrategy; private Button ButtonCreateArmoredTransport; private Button ButtonStep; + private Button ButtonSelectArmoredTransport; } } \ No newline at end of file diff --git a/ProjectTank/ProjectTank/TankForm.cs b/ProjectTank/ProjectTank/TankForm.cs index 4402c9e..9bebbd4 100644 --- a/ProjectTank/ProjectTank/TankForm.cs +++ b/ProjectTank/ProjectTank/TankForm.cs @@ -53,9 +53,17 @@ namespace ProjectTank { Random random = new(); Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); - //TODO + ColorDialog dialogMain = new(); + if (dialogMain.ShowDialog() == DialogResult.OK) + { + color = dialogMain.Color; + } Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); - //TODO + ColorDialog dialogDop = new(); + if (dialogDop.ShowDialog() == DialogResult.OK) + { + dopColor = dialogDop.Color; + } _drawningArmoredTransport = new DrawningTank(random.Next(100, 300), random.Next(1000, 3000), color, dopColor,Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), @@ -73,6 +81,11 @@ namespace ProjectTank Random random = new(); Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); //TODO + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } _drawningArmoredTransport = new DrawningArmoredTransport(random.Next(100, 300),random.Next(1000, 3000), color, pictureBoxTanks.Width, pictureBoxTanks.Height); _drawningArmoredTransport.SetPosition(random.Next(10, 100), random.Next(10,100)); @@ -152,7 +165,7 @@ namespace ProjectTank /// /// /// - private void ButtonSelectCar_Click(object sender, EventArgs e) + private void ButtonSelectArmoredTransport_Click(object sender, EventArgs e) { SelectedArmoredTransport = _drawningArmoredTransport; DialogResult = DialogResult.OK; -- 2.25.1