From 00b1a7182c46ab4be223ef1cefa53c1bb2a09c6f Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 10 Dec 2023 16:18:45 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=20=D0=BF?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AdditionalGeneric.cs | 95 ++++++++++++++ AirBomber/AirBomber/DrawningEnginesCircle.cs | 15 +++ .../AirBomber/DrawningEnginesRectangle.cs | 15 +++ .../AirBomber/DrawningEnginesTriangle.cs | 15 +++ .../FormAdditionalGeneric.Designer.cs | 39 ++++++ AirBomber/AirBomber/FormAdditionalGeneric.cs | 20 +++ .../AirBomber/FormAdditionalGeneric.resx | 120 ++++++++++++++++++ AirBomber/AirBomber/IDrawningEngines.cs | 4 +- 8 files changed, 322 insertions(+), 1 deletion(-) create mode 100644 AirBomber/AirBomber/AdditionalGeneric.cs create mode 100644 AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs create mode 100644 AirBomber/AirBomber/FormAdditionalGeneric.cs create mode 100644 AirBomber/AirBomber/FormAdditionalGeneric.resx diff --git a/AirBomber/AirBomber/AdditionalGeneric.cs b/AirBomber/AirBomber/AdditionalGeneric.cs new file mode 100644 index 0000000..a6f1201 --- /dev/null +++ b/AirBomber/AirBomber/AdditionalGeneric.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + public class AdditionalGeneric + where T : EntityAirPlane + where U : IDrawningEngines + { + private T[] planes; + private U[] engines; + + private int planesCount = 0; + private int enginesCount = 0; + + private int _pictureWidth; + private int _pictureHeight; + + private Random random; + + public AdditionalGeneric(int count, int width, int height) + { + planes = new T[count]; + engines = new U[count]; + + _pictureWidth = width; + _pictureHeight = height; + + random = new Random(); + } + public bool Add(T plane) + { + for (int i = 0; i < planes.Length; i++) + { + if (planes[i] == null) + { + planes[i] = plane; + planesCount++; + return true; + } + } + return false; + } + public bool Add(U engine) + { + for (int i = 0; i < planes.Length; i++) + { + if (engines[i] == null) + { + engines[i] = engine; + enginesCount++; + return true; + } + } + return false; + } + public DrawningAirPlane CreateDrawObject() + { + Random rand = new Random(); + EntityAirPlane plane = planes[rand.Next(0, planesCount)]; + IDrawningEngines engine = engines[rand.Next(0, enginesCount)]; + + if (plane is EntityAirBomber airBomber) + { + return new DrawningAirBomber( + plane.Speed, + plane.Weight, + plane.BodyColor, + airBomber.AdditionalColor, + airBomber.Bombs, + airBomber.FuelTanks, + _pictureWidth, + _pictureHeight, + engine.GetAmount(), + engine.GetShape() + ); + } + + return new DrawningAirPlane( + plane.Speed, + plane.Weight, + plane.BodyColor, + _pictureWidth, + _pictureHeight, + engine.GetAmount(), + engine.GetShape() + ); + } + + + } +} diff --git a/AirBomber/AirBomber/DrawningEnginesCircle.cs b/AirBomber/AirBomber/DrawningEnginesCircle.cs index e6ae763..19f5967 100644 --- a/AirBomber/AirBomber/DrawningEnginesCircle.cs +++ b/AirBomber/AirBomber/DrawningEnginesCircle.cs @@ -9,6 +9,21 @@ namespace AirBomber public class DrawningEnginesCircle : IDrawningEngines { private Engines amount; + public int GetShape() + { + return 2; + } + public int GetAmount() + { + int x = 0; + if (amount == Engines.Two) + x = 2; + if (amount == Engines.Four) + x = 4; + if (amount == Engines.Six) + x = 6; + return x; + } public void SetAmount(int a) { if (a <= 2) diff --git a/AirBomber/AirBomber/DrawningEnginesRectangle.cs b/AirBomber/AirBomber/DrawningEnginesRectangle.cs index 8801ec8..a9814cf 100644 --- a/AirBomber/AirBomber/DrawningEnginesRectangle.cs +++ b/AirBomber/AirBomber/DrawningEnginesRectangle.cs @@ -10,6 +10,21 @@ namespace AirBomber public class DrawningEnginesRectangle : IDrawningEngines { private Engines amount; + public int GetShape() + { + return 0; + } + public int GetAmount() + { + int x = 0; + if (amount == Engines.Two) + x = 2; + if (amount == Engines.Four) + x = 4; + if (amount == Engines.Six) + x = 6; + return x; + } public void SetAmount(int a) { if (a <= 2) diff --git a/AirBomber/AirBomber/DrawningEnginesTriangle.cs b/AirBomber/AirBomber/DrawningEnginesTriangle.cs index bd6b48b..0087ea0 100644 --- a/AirBomber/AirBomber/DrawningEnginesTriangle.cs +++ b/AirBomber/AirBomber/DrawningEnginesTriangle.cs @@ -9,6 +9,21 @@ namespace AirBomber public class DrawningEnginesTriangle : IDrawningEngines { private Engines amount; + public int GetShape() + { + return 1; + } + public int GetAmount() + { + int x = 0; + if (amount == Engines.Two) + x = 2; + if (amount == Engines.Four) + x = 4; + if (amount == Engines.Six) + x = 6; + return x; + } public void SetAmount(int a) { if (a <= 2) diff --git a/AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs b/AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs new file mode 100644 index 0000000..0a9e5eb --- /dev/null +++ b/AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs @@ -0,0 +1,39 @@ +namespace AirBomber +{ + partial class FormAdditionalGeneric + { + /// + /// 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 = "FormAdditionalGeneric"; + } + + #endregion + } +} \ No newline at end of file diff --git a/AirBomber/AirBomber/FormAdditionalGeneric.cs b/AirBomber/AirBomber/FormAdditionalGeneric.cs new file mode 100644 index 0000000..53ef532 --- /dev/null +++ b/AirBomber/AirBomber/FormAdditionalGeneric.cs @@ -0,0 +1,20 @@ +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; + +namespace AirBomber +{ + public partial class FormAdditionalGeneric : Form + { + public FormAdditionalGeneric() + { + InitializeComponent(); + } + } +} diff --git a/AirBomber/AirBomber/FormAdditionalGeneric.resx b/AirBomber/AirBomber/FormAdditionalGeneric.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AirBomber/AirBomber/FormAdditionalGeneric.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/AirBomber/AirBomber/IDrawningEngines.cs b/AirBomber/AirBomber/IDrawningEngines.cs index dfeb2c8..04bae50 100644 --- a/AirBomber/AirBomber/IDrawningEngines.cs +++ b/AirBomber/AirBomber/IDrawningEngines.cs @@ -6,9 +6,11 @@ using System.Threading.Tasks; namespace AirBomber { - internal interface IDrawningEngines + public interface IDrawningEngines { public void SetAmount(int a); public void DrawEngines(Graphics g, int _startPosX, int _startPosY); + public int GetAmount(); + public int GetShape(); } }