diff --git a/AirBomber/AirBomber.csproj b/AirBomber/AirBomber.csproj index b57c89e..13ee123 100644 --- a/AirBomber/AirBomber.csproj +++ b/AirBomber/AirBomber.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/AirBomber/BomberEntity.cs b/AirBomber/BomberEntity.cs new file mode 100644 index 0000000..ddf7de2 --- /dev/null +++ b/AirBomber/BomberEntity.cs @@ -0,0 +1,23 @@ +namespace AirBomber +{ + public class BomberEntity + { + public int Speed { get; private set; } + public double Weight { get; private set; } + public Color BodyColor { get; private set; } + public Color AdditionalColor { get; private set; } + public bool Bombs { get; private set; } + public bool FuelTanks { get; private set; } + public double Step => (double)Speed * 100 / Weight * 5 / 2; + + public void Init(int Speed, double Weight, Color BodyColor, Color AdditionalColor, bool FuelTanks, bool Bombs) + { + this.Speed = Speed; + this.Weight = Weight; + this.BodyColor = BodyColor; + this.AdditionalColor = AdditionalColor; + this.FuelTanks = FuelTanks; + this.Bombs = Bombs; + } + } +} diff --git a/AirBomber/BomberForm.Designer.cs b/AirBomber/BomberForm.Designer.cs new file mode 100644 index 0000000..3203c1f --- /dev/null +++ b/AirBomber/BomberForm.Designer.cs @@ -0,0 +1,137 @@ +namespace AirBomber +{ + partial class BomberForm + { + /// + /// 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() + { + BomberPictureBox = new PictureBox(); + CreateButton = new Button(); + ButtonRight = new Button(); + ButtonDown = new Button(); + ButtonLeft = new Button(); + ButtonUp = new Button(); + ((System.ComponentModel.ISupportInitialize)BomberPictureBox).BeginInit(); + SuspendLayout(); + // + // BomberPictureBox + // + BomberPictureBox.Dock = DockStyle.Fill; + BomberPictureBox.Location = new Point(0, 0); + BomberPictureBox.Name = "BomberPictureBox"; + BomberPictureBox.Size = new Size(884, 461); + BomberPictureBox.SizeMode = PictureBoxSizeMode.AutoSize; + BomberPictureBox.TabIndex = 0; + BomberPictureBox.TabStop = false; + // + // CreateButton + // + CreateButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + CreateButton.Location = new Point(12, 419); + CreateButton.Name = "CreateButton"; + CreateButton.Size = new Size(75, 30); + CreateButton.TabIndex = 1; + CreateButton.Text = "Создать"; + CreateButton.UseVisualStyleBackColor = true; + CreateButton.Click += ButtonCreate_Click; + // + // ButtonRight + // + ButtonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + ButtonRight.BackgroundImage = Properties.Resources.ArrowRight; + ButtonRight.BackgroundImageLayout = ImageLayout.Zoom; + ButtonRight.Location = new Point(842, 419); + ButtonRight.Name = "ButtonRight"; + ButtonRight.Size = new Size(30, 30); + ButtonRight.TabIndex = 2; + ButtonRight.UseVisualStyleBackColor = true; + ButtonRight.Click += ButtonMove_Click; + // + // ButtonDown + // + ButtonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + ButtonDown.BackgroundImage = Properties.Resources.ArrowDown; + ButtonDown.BackgroundImageLayout = ImageLayout.Zoom; + ButtonDown.Location = new Point(806, 419); + ButtonDown.Name = "ButtonDown"; + ButtonDown.Size = new Size(30, 30); + ButtonDown.TabIndex = 3; + ButtonDown.UseVisualStyleBackColor = true; + ButtonDown.Click += ButtonMove_Click; + // + // ButtonLeft + // + ButtonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + ButtonLeft.BackgroundImage = Properties.Resources.ArrowLeft; + ButtonLeft.BackgroundImageLayout = ImageLayout.Zoom; + ButtonLeft.Location = new Point(770, 419); + ButtonLeft.Name = "ButtonLeft"; + ButtonLeft.Size = new Size(30, 30); + ButtonLeft.TabIndex = 4; + ButtonLeft.UseVisualStyleBackColor = true; + ButtonLeft.Click += ButtonMove_Click; + // + // ButtonUp + // + ButtonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + ButtonUp.BackgroundImage = Properties.Resources.ArrowUp; + ButtonUp.BackgroundImageLayout = ImageLayout.Zoom; + ButtonUp.Location = new Point(806, 383); + ButtonUp.Name = "ButtonUp"; + ButtonUp.Size = new Size(30, 30); + ButtonUp.TabIndex = 5; + ButtonUp.UseVisualStyleBackColor = true; + ButtonUp.Click += ButtonMove_Click; + // + // BomberForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(884, 461); + Controls.Add(ButtonUp); + Controls.Add(ButtonLeft); + Controls.Add(ButtonDown); + Controls.Add(ButtonRight); + Controls.Add(CreateButton); + Controls.Add(BomberPictureBox); + Name = "BomberForm"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Бомбардировщик"; + ((System.ComponentModel.ISupportInitialize)BomberPictureBox).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private PictureBox BomberPictureBox; + private Button CreateButton; + private Button ButtonRight; + private Button ButtonDown; + private Button ButtonLeft; + private Button ButtonUp; + } +} \ No newline at end of file diff --git a/AirBomber/BomberForm.cs b/AirBomber/BomberForm.cs new file mode 100644 index 0000000..92e4316 --- /dev/null +++ b/AirBomber/BomberForm.cs @@ -0,0 +1,73 @@ +namespace AirBomber +{ + public partial class BomberForm : Form + { + private BomberRenderer? _bomberRenderer; + + public BomberForm() + { + InitializeComponent(); + } + + private void Draw() + { + if (_bomberRenderer == null) + return; + + Bitmap bmp = new Bitmap(BomberPictureBox.Width, BomberPictureBox.Height); + Graphics g = Graphics.FromImage(bmp); + _bomberRenderer.DrawEntity(g); + + BomberPictureBox.Image = bmp; + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random random = new Random(); + _bomberRenderer = new BomberRenderer(); + + _bomberRenderer.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)), + true, + true, + BomberPictureBox.Width, + BomberPictureBox.Height + ); + _bomberRenderer.SetPosition(random.Next(20, 100), random.Next(20, 100)); + + Draw(); + } + + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_bomberRenderer == null) + return; + + string ButtonName = ((Button)sender)?.Name ?? string.Empty; + + switch (ButtonName) + { + case "ButtonUp": + _bomberRenderer.MoveEntity(DirectionType.Up); + break; + + case "ButtonDown": + _bomberRenderer.MoveEntity(DirectionType.Down); + break; + + case "ButtonLeft": + _bomberRenderer.MoveEntity(DirectionType.Left); + break; + + case "ButtonRight": + _bomberRenderer.MoveEntity(DirectionType.Right); + break; + } + + Draw(); + } + } +} diff --git a/AirBomber/Form1.resx b/AirBomber/BomberForm.resx similarity index 93% rename from AirBomber/Form1.resx rename to AirBomber/BomberForm.resx index 1af7de1..af32865 100644 --- a/AirBomber/Form1.resx +++ b/AirBomber/BomberForm.resx @@ -1,17 +1,17 @@  - diff --git a/AirBomber/BomberRenderer.cs b/AirBomber/BomberRenderer.cs new file mode 100644 index 0000000..e2a7ef0 --- /dev/null +++ b/AirBomber/BomberRenderer.cs @@ -0,0 +1,176 @@ +namespace AirBomber +{ + public class BomberRenderer + { + /// + /// Класс, отвечающий за прорисовку и перемещение объекта-сущности + /// + public BomberEntity? EntityBomber { get; private set; } + + private int _pictureWidth; + private int _pictureHeight; + + private int _startPosX; + private int _startPosY; + + private readonly int _bomberWidth = 200; + private readonly int _bomberHeight = 200; + + public bool Init(int Speed, double Weight, Color BodyColor, Color AdditionalColor, bool FuelTanks, bool Bombs, int Width, int Height) + { + if (Width < _bomberWidth || Height < _bomberHeight) + return false; + + _pictureWidth = Width; + _pictureHeight = Height; + + EntityBomber = new BomberEntity(); + EntityBomber.Init(Speed, Weight, BodyColor, AdditionalColor, FuelTanks, Bombs); + + return true; + } + + public void SetPosition(int x, int y) + { + if (EntityBomber is null) + return; + + if (x < 0) + x = 0; + else if (x + _bomberWidth > _pictureWidth) + x = _pictureWidth - _bomberWidth; + + _startPosX = x; + + if (y < 0) + y = 0; + else if (y + _bomberHeight > _pictureHeight) + y = _pictureHeight - _bomberHeight; + + _startPosY = y; + } + + public void MoveEntity(DirectionType Direction) + { + if (EntityBomber == null) + return; + + switch (Direction) + { + case DirectionType.Up: + if (_startPosY - EntityBomber.Step > 0) + _startPosY -= (int)EntityBomber.Step; + + break; + + case DirectionType.Down: + if (_startPosY + _bomberHeight + EntityBomber.Step <= _pictureHeight) + _startPosY += (int)EntityBomber.Step; + + break; + + case DirectionType.Left: + if (_startPosX - EntityBomber.Step > 0) + _startPosX -= (int)EntityBomber.Step; + + break; + + case DirectionType.Right: + if (_startPosX + _bomberWidth + EntityBomber.Step <= _pictureWidth) + _startPosX += (int)EntityBomber.Step; + + break; + } + } + + public void DrawEntity(Graphics g) + { + if (EntityBomber == null) + return; + + Pen pen = new Pen(EntityBomber.BodyColor); + Brush Brush = new SolidBrush(EntityBomber.BodyColor); + Brush AdditionalBrush = new SolidBrush(EntityBomber.AdditionalColor); + + /** Отрисовка основной части */ + Point[] LeftWing = { + new Point(_startPosX + 90, _startPosY), + new Point(_startPosX + 100, _startPosY), + new Point(_startPosX + 108, _startPosY + 85), + new Point(_startPosX + 90, _startPosY + 85), + }; + g.DrawPolygon(pen, LeftWing); + + Point[] RightWing = { + new Point(_startPosX + 90, _startPosY + 200), + new Point(_startPosX + 100, _startPosY + 200), + new Point(_startPosX + 108, _startPosY + 115), + new Point(_startPosX + 90, _startPosY + 115), + }; + g.DrawPolygon(pen, RightWing); + + Point[] Body = { + new Point(_startPosX + 35, _startPosY + 85), + new Point(_startPosX + 200, _startPosY + 85), + new Point(_startPosX + 200, _startPosY + 115), + new Point(_startPosX + 35, _startPosY + 115), + }; + g.DrawPolygon(pen, Body); + + Point[] Nose = { + new Point(_startPosX, _startPosY + 100), + new Point(_startPosX + 35, _startPosY + 85), + new Point(_startPosX + 35, _startPosY + 115), + }; + g.FillPolygon(Brush, Nose); + + Point[] BackLeftWing = { + new Point(_startPosX + 170, _startPosY + 70), + new Point(_startPosX + 200, _startPosY + 40), + new Point(_startPosX + 200, _startPosY + 85), + new Point(_startPosX + 170, _startPosY + 85), + }; + g.DrawPolygon(pen, BackLeftWing); + + Point[] BackRightWing = { + new Point(_startPosX + 170, _startPosY + 130), + new Point(_startPosX + 200, _startPosY + 160), + new Point(_startPosX + 200, _startPosY + 115), + new Point(_startPosX + 170, _startPosY + 115), + }; + g.DrawPolygon(pen, BackRightWing); + + + /** Отрисовка дополнительных элементов */ + if (EntityBomber.FuelTanks) + { + Point[] LeftGasTank = { + new Point(_startPosX + 50, _startPosY + 85), + new Point(_startPosX + 75, _startPosY + 85), + new Point(_startPosX + 75, _startPosY + 70), + new Point(_startPosX + 50, _startPosY + 70), + }; + g.FillPolygon(AdditionalBrush, LeftGasTank); + + Point[] RightGasTank = { + new Point(_startPosX + 50, _startPosY + 115), + new Point(_startPosX + 75, _startPosY + 115), + new Point(_startPosX + 75, _startPosY + 130), + new Point(_startPosX + 50, _startPosY + 130), + }; + g.FillPolygon(AdditionalBrush, RightGasTank); + } + + if (EntityBomber.Bombs) + { + Point LeftBombStartXY = new Point(_startPosX + 110, _startPosY + 115); + Size LeftBombSize = new Size(50, 25); + g.FillEllipse(AdditionalBrush, new Rectangle(LeftBombStartXY, LeftBombSize)); + + Point RightBombStartXY = new Point(_startPosX + 110, _startPosY + 60); + Size RightBombSize = new Size(50, 25); + g.FillEllipse(AdditionalBrush, new Rectangle(RightBombStartXY, RightBombSize)); + } + } + } +} diff --git a/AirBomber/DirectionType.cs b/AirBomber/DirectionType.cs new file mode 100644 index 0000000..dfc1798 --- /dev/null +++ b/AirBomber/DirectionType.cs @@ -0,0 +1,10 @@ +namespace AirBomber +{ + public enum DirectionType + { + Up = 1, + Down, + Left, + Right + } +} diff --git a/AirBomber/Form1.Designer.cs b/AirBomber/Form1.Designer.cs deleted file mode 100644 index 185eea6..0000000 --- a/AirBomber/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace AirBomber -{ - 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/AirBomber/Form1.cs b/AirBomber/Form1.cs deleted file mode 100644 index 0ca8021..0000000 --- a/AirBomber/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AirBomber -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/AirBomber/Program.cs b/AirBomber/Program.cs index 34d9512..75d57f9 100644 --- a/AirBomber/Program.cs +++ b/AirBomber/Program.cs @@ -2,16 +2,11 @@ namespace AirBomber { 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 Form1()); + Application.Run(new BomberForm()); } } } \ No newline at end of file diff --git a/AirBomber/Properties/Resources.Designer.cs b/AirBomber/Properties/Resources.Designer.cs new file mode 100644 index 0000000..6a4bdb7 --- /dev/null +++ b/AirBomber/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace AirBomber.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("AirBomber.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap ArrowDown { + get { + object obj = ResourceManager.GetObject("ArrowDown", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap ArrowLeft { + get { + object obj = ResourceManager.GetObject("ArrowLeft", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap ArrowRight { + get { + object obj = ResourceManager.GetObject("ArrowRight", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap ArrowUp { + get { + object obj = ResourceManager.GetObject("ArrowUp", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/AirBomber/Properties/Resources.resx b/AirBomber/Properties/Resources.resx new file mode 100644 index 0000000..1ee1a77 --- /dev/null +++ b/AirBomber/Properties/Resources.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\ArrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\ArrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\ArrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\ArrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/AirBomber/Resources/ArrowDown.png b/AirBomber/Resources/ArrowDown.png new file mode 100644 index 0000000..c8222f8 Binary files /dev/null and b/AirBomber/Resources/ArrowDown.png differ diff --git a/AirBomber/Resources/ArrowLeft.png b/AirBomber/Resources/ArrowLeft.png new file mode 100644 index 0000000..ff74fb3 Binary files /dev/null and b/AirBomber/Resources/ArrowLeft.png differ diff --git a/AirBomber/Resources/ArrowRight.png b/AirBomber/Resources/ArrowRight.png new file mode 100644 index 0000000..ee722eb Binary files /dev/null and b/AirBomber/Resources/ArrowRight.png differ diff --git a/AirBomber/Resources/ArrowUp.png b/AirBomber/Resources/ArrowUp.png new file mode 100644 index 0000000..0c80a4f Binary files /dev/null and b/AirBomber/Resources/ArrowUp.png differ