done
This commit is contained in:
parent
eda14d9810
commit
aade6261c5
@ -61,7 +61,7 @@ namespace Catamaran
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
|
||||
|
||||
protected abstract void MoveToTarget();
|
||||
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
|
90
Catamaran/CatamaransGenericCollection.cs
Normal file
90
Catamaran/CatamaransGenericCollection.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Catamaran
|
||||
{
|
||||
internal class CatamaransGenericCollection<T, U>
|
||||
where T : DrawningCatamaran
|
||||
where U : IMoveableObject
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
private readonly int _placeSizeWidth = 210;
|
||||
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
|
||||
private readonly SetGeneric<T> _collection;
|
||||
|
||||
public CatamaransGenericCollection(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 +(CatamaransGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return -1;
|
||||
return collect?._collection.Insert(obj) ?? -1;
|
||||
}
|
||||
|
||||
public static bool operator -(CatamaransGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
if (obj != null)
|
||||
collect._collection.Remove(pos);
|
||||
return false;
|
||||
}
|
||||
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
}
|
||||
|
||||
public Bitmap ShowCats()
|
||||
{
|
||||
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, 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);
|
||||
}
|
||||
}
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
DrawningCatamaran catamaran = _collection.Get(i);
|
||||
if (catamaran != null)
|
||||
{
|
||||
int inRow = _pictureWidth / _placeSizeWidth;
|
||||
catamaran.SetPosition(i % inRow * _placeSizeWidth, ((_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight)+5);
|
||||
catamaran.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -21,7 +21,9 @@ namespace Catamaran
|
||||
public readonly int _catamaranWidth = 120;
|
||||
|
||||
public readonly int _catamaranHeight = 80;
|
||||
|
||||
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectCatamaran(this);
|
||||
|
||||
public DrawningCatamaran(int speed, double weight, Color bodyColor, Color additioncolor, int width, int height, bool seats)
|
||||
{
|
||||
if (_pictureHeight < _catamaranWidth && _pictureWidth < _catamaranHeight) return;
|
||||
@ -85,7 +87,6 @@ namespace Catamaran
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityCatamaran == null)
|
||||
|
20
Catamaran/FormCatamaran.Designer.cs
generated
20
Catamaran/FormCatamaran.Designer.cs
generated
@ -2,7 +2,9 @@
|
||||
{
|
||||
partial class FormCatamaran
|
||||
{
|
||||
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
@ -14,10 +16,6 @@
|
||||
|
||||
#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()
|
||||
{
|
||||
pictureBox=new PictureBox();
|
||||
@ -29,6 +27,7 @@
|
||||
buttonCreatePro=new Button();
|
||||
comboBox=new ComboBox();
|
||||
buttonStep=new Button();
|
||||
buttonSelect=new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -136,11 +135,23 @@
|
||||
buttonStep.UseVisualStyleBackColor=true;
|
||||
buttonStep.Click+=buttonStep_Click;
|
||||
//
|
||||
// buttonSelect
|
||||
//
|
||||
buttonSelect.ImageAlign=ContentAlignment.TopCenter;
|
||||
buttonSelect.Location=new Point(431, 638);
|
||||
buttonSelect.Name="buttonSelect";
|
||||
buttonSelect.Size=new Size(197, 73);
|
||||
buttonSelect.TabIndex=14;
|
||||
buttonSelect.Text="Выбрать катамаран";
|
||||
buttonSelect.UseVisualStyleBackColor=true;
|
||||
buttonSelect.Click+=buttonSelect_Click;
|
||||
//
|
||||
// FormCatamaran
|
||||
//
|
||||
AutoScaleDimensions=new SizeF(10F, 25F);
|
||||
AutoScaleMode=AutoScaleMode.Font;
|
||||
ClientSize=new Size(1143, 750);
|
||||
Controls.Add(buttonSelect);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(comboBox);
|
||||
Controls.Add(buttonCreatePro);
|
||||
@ -170,5 +181,6 @@
|
||||
private Button buttonCreatePro;
|
||||
private ComboBox comboBox;
|
||||
private Button buttonStep;
|
||||
public Button buttonSelect;
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ namespace Catamaran
|
||||
|
||||
private DrawningCatamaran? _DrawningCatamaran;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawningCatamaran? SelectedCatamaran { get; private set; }
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
@ -22,7 +23,6 @@ namespace Catamaran
|
||||
pictureBox.Image = bmp;
|
||||
}
|
||||
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_DrawningCatamaran == null)
|
||||
@ -53,7 +53,13 @@ namespace Catamaran
|
||||
Random random = new();
|
||||
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
_DrawningCatamaran = new DrawningCatamaran(random.Next(10, 30), random.Next(100, 300),bodyColor,additionalColor, pictureBox.Width, pictureBox.Height,true);
|
||||
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
bodyColor = dialog.Color;
|
||||
}
|
||||
_DrawningCatamaran = new DrawningCatamaran(random.Next(10, 30), random.Next(100, 300), bodyColor, additionalColor, pictureBox.Width, pictureBox.Height, true);
|
||||
|
||||
_DrawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
@ -66,8 +72,19 @@ namespace Catamaran
|
||||
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color otherColor = 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;
|
||||
}
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
additionalColor = dialog.Color;
|
||||
}
|
||||
|
||||
_DrawningCatamaran = new DrawningCatamaranPro(random.Next(100, 300),
|
||||
random.Next(1000, 3000),bodyColor,additionalColor,otherColor, true, true, true, pictureBox.Width, pictureBox.Height, true);
|
||||
random.Next(1000, 3000), bodyColor, otherColor, additionalColor, true, true, true, pictureBox.Width, pictureBox.Height, true);
|
||||
_DrawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
|
||||
@ -110,5 +127,12 @@ namespace Catamaran
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSelect_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedCatamaran = _DrawningCatamaran;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
114
Catamaran/FormCatamaranCollection.Designer.cs
generated
Normal file
114
Catamaran/FormCatamaranCollection.Designer.cs
generated
Normal file
@ -0,0 +1,114 @@
|
||||
namespace Catamaran
|
||||
{
|
||||
partial class FormCatamaranCollection
|
||||
{
|
||||
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBoxCollection=new GroupBox();
|
||||
maskedTextBox=new MaskedTextBox();
|
||||
buttonUpdateCollection=new Button();
|
||||
buttonDeleteCat=new Button();
|
||||
buttonAddCat=new Button();
|
||||
pictureBoxCollection=new PictureBox();
|
||||
groupBoxCollection.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxCollection
|
||||
//
|
||||
groupBoxCollection.Controls.Add(maskedTextBox);
|
||||
groupBoxCollection.Controls.Add(buttonUpdateCollection);
|
||||
groupBoxCollection.Controls.Add(buttonDeleteCat);
|
||||
groupBoxCollection.Controls.Add(buttonAddCat);
|
||||
groupBoxCollection.Location=new Point(889, 12);
|
||||
groupBoxCollection.Name="groupBoxCollection";
|
||||
groupBoxCollection.Size=new Size(242, 637);
|
||||
groupBoxCollection.TabIndex=0;
|
||||
groupBoxCollection.TabStop=false;
|
||||
groupBoxCollection.Text="Инструменты";
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location=new Point(21, 138);
|
||||
maskedTextBox.Name="maskedTextBox";
|
||||
maskedTextBox.Size=new Size(215, 31);
|
||||
maskedTextBox.TabIndex=2;
|
||||
//
|
||||
// buttonUpdateCollection
|
||||
//
|
||||
buttonUpdateCollection.Location=new Point(21, 286);
|
||||
buttonUpdateCollection.Name="buttonUpdateCollection";
|
||||
buttonUpdateCollection.Size=new Size(215, 54);
|
||||
buttonUpdateCollection.TabIndex=2;
|
||||
buttonUpdateCollection.Text="Обновить коллекцию";
|
||||
buttonUpdateCollection.UseVisualStyleBackColor=true;
|
||||
buttonUpdateCollection.Click+=ButtonRefreshCollection_Click;
|
||||
//
|
||||
// buttonDeleteCat
|
||||
//
|
||||
buttonDeleteCat.Location=new Point(21, 186);
|
||||
buttonDeleteCat.Name="buttonDeleteCat";
|
||||
buttonDeleteCat.Size=new Size(215, 54);
|
||||
buttonDeleteCat.TabIndex=1;
|
||||
buttonDeleteCat.Text="Удалить катамаран";
|
||||
buttonDeleteCat.UseVisualStyleBackColor=true;
|
||||
buttonDeleteCat.Click+=ButtonRemoveCat_Click;
|
||||
//
|
||||
// buttonAddCat
|
||||
//
|
||||
buttonAddCat.Location=new Point(21, 39);
|
||||
buttonAddCat.Name="buttonAddCat";
|
||||
buttonAddCat.Size=new Size(215, 54);
|
||||
buttonAddCat.TabIndex=0;
|
||||
buttonAddCat.Text="Добавить катамаран";
|
||||
buttonAddCat.UseVisualStyleBackColor=true;
|
||||
buttonAddCat.Click+=ButtonAddCat_Click;
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Location=new Point(0, 0);
|
||||
pictureBoxCollection.Name="pictureBoxCollection";
|
||||
pictureBoxCollection.Size=new Size(883, 750);
|
||||
pictureBoxCollection.TabIndex=1;
|
||||
pictureBoxCollection.TabStop=false;
|
||||
//
|
||||
// FormCatamaranCollection
|
||||
//
|
||||
AutoScaleDimensions=new SizeF(10F, 25F);
|
||||
AutoScaleMode=AutoScaleMode.Font;
|
||||
ClientSize=new Size(1143, 750);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(groupBoxCollection);
|
||||
Name="FormCatamaranCollection";
|
||||
Text="FormCatamaranCollection";
|
||||
groupBoxCollection.ResumeLayout(false);
|
||||
groupBoxCollection.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxCollection;
|
||||
private Button buttonAddCat;
|
||||
private Button buttonUpdateCollection;
|
||||
private Button buttonDeleteCat;
|
||||
private MaskedTextBox maskedTextBox;
|
||||
public PictureBox pictureBoxCollection;
|
||||
}
|
||||
}
|
66
Catamaran/FormCatamaranCollection.cs
Normal file
66
Catamaran/FormCatamaranCollection.cs
Normal file
@ -0,0 +1,66 @@
|
||||
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 Catamaran
|
||||
{
|
||||
public partial class FormCatamaranCollection : Form
|
||||
{
|
||||
|
||||
private readonly CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran> _cats;
|
||||
|
||||
public FormCatamaranCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_cats = new CatamaransGenericCollection<DrawningCatamaran,
|
||||
DrawningObjectCatamaran>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
|
||||
private void ButtonAddCat_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormCatamaran form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_cats + form.SelectedCatamaran != null)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _cats.ShowCats();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRemoveCat_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (_cats - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _cats.ShowCats();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _cats.ShowCats();
|
||||
}
|
||||
}
|
||||
}
|
120
Catamaran/FormCatamaranCollection.resx
Normal file
120
Catamaran/FormCatamaranCollection.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>
|
@ -2,12 +2,16 @@ namespace Catamaran
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormCatamaran());
|
||||
Application.Run(new FormCatamaranCollection());
|
||||
}
|
||||
|
||||
}
|
||||
|
61
Catamaran/SetGeneric.cs
Normal file
61
Catamaran/SetGeneric.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Catamaran
|
||||
{
|
||||
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 catamaran)
|
||||
{
|
||||
if (_places[Count-1] != null)
|
||||
return -1;
|
||||
return Insert(catamaran, 0);
|
||||
}
|
||||
|
||||
public int Insert(T catamaran, int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return -1;
|
||||
if (_places[position] != null)
|
||||
{
|
||||
int ind = position;
|
||||
while (ind < Count && _places[ind] != null)
|
||||
ind++;
|
||||
if (ind == Count)
|
||||
return -1;
|
||||
for (int i = ind - 1; i >= position; i--)
|
||||
_places[i + 1] = _places[i];
|
||||
}
|
||||
_places[position] = catamaran;
|
||||
return position;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count) || _places[position] == null)
|
||||
return false;
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user