diff --git a/Tank/Tank.sln b/Tank/Tank.sln new file mode 100644 index 0000000..f5e6e36 --- /dev/null +++ b/Tank/Tank.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33801.468 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tank", "Tank\Tank.csproj", "{394C34D3-98AF-48A5-B765-763149963292}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {394C34D3-98AF-48A5-B765-763149963292}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {394C34D3-98AF-48A5-B765-763149963292}.Debug|Any CPU.Build.0 = Debug|Any CPU + {394C34D3-98AF-48A5-B765-763149963292}.Release|Any CPU.ActiveCfg = Release|Any CPU + {394C34D3-98AF-48A5-B765-763149963292}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {29179072-02D8-4625-BA39-9548F5C3A015} + EndGlobalSection +EndGlobal diff --git a/Tank/Tank/Direction.cs b/Tank/Tank/Direction.cs new file mode 100644 index 0000000..d4c104f --- /dev/null +++ b/Tank/Tank/Direction.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tank +{ + public enum Direction + { + Up = 1, + Down = 2, + Left = 3, + Right = 4 + } +} diff --git a/Tank/Tank/DrawingTank.cs b/Tank/Tank/DrawingTank.cs new file mode 100644 index 0000000..8f73c5a --- /dev/null +++ b/Tank/Tank/DrawingTank.cs @@ -0,0 +1,139 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using System.Text; +using System.Threading.Tasks; + +namespace Tank +{ + public class DrawingTank + { + public EntityTank Tank { get; set; } + private int _startPosX; + private int _startPosY; + private int? _pictureWidth = null; + private int? _pictureHeight = null; + private readonly int _TankWidth = 160; + public readonly int _TankHeight = 90; + + public void Init(int speed, float weight, Color bodyColor, Color additionalColor, int Step, int width, int height, bool bodykit, bool wing, bool roadline) + { + _pictureWidth = width; + _pictureHeight = height; + Tank = new EntityTank(); + Tank.Init(speed, weight, bodyColor, additionalColor, Step, width, height, bodykit, wing, roadline); + } + + public void SetPosition(int x, int y, int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + if (x >= 0 && x + _TankWidth <= width && y >= 0 && y + _TankHeight <= height) + { + _startPosX = x; + _startPosY = y; + } + } + + public void MoveTransport(Direction direction) + { + if (!_pictureWidth.HasValue || !_pictureHeight.HasValue) + { + return; + } + switch (direction) + { + // вправо + case Direction.Right: + if (_startPosX + _TankWidth + Tank.Step < _pictureWidth) + { + _startPosX += Tank.Step; + } + break; + // влево + case Direction.Left: + if (_startPosX - Tank.Step > 0) + { + _startPosX -= Tank.Step; + } + break; + // вверх + case Direction.Up: + if (_startPosY - Tank.Step > 0) + { + _startPosY -= Tank.Step; + } + break; + // вниз + case Direction.Down: + if (_startPosY + _TankHeight + Tank.Step < _pictureHeight) + { + _startPosY += Tank.Step; + } + break; + } + } + + public void DrawTransport(Graphics g) + { + if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + Pen pen = new(Color.Black); + + // Отрисовка танковых катков + Brush BrushBlack = new SolidBrush(Color.Black); + g.FillEllipse(BrushBlack, _startPosX + 113, _startPosY + 41, 11, 11); + g.FillEllipse(BrushBlack, _startPosX + 13, _startPosY + 40, 11, 11); + + // Гусеница + Brush BrushGray = new SolidBrush(Color.DarkGray); + g.DrawEllipse(pen, _startPosX + 10, _startPosY + 30, 120, 30); + + // Корпус танка + Point[] pointsbody = { new Point(_startPosX + 5, _startPosY + 30), new Point(_startPosX + 140, _startPosY + 30), + new Point(_startPosX + 130, _startPosY + 42), new Point(_startPosX + 12, _startPosY + 42) }; + g.FillPolygon(BrushGray, pointsbody); + + Point[] pointtower = { new Point(_startPosX + 52, _startPosY + 30), new Point(_startPosX + 52, _startPosY + 27), new Point(_startPosX + 40, _startPosY + 23), + new Point(_startPosX + 15, _startPosY + 18), new Point(_startPosX + 15,_startPosY + 15), new Point(_startPosX + 60, _startPosY + 11), new Point(_startPosX + 90, _startPosY + 11), + new Point(_startPosX + 120, _startPosY + 20), new Point(_startPosX + 100,_startPosY + 25), new Point(_startPosX + 95, _startPosY + 27), new Point(_startPosX + 90, _startPosY + 30)}; + + g.FillPolygon(BrushGray, pointtower); + + // Орудие + g.FillRectangle(BrushGray, _startPosX + 111, _startPosY + 17, 55, 5); + + // Зенитное орудие + Brush BrushRandom = new SolidBrush(Tank?.AdditionalColor ?? Color.Black); + Point[] pointgun = { new Point(_startPosX + 44, _startPosY + 13), new Point(_startPosX + 45, _startPosY + 12), new Point(_startPosX + 41, _startPosY + 8), new Point(_startPosX + 41, _startPosY + 7), + new Point(_startPosX + 42, _startPosY + 5), new Point(_startPosX + 41, _startPosY + 4), new Point(_startPosX + 44, _startPosY + 3), new Point(_startPosX + 50, _startPosY + 3), + new Point(_startPosX + 52, _startPosY + 5), new Point(_startPosX + 53, _startPosY + 7), new Point(_startPosX + 58, _startPosY + 11)}; + g.FillPolygon(BrushRandom, pointgun); + + g.FillRectangle(BrushRandom, _startPosX + 50, _startPosY + 5, 20, 2); + } + + public void ChangeBorders(int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + if (_pictureWidth <= _TankWidth || _pictureHeight <= _TankHeight) + { + _pictureWidth = null; + _pictureHeight = null; + return; + } + if (_startPosX + _TankWidth > _pictureWidth) + { + _startPosX = _pictureWidth.Value - _TankWidth; + } + if (_startPosY + _TankHeight > _pictureHeight) + { + _startPosY = _pictureHeight.Value - _TankHeight; + } + } + } +} diff --git a/Tank/Tank/EntityTank.cs b/Tank/Tank/EntityTank.cs new file mode 100644 index 0000000..8eae7ba --- /dev/null +++ b/Tank/Tank/EntityTank.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using System.Text; +using System.Threading.Tasks; + +namespace Tank +{ + public class EntityTank + { + public int Speed { get; private set; } + public float Weight { get; private set; } + public Color BodyColor { get; private set; } + public Color AdditionalColor { get; private set; } + public int Step => Speed * 100 / (int)Weight; + + public bool BodyKit { get; private set; } + public bool Wing { get; private set; } + public bool RoadLine { get; private set; } + + public void Init(int speed, float weight, Color bodyColor, Color additionalcolor, int step, int width, int height, bool bodyKit, bool wing, bool roadline) + { + Random random = new Random(); + Speed = speed <= 0 ? random.Next(50, 100) : speed; + Weight = weight <= 0 ? random.Next(30,60) : weight; + BodyColor = bodyColor; + AdditionalColor = additionalcolor; + BodyKit = bodyKit; + Wing = wing; + RoadLine = roadline; + } + } +} diff --git a/Tank/Tank/FormTank.Designer.cs b/Tank/Tank/FormTank.Designer.cs new file mode 100644 index 0000000..dda0b88 --- /dev/null +++ b/Tank/Tank/FormTank.Designer.cs @@ -0,0 +1,139 @@ +namespace Tank +{ + partial class FormTank + { + /// + /// 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() + { + pictureBoxTank = new PictureBox(); + ButtonCreate = new Button(); + keyDown = new Button(); + keyUp = new Button(); + keyLeft = new Button(); + keyRight = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxTank).BeginInit(); + SuspendLayout(); + // + // pictureBoxTank + // + pictureBoxTank.Location = new Point(1, 0); + pictureBoxTank.Margin = new Padding(3, 4, 3, 4); + pictureBoxTank.Name = "pictureBoxTank"; + pictureBoxTank.Size = new Size(913, 599); + pictureBoxTank.TabIndex = 0; + pictureBoxTank.TabStop = false; + // + // ButtonCreate + // + ButtonCreate.Location = new Point(14, 523); + ButtonCreate.Margin = new Padding(3, 4, 3, 4); + ButtonCreate.Name = "ButtonCreate"; + ButtonCreate.Size = new Size(90, 31); + ButtonCreate.TabIndex = 1; + ButtonCreate.Text = "button"; + ButtonCreate.UseVisualStyleBackColor = true; + ButtonCreate.Click += ButtonCreate_Click; + // + // keyDown + // + keyDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + keyDown.BackgroundImage = Properties.Resources.KeyDown; + keyDown.BackgroundImageLayout = ImageLayout.Stretch; + keyDown.Location = new Point(820, 514); + keyDown.Margin = new Padding(3, 4, 3, 4); + keyDown.Name = "keyDown"; + keyDown.Size = new Size(34, 40); + keyDown.TabIndex = 11; + keyDown.UseVisualStyleBackColor = true; + keyDown.Click += ButtonMove_Click; + // + // keyUp + // + keyUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + keyUp.BackgroundImage = Properties.Resources.KeyUp; + keyUp.BackgroundImageLayout = ImageLayout.Stretch; + keyUp.Location = new Point(820, 466); + keyUp.Margin = new Padding(3, 4, 3, 4); + keyUp.Name = "keyUp"; + keyUp.Size = new Size(34, 40); + keyUp.TabIndex = 12; + keyUp.UseVisualStyleBackColor = true; + keyUp.Click += ButtonMove_Click; + // + // keyLeft + // + keyLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + keyLeft.BackgroundImage = Properties.Resources.KeyLeft; + keyLeft.BackgroundImageLayout = ImageLayout.Stretch; + keyLeft.Location = new Point(779, 514); + keyLeft.Margin = new Padding(3, 4, 3, 4); + keyLeft.Name = "keyLeft"; + keyLeft.Size = new Size(34, 40); + keyLeft.TabIndex = 13; + keyLeft.UseVisualStyleBackColor = true; + keyLeft.Click += ButtonMove_Click; + // + // keyRight + // + keyRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + keyRight.BackgroundImage = Properties.Resources.KeyRight; + keyRight.BackgroundImageLayout = ImageLayout.Stretch; + keyRight.Location = new Point(861, 514); + keyRight.Margin = new Padding(3, 4, 3, 4); + keyRight.Name = "keyRight"; + keyRight.Size = new Size(34, 40); + keyRight.TabIndex = 14; + keyRight.UseVisualStyleBackColor = true; + keyRight.Click += ButtonMove_Click; + // + // FormTank + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(914, 568); + Controls.Add(keyRight); + Controls.Add(keyLeft); + Controls.Add(keyUp); + Controls.Add(keyDown); + Controls.Add(ButtonCreate); + Controls.Add(pictureBoxTank); + Margin = new Padding(3, 4, 3, 4); + Name = "FormTank"; + Text = "FormTank"; + ((System.ComponentModel.ISupportInitialize)pictureBoxTank).EndInit(); + ResumeLayout(false); + } + + #endregion + + private PictureBox pictureBoxTank; + private Button ButtonCreate; + private Button keyRight; + private Button keyLeft; + private Button keyUp; + private Button keyDown; + } +} \ No newline at end of file diff --git a/Tank/Tank/FormTank.cs b/Tank/Tank/FormTank.cs new file mode 100644 index 0000000..d6546c5 --- /dev/null +++ b/Tank/Tank/FormTank.cs @@ -0,0 +1,55 @@ +namespace Tank +{ + public partial class FormTank : Form + { + private DrawingTank _Tank; + public FormTank() + { + InitializeComponent(); + } + + private void Draw() + { + Bitmap bmp = new(pictureBoxTank.Width, pictureBoxTank.Height); + Graphics gr = Graphics.FromImage(bmp); + _Tank?.DrawTransport(gr); + pictureBoxTank.Image = bmp; + } + private void PictureBoxTank_Resize(object sender, EventArgs e) + { + _Tank?.ChangeBorders(pictureBoxTank.Width, pictureBoxTank.Height); + Draw(); + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + _Tank = new DrawingTank(); + _Tank.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), 0, pictureBoxTank.Width, pictureBoxTank.Height, true, true, true); + _Tank.SetPosition(rnd.Next(10, 50), rnd.Next(30, 70), pictureBoxTank.Width, pictureBoxTank.Height); + Draw(); + } + + private void ButtonMove_Click(object sender, EventArgs e) + { + // + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "keyUp": + _Tank?.MoveTransport(Direction.Up); + break; + case "keyDown": + _Tank?.MoveTransport(Direction.Down); + break; + case "keyLeft": + _Tank?.MoveTransport(Direction.Left); + break; + case "keyRight": + _Tank?.MoveTransport(Direction.Right); + break; + } + Draw(); + } + } +} \ No newline at end of file diff --git a/Tank/Tank/FormTank.resx b/Tank/Tank/FormTank.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/Tank/Tank/FormTank.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Tank/Tank/Program.cs b/Tank/Tank/Program.cs new file mode 100644 index 0000000..3fbc0e1 --- /dev/null +++ b/Tank/Tank/Program.cs @@ -0,0 +1,17 @@ +namespace Tank +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new FormTank()); + } + } +} \ No newline at end of file diff --git a/Tank/Tank/Properties/Resources.Designer.cs b/Tank/Tank/Properties/Resources.Designer.cs new file mode 100644 index 0000000..160a61c --- /dev/null +++ b/Tank/Tank/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace Tank.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("Tank.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 KeyDown { + get { + object obj = ResourceManager.GetObject("KeyDown", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap KeyLeft { + get { + object obj = ResourceManager.GetObject("KeyLeft", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap KeyRight { + get { + object obj = ResourceManager.GetObject("KeyRight", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap KeyUp { + get { + object obj = ResourceManager.GetObject("KeyUp", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/Tank/Tank/Properties/Resources.resx b/Tank/Tank/Properties/Resources.resx new file mode 100644 index 0000000..3cca124 --- /dev/null +++ b/Tank/Tank/Properties/Resources.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\KeyDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\KeyLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\KeyRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\KeyUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/Tank/Tank/Resources/KeyDown.png b/Tank/Tank/Resources/KeyDown.png new file mode 100644 index 0000000..ff09b70 Binary files /dev/null and b/Tank/Tank/Resources/KeyDown.png differ diff --git a/Tank/Tank/Resources/KeyLeft.png b/Tank/Tank/Resources/KeyLeft.png new file mode 100644 index 0000000..b64110a Binary files /dev/null and b/Tank/Tank/Resources/KeyLeft.png differ diff --git a/Tank/Tank/Resources/KeyRight.png b/Tank/Tank/Resources/KeyRight.png new file mode 100644 index 0000000..478e541 Binary files /dev/null and b/Tank/Tank/Resources/KeyRight.png differ diff --git a/Tank/Tank/Resources/KeyUp.png b/Tank/Tank/Resources/KeyUp.png new file mode 100644 index 0000000..0e4bf6f Binary files /dev/null and b/Tank/Tank/Resources/KeyUp.png differ diff --git a/Tank/Tank/Tank.csproj b/Tank/Tank/Tank.csproj new file mode 100644 index 0000000..13ee123 --- /dev/null +++ b/Tank/Tank/Tank.csproj @@ -0,0 +1,26 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + \ No newline at end of file