ПИбд-21 Ярускин Салих 3 лаб простая #3
107
AirBomber/BomberGenericCollection.cs
Normal file
107
AirBomber/BomberGenericCollection.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirBomber.DrawningObjects;
|
||||
using AirBomber.MovementStrategy;
|
||||
using ProjectBomber.Generics;
|
||||
|
||||
|
||||
namespace AirBomber.Generics
|
||||
{
|
||||
internal class BomberGenericCollection<T, U>
|
||||
where T : DrawningBomber
|
||||
where U : IMoveableObject
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly int _placeSizeWidth = 155;
|
||||
private readonly int _placeSizeHeight = 185;
|
||||
private readonly SetGeneric<T> _collection;
|
||||
|
||||
public BomberGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
|
||||
public static int operator +(BomberGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect._collection.Insert(obj);
|
||||
}
|
||||
|
||||
public static bool operator -(BomberGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T obj = collect._collection.Get(pos);
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect._collection.Remove(pos);
|
||||
}
|
||||
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
}
|
||||
|
||||
public Bitmap ShowBomber()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new Pen(Color.Black, 3);
|
||||
int numColumns = _pictureWidth / _placeSizeWidth;
|
||||
int numRows = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
for (int i = 0; i <= numColumns; i++)
|
||||
{
|
||||
for (int j = 0; j <= numRows; ++j)
|
||||
{
|
||||
int x = i * _placeSizeWidth;
|
||||
int y = j * _placeSizeHeight;
|
||||
g.DrawLine(pen, x, y, x + _placeSizeWidth / 2, y);
|
||||
}
|
||||
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, numRows * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int numColumns = _pictureWidth / _placeSizeWidth;
|
||||
int numRows = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
DrawningBomber air = _collection.Get(i);
|
||||
if (air != null)
|
||||
{
|
||||
int row = i / numColumns;
|
||||
int column = numColumns - 1 - (i % numColumns);
|
||||
int x = column * _placeSizeWidth;
|
||||
int y = row * _placeSizeHeight;
|
||||
|
||||
air.SetPosition(x, y);
|
||||
air.DrawBomber(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AirBomber.Entities;
|
||||
using AirBomber.MovementStrategy;
|
||||
|
||||
namespace AirBomber.DrawningObjects
|
||||
{
|
||||
@ -24,6 +25,8 @@ namespace AirBomber.DrawningObjects
|
||||
public int GetWidth => _PlaneWidth;
|
||||
public int GetHeight => _PlaneHeight;
|
||||
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectBomber(this);
|
||||
|
||||
public DrawningBomber(int speed, double weight, Color bodycolor, int width, int height)
|
||||
{
|
||||
if (width < _pictureWidth || height < _pictureHeight)
|
||||
|
13
AirBomber/FormAirBomber.Designer.cs
generated
13
AirBomber/FormAirBomber.Designer.cs
generated
@ -37,6 +37,7 @@
|
||||
buttonCreateWarBomber = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
ButtonStep = new Button();
|
||||
ButtonSelectCar = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -138,11 +139,22 @@
|
||||
ButtonStep.UseVisualStyleBackColor = true;
|
||||
ButtonStep.Click += ButtonStep_Click;
|
||||
//
|
||||
// ButtonSelectCar
|
||||
//
|
||||
ButtonSelectCar.Location = new Point(420, 391);
|
||||
ButtonSelectCar.Name = "ButtonSelectCar";
|
||||
ButtonSelectCar.Size = new Size(118, 53);
|
||||
ButtonSelectCar.TabIndex = 10;
|
||||
ButtonSelectCar.Text = "Выбрать";
|
||||
ButtonSelectCar.UseVisualStyleBackColor = true;
|
||||
ButtonSelectCar.Click += ButtonSelectCar_Click;
|
||||
//
|
||||
// FormAirBomber
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(ButtonSelectCar);
|
||||
Controls.Add(ButtonStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateWarBomber);
|
||||
@ -169,5 +181,6 @@
|
||||
private Button buttonCreateWarBomber;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button ButtonStep;
|
||||
private Button ButtonSelectCar;
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ namespace AirBomber
|
||||
{
|
||||
private DrawningBomber? _drawningBomber;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawningBomber? SelectedBomber { get; private set; }
|
||||
|
||||
public FormAirBomber()
|
||||
{
|
||||
@ -29,8 +30,14 @@ namespace AirBomber
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningBomber = new DrawningBomber(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), pictureBox.Width, pictureBox.Height);
|
||||
Color bodycolor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog mainColorDialog = new ColorDialog();
|
||||
if (mainColorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
bodycolor = mainColorDialog.Color;
|
||||
}
|
||||
_drawningBomber = new DrawningBomber(random.Next(100, 300), random.Next(1000, 3000), bodycolor,
|
||||
pictureBox.Width, pictureBox.Height);
|
||||
_drawningBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
@ -98,18 +105,32 @@ namespace AirBomber
|
||||
|
||||
private void buttonCreateWarBomber_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Random random = new Random();
|
||||
Color bodycolor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog mainColorDialog = new ColorDialog();
|
||||
if (mainColorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
bodycolor = mainColorDialog.Color;
|
||||
}
|
||||
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dopColorDialog = new ColorDialog();
|
||||
if (dopColorDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dopColorDialog.Color;
|
||||
}
|
||||
|
||||
_drawningBomber = new DrawningAirBomber(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(1, 2)),
|
||||
pictureBox.Width, pictureBox.Height);
|
||||
_drawningBomber.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
random.Next(1000, 3000), bodycolor, dopColor,
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(1, 2)),
|
||||
pictureBox.Width, pictureBox.Height);
|
||||
_drawningBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void ButtonSelectCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedBomber = _drawningBomber;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
123
AirBomber/FormBomberCollection.Designer.cs
generated
Normal file
123
AirBomber/FormBomberCollection.Designer.cs
generated
Normal file
@ -0,0 +1,123 @@
|
||||
namespace AirBomber
|
||||
{
|
||||
partial class FormBomberCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
Tools = new GroupBox();
|
||||
ButtonRefreshCollection = new Button();
|
||||
ButtonRemoveBomber = new Button();
|
||||
ButtonAddBomber = new Button();
|
||||
MessageBoxBomber = new TextBox();
|
||||
PicBoxBomberCollection = new PictureBox();
|
||||
Tools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)PicBoxBomberCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// Tools
|
||||
//
|
||||
Tools.Controls.Add(ButtonRefreshCollection);
|
||||
Tools.Controls.Add(ButtonRemoveBomber);
|
||||
Tools.Controls.Add(ButtonAddBomber);
|
||||
Tools.Controls.Add(MessageBoxBomber);
|
||||
Tools.Location = new Point(538, 5);
|
||||
Tools.Name = "Tools";
|
||||
Tools.Size = new Size(250, 443);
|
||||
Tools.TabIndex = 0;
|
||||
Tools.TabStop = false;
|
||||
Tools.Text = "Инструменты";
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
ButtonRefreshCollection.Location = new Point(25, 243);
|
||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
ButtonRefreshCollection.Size = new Size(193, 37);
|
||||
ButtonRefreshCollection.TabIndex = 3;
|
||||
ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
|
||||
//
|
||||
// ButtonRemoveBomber
|
||||
//
|
||||
ButtonRemoveBomber.Location = new Point(25, 178);
|
||||
ButtonRemoveBomber.Name = "ButtonRemoveBomber";
|
||||
ButtonRemoveBomber.Size = new Size(193, 41);
|
||||
ButtonRemoveBomber.TabIndex = 2;
|
||||
ButtonRemoveBomber.Text = "Удалить самолёт";
|
||||
ButtonRemoveBomber.UseVisualStyleBackColor = true;
|
||||
ButtonRemoveBomber.Click += ButtonRemoveBomber_Click;
|
||||
//
|
||||
// ButtonAddBomber
|
||||
//
|
||||
ButtonAddBomber.Location = new Point(25, 42);
|
||||
ButtonAddBomber.Name = "ButtonAddBomber";
|
||||
ButtonAddBomber.Size = new Size(193, 41);
|
||||
ButtonAddBomber.TabIndex = 1;
|
||||
ButtonAddBomber.Text = "Добавить самолёт";
|
||||
ButtonAddBomber.UseVisualStyleBackColor = true;
|
||||
ButtonAddBomber.Click += ButtonAddBomber_Click;
|
||||
//
|
||||
// MessageBoxBomber
|
||||
//
|
||||
MessageBoxBomber.Location = new Point(25, 109);
|
||||
MessageBoxBomber.Name = "MessageBoxBomber";
|
||||
MessageBoxBomber.Size = new Size(193, 27);
|
||||
MessageBoxBomber.TabIndex = 0;
|
||||
//
|
||||
// PicBoxBomberCollection
|
||||
//
|
||||
PicBoxBomberCollection.Location = new Point(1, -2);
|
||||
PicBoxBomberCollection.Name = "PicBoxBomberCollection";
|
||||
PicBoxBomberCollection.Size = new Size(473, 563);
|
||||
PicBoxBomberCollection.TabIndex = 1;
|
||||
PicBoxBomberCollection.TabStop = false;
|
||||
//
|
||||
// FormBomberCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 581);
|
||||
Controls.Add(PicBoxBomberCollection);
|
||||
Controls.Add(Tools);
|
||||
Name = "FormBomberCollection";
|
||||
Text = "FormBomberCollection";
|
||||
Tools.ResumeLayout(false);
|
||||
Tools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)PicBoxBomberCollection).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox Tools;
|
||||
private TextBox MessageBoxBomber;
|
||||
private PictureBox PicBoxBomberCollection;
|
||||
private Button ButtonRefreshCollection;
|
||||
private Button ButtonRemoveBomber;
|
||||
private Button ButtonAddBomber;
|
||||
}
|
||||
}
|
66
AirBomber/FormBomberCollection.cs
Normal file
66
AirBomber/FormBomberCollection.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using AirBomber.DrawningObjects;
|
||||
using AirBomber.Generics;
|
||||
using AirBomber.MovementStrategy;
|
||||
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 FormBomberCollection : Form
|
||||
{
|
||||
private readonly BomberGenericCollection<DrawningBomber, DrawningObjectBomber> _bomber;
|
||||
|
||||
public FormBomberCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_bomber = new BomberGenericCollection<DrawningBomber, DrawningObjectBomber>(PicBoxBomberCollection.Width, PicBoxBomberCollection.Height);
|
||||
}
|
||||
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
PicBoxBomberCollection.Image = _bomber.ShowBomber();
|
||||
}
|
||||
|
||||
private void ButtonAddBomber_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormAirBomber form = new FormAirBomber();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_bomber + form.SelectedBomber != 1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
PicBoxBomberCollection.Image = _bomber.ShowBomber();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRemoveBomber_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(MessageBoxBomber.Text);
|
||||
if (_bomber - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
PicBoxBomberCollection.Image = _bomber.ShowBomber();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
AirBomber/FormBomberCollection.resx
Normal file
120
AirBomber/FormBomberCollection.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
@ -11,7 +11,7 @@ namespace AirBomber
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormAirBomber());
|
||||
Application.Run(new FormBomberCollection());
|
||||
}
|
||||
}
|
||||
}
|
105
AirBomber/SetGeneric.cs
Normal file
105
AirBomber/SetGeneric.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBomber.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T[] _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="plane">Добавляемая установка</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T plane)
|
||||
{
|
||||
return Insert(plane, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="plane">Добавляемая установка</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T plane, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position < 0 && position > Count)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (_places[position] != null)
|
||||
{
|
||||
int d = 0;
|
||||
for (int j = 1; j < Count - position; j++)
|
||||
{
|
||||
if (_places[position + j] == null)
|
||||
{
|
||||
d = position + j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (d == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (int j = d; j > position; j--)
|
||||
{
|
||||
_places[j] = _places[j - 1];
|
||||
}
|
||||
}
|
||||
_places[position] = plane;
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
/// Проверка позиции
|
||||
if (position < 0 || position >= _places.Length)
|
||||
return false;
|
||||
/// Удаление объекта из массива, присвоив элементу массива значение null
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
{
|
||||
// Проверка позиции
|
||||
if (position < 0 || position >= _places.Length)
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user