This commit is contained in:
Whoisthatjulia 2023-12-13 02:54:38 +04:00
parent e40ae5a4ee
commit ce8e5ace33
13 changed files with 566 additions and 49 deletions

View File

@ -0,0 +1,97 @@
using AirFighter.Drawnings;
using AirFighter.MovementStrategy;
using AirFighter.DrawningObjects;
using AirFighter.Generics;
using AirFighter.MovementStrategy;
namespace AirFighter.Generics
{
internal class AirFighterGenericCollection<T, U>
where T : DrawningAirFighter
where U : IMoveableObject
{
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 210;
private readonly int _placeSizeHeight = 180;
private readonly SetGeneric<T> _collection;
public AirFighterGenericCollection(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 +(AirFighterGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
{
return -1;
}
return collect?._collection.Insert(obj);
}
public static bool operator -(AirFighterGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection.Get(pos);
if (obj != null)
{
return collect._collection.Remove(pos);
}
return false;
}
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
}
public Bitmap ShowAirFighter()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 2);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
{
g.DrawLine(pen, i * _placeSizeWidth, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth, j *
_placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
private void DrawObjects(Graphics g)
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
for (int i = 0; i < _collection.Count; i++)
{
DrawningAirFighter? fighter = _collection.Get(i);
if (fighter == null)
continue;
int row = height - 1 - (i / width);
int col = width - 1 - (i % width);
fighter.SetPosition(col * _placeSizeWidth + 10, row * _placeSizeHeight + 5);
fighter.DrawTransport(g);
}
}
}
}

View File

@ -9,6 +9,7 @@ using System.Threading.Tasks;
using AirFighter.Entities; using AirFighter.Entities;
using AirFighter.Drawnings; using AirFighter.Drawnings;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using AirFighter.MovementStrategy;
namespace AirFighter.DrawningObjects namespace AirFighter.DrawningObjects
{ {
@ -69,14 +70,7 @@ namespace AirFighter.DrawningObjects
_startPosX = x; _startPosX = x;
_startPosY = y; _startPosY = y;
} }
protected int PictureWidth public IMoveableObject GetMoveableObject => new DrawningObjectAirFighter(this);
{
get { return _pictureWidth; }
}
protected int PictureHeight
{
get { return _pictureHeight; }
}
public int GetPosX => _startPosX; public int GetPosX => _startPosX;
public int GetPosY => _startPosY; public int GetPosY => _startPosY;
public int GetWidth => _fighterWidth; public int GetWidth => _fighterWidth;

View File

@ -34,9 +34,10 @@
buttonRight = new Button(); buttonRight = new Button();
buttonUp = new Button(); buttonUp = new Button();
buttonCreate = new Button(); buttonCreate = new Button();
ButtonStepAirFighter = new Button(); ButtonStep = new Button();
comboBoxAirFighter = new ComboBox(); comboBoxStrategy = new ComboBox();
ButtonCreateFighter = new Button(); ButtonCreateFighter = new Button();
buttonSelectFighter = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxAirFighter).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirFighter).BeginInit();
SuspendLayout(); SuspendLayout();
// //
@ -110,27 +111,27 @@
buttonCreate.UseVisualStyleBackColor = true; buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreateAirFighterMilitary_Click; buttonCreate.Click += buttonCreateAirFighterMilitary_Click;
// //
// ButtonStepAirFighter // ButtonStep
// //
ButtonStepAirFighter.BackColor = Color.Azure; ButtonStep.BackColor = Color.Azure;
ButtonStepAirFighter.Font = new Font("Times New Roman", 9.75F, FontStyle.Bold, GraphicsUnit.Point); ButtonStep.Font = new Font("Times New Roman", 9.75F, FontStyle.Bold, GraphicsUnit.Point);
ButtonStepAirFighter.Location = new Point(713, 57); ButtonStep.Location = new Point(713, 57);
ButtonStepAirFighter.Name = "ButtonStepAirFighter"; ButtonStep.Name = "ButtonStep";
ButtonStepAirFighter.Size = new Size(75, 23); ButtonStep.Size = new Size(75, 23);
ButtonStepAirFighter.TabIndex = 3; ButtonStep.TabIndex = 3;
ButtonStepAirFighter.Text = "Шаг"; ButtonStep.Text = "Шаг";
ButtonStepAirFighter.UseVisualStyleBackColor = true; ButtonStep.UseVisualStyleBackColor = true;
ButtonStepAirFighter.Click += ButtonStep_Click; ButtonStep.Click += ButtonStep_Click;
// //
// comboBoxAirFighter // comboBoxStrategy
// //
comboBoxAirFighter.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxAirFighter.FormattingEnabled = true; comboBoxStrategy.FormattingEnabled = true;
comboBoxAirFighter.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder", "-" }); comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder", "-" });
comboBoxAirFighter.Location = new Point(667, 12); comboBoxStrategy.Location = new Point(667, 12);
comboBoxAirFighter.Name = "comboBoxAirFighter"; comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxAirFighter.Size = new Size(121, 23); comboBoxStrategy.Size = new Size(121, 23);
comboBoxAirFighter.TabIndex = 6; comboBoxStrategy.TabIndex = 6;
// //
// ButtonCreateFighter // ButtonCreateFighter
// //
@ -143,14 +144,26 @@
ButtonCreateFighter.UseVisualStyleBackColor = true; ButtonCreateFighter.UseVisualStyleBackColor = true;
ButtonCreateFighter.Click += ButtonCreateFighter_Click; ButtonCreateFighter.Click += ButtonCreateFighter_Click;
// //
// buttonSelectFighter
//
buttonSelectFighter.Font = new Font("Times New Roman", 12F, FontStyle.Regular, GraphicsUnit.Point);
buttonSelectFighter.Location = new Point(352, 390);
buttonSelectFighter.Name = "buttonSelectFighter";
buttonSelectFighter.Size = new Size(164, 47);
buttonSelectFighter.TabIndex = 7;
buttonSelectFighter.Text = "Выбор";
buttonSelectFighter.UseVisualStyleBackColor = true;
buttonSelectFighter.Click += ButtonSelectAirFighter_Click;
//
// FormAirFighter // FormAirFighter
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450); ClientSize = new Size(800, 450);
Controls.Add(buttonSelectFighter);
Controls.Add(ButtonCreateFighter); Controls.Add(ButtonCreateFighter);
Controls.Add(comboBoxAirFighter); Controls.Add(comboBoxStrategy);
Controls.Add(ButtonStepAirFighter); Controls.Add(ButtonStep);
Controls.Add(buttonCreate); Controls.Add(buttonCreate);
Controls.Add(buttonUp); Controls.Add(buttonUp);
Controls.Add(buttonRight); Controls.Add(buttonRight);
@ -172,8 +185,9 @@
private Button buttonRight; private Button buttonRight;
private Button buttonUp; private Button buttonUp;
private Button buttonCreate; private Button buttonCreate;
private Button ButtonStepAirFighter; private Button ButtonStep;
private ComboBox comboBoxAirFighter; private ComboBox comboBoxStrategy;
private Button ButtonCreateFighter; private Button ButtonCreateFighter;
private Button buttonSelectFighter;
} }
} }

View File

@ -8,9 +8,12 @@ namespace AirFighter
{ {
private DrawningAirFighter? _drawningAirFighter; private DrawningAirFighter? _drawningAirFighter;
private AbstractStrategy? _abstractStrategy; private AbstractStrategy? _abstractStrategy;
public DrawningAirFighter? SelectedAirFighter { get; private set; }
public FormAirFighter() public FormAirFighter()
{ {
InitializeComponent(); InitializeComponent();
_abstractStrategy = null;
SelectedAirFighter = null;
} }
private void Draw() private void Draw()
{ {
@ -27,12 +30,26 @@ namespace AirFighter
private void buttonCreateAirFighterMilitary_Click(object sender, EventArgs e) private void buttonCreateAirFighterMilitary_Click(object sender, EventArgs e)
{ {
Random random = new(); Random random = new();
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
//TODO âűáîđ îńíîâíîăî öâĺňŕ
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
//TODO âűáîđ äîďîëíčňĺëüíîăî öâĺňŕ
ColorDialog dialog_dop = new();
if (dialog_dop.ShowDialog() == DialogResult.OK)
{
dopColor = dialog_dop.Color;
}
_drawningAirFighter = new DrawningAirFighterMilitary(random.Next(100, 300), _drawningAirFighter = new DrawningAirFighterMilitary(random.Next(100, 300),
random.Next(1000, 3000), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), color,
random.Next(0, 256)), dopColor,
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
_drawningAirFighter.SetPosition(random.Next(10, 100), random.Next(10, _drawningAirFighter.SetPosition(random.Next(10, 100), random.Next(10,
@ -42,10 +59,17 @@ namespace AirFighter
private void ButtonCreateFighter_Click(object sender, EventArgs e) private void ButtonCreateFighter_Click(object sender, EventArgs e)
{ {
Random random = new(); Random random = new();
Color color = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_drawningAirFighter = new DrawningAirFighter(random.Next(100, 300), _drawningAirFighter = new DrawningAirFighter(random.Next(100, 300),
random.Next(1000, 3000), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), color,
random.Next(0, 256)),
pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
_drawningAirFighter.SetPosition(random.Next(10, 100), random.Next(10, _drawningAirFighter.SetPosition(random.Next(10, 100), random.Next(10,
100)); 100));
@ -82,9 +106,9 @@ namespace AirFighter
{ {
return; return;
} }
if (comboBoxAirFighter.Enabled) if (comboBoxStrategy.Enabled)
{ {
_abstractStrategy = comboBoxAirFighter.SelectedIndex _abstractStrategy = comboBoxStrategy.SelectedIndex
switch switch
{ {
0 => new MoveToCenter(), 0 => new MoveToCenter(),
@ -98,7 +122,7 @@ namespace AirFighter
_abstractStrategy.SetData(new _abstractStrategy.SetData(new
DrawningObjectAirFighter(_drawningAirFighter), pictureBoxAirFighter.Width, DrawningObjectAirFighter(_drawningAirFighter), pictureBoxAirFighter.Width,
pictureBoxAirFighter.Height); pictureBoxAirFighter.Height);
comboBoxAirFighter.Enabled = false; comboBoxStrategy.Enabled = false;
} }
if (_abstractStrategy != null) if (_abstractStrategy != null)
{ {
@ -107,12 +131,18 @@ namespace AirFighter
if (_abstractStrategy.GetStatus() == Status.Finish) if (_abstractStrategy.GetStatus() == Status.Finish)
{ {
comboBoxAirFighter.Enabled = true; comboBoxStrategy.Enabled = true;
_abstractStrategy = null; _abstractStrategy = null;
} }
} }
} }
private void ButtonSelectAirFighter_Click(object sender, EventArgs e)
{
SelectedAirFighter = _drawningAirFighter;
DialogResult = DialogResult.OK;
}
} }
} }

View File

@ -0,0 +1,127 @@
namespace AirFighter
{
partial class FormFighterCollection
{
/// <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()
{
groupBox1 = new GroupBox();
maskedTextBoxNumber = new MaskedTextBox();
buttonRemoveFighter = new Button();
buttonRefreshCollection = new Button();
buttonAddFighter = new Button();
pictureBoxCollection = new PictureBox();
groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
SuspendLayout();
//
// groupBox1
//
groupBox1.Controls.Add(maskedTextBoxNumber);
groupBox1.Controls.Add(buttonRemoveFighter);
groupBox1.Controls.Add(buttonRefreshCollection);
groupBox1.Controls.Add(buttonAddFighter);
groupBox1.Location = new Point(740, 0);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(213, 448);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Инструменты";
//
// maskedTextBoxNumber
//
maskedTextBoxNumber.Font = new Font("Showcard Gothic", 9F, FontStyle.Regular, GraphicsUnit.Point);
maskedTextBoxNumber.Location = new Point(37, 103);
maskedTextBoxNumber.Mask = "00";
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(100, 22);
maskedTextBoxNumber.TabIndex = 5;
//
// buttonRemoveFighter
//
buttonRemoveFighter.Location = new Point(37, 155);
buttonRemoveFighter.Name = "buttonRemoveFighter";
buttonRemoveFighter.Size = new Size(166, 31);
buttonRemoveFighter.TabIndex = 3;
buttonRemoveFighter.Text = "Удалить истребитель";
buttonRemoveFighter.UseVisualStyleBackColor = true;
buttonRemoveFighter.Click += ButtonRemoveAirFighter_Click;
//
// buttonRefreshCollection
//
buttonRefreshCollection.Location = new Point(37, 209);
buttonRefreshCollection.Name = "buttonRefreshCollection";
buttonRefreshCollection.Size = new Size(166, 31);
buttonRefreshCollection.TabIndex = 4;
buttonRefreshCollection.Text = "Обновить коллекцию";
buttonRefreshCollection.UseVisualStyleBackColor = true;
buttonRefreshCollection.Click += ButtonRefreshCollection_Click;
//
// buttonAddFighter
//
buttonAddFighter.Location = new Point(37, 36);
buttonAddFighter.Name = "buttonAddFighter";
buttonAddFighter.Size = new Size(166, 31);
buttonAddFighter.TabIndex = 2;
buttonAddFighter.Text = "Добавить истребитель ";
buttonAddFighter.UseVisualStyleBackColor = true;
buttonAddFighter.Click += ButtonAddAirFighter_Click;
//
// pictureBoxCollection
//
pictureBoxCollection.Location = new Point(0, 0);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(734, 448);
pictureBoxCollection.SizeMode = PictureBoxSizeMode.Zoom;
pictureBoxCollection.TabIndex = 1;
pictureBoxCollection.TabStop = false;
pictureBoxCollection.Click += ButtonAddAirFighter_Click;
//
// FormFighterCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(953, 448);
Controls.Add(pictureBoxCollection);
Controls.Add(groupBox1);
Name = "FormFighterCollection";
Text = "Набор истребителя";
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBox1;
private PictureBox pictureBoxCollection;
private Button buttonRemoveFighter;
private Button buttonRefreshCollection;
private Button buttonAddFighter;
private MaskedTextBox maskedTextBoxNumber;
}
}

View File

@ -0,0 +1,69 @@
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 AirFighter.DrawningObjects;
using AirFighter.Drawnings;
using AirFighter.Generics;
using AirFighter.MovementStrategy;
namespace AirFighter
{
public partial class FormFighterCollection : Form
{
private readonly AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter> _fighter;
public FormFighterCollection()
{
InitializeComponent();
_fighter = new AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter>(pictureBoxCollection.Width, pictureBoxCollection.Height);
}
private void ButtonAddAirFighter_Click(object sender, EventArgs e)
{
FormAirFighter form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_fighter + form.SelectedAirFighter != null)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _fighter.ShowAirFighter();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void ButtonRemoveAirFighter_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (_fighter - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = _fighter.ShowAirFighter();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
pictureBoxCollection.Image = _fighter.ShowAirFighter();
}
}
}

View 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>

View File

@ -14,5 +14,7 @@ namespace AirFighter.MovementStrategy
int GetStep { get; } int GetStep { get; }
bool CheckCanMove(DirectionAirFighter direction); bool CheckCanMove(DirectionAirFighter direction);
void MoveObject(DirectionAirFighter direction); void MoveObject(DirectionAirFighter direction);
void SetPosition(int x, int y);
void Draw(Graphics g);
} }
} }

View File

@ -33,5 +33,19 @@ namespace AirFighter.MovementStrategy
_drawningAirFighter?.CanMove(direction) ?? false; _drawningAirFighter?.CanMove(direction) ?? false;
public void MoveObject(DirectionAirFighter direction) => public void MoveObject(DirectionAirFighter direction) =>
_drawningAirFighter?.MoveTransport(direction); _drawningAirFighter?.MoveTransport(direction);
public void SetPosition(int x, int y)
{
if (_drawningAirFighter != null)
{
_drawningAirFighter.SetPosition(x, y);
}
}
public void Draw(Graphics g)
{
if (_drawningAirFighter != null)
{
_drawningAirFighter.DrawTransport(g);
}
}
} }
} }

View File

@ -6,9 +6,6 @@ using System.Threading.Tasks;
namespace AirFighter.MovementStrategy namespace AirFighter.MovementStrategy
{ {
/// <summary>
/// Стратегия перемещения объекта к границе экрана
/// </summary>
public class MoveToBorder : AbstractStrategy public class MoveToBorder : AbstractStrategy
{ {
protected override bool IsTargetDestinaion() protected override bool IsTargetDestinaion()

View File

@ -6,9 +6,6 @@ using System.Threading.Tasks;
namespace AirFighter.MovementStrategy namespace AirFighter.MovementStrategy
{ {
/// <summary>
/// Стратегия перемещения объекта в центр экрана
/// </summary>
public class MoveToCenter : AbstractStrategy public class MoveToCenter : AbstractStrategy
{ {
protected override bool IsTargetDestinaion() protected override bool IsTargetDestinaion()

View File

@ -11,7 +11,7 @@ namespace AirFighter
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormAirFighter()); Application.Run(new FormFighterCollection());
} }
} }
} }

View File

@ -0,0 +1,56 @@
namespace AirFighter.Generics
{
internal class SetGeneric<T>
where T : class
{
private readonly T[] _places;
public int Count => _places.Length;
public SetGeneric(int count)
{
_places = new T[count];
}
public int Insert(T fighter)
{
for (int i = 0; i < _places.Length; i++)
{
if (_places[i] == null)
{
_places[i] = fighter;
return i;
}
}
return -1;
}
public int Insert(T fighter, int position)
{
int index = position;
while (_places[index] != null && index < _places.Length) index++;
if (index == _places.Length) return -1;
for (int i = index; i > position; --i) _places[i] = _places[i - 1];
_places[position] = fighter;
return position;
}
public bool Remove(int position)
{
if (position < 0 || position >= _places.Length)
{
return false;
}
_places[position] = null;
return true;
}
public T? Get(int position)
{
if (position < 0 || position >= _places.Length)
{
return null;
}
return _places[position];
}
}
}