done
This commit is contained in:
parent
c4e6dfff50
commit
83429b9e53
@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using WarmlyShip.Entities;
|
using WarmlyShip.Entities;
|
||||||
|
using WarmlyShip.MovementStrategy;
|
||||||
|
|
||||||
namespace WarmlyShip.DrawningObjects
|
namespace WarmlyShip.DrawningObjects
|
||||||
{
|
{
|
||||||
@ -16,6 +17,12 @@ namespace WarmlyShip.DrawningObjects
|
|||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityShip? EntityShip { get; protected set; }
|
public EntityShip? EntityShip { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта IMoveableObject из объекта DrawningShip
|
||||||
|
/// </summary>
|
||||||
|
public IMoveableObject GetMoveableObject => new DrawningObjectShip(this);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
135
WarmlyShip/FormShipCollection.Designer.cs
generated
Normal file
135
WarmlyShip/FormShipCollection.Designer.cs
generated
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
namespace WarmlyShip
|
||||||
|
{
|
||||||
|
partial class FormShipCollection
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
pictureBoxCollection = new PictureBox();
|
||||||
|
toolsLabel = new Panel();
|
||||||
|
label1 = new Label();
|
||||||
|
ButtonRefreshCollection = new Button();
|
||||||
|
ButtonDeleteShip = new Button();
|
||||||
|
maskedTextBoxNumber = new TextBox();
|
||||||
|
ButtonAddShip = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
toolsLabel.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
pictureBoxCollection.Location = new Point(0, 0);
|
||||||
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
pictureBoxCollection.Size = new Size(655, 395);
|
||||||
|
pictureBoxCollection.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
|
pictureBoxCollection.TabIndex = 0;
|
||||||
|
pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
|
// toolsLabel
|
||||||
|
//
|
||||||
|
toolsLabel.Controls.Add(label1);
|
||||||
|
toolsLabel.Controls.Add(ButtonRefreshCollection);
|
||||||
|
toolsLabel.Controls.Add(ButtonDeleteShip);
|
||||||
|
toolsLabel.Controls.Add(maskedTextBoxNumber);
|
||||||
|
toolsLabel.Controls.Add(ButtonAddShip);
|
||||||
|
toolsLabel.Location = new Point(660, 12);
|
||||||
|
toolsLabel.Name = "toolsLabel";
|
||||||
|
toolsLabel.Size = new Size(212, 383);
|
||||||
|
toolsLabel.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
label1.AutoSize = true;
|
||||||
|
label1.Location = new Point(58, -3);
|
||||||
|
label1.Name = "label1";
|
||||||
|
label1.Size = new Size(83, 15);
|
||||||
|
label1.TabIndex = 1;
|
||||||
|
label1.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// ButtonRefreshCollection
|
||||||
|
//
|
||||||
|
ButtonRefreshCollection.Location = new Point(35, 187);
|
||||||
|
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
|
ButtonRefreshCollection.Size = new Size(142, 37);
|
||||||
|
ButtonRefreshCollection.TabIndex = 2;
|
||||||
|
ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||||
|
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
|
||||||
|
//
|
||||||
|
// ButtonDeleteShip
|
||||||
|
//
|
||||||
|
ButtonDeleteShip.Location = new Point(35, 128);
|
||||||
|
ButtonDeleteShip.Name = "ButtonDeleteShip";
|
||||||
|
ButtonDeleteShip.Size = new Size(142, 37);
|
||||||
|
ButtonDeleteShip.TabIndex = 2;
|
||||||
|
ButtonDeleteShip.Text = "Удалить корабль";
|
||||||
|
ButtonDeleteShip.UseVisualStyleBackColor = true;
|
||||||
|
ButtonDeleteShip.Click += ButtonDeleteShip_Click;
|
||||||
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
maskedTextBoxNumber.Location = new Point(58, 83);
|
||||||
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
maskedTextBoxNumber.Size = new Size(100, 23);
|
||||||
|
maskedTextBoxNumber.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// ButtonAddShip
|
||||||
|
//
|
||||||
|
ButtonAddShip.Location = new Point(35, 31);
|
||||||
|
ButtonAddShip.Name = "ButtonAddShip";
|
||||||
|
ButtonAddShip.Size = new Size(142, 36);
|
||||||
|
ButtonAddShip.TabIndex = 2;
|
||||||
|
ButtonAddShip.Text = "Добавить корабль";
|
||||||
|
ButtonAddShip.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddShip.Click += ButtonAddShip_Click;
|
||||||
|
//
|
||||||
|
// FormShipCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(884, 395);
|
||||||
|
Controls.Add(toolsLabel);
|
||||||
|
Controls.Add(pictureBoxCollection);
|
||||||
|
Name = "FormShipCollection";
|
||||||
|
Text = "Набор кораблей";
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
toolsLabel.ResumeLayout(false);
|
||||||
|
toolsLabel.PerformLayout();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private PictureBox pictureBoxCollection;
|
||||||
|
private Panel toolsLabel;
|
||||||
|
private Button ButtonAddShip;
|
||||||
|
private Label label1;
|
||||||
|
private TextBox maskedTextBoxNumber;
|
||||||
|
private Button ButtonDeleteShip;
|
||||||
|
private Button ButtonRefreshCollection;
|
||||||
|
}
|
||||||
|
}
|
93
WarmlyShip/FormShipCollection.cs
Normal file
93
WarmlyShip/FormShipCollection.cs
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
using WarmlyShip.Generics;
|
||||||
|
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 WarmlyShip.DrawningObjects;
|
||||||
|
using WarmlyShip.MovementStrategy;
|
||||||
|
|
||||||
|
namespace WarmlyShip
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Форма для работы с набором объектов класса DrawningShip
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormShipCollection : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly ShipsGenericCollection<DrawningShip, DrawningObjectShip> _theShips;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormShipCollection()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_theShips = new ShipsGenericCollection<DrawningShip, DrawningObjectShip>
|
||||||
|
(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddShip_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
FormWarmlyShip form = new();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_theShips + form.SelectedShip != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBoxCollection.Image = _theShips.ShowShips();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonDeleteShip_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
|
||||||
|
if (_theShips - pos != true)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBoxCollection.Image = _theShips.ShowShips();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обновление рисунка по набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _theShips.ShowShips();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
WarmlyShip/FormShipCollection.resx
Normal file
120
WarmlyShip/FormShipCollection.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>
|
14
WarmlyShip/FormWarmlyShip.Designer.cs
generated
14
WarmlyShip/FormWarmlyShip.Designer.cs
generated
@ -37,6 +37,7 @@
|
|||||||
buttonCreateShip = new Button();
|
buttonCreateShip = new Button();
|
||||||
buttonStep = new Button();
|
buttonStep = new Button();
|
||||||
buttonCreateWarmlyShip = new Button();
|
buttonCreateWarmlyShip = new Button();
|
||||||
|
ButtonSelectedShip = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyShip).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyShip).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -142,11 +143,23 @@
|
|||||||
buttonCreateWarmlyShip.UseVisualStyleBackColor = true;
|
buttonCreateWarmlyShip.UseVisualStyleBackColor = true;
|
||||||
buttonCreateWarmlyShip.Click += buttonCreateWarmlyShip_Click;
|
buttonCreateWarmlyShip.Click += buttonCreateWarmlyShip_Click;
|
||||||
//
|
//
|
||||||
|
// ButtonSelectedShip
|
||||||
|
//
|
||||||
|
ButtonSelectedShip.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
ButtonSelectedShip.Location = new Point(213, 407);
|
||||||
|
ButtonSelectedShip.Name = "ButtonSelectedShip";
|
||||||
|
ButtonSelectedShip.Size = new Size(105, 42);
|
||||||
|
ButtonSelectedShip.TabIndex = 10;
|
||||||
|
ButtonSelectedShip.Text = "Добавить корабль";
|
||||||
|
ButtonSelectedShip.UseVisualStyleBackColor = true;
|
||||||
|
ButtonSelectedShip.Click += ButtonSelectedShip_Click;
|
||||||
|
//
|
||||||
// FormWarmlyShip
|
// FormWarmlyShip
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(884, 461);
|
ClientSize = new Size(884, 461);
|
||||||
|
Controls.Add(ButtonSelectedShip);
|
||||||
Controls.Add(buttonCreateWarmlyShip);
|
Controls.Add(buttonCreateWarmlyShip);
|
||||||
Controls.Add(buttonStep);
|
Controls.Add(buttonStep);
|
||||||
Controls.Add(buttonCreateShip);
|
Controls.Add(buttonCreateShip);
|
||||||
@ -176,5 +189,6 @@
|
|||||||
private Button buttonCreateShip;
|
private Button buttonCreateShip;
|
||||||
private Button buttonStep;
|
private Button buttonStep;
|
||||||
private Button buttonCreateWarmlyShip;
|
private Button buttonCreateWarmlyShip;
|
||||||
|
private Button ButtonSelectedShip;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,13 +13,21 @@ namespace WarmlyShip
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Стратегия перемещения
|
/// Стратегия перемещения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private AbstractStrategy? _abstractStrategy;
|
private AbstractStrategy? _strategy;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Выбранный корабль
|
||||||
|
/// </summary>
|
||||||
|
public DrawningShip? SelectedShip { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация формы
|
/// Инициализация формы
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormWarmlyShip()
|
public FormWarmlyShip()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_strategy = null;
|
||||||
|
SelectedShip = null;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Метод прорисовки корабля
|
/// Метод прорисовки корабля
|
||||||
@ -43,10 +51,24 @@ namespace WarmlyShip
|
|||||||
private void buttonCreateWarmlyShip_Click(object sender, EventArgs e)
|
private void buttonCreateWarmlyShip_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 dialogColor = new();
|
||||||
|
if (dialogColor.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialogColor.Color;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color dopColor = Color.FromArgb(random.Next(0, 256),
|
||||||
|
random.Next(0, 256), random.Next(0, 256));
|
||||||
|
ColorDialog dialogDopColor = new();
|
||||||
|
if (dialogDopColor.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
dopColor = dialogDopColor.Color;
|
||||||
|
}
|
||||||
|
|
||||||
_drawningShip = new DrawningWarmlyShip(random.Next(100, 300),
|
_drawningShip = new DrawningWarmlyShip(random.Next(100, 300),
|
||||||
random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(0, 2)),
|
||||||
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(0, 2)),
|
Convert.ToBoolean(random.Next(0, 2)),
|
||||||
pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
||||||
_drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
@ -60,9 +82,16 @@ namespace WarmlyShip
|
|||||||
private void buttonCreateShip_Click(object sender, EventArgs e)
|
private void buttonCreateShip_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 dialogColor = new();
|
||||||
|
if (dialogColor.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
color = dialogColor.Color;
|
||||||
|
}
|
||||||
|
|
||||||
_drawningShip = new DrawningShip(random.Next(100, 300), random.Next(1000, 3000),
|
_drawningShip = new DrawningShip(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
color, pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
||||||
pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
|
||||||
_drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
@ -110,33 +139,37 @@ namespace WarmlyShip
|
|||||||
}
|
}
|
||||||
if (comboBoxStrategy.Enabled)
|
if (comboBoxStrategy.Enabled)
|
||||||
{
|
{
|
||||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||||
switch
|
|
||||||
{
|
{
|
||||||
0 => new MoveToCenter(),
|
0 => new MoveToCenter(),
|
||||||
1 => new MoveToBorder(),
|
1 => new MoveToBorder(),
|
||||||
_ => null,
|
_ => null,
|
||||||
};
|
};
|
||||||
if (_abstractStrategy == null)
|
if (_strategy == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_abstractStrategy.SetData(new
|
_strategy.SetData(_drawningShip.GetMoveableObject,
|
||||||
DrawningObjectShip(_drawningShip), pictureBoxWarmlyShip.Width,
|
pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
|
||||||
pictureBoxWarmlyShip.Height);
|
|
||||||
comboBoxStrategy.Enabled = false;
|
|
||||||
}
|
}
|
||||||
if (_abstractStrategy == null)
|
if (_strategy == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_abstractStrategy.MakeStep();
|
comboBoxStrategy.Enabled = false;
|
||||||
|
_strategy.MakeStep();
|
||||||
Draw();
|
Draw();
|
||||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
if (_strategy.GetStatus() == Status.Finish)
|
||||||
{
|
{
|
||||||
comboBoxStrategy.Enabled = true;
|
comboBoxStrategy.Enabled = true;
|
||||||
_abstractStrategy = null;
|
_strategy = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonSelectedShip_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SelectedShip = _drawningShip;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
114
WarmlyShip/Generics/SetGeneric.cs
Normal file
114
WarmlyShip/Generics/SetGeneric.cs
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WarmlyShip.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="ship">Добавляемый корабль</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T ship)
|
||||||
|
{
|
||||||
|
return Insert(ship, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ship">Добавляемый корабль</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int Insert(T ship, 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] = ship;
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
153
WarmlyShip/Generics/ShipsGenericCollection.cs
Normal file
153
WarmlyShip/Generics/ShipsGenericCollection.cs
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.VisualBasic;
|
||||||
|
using WarmlyShip.DrawningObjects;
|
||||||
|
using WarmlyShip.MovementStrategy;
|
||||||
|
|
||||||
|
namespace WarmlyShip.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный класс для набора объектов DrawningShip
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <typeparam name="U"></typeparam>
|
||||||
|
internal class ShipsGenericCollection<T, U>
|
||||||
|
where T : DrawningShip
|
||||||
|
where U : IMoveableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна прорисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeWidth = 210;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Размер занимаемого объектом места (высота)
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _placeSizeHeight = 90;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly SetGeneric<T> _collection;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
public ShipsGenericCollection(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 +(ShipsGenericCollection<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 -(ShipsGenericCollection<T, U> collect, int
|
||||||
|
pos)
|
||||||
|
{
|
||||||
|
T? obj = collect._collection.Get(pos);
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
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 ShowShips()
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
|
{
|
||||||
|
DrawningShip ship = _collection.Get(i);
|
||||||
|
|
||||||
|
if (ship != null)
|
||||||
|
{
|
||||||
|
int inRow = _pictureWidth / _placeSizeWidth;
|
||||||
|
ship.SetPosition((inRow - 1 - (i % inRow)) * _placeSizeWidth, i / inRow * _placeSizeHeight);
|
||||||
|
ship.DrawTransport(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,7 @@ namespace WarmlyShip
|
|||||||
// 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 FormWarmlyShip());
|
Application.Run(new FormShipCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user