This commit is contained in:
DeerElk 2024-02-08 04:16:08 +04:00
parent 9c923bdc24
commit 9b908da61c
11 changed files with 629 additions and 26 deletions

View File

@ -27,7 +27,8 @@ namespace ProjectAircraftCarrier.MovementStrategy
return null;
}
return new ObjectParameters(_drawingWarship.GetPosX,
_drawingWarship.GetPosY, _drawingWarship.GetWidth, _drawingWarship.GetHeight);
_drawingWarship.GetPosY, _drawingWarship.GetWidth,
_drawingWarship.GetHeight);
}
}
public int GetStep => (int)(_drawingWarship?.EntityWarship?.Step ?? 0);

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectAircraftCarrier.Entities;
using ProjectAircraftCarrier.MovementStrategy;
namespace ProjectAircraftCarrier.DrawingObjects
{
@ -91,7 +92,6 @@ width, int height, int warshipWidth, int warshipHeight)
_warshipHeight = warshipHeight;
EntityWarship = new EntityWarship(speed, weight, bodyColor);
}
/// <summary>
/// Установка позиции
/// </summary>
@ -99,13 +99,13 @@ width, int height, int warshipWidth, int warshipHeight)
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
if (x < 0 || y < 0 || x + _warshipWidth > _pictureWidth || y + _warshipHeight > _pictureHeight)
{
x = 0;
y = 0;
}
_startPosX = x;
_startPosY = y;
if (_startPosX < 0 || _startPosY < 0)
{
_startPosX = 50;
_startPosY = 50;
}
}
/// <summary>
/// Проверка, что объект может переместится по указанному направлению
@ -212,5 +212,9 @@ width, int height, int warshipWidth, int warshipHeight)
g.DrawEllipse(pen, _startPosX + 138, _startPosY + 22, 11, 11);
g.FillEllipse(brBlack, _startPosX + 138, _startPosY + 22, 11, 11);
}
/// <summary>
/// Получение объекта IMoveableObject из объекта DrawningCar
/// </summary>
public IMoveableObject GetMoveableObject => new DrawingObjectWarship(this);
}
}

View File

@ -40,16 +40,17 @@ namespace ProjectAircraftCarrier
comboBoxStrategy = new ComboBox();
buttonStep = new Button();
buttonCreateWarship = new Button();
buttonSelectWarship = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxAircraftCarrier).BeginInit();
SuspendLayout();
//
// buttonCreateAircraftCarrier
//
buttonCreateAircraftCarrier.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateAircraftCarrier.Location = new Point(4, 527);
buttonCreateAircraftCarrier.Location = new Point(8, 523);
buttonCreateAircraftCarrier.Margin = new Padding(4, 3, 4, 3);
buttonCreateAircraftCarrier.Name = "buttonCreateAircraftCarrier";
buttonCreateAircraftCarrier.Size = new Size(193, 37);
buttonCreateAircraftCarrier.Size = new Size(200, 37);
buttonCreateAircraftCarrier.TabIndex = 0;
buttonCreateAircraftCarrier.Text = "Create Aircraft Carrier";
buttonCreateAircraftCarrier.UseVisualStyleBackColor = true;
@ -120,6 +121,7 @@ namespace ProjectAircraftCarrier
//
// comboBoxStrategy
//
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "Move to center", "Move to border" });
@ -144,20 +146,32 @@ namespace ProjectAircraftCarrier
// buttonCreateWarship
//
buttonCreateWarship.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateWarship.Location = new Point(206, 525);
buttonCreateWarship.Location = new Point(216, 523);
buttonCreateWarship.Margin = new Padding(4, 3, 4, 3);
buttonCreateWarship.Name = "buttonCreateWarship";
buttonCreateWarship.Size = new Size(200, 38);
buttonCreateWarship.Size = new Size(200, 37);
buttonCreateWarship.TabIndex = 8;
buttonCreateWarship.Text = "Create Warship";
buttonCreateWarship.UseVisualStyleBackColor = true;
buttonCreateWarship.Click += ButtonCreateWarship_Click;
//
// buttonSelectWarship
//
buttonSelectWarship.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonSelectWarship.Location = new Point(424, 523);
buttonSelectWarship.Name = "buttonSelectWarship";
buttonSelectWarship.Size = new Size(200, 37);
buttonSelectWarship.TabIndex = 9;
buttonSelectWarship.Text = "Select Warship";
buttonSelectWarship.UseVisualStyleBackColor = true;
buttonSelectWarship.Click += ButtonSelectWarhip_Click;
//
// FormAircraftCarrier
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1103, 567);
Controls.Add(buttonSelectWarship);
Controls.Add(buttonCreateWarship);
Controls.Add(buttonStep);
Controls.Add(comboBoxStrategy);
@ -170,7 +184,7 @@ namespace ProjectAircraftCarrier
Margin = new Padding(4, 3, 4, 3);
Name = "FormAircraftCarrier";
StartPosition = FormStartPosition.CenterScreen;
Text = "AircraftCarrier";
Text = "Aircraft Carrier";
((System.ComponentModel.ISupportInitialize)pictureBoxAircraftCarrier).EndInit();
ResumeLayout(false);
}
@ -186,5 +200,6 @@ namespace ProjectAircraftCarrier
private ComboBox comboBoxStrategy;
private Button buttonStep;
private Button buttonCreateWarship;
private Button buttonSelectWarship;
}
}

View File

@ -15,11 +15,17 @@ namespace ProjectAircraftCarrier
/// </summary>
private AbstractStrategy? _abstractStrategy;
/// <summary>
/// Âűáđŕííűé ŕâňîěîáčëü
/// </summary>
public DrawingWarship? SelectedWarship { get; private set; }
/// <summary>
/// Èíèöèàëèçàöèÿ ôîðìû
/// </summary>
public FormAircraftCarrier()
{
InitializeComponent();
SelectedWarship = null;
_abstractStrategy = null;
}
/// <summary>
/// Ìåòîä ïðîðèñîâêè àâèàíîñöà
@ -44,17 +50,25 @@ namespace ProjectAircraftCarrier
private void ButtonCreateAircraftCarrier_Click(object sender, EventArgs e)
{
Random random = new();
Color bodyColor = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
bodyColor = dialog.Color;
}
Color additColor = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
if (dialog.ShowDialog() == DialogResult.OK)
{
additColor = dialog.Color;
}
_drawingWarship = new DrawingAircraftCarrier(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)),
random.Next(1000, 3000), bodyColor,
additColor, Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height);
_drawingWarship.SetPosition(random.Next(0, pictureBoxAircraftCarrier.Width),
random.Next(0, pictureBoxAircraftCarrier.Height));
_drawingWarship.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
/// <summary>
@ -65,9 +79,16 @@ namespace ProjectAircraftCarrier
private void ButtonCreateWarship_Click(object sender, EventArgs e)
{
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;
}
_drawingWarship = new DrawingWarship(random.Next(100, 300),
random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256)), pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height);
random.Next(1000, 3000), color,
pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height);
_drawingWarship.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
@ -100,6 +121,11 @@ namespace ProjectAircraftCarrier
}
Draw();
}
private void ButtonSelectWarhip_Click(object sender, EventArgs e)
{
SelectedWarship = _drawingWarship;
DialogResult = DialogResult.OK;
}
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
/// </summary>

View File

@ -121,7 +121,7 @@
<data name="buttonLeft.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAA5gAAAOYBAMAAABC5kGOAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
////AAAAIyMjycnJiIiI9drrEwAAAAlwSFlzAAAOwQAADsEBuJFr7QAAE2hJREFUeNrtncty01wWRqUK
////AAAAIyMjycnJiIiI9drrEwAAAAlwSFlzAAAOvQAADr0BR/uQrQAAE2hJREFUeNrtncty01wWRqUK
nkvV9gvIZE6bMCdtmJME3v9VmkC4JU4sW/t2vqxdXdX/YqKtvUqfFZ0juxvHoftZ488Cm0VkIhOsiMhE
JlgRv1f/8E+gADIJIWQSQsgkhJBJCCGTEEImIYRMQgiZhBAyCSFkEkLIJISQSQghkxBCJiGDLAbqIDKR
CVZEZCITrIjIRCZYEZGJTLAiIhOZYEVEJjLBiohMZIIVsWMxUAqZhBAyCSFkEkLIJISQSQghkxBCJiGE
@ -310,7 +310,7 @@
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAA5gAAAOYBAMAAABC5kGOAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
////AAAAIyMjycnJiIiI9drrEwAAAAlwSFlzAAAOwQAADsEBuJFr7QAAFo9JREFUeNrtnc162zgSRYuf
////AAAAIyMjycnJiIiI9drrEwAAAAlwSFlzAAAOvQAADr0BR/uQrQAAFo9JREFUeNrtnc162zgSRYuf
23vqG+kFSHOvdpR9nHT2ktL9/q8yhghIsiPFtswf3MK5M5ujzRTrDBCAIGmLqRZ9QGE0OuEHjU74QaMT
ftDohB+0+EsdfwKVkU44QjrhCOmEI6QTjpBOOEI64QjphCOkE46QTjhCOuEI6YQjpBOOkE44QjrhDI3D
QBdodMIPGp3wg0Yn/KDRCT9odMIPGp3wg0Yn/KDRCT9odMIPGp3wg0Yn/KDRCT9odMIPGp3wgxwGekI6
@ -413,7 +413,7 @@
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAA5gAAAOYBAMAAABC5kGOAAAABGdBTUEAALGPC/xhBQAAABJQTFRF5ubm
////AAAAIyMjycnJiIiI9drrEwAAAAlwSFlzAAAOwQAADsEBuJFr7QAAFRpJREFUeNrt3cGS2zYWRmGw
////AAAAIyMjycnJiIiI9drrEwAAAAlwSFlzAAAOvQAADr0BR/uQrQAAFRpJREFUeNrt3cGS2zYWRmGw
4uzJiv0CTXGvtuV9mEn2ouO8/6tMS6Laduva3ZJI4N4fRzWbk8WMiW+IgAAlp5Sa7vRJpw8ZORkJoWQk
hJKREEpGQigZCaFkJISSkRBKRkIoGQmhZCSEkpEQSkZCKBkJoWQkZLLr2vkfzf+EDJtggkl6TDDBJD0m
mGCSHhNMMEmPCSaYpMcEE0zSY4IJJukxE4eBUslICCUjIZSMhFAyEkLJSAglIyGUjIRQMhJCyUgIJSMh

View File

@ -0,0 +1,133 @@
namespace ProjectAircraftCarrier
{
partial class FormWarshipCollection
{
/// <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()
{
groupBoxCollection = new GroupBox();
maskedTextBoxNumber = new MaskedTextBox();
buttonRefreshCollection = new Button();
buttonRemoveWarship = new Button();
buttonAddWarship = new Button();
pictureBoxCollection = new PictureBox();
groupBoxCollection.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
SuspendLayout();
//
// groupBoxCollection
//
groupBoxCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
groupBoxCollection.Controls.Add(maskedTextBoxNumber);
groupBoxCollection.Controls.Add(buttonRefreshCollection);
groupBoxCollection.Controls.Add(buttonRemoveWarship);
groupBoxCollection.Controls.Add(buttonAddWarship);
groupBoxCollection.Location = new Point(893, 3);
groupBoxCollection.Margin = new Padding(4, 5, 4, 5);
groupBoxCollection.Name = "groupBoxCollection";
groupBoxCollection.Padding = new Padding(4, 5, 4, 5);
groupBoxCollection.Size = new Size(247, 743);
groupBoxCollection.TabIndex = 0;
groupBoxCollection.TabStop = false;
groupBoxCollection.Text = "Tools";
//
// maskedTextBoxNumber
//
maskedTextBoxNumber.Location = new Point(56, 115);
maskedTextBoxNumber.Margin = new Padding(4, 5, 4, 5);
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(141, 31);
maskedTextBoxNumber.TabIndex = 4;
maskedTextBoxNumber.Text = "_";
//
// buttonRefreshCollection
//
buttonRefreshCollection.Location = new Point(9, 300);
buttonRefreshCollection.Margin = new Padding(4, 5, 4, 5);
buttonRefreshCollection.Name = "buttonRefreshCollection";
buttonRefreshCollection.Size = new Size(224, 45);
buttonRefreshCollection.TabIndex = 3;
buttonRefreshCollection.Text = "Refresh collection";
buttonRefreshCollection.UseVisualStyleBackColor = true;
buttonRefreshCollection.Click += ButtonRefreshCollection_Click;
//
// buttonRemoveWarship
//
buttonRemoveWarship.Location = new Point(9, 187);
buttonRemoveWarship.Margin = new Padding(4, 5, 4, 5);
buttonRemoveWarship.Name = "buttonRemoveWarship";
buttonRemoveWarship.Size = new Size(224, 45);
buttonRemoveWarship.TabIndex = 2;
buttonRemoveWarship.Text = "Remove warship";
buttonRemoveWarship.UseVisualStyleBackColor = true;
buttonRemoveWarship.Click += ButtonRemoveWarship_Click;
//
// buttonAddWarship
//
buttonAddWarship.Location = new Point(9, 37);
buttonAddWarship.Margin = new Padding(4, 5, 4, 5);
buttonAddWarship.Name = "buttonAddWarship";
buttonAddWarship.Size = new Size(230, 45);
buttonAddWarship.TabIndex = 0;
buttonAddWarship.Text = "Add warship";
buttonAddWarship.UseVisualStyleBackColor = true;
buttonAddWarship.Click += ButtonAddWarship_Click;
//
// pictureBoxCollection
//
pictureBoxCollection.Location = new Point(0, 2);
pictureBoxCollection.Margin = new Padding(4, 5, 4, 5);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(893, 745);
pictureBoxCollection.TabIndex = 1;
pictureBoxCollection.TabStop = false;
//
// FormWarshipCollection
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1143, 750);
Controls.Add(pictureBoxCollection);
Controls.Add(groupBoxCollection);
Margin = new Padding(4, 5, 4, 5);
Name = "FormWarshipCollection";
Text = "Warship Collection";
groupBoxCollection.ResumeLayout(false);
groupBoxCollection.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxCollection;
private Button buttonRefreshCollection;
private Button buttonRemoveWarship;
private Button buttonAddWarship;
private PictureBox pictureBoxCollection;
private MaskedTextBox maskedTextBoxNumber;
}
}

View File

@ -0,0 +1,80 @@
using ProjectAircraftCarrier.DrawingObjects;
using ProjectAircraftCarrier.Generics;
using ProjectAircraftCarrier.MovementStrategy;
namespace ProjectAircraftCarrier
{
/// <summary>
/// Форма для работы с набором объектов класса DrawningCar
/// </summary>
public partial class FormWarshipCollection : Form
{
/// <summary>
/// Набор объектов
/// </summary>
private readonly WarshipsGenericCollection<DrawingWarship,
DrawingObjectWarship> _warships;
/// <summary>
/// Конструктор
/// </summary>
public FormWarshipCollection()
{
InitializeComponent();
_warships = new WarshipsGenericCollection<DrawingWarship,
DrawingObjectWarship>(pictureBoxCollection.Width,
pictureBoxCollection.Height);
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddWarship_Click(object sender, EventArgs e)
{
FormAircraftCarrier form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_warships + form.SelectedWarship != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _warships.ShowWarships();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта из набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveWarship_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (_warships - pos)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = _warships.ShowWarships();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Обновление рисунка по набору
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
pictureBoxCollection.Image = _warships.ShowWarships();
}
}
}

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

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

View File

@ -0,0 +1,88 @@
namespace ProjectAircraftCarrier.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="warship">Добавляемый автомобиль</param>
/// <returns></returns>
public int Insert(T warship)
{
if (_places[Count - 1] != null)
return -1;
return Insert(warship, 0);
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="warship">Добавляемый автомобиль</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public int Insert(T warship, int position)
{
int nullIndex = -1, i;
if (position < 0 || position >= Count)
return -1;
for (i = position; i < Count; i++)
{
if (_places[i] == null)
{
nullIndex = i;
break;
}
}
if (nullIndex < 0)
return -1;
for (i = nullIndex; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = warship;
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public bool Remove(int position)
{
if (position < 0 || position >= Count) return false;
_places[position] = null;
return true;
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T? Get(int position)
{
if (position < 0 || position >= Count)
return null;
return _places[position];
}
}
}

View File

@ -0,0 +1,136 @@
using ProjectAircraftCarrier.DrawingObjects;
using ProjectAircraftCarrier.MovementStrategy;
namespace ProjectAircraftCarrier.Generics
{
/// <summary>
/// Параметризованный класс для набора объектов DrawningCar
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam>
internal class WarshipsGenericCollection<T, U>
where T : DrawingWarship
where U : IMoveableObject
{
/// <summary>
/// Ширина окна прорисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна прорисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 196;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 58;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetGeneric<T> _collection;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
public WarshipsGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static int operator +(WarshipsGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
{
return -1;
}
return collect._collection.Insert(obj);
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static bool operator -(WarshipsGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection.Get(pos);
if (obj != null)
{
return collect._collection.Remove(pos);
}
return false;
}
/// <summary>
/// Получение объекта IMoveableObject
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowWarships()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
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 / 2, j *
_placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawObjects(Graphics g)
{
int inRow = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _collection.Count; i++)
{
DrawingWarship warship = _collection.Get(i);
if (warship != null)
{
warship.SetPosition(i % inRow * _placeSizeWidth + 3, (_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight + 5);
warship.DrawTransport(g);
}
}
}
}
}