Compare commits
3 Commits
0f18368d7f
...
d2624a12bb
Author | SHA1 | Date | |
---|---|---|---|
d2624a12bb | |||
294c75c51c | |||
00b1a7182c |
93
AirBomber/AirBomber/AdditionalGeneric.cs
Normal file
93
AirBomber/AirBomber/AdditionalGeneric.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirBomber
|
||||
{
|
||||
public class AdditionalGeneric<T, U>
|
||||
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()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
73
AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs
generated
Normal file
73
AirBomber/AirBomber/FormAdditionalGeneric.Designer.cs
generated
Normal file
@ -0,0 +1,73 @@
|
||||
namespace AirBomber
|
||||
{
|
||||
partial class FormAdditionalGeneric
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxObject = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
pictureBoxObject.Dock = DockStyle.Fill;
|
||||
pictureBoxObject.Location = new Point(0, 0);
|
||||
pictureBoxObject.Name = "pictureBoxObject";
|
||||
pictureBoxObject.Size = new Size(908, 460);
|
||||
pictureBoxObject.TabIndex = 0;
|
||||
pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Location = new Point(726, 28);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(152, 66);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// FormAdditionalGeneric
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(908, 460);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxObject);
|
||||
Name = "FormAdditionalGeneric";
|
||||
Text = "FormAdditionalGeneric";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxObject;
|
||||
private Button buttonCreate;
|
||||
}
|
||||
}
|
87
AirBomber/AirBomber/FormAdditionalGeneric.cs
Normal file
87
AirBomber/AirBomber/FormAdditionalGeneric.cs
Normal file
@ -0,0 +1,87 @@
|
||||
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 static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;
|
||||
|
||||
namespace AirBomber
|
||||
{
|
||||
public partial class FormAdditionalGeneric : Form
|
||||
{
|
||||
private DrawningAirPlane _drawningAirPlane;
|
||||
private AdditionalGeneric<EntityAirPlane, IDrawningEngines> additionalGeneric;
|
||||
private readonly int _pictureWidth = 400;
|
||||
private readonly int _pictureHeight = 400;
|
||||
Random random = new Random();
|
||||
public FormAdditionalGeneric()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningAirPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningAirPlane.DrawPlane(gr);
|
||||
pictureBoxObject.Image = bmp;
|
||||
}
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
int size = random.Next(1, 10);
|
||||
additionalGeneric = new AdditionalGeneric<EntityAirPlane, IDrawningEngines>(size, _pictureWidth, _pictureHeight);
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
EntityAirPlane plane = CreateRandomPlane();
|
||||
IDrawningEngines engines = CreateRandomEngines();
|
||||
additionalGeneric.Add(plane);
|
||||
additionalGeneric.Add(engines);
|
||||
_drawningAirPlane = additionalGeneric.CreateDrawObject();
|
||||
_drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
public EntityAirPlane CreateRandomPlane()
|
||||
{
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
EntityAirPlane plane;
|
||||
switch (random.Next(0, 2))
|
||||
{
|
||||
case 1:
|
||||
plane = new EntityAirBomber(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(2)), Convert.ToBoolean(random.Next(2)));
|
||||
break;
|
||||
default:
|
||||
plane = new EntityAirPlane(random.Next(100, 300), random.Next(1000, 3000), color);
|
||||
break;
|
||||
}
|
||||
return plane;
|
||||
}
|
||||
public IDrawningEngines CreateRandomEngines()
|
||||
{
|
||||
IDrawningEngines engines;
|
||||
switch (random.Next(3))
|
||||
{
|
||||
case 1:
|
||||
engines = new DrawningEnginesTriangle();
|
||||
break;
|
||||
case 2:
|
||||
engines = new DrawningEnginesCircle();
|
||||
break;
|
||||
default:
|
||||
engines = new DrawningEnginesRectangle();
|
||||
break;
|
||||
}
|
||||
engines.SetAmount((random.Next(1, 4) * 2));
|
||||
return engines;
|
||||
}
|
||||
}
|
||||
}
|
60
AirBomber/AirBomber/FormAdditionalGeneric.resx
Normal file
60
AirBomber/AirBomber/FormAdditionalGeneric.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
13
AirBomber/AirBomber/FormPlaneCollection.Designer.cs
generated
13
AirBomber/AirBomber/FormPlaneCollection.Designer.cs
generated
@ -34,12 +34,14 @@
|
||||
maskedTextBoxNumber = new MaskedTextBox();
|
||||
buttonAddPlane = new Button();
|
||||
pictureBoxCollection = new PictureBox();
|
||||
buttonToFormAddGeneric = new Button();
|
||||
groupBoxTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(buttonToFormAddGeneric);
|
||||
groupBoxTools.Controls.Add(buttonRefreshCollection);
|
||||
groupBoxTools.Controls.Add(buttonRemovePlane);
|
||||
groupBoxTools.Controls.Add(maskedTextBoxNumber);
|
||||
@ -99,6 +101,16 @@
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// buttonToFormAddGeneric
|
||||
//
|
||||
buttonToFormAddGeneric.Location = new Point(17, 545);
|
||||
buttonToFormAddGeneric.Name = "buttonToFormAddGeneric";
|
||||
buttonToFormAddGeneric.Size = new Size(290, 61);
|
||||
buttonToFormAddGeneric.TabIndex = 4;
|
||||
buttonToFormAddGeneric.Text = "Перейти к генерации объектов";
|
||||
buttonToFormAddGeneric.UseVisualStyleBackColor = true;
|
||||
buttonToFormAddGeneric.Click += buttonToFormAddGeneric_Click;
|
||||
//
|
||||
// FormPlaneCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
@ -122,5 +134,6 @@
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private Button buttonAddPlane;
|
||||
private PictureBox pictureBoxCollection;
|
||||
private Button buttonToFormAddGeneric;
|
||||
}
|
||||
}
|
@ -55,5 +55,10 @@ namespace AirBomber
|
||||
{
|
||||
pictureBoxCollection.Image = _planes.ShowPlanes();
|
||||
}
|
||||
private void buttonToFormAddGeneric_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormAdditionalGeneric form = new();
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user