From 57e736cf992e814be233038d9822062af7b4dd50 Mon Sep 17 00:00:00 2001 From: Garifullin-Farid <95081032+Garifullin-Farid@users.noreply.github.com> Date: Tue, 12 Mar 2024 10:11:39 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D0=BD=D1=80=D0=BD=D0=B0=D1=8F=E2=84=961=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{DicretionType.cs => DirectionType.cs} | 10 +- ...{DrawningTank.cs => DrawningBattleTank.cs} | 109 +++++++++--------- .../{EntityTank.cs => EntiyBattleTank.cs} | 6 +- ...Designer.cs => FormBattleTank.Designer.cs} | 107 +++++++++-------- .../{FormTank.cs => FormBattleTank.cs} | 41 +++---- .../{FormTank.resx => FormBattleTank.resx} | 0 ProjectTank/ProjectTank/Program.cs | 2 +- 7 files changed, 139 insertions(+), 136 deletions(-) rename ProjectTank/ProjectTank/{DicretionType.cs => DirectionType.cs} (80%) rename ProjectTank/ProjectTank/{DrawningTank.cs => DrawningBattleTank.cs} (68%) rename ProjectTank/ProjectTank/{EntityTank.cs => EntiyBattleTank.cs} (89%) rename ProjectTank/ProjectTank/{FormTank.Designer.cs => FormBattleTank.Designer.cs} (63%) rename ProjectTank/ProjectTank/{FormTank.cs => FormBattleTank.cs} (62%) rename ProjectTank/ProjectTank/{FormTank.resx => FormBattleTank.resx} (100%) diff --git a/ProjectTank/ProjectTank/DicretionType.cs b/ProjectTank/ProjectTank/DirectionType.cs similarity index 80% rename from ProjectTank/ProjectTank/DicretionType.cs rename to ProjectTank/ProjectTank/DirectionType.cs index fa4a350..7810a36 100644 --- a/ProjectTank/ProjectTank/DicretionType.cs +++ b/ProjectTank/ProjectTank/DirectionType.cs @@ -3,23 +3,23 @@ /// /// направление перемещенния /// - public enum DicretionType + public enum DirectionType { /// /// Вверх /// - Up= 1, + Up = 1, /// /// Вниз /// - Down= 2, + Down = 2, /// /// Влево /// - Left =3, + Left = 3, /// /// Вправо /// - Right=4, + Right = 4, } } diff --git a/ProjectTank/ProjectTank/DrawningTank.cs b/ProjectTank/ProjectTank/DrawningBattleTank.cs similarity index 68% rename from ProjectTank/ProjectTank/DrawningTank.cs rename to ProjectTank/ProjectTank/DrawningBattleTank.cs index cde4615..0b3e6a3 100644 --- a/ProjectTank/ProjectTank/DrawningTank.cs +++ b/ProjectTank/ProjectTank/DrawningBattleTank.cs @@ -2,12 +2,12 @@ /// /// Класс, отвечающий за прорисовку и перемещение объекта-сущности /// -public class DrawningTank +public class DrawningBattleTank { /// /// класс - сущность /// - public EntityTank? EntityTank { get; private set; } + public EntityBattleTank? EntityBattleTank { get; private set; } /// /// ширина окна @@ -48,9 +48,9 @@ public class DrawningTank /// Дополнительный цвет /// орудие /// пулемет на башне - public void Init(EntityTank entityTank) + public void Init(EntityBattleTank entityBattleTank) { - EntityTank = entityTank; + EntityBattleTank = entityBattleTank; _pictureHeight = null; _pictureWidth = null; _startPosX = null; @@ -66,15 +66,16 @@ public class DrawningTank /// true - границы заданы, false - проверка не пройдена , нельзя разместить объект в этих размерах public bool SetPictureSize(int width, int height) { - + if (height < _drawingTankHeight || width < _drawningTankWidth) { return false; } _pictureHeight = height; _pictureWidth = width; - if(_startPosX != null && _startPosY!=null) { - if (_startPosX < 0) _startPosX=0; + if (_startPosX != null && _startPosY != null) + { + if (_startPosX < 0) _startPosX = 0; if (_startPosY < 0) _startPosY = 0; if (_pictureHeight.Value < (_startPosY + _drawingTankHeight)) { @@ -85,15 +86,16 @@ public class DrawningTank _startPosX = _pictureWidth - _drawningTankWidth; } } - + return true; } - /// - /// Установка позиции - /// - /// Координата X - /// Координата Y - public void SetPosition(int x, int y){ + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { if (!_pictureWidth.HasValue || !_pictureHeight.HasValue) { return; @@ -102,8 +104,9 @@ public class DrawningTank _startPosY = y; if (_startPosX < 0) _startPosX = 0; if (_startPosY < 0) _startPosY = 0; - if (_pictureHeight.Value<(_startPosY + _drawingTankHeight)){ - _startPosY = _pictureHeight-_drawingTankHeight; + if (_pictureHeight.Value < (_startPosY + _drawingTankHeight)) + { + _startPosY = _pictureHeight - _drawingTankHeight; } if (_pictureWidth.Value < (_startPosX + _drawningTankWidth)) { @@ -116,76 +119,78 @@ public class DrawningTank /// /// направление /// - public bool MoveTransport(DicretionType dicretion){ - if(EntityTank == null || _startPosX == null || _startPosY == null) + public bool MoveTransport(DirectionType dicretion) + { + if (EntityBattleTank == null || _startPosX == null || _startPosY == null) { return false; } - switch(dicretion) + switch (dicretion) { //влево - case DicretionType.Left: - if(_startPosX.Value - EntityTank.Step > 0) + case DirectionType.Left: + if (_startPosX.Value - EntityBattleTank.Step > 0) { - _startPosX -= (int)EntityTank.Step; + _startPosX -= (int)EntityBattleTank.Step; } return true; //вправо - case DicretionType.Right: - if (_startPosX.Value+ _drawningTankWidth + EntityTank.Step < _pictureWidth) + case DirectionType.Right: + if (_startPosX.Value + _drawningTankWidth + EntityBattleTank.Step < _pictureWidth) { - _startPosX += (int)EntityTank.Step; + _startPosX += (int)EntityBattleTank.Step; } return true; //вверх - case DicretionType.Up: - if(_startPosY.Value - EntityTank.Step > 0) + case DirectionType.Up: + if (_startPosY.Value - EntityBattleTank.Step > 0) { - _startPosY -= (int)EntityTank.Step; + _startPosY -= (int)EntityBattleTank.Step; } return true; //вниз - case DicretionType.Down: - if(_startPosY + EntityTank.Step+ _drawingTankHeight < _pictureHeight) + case DirectionType.Down: + if (_startPosY + EntityBattleTank.Step + _drawingTankHeight < _pictureHeight) { - _startPosY += (int)EntityTank.Step; + _startPosY += (int)EntityBattleTank.Step; } return true; - default: + default: return false; } } - + /// /// прорисовка танка /// /// public void DrawTransport(Graphics g) { - if(EntityTank == null || !_startPosX.HasValue || !_startPosY.HasValue) { + if (EntityBattleTank == null || !_startPosX.HasValue || !_startPosY.HasValue) + { return; } Pen pen = new(Color.Black); - Brush addititionalBrush = new SolidBrush(EntityTank.AdditionalColor); - Brush Br = new SolidBrush(EntityTank.BodyColor); + Brush addititionalBrush = new SolidBrush(EntityBattleTank.AdditionalColor); + Brush Br = new SolidBrush(EntityBattleTank.BodyColor); //основная часть танка - g.DrawRectangle(pen, _startPosX.Value+6, _startPosY.Value+40, 135, 20); - g.DrawRectangle(pen, _startPosX.Value+45, _startPosY.Value+20, 55, 20); - + g.DrawRectangle(pen, _startPosX.Value + 6, _startPosY.Value + 40, 135, 20); + g.DrawRectangle(pen, _startPosX.Value + 45, _startPosY.Value + 20, 55, 20); + g.FillRectangle(Br, _startPosX.Value + 6, _startPosY.Value + 40, 135, 20); g.FillRectangle(Br, _startPosX.Value + 45, _startPosY.Value + 20, 55, 20); //гусеницы - - g.DrawArc(pen, _startPosX.Value, _startPosY.Value + 60, 15,30,100,170); - g.DrawArc(pen, _startPosX.Value+135, _startPosY.Value + 60, 15, 30, -90, 170); - g.DrawLine(pen, _startPosX.Value+5, _startPosY.Value + 60, _startPosX.Value+145, _startPosY.Value + 60); - g.DrawLine(pen, _startPosX.Value+5 , _startPosY.Value + 90, _startPosX.Value + 145, _startPosY.Value + 90); + + g.DrawArc(pen, _startPosX.Value, _startPosY.Value + 60, 15, 30, 100, 170); + g.DrawArc(pen, _startPosX.Value + 135, _startPosY.Value + 60, 15, 30, -90, 170); + g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 60, _startPosX.Value + 145, _startPosY.Value + 60); + g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 90, _startPosX.Value + 145, _startPosY.Value + 90); Pen WidePen = new(Color.Black); WidePen.Width = 2; - g.DrawEllipse(WidePen, _startPosX.Value, _startPosY.Value+60, 24, 24); - g.DrawEllipse(WidePen, _startPosX.Value +125, _startPosY.Value + 60, 24, 24); + g.DrawEllipse(WidePen, _startPosX.Value, _startPosY.Value + 60, 24, 24); + g.DrawEllipse(WidePen, _startPosX.Value + 125, _startPosY.Value + 60, 24, 24); //катки g.DrawEllipse(pen, _startPosX.Value + 26, _startPosY.Value + 70, 20, 20); @@ -199,16 +204,16 @@ public class DrawningTank g.DrawEllipse(pen, _startPosX.Value + 101, _startPosY.Value + 60, 5, 5); //пушка - Brush AdditionalBrush = new SolidBrush(EntityTank.AdditionalColor); - if (EntityTank.Gun) - { - g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value +30, 45, 5); + Brush AdditionalBrush = new SolidBrush(EntityBattleTank.AdditionalColor); + if (EntityBattleTank.Gun) + { + g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 30, 45, 5); - g.FillRectangle(AdditionalBrush, _startPosX.Value, _startPosY.Value +30, 45, 5); + g.FillRectangle(AdditionalBrush, _startPosX.Value, _startPosY.Value + 30, 45, 5); } //пулемет - if (EntityTank.MachinGun) + if (EntityBattleTank.MachinGun) { g.DrawRectangle(pen, _startPosX.Value + 65, _startPosY.Value + 15, 16, 5); g.DrawRectangle(pen, _startPosX.Value + 72, _startPosY.Value + 10, 5, 5); diff --git a/ProjectTank/ProjectTank/EntityTank.cs b/ProjectTank/ProjectTank/EntiyBattleTank.cs similarity index 89% rename from ProjectTank/ProjectTank/EntityTank.cs rename to ProjectTank/ProjectTank/EntiyBattleTank.cs index 373b0dc..d90eb21 100644 --- a/ProjectTank/ProjectTank/EntityTank.cs +++ b/ProjectTank/ProjectTank/EntiyBattleTank.cs @@ -3,7 +3,7 @@ /// /// Класс-сущность танк /// - public class EntityTank + public class EntityBattleTank { /// /// скорость @@ -32,7 +32,7 @@ /// /// Признак (опция) наличия пулемета /// - public bool MachinGun { get; private set; } + public bool MachinGun { get; private set; } /// /// шаг /// @@ -46,7 +46,7 @@ /// Дополнительный цвет /// орудие /// пулемет на башне - public void Init(int speed, double weight,Color bodyColor , Color additionalColor, bool gun, bool machinGun) + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool gun, bool machinGun) { Speed = speed; Weight = weight; diff --git a/ProjectTank/ProjectTank/FormTank.Designer.cs b/ProjectTank/ProjectTank/FormBattleTank.Designer.cs similarity index 63% rename from ProjectTank/ProjectTank/FormTank.Designer.cs rename to ProjectTank/ProjectTank/FormBattleTank.Designer.cs index 2f2c6cd..fab9104 100644 --- a/ProjectTank/ProjectTank/FormTank.Designer.cs +++ b/ProjectTank/ProjectTank/FormBattleTank.Designer.cs @@ -1,6 +1,6 @@ namespace ProjectTank { - partial class FormTank + partial class FormBattleTank { /// /// Required designer variable. @@ -28,45 +28,45 @@ /// private void InitializeComponent() { - pictureBoxTank = new PictureBox(); - ButtonCreate = new Button(); + pictureBoxBattleTank = new PictureBox(); + Создать = new Button(); buttonLeft = new Button(); buttonUp = new Button(); - buttonDown = new Button(); buttonRight = new Button(); - ((System.ComponentModel.ISupportInitialize)pictureBoxTank).BeginInit(); + buttonDown = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxBattleTank).BeginInit(); SuspendLayout(); // - // pictureBoxTank + // pictureBoxBattleTank // - pictureBoxTank.Dock = DockStyle.Fill; - pictureBoxTank.Location = new Point(0, 0); - pictureBoxTank.Name = "pictureBoxTank"; - pictureBoxTank.Size = new Size(941, 462); - pictureBoxTank.TabIndex = 0; - pictureBoxTank.TabStop = false; + pictureBoxBattleTank.Dock = DockStyle.Fill; + pictureBoxBattleTank.Location = new Point(0, 0); + pictureBoxBattleTank.Name = "pictureBoxBattleTank"; + pictureBoxBattleTank.Size = new Size(831, 478); + pictureBoxBattleTank.TabIndex = 0; + pictureBoxBattleTank.TabStop = false; + pictureBoxBattleTank.Click += ButtonMove_Click; // - // ButtonCreate + // Создать // - ButtonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - ButtonCreate.Location = new Point(12, 427); - ButtonCreate.Name = "ButtonCreate"; - ButtonCreate.Size = new Size(75, 23); - ButtonCreate.TabIndex = 1; - ButtonCreate.Text = "создать"; - ButtonCreate.UseVisualStyleBackColor = true; - ButtonCreate.Click += ButtonCreate_Click; + Создать.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + Создать.Location = new Point(12, 443); + Создать.Name = "Создать"; + Создать.Size = new Size(75, 23); + Создать.TabIndex = 1; + Создать.Text = "Создать"; + Создать.UseVisualStyleBackColor = true; + Создать.Click += ButtonCreate_Click; // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.BackgroundImage = Properties.Resources.arrowLeft; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; - buttonLeft.Location = new Point(786, 421); + buttonLeft.Location = new Point(672, 426); buttonLeft.Name = "buttonLeft"; - buttonLeft.Size = new Size(35, 35); + buttonLeft.Size = new Size(40, 40); buttonLeft.TabIndex = 2; - buttonLeft.UseCompatibleTextRendering = true; buttonLeft.UseVisualStyleBackColor = true; buttonLeft.Click += ButtonMove_Click; // @@ -75,64 +75,61 @@ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.BackgroundImage = Properties.Resources.arrowUp; buttonUp.BackgroundImageLayout = ImageLayout.Stretch; - buttonUp.Location = new Point(827, 380); + buttonUp.Location = new Point(718, 380); buttonUp.Name = "buttonUp"; - buttonUp.Size = new Size(35, 35); + buttonUp.Size = new Size(40, 40); buttonUp.TabIndex = 3; - buttonUp.UseCompatibleTextRendering = true; buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += ButtonMove_Click; // + // buttonRight + // + buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRight.BackgroundImage = Properties.Resources.arrowRight_; + buttonRight.BackgroundImageLayout = ImageLayout.Zoom; + buttonRight.Location = new Point(764, 426); + buttonRight.Name = "buttonRight"; + buttonRight.Size = new Size(40, 40); + buttonRight.TabIndex = 4; + buttonRight.UseVisualStyleBackColor = true; + buttonRight.Click += ButtonMove_Click; + // // buttonDown // buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.BackgroundImage = Properties.Resources.arrowDown; buttonDown.BackgroundImageLayout = ImageLayout.Stretch; - buttonDown.Location = new Point(827, 421); + buttonDown.Location = new Point(718, 426); buttonDown.Name = "buttonDown"; - buttonDown.Size = new Size(35, 35); - buttonDown.TabIndex = 4; - buttonDown.UseCompatibleTextRendering = true; + buttonDown.Size = new Size(40, 40); + buttonDown.TabIndex = 5; buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += ButtonMove_Click; // - // buttonRight - // - buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonRight.BackgroundImage = Properties.Resources.arrowRight_; - buttonRight.BackgroundImageLayout = ImageLayout.Stretch; - buttonRight.Location = new Point(868, 421); - buttonRight.Name = "buttonRight"; - buttonRight.Size = new Size(35, 35); - buttonRight.TabIndex = 5; - buttonRight.UseCompatibleTextRendering = true; - buttonRight.UseVisualStyleBackColor = true; - buttonRight.Click += ButtonMove_Click; - // - // FormTank + // FormBattleTank // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(941, 462); - Controls.Add(buttonRight); + ClientSize = new Size(831, 478); Controls.Add(buttonDown); + Controls.Add(buttonRight); Controls.Add(buttonUp); Controls.Add(buttonLeft); - Controls.Add(ButtonCreate); - Controls.Add(pictureBoxTank); - Name = "FormTank"; - Text = "Танк"; - ((System.ComponentModel.ISupportInitialize)pictureBoxTank).EndInit(); + Controls.Add(Создать); + Controls.Add(pictureBoxBattleTank); + Name = "FormBattleTank"; + Text = "FormBattleTank"; + ((System.ComponentModel.ISupportInitialize)pictureBoxBattleTank).EndInit(); ResumeLayout(false); } #endregion - private PictureBox pictureBoxTank; - private Button ButtonCreate; + private PictureBox pictureBoxBattleTank; + private Button Создать; private Button buttonLeft; private Button buttonUp; - private Button buttonDown; private Button buttonRight; + private Button buttonDown; } } \ No newline at end of file diff --git a/ProjectTank/ProjectTank/FormTank.cs b/ProjectTank/ProjectTank/FormBattleTank.cs similarity index 62% rename from ProjectTank/ProjectTank/FormTank.cs rename to ProjectTank/ProjectTank/FormBattleTank.cs index a2da00d..7aeaa4d 100644 --- a/ProjectTank/ProjectTank/FormTank.cs +++ b/ProjectTank/ProjectTank/FormBattleTank.cs @@ -3,38 +3,39 @@ /// /// Форма работы с объектом "Танк" /// - public partial class FormTank : Form + public partial class FormBattleTank : Form { /// /// Поле-объект для прорисовки объекта /// - private DrawningTank? _drawningTank; + private DrawningBattleTank? _drawningBattleTank; /// /// класс - сущность /// - private EntityTank? _entityTank; + private EntityBattleTank? _entityBattleTank; /// /// Конструктор формы /// - public FormTank() + public FormBattleTank() { InitializeComponent(); } + /// - /// Метод прорисовки танка + /// Метод прорисовки танкаx /// private void Draw() { - if (_drawningTank == null) + if (_drawningBattleTank == null) { return; } - Bitmap bmp = new(pictureBoxTank.Width, pictureBoxTank.Height); + Bitmap bmp = new(pictureBoxBattleTank.Width, pictureBoxBattleTank.Height); Graphics gr = Graphics.FromImage(bmp); - _drawningTank.DrawTransport(gr); - pictureBoxTank.Image = bmp; + _drawningBattleTank.DrawTransport(gr); + pictureBoxBattleTank.Image = bmp; } /// @@ -45,15 +46,15 @@ private void ButtonCreate_Click(object sender, EventArgs e) { Random random = new Random(); - _drawningTank = new DrawningTank(); - _entityTank = new EntityTank(); - _entityTank.Init(random.Next(100, 300), random.Next(1000, 3000), + _drawningBattleTank = new DrawningBattleTank(); + _entityBattleTank = new EntityBattleTank(); + _entityBattleTank.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))); - _drawningTank.Init(_entityTank); - _drawningTank.SetPictureSize(pictureBoxTank.Width, pictureBoxTank.Height); - _drawningTank.SetPosition(random.Next(10,100),random.Next(10,100)); + _drawningBattleTank.Init(_entityBattleTank); + _drawningBattleTank.SetPictureSize(pictureBoxBattleTank.Width, pictureBoxBattleTank.Height); + _drawningBattleTank.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } /// @@ -63,7 +64,7 @@ /// private void ButtonMove_Click(object sender, EventArgs e) { - if(_drawningTank == null) + if (_drawningBattleTank == null) { return; } @@ -72,16 +73,16 @@ switch (name) { case "buttonUp": - result = _drawningTank.MoveTransport(DicretionType.Up); + result = _drawningBattleTank.MoveTransport(DirectionType.Up); break; case "buttonLeft": - result = _drawningTank.MoveTransport(DicretionType.Left); + result = _drawningBattleTank.MoveTransport(DirectionType.Left); break; case "buttonRight": - result = _drawningTank.MoveTransport(DicretionType.Right); + result = _drawningBattleTank.MoveTransport(DirectionType.Right); break; case "buttonDown": - result = _drawningTank.MoveTransport(DicretionType.Down); + result = _drawningBattleTank.MoveTransport(DirectionType.Down); break; } if (result) diff --git a/ProjectTank/ProjectTank/FormTank.resx b/ProjectTank/ProjectTank/FormBattleTank.resx similarity index 100% rename from ProjectTank/ProjectTank/FormTank.resx rename to ProjectTank/ProjectTank/FormBattleTank.resx diff --git a/ProjectTank/ProjectTank/Program.cs b/ProjectTank/ProjectTank/Program.cs index 61d6fe8..fc0d74f 100644 --- a/ProjectTank/ProjectTank/Program.cs +++ b/ProjectTank/ProjectTank/Program.cs @@ -11,7 +11,7 @@ namespace ProjectTank // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormTank()); + Application.Run(new FormBattleTank()); } } } \ No newline at end of file