PIbd-22. Stroev V.M. Lab Work 04 #6

Closed
StroevVladimir wants to merge 3 commits from Lab04 into Lab03
6 changed files with 654 additions and 432 deletions
Showing only changes of commit 5befb89c6b - Show all commits

View File

@ -1,138 +1,213 @@
namespace Monorail namespace Monorail
{ {
partial class FormMonorailCollection partial class FormMonorailCollection
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// Clean up any resources being used. /// Clean up any resources being used.
/// </summary> /// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
{ {
components.Dispose(); components.Dispose();
} }
base.Dispose(disposing); base.Dispose(disposing);
} }
#region Windows Form Designer generated code #region Windows Form Designer generated code
/// <summary> /// <summary>
/// Required method for Designer support - do not modify /// Required method for Designer support - do not modify
/// the contents of this method with the code editor. /// the contents of this method with the code editor.
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
pictureBoxCollection = new PictureBox(); pictureBoxCollection = new PictureBox();
panel1 = new Panel(); panel1 = new Panel();
maskedTextBoxNumber = new TextBox(); panel2 = new Panel();
buttonRefreshCol = new Button(); label2 = new Label();
buttonDelMonorail = new Button(); listBoxStorages = new ListBox();
buttonAddMonorail = new Button(); textBoxStorageName = new TextBox();
label1 = new Label(); button1 = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); ButtonAddObject = new Button();
panel1.SuspendLayout(); maskedTextBoxNumber = new TextBox();
SuspendLayout(); buttonRefreshCol = new Button();
// buttonDelMonorail = new Button();
// pictureBoxCollection buttonAddMonorail = new Button();
// label1 = new Label();
pictureBoxCollection.Location = new Point(5, -1); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
pictureBoxCollection.Name = "pictureBoxCollection"; panel1.SuspendLayout();
pictureBoxCollection.Size = new Size(931, 454); panel2.SuspendLayout();
pictureBoxCollection.TabIndex = 5; SuspendLayout();
pictureBoxCollection.TabStop = false; //
// // pictureBoxCollection
// panel1 //
// pictureBoxCollection.Location = new Point(5, -1);
panel1.BackColor = SystemColors.Info; pictureBoxCollection.Name = "pictureBoxCollection";
panel1.Controls.Add(maskedTextBoxNumber); pictureBoxCollection.Size = new Size(1017, 517);
panel1.Controls.Add(buttonRefreshCol); pictureBoxCollection.TabIndex = 5;
panel1.Controls.Add(buttonDelMonorail); pictureBoxCollection.TabStop = false;
panel1.Controls.Add(buttonAddMonorail); //
panel1.Controls.Add(label1); // panel1
panel1.Location = new Point(942, 12); //
panel1.Name = "panel1"; panel1.BackColor = SystemColors.Info;
panel1.Size = new Size(190, 429); panel1.Controls.Add(panel2);
panel1.TabIndex = 4; panel1.Controls.Add(maskedTextBoxNumber);
// panel1.Controls.Add(buttonRefreshCol);
// maskedTextBoxNumber panel1.Controls.Add(buttonDelMonorail);
// panel1.Controls.Add(buttonAddMonorail);
maskedTextBoxNumber.Location = new Point(29, 109); panel1.Controls.Add(label1);
maskedTextBoxNumber.Name = "maskedTextBoxNumber"; panel1.Location = new Point(1025, -1);
maskedTextBoxNumber.Size = new Size(125, 27); panel1.Name = "panel1";
maskedTextBoxNumber.TabIndex = 4; panel1.Size = new Size(204, 517);
// panel1.TabIndex = 4;
// buttonRefreshCol //
// // panel2
buttonRefreshCol.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point); //
buttonRefreshCol.Location = new Point(12, 237); panel2.Controls.Add(label2);
buttonRefreshCol.Name = "buttonRefreshCol"; panel2.Controls.Add(listBoxStorages);
buttonRefreshCol.Size = new Size(166, 41); panel2.Controls.Add(textBoxStorageName);
buttonRefreshCol.TabIndex = 3; panel2.Controls.Add(button1);
buttonRefreshCol.Text = "Обновить коллекцию"; panel2.Controls.Add(ButtonAddObject);
buttonRefreshCol.UseVisualStyleBackColor = true; panel2.Location = new Point(12, 20);
buttonRefreshCol.Click += ButtonRefreshCollection_Click; panel2.Name = "panel2";
// panel2.Size = new Size(179, 263);
// buttonDelMonorail panel2.TabIndex = 7;
// //
buttonDelMonorail.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point); // label2
buttonDelMonorail.Location = new Point(12, 174); //
buttonDelMonorail.Name = "buttonDelMonorail"; label2.AutoSize = true;
buttonDelMonorail.Size = new Size(166, 41); label2.Location = new Point(3, -3);
buttonDelMonorail.TabIndex = 2; label2.Name = "label2";
buttonDelMonorail.Text = "Удалить монорельс"; label2.Size = new Size(66, 20);
buttonDelMonorail.UseVisualStyleBackColor = true; label2.TabIndex = 8;
buttonDelMonorail.Click += ButtonRemoveMonorail_Click; label2.Text = "Наборы";
// //
// buttonAddMonorail // listBoxStorages
// //
buttonAddMonorail.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point); listBoxStorages.FormattingEnabled = true;
buttonAddMonorail.Location = new Point(12, 29); listBoxStorages.ItemHeight = 20;
buttonAddMonorail.Name = "buttonAddMonorail"; listBoxStorages.Location = new Point(17, 109);
buttonAddMonorail.Size = new Size(166, 41); listBoxStorages.Name = "listBoxStorages";
buttonAddMonorail.TabIndex = 1; listBoxStorages.Size = new Size(144, 104);
buttonAddMonorail.Text = "Добавить монорельс"; listBoxStorages.TabIndex = 9;
buttonAddMonorail.UseVisualStyleBackColor = true; //
buttonAddMonorail.Click += ButtonAddMonorail_Click; // textBoxStorageName
// //
// label1 textBoxStorageName.Location = new Point(18, 29);
// textBoxStorageName.Name = "textBoxStorageName";
label1.AutoSize = true; textBoxStorageName.Size = new Size(143, 27);
label1.Location = new Point(3, -3); textBoxStorageName.TabIndex = 8;
label1.Name = "label1"; //
label1.Size = new Size(103, 20); // button1
label1.TabIndex = 0; //
label1.Text = "Инструменты"; button1.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
// button1.Location = new Point(18, 219);
// FormMonorailCollection button1.Name = "button1";
// button1.Size = new Size(143, 41);
AutoScaleDimensions = new SizeF(8F, 20F); button1.TabIndex = 5;
AutoScaleMode = AutoScaleMode.Font; button1.Text = "Удалить набор";
BackColor = SystemColors.ControlDarkDark; button1.UseVisualStyleBackColor = true;
ClientSize = new Size(1144, 453); button1.Click += ButtonDelObject_Click;
Controls.Add(pictureBoxCollection); //
Controls.Add(panel1); // ButtonAddObject
Name = "FormMonorailCollection"; //
Text = "Набор Монорельсов"; ButtonAddObject.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); ButtonAddObject.Location = new Point(18, 62);
panel1.ResumeLayout(false); ButtonAddObject.Name = "ButtonAddObject";
panel1.PerformLayout(); ButtonAddObject.Size = new Size(143, 41);
ResumeLayout(false); ButtonAddObject.TabIndex = 6;
} ButtonAddObject.Text = "Добавить набор";
ButtonAddObject.UseVisualStyleBackColor = true;
#endregion ButtonAddObject.Click += ButtonAddObject_Click;
//
private PictureBox pictureBoxCollection; // maskedTextBoxNumber
private Panel panel1; //
private Button buttonRefreshCol; maskedTextBoxNumber.Location = new Point(30, 336);
private Button buttonDelMonorail; maskedTextBoxNumber.Name = "maskedTextBoxNumber";
private Button buttonAddMonorail; maskedTextBoxNumber.Size = new Size(125, 27);
private Label label1; maskedTextBoxNumber.TabIndex = 4;
private TextBox maskedTextBoxNumber; //
} // buttonRefreshCol
//
buttonRefreshCol.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
buttonRefreshCol.Location = new Point(12, 466);
buttonRefreshCol.Name = "buttonRefreshCol";
buttonRefreshCol.Size = new Size(179, 41);
buttonRefreshCol.TabIndex = 3;
buttonRefreshCol.Text = "Обновить коллекцию";
buttonRefreshCol.UseVisualStyleBackColor = true;
buttonRefreshCol.Click += ButtonRefreshCollection_Click;
//
// buttonDelMonorail
//
buttonDelMonorail.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
buttonDelMonorail.Location = new Point(12, 369);
buttonDelMonorail.Name = "buttonDelMonorail";
buttonDelMonorail.Size = new Size(179, 41);
buttonDelMonorail.TabIndex = 2;
buttonDelMonorail.Text = "Удалить монорельс";
buttonDelMonorail.UseVisualStyleBackColor = true;
buttonDelMonorail.Click += ButtonRemoveMonorail_Click;
//
// buttonAddMonorail
//
buttonAddMonorail.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
buttonAddMonorail.Location = new Point(12, 289);
buttonAddMonorail.Name = "buttonAddMonorail";
buttonAddMonorail.Size = new Size(179, 41);
buttonAddMonorail.TabIndex = 1;
buttonAddMonorail.Text = "Добавить монорельс";
buttonAddMonorail.UseVisualStyleBackColor = true;
buttonAddMonorail.Click += ButtonAddMonorail_Click;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(3, -3);
label1.Name = "label1";
label1.Size = new Size(103, 20);
label1.TabIndex = 0;
label1.Text = "Инструменты";
//
// FormMonorailCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
BackColor = SystemColors.ControlDarkDark;
ClientSize = new Size(1228, 518);
Controls.Add(pictureBoxCollection);
Controls.Add(panel1);
Name = "FormMonorailCollection";
Text = "Набор Монорельсов";
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
panel1.ResumeLayout(false);
panel1.PerformLayout();
panel2.ResumeLayout(false);
panel2.PerformLayout();
ResumeLayout(false);
}
#endregion
private PictureBox pictureBoxCollection;
private Panel panel1;
private Button buttonRefreshCol;
private Button buttonDelMonorail;
private Button buttonAddMonorail;
private Label label1;
private TextBox maskedTextBoxNumber;
private Button button1;
private Panel panel2;
private Label label2;
private ListBox listBoxStorages;
private TextBox textBoxStorageName;
private Button ButtonAddObject;
}
} }

View File

@ -1,75 +1,161 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Monorail.DrawningObjects; using Monorail.DrawningObjects;
using Monorail.Generics; using Monorail.Generics;
using Monorail.MovementStrategy; using Monorail.MovementStrategy;
namespace Monorail namespace Monorail
{ {
public partial class FormMonorailCollection : Form
{ public partial class FormMonorailCollection : Form
private readonly MonorailsGenericCollection<DrawningMonorail, DrawningObjectMonorail> _monorails; {
private readonly MonorailsGenericStorage _storage;
public FormMonorailCollection()
{ public FormMonorailCollection()
InitializeComponent(); {
_monorails = new MonorailsGenericCollection<DrawningMonorail, DrawningObjectMonorail> InitializeComponent();
(pictureBoxCollection.Width, pictureBoxCollection.Height); _storage = new MonorailsGenericStorage
} (pictureBoxCollection.Width, pictureBoxCollection.Height);
private void ButtonAddMonorail_Click(object sender, EventArgs e) }
{ private void ReloadObjects()
FormMonorail form = new(); {
int index = listBoxStorages.SelectedIndex;
if (form.ShowDialog() == DialogResult.OK) listBoxStorages.Items.Clear();
{ for (int i = 0; i < _storage.Keys.Count; i++)
if (_monorails + form.SelectedMonorail != -1) {
{ listBoxStorages.Items.Add(_storage.Keys[i]);
MessageBox.Show("Объект добавлен"); }
pictureBoxCollection.Image = _monorails.ShowMonorails(); if (listBoxStorages.Items.Count > 0 && (index == -1 || index
} >= listBoxStorages.Items.Count))
else {
{ listBoxStorages.SelectedIndex = 0;
MessageBox.Show("Не удалось добавить объект"); }
} else if (listBoxStorages.Items.Count > 0 && index > -1 &&
} index < listBoxStorages.Items.Count)
} {
private void ButtonRemoveMonorail_Click(object sender, EventArgs e) listBoxStorages.SelectedIndex = index;
{ }
if (MessageBox.Show("Удалить объект?", "Удаление", }
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) private void ButtonAddObject_Click(object sender, EventArgs e)
{ {
return; if (string.IsNullOrEmpty(textBoxStorageName.Text))
} {
int pos; MessageBox.Show("Не все данные заполнены", "Ошибка",
if (maskedTextBoxNumber.Text == "") MessageBoxButtons.OK, MessageBoxIcon.Error);
{ return;
MessageBox.Show("Введите позицию элемента выше"); }
return;
} _storage.AddSet(textBoxStorageName.Text);
else ReloadObjects();
{ }
pos = Convert.ToInt32(maskedTextBoxNumber.Text); private void ListBoxObjects_SelectedIndexChanged(object sender,
} EventArgs e)
if (_monorails - pos != null) {
{ pictureBoxCollection.Image =
MessageBox.Show("Объект удален"); _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowMonorails();
pictureBoxCollection.Image = _monorails.ShowMonorails(); }
} private void ButtonDelObject_Click(object sender, EventArgs e)
else {
{ if (listBoxStorages.SelectedIndex == -1)
MessageBox.Show("Не удалось удалить объект"); {
} return;
} }
private void ButtonRefreshCollection_Click(object sender, EventArgs e) if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?",
{ "Удаление", MessageBoxButtons.YesNo,
pictureBoxCollection.Image = _monorails.ShowMonorails(); MessageBoxIcon.Question) == DialogResult.Yes)
} {
} _storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
} ReloadObjects();
}
}
private void ButtonAddMonorail_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
FormMonorail form = new();
if (form.ShowDialog() == DialogResult.OK)
{
int addedIndex = obj + form.SelectedMonorail;
if (addedIndex != -1 && addedIndex <= 20)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowMonorails();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void ButtonRemoveMonorail_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos;
if (maskedTextBoxNumber.Text == "")
{
MessageBox.Show("Введите позицию элемента выше");
return;
}
else
{
pos = Convert.ToInt32(maskedTextBoxNumber.Text);
}
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = obj.ShowMonorails();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollection.Image = obj.ShowMonorails();
}
}
}

View File

@ -1,120 +1,120 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<root> <root>
<!-- <!--
Microsoft ResX Schema Microsoft ResX Schema
Version 2.0 Version 2.0
The primary goals of this format is to allow a simple XML format The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes various data types are done through the TypeConverter classes
associated with the data types. associated with the data types.
Example: Example:
... ado.net/XML headers & schema ... ... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader> <resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader> <resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, 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="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="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value> <value>[base64 mime encoded serialized .NET Framework object]</value>
</data> </data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <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> <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment> <comment>This is a comment</comment>
</data> </data>
There are any number of "resheader" rows that contain simple There are any number of "resheader" rows that contain simple
name/value pairs. name/value pairs.
Each data row contains a name, and value. The row also contains a Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture. text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the Classes that don't support this are serialized and stored with the
mimetype set. mimetype set.
The mimetype is used for serialized objects, and tells the The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly: extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below. read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64 mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64 mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64 mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter : using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding. : 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: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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType> <xsd:complexType>
<xsd:choice maxOccurs="unbounded"> <xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata"> <xsd:element name="metadata">
<xsd:complexType> <xsd:complexType>
<xsd:sequence> <xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" /> <xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence> </xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" /> <xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" /> <xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" /> <xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" /> <xsd:attribute ref="xml:space" />
</xsd:complexType> </xsd:complexType>
</xsd:element> </xsd:element>
<xsd:element name="assembly"> <xsd:element name="assembly">
<xsd:complexType> <xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" /> <xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" /> <xsd:attribute name="name" type="xsd:string" />
</xsd:complexType> </xsd:complexType>
</xsd:element> </xsd:element>
<xsd:element name="data"> <xsd:element name="data">
<xsd:complexType> <xsd:complexType>
<xsd:sequence> <xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> <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:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence> </xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> <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="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" /> <xsd:attribute ref="xml:space" />
</xsd:complexType> </xsd:complexType>
</xsd:element> </xsd:element>
<xsd:element name="resheader"> <xsd:element name="resheader">
<xsd:complexType> <xsd:complexType>
<xsd:sequence> <xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence> </xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" /> <xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType> </xsd:complexType>
</xsd:element> </xsd:element>
</xsd:choice> </xsd:choice>
</xsd:complexType> </xsd:complexType>
</xsd:element> </xsd:element>
</xsd:schema> </xsd:schema>
<resheader name="resmimetype"> <resheader name="resmimetype">
<value>text/microsoft-resx</value> <value>text/microsoft-resx</value>
</resheader> </resheader>
<resheader name="version"> <resheader name="version">
<value>2.0</value> <value>2.0</value>
</resheader> </resheader>
<resheader name="reader"> <resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
</root> </root>

View File

@ -33,18 +33,18 @@ namespace Monorail.Generics
} }
return collect._collection.Insert(obj); return collect._collection.Insert(obj);
} }
public static bool operator -(MonorailsGenericCollection<T, U> collect, int pos) public static T? operator -(MonorailsGenericCollection<T, U> collect, int pos)
{ {
T? obj = collect._collection.Get(pos); T? obj = collect._collection[pos];
if (obj != null) if (obj != null)
{ {
return collect._collection.Remove(pos); collect._collection.Remove(pos);
} }
return false; return obj;
} }
public U? GetU(int pos) public U? GetU(int pos)
{ {
return (U?)_collection.Get(pos)?.GetMoveableObject; return (U?)_collection[pos]?.GetMoveableObject;
} }
public Bitmap ShowMonorails() public Bitmap ShowMonorails()
{ {
@ -78,7 +78,7 @@ namespace Monorail.Generics
{ {
// TODO получение объекта // TODO получение объекта
DrawningMonorail? _monorail = _collection.Get(indexPlaces); DrawningMonorail? _monorail = _collection[indexPlaces];
indexPlaces++; indexPlaces++;
if (_monorail != null) if (_monorail != null)

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Monorail.DrawningObjects;
using Monorail.MovementStrategy;
namespace Monorail.Generics
{
internal class MonorailsGenericStorage
{
readonly Dictionary<string, MonorailsGenericCollection<DrawningMonorail,
DrawningObjectMonorail>> _monorailsStorages;
public List<string> Keys => _monorailsStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
public MonorailsGenericStorage(int pictureWidth, int pictureHeight)
{
_monorailsStorages = new Dictionary<string, MonorailsGenericCollection<DrawningMonorail,
DrawningObjectMonorail>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight; ;
}
public void AddSet(string name)
{
//TO DO
_monorailsStorages.Add(name, new MonorailsGenericCollection<DrawningMonorail,
DrawningObjectMonorail>(_pictureWidth, _pictureHeight));
}
public void DelSet(string name)
{
if (_monorailsStorages[name] == null)
{
return;
}
_monorailsStorages[name] = null;
}
public MonorailsGenericCollection<DrawningMonorail, DrawningObjectMonorail>? this[string ind]
{
get
{
//TO DO
if (_monorailsStorages[ind] == null)
{
return null;
}
return _monorailsStorages[ind];
}
}
}
}

View File

@ -1,95 +1,104 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Monorail.Generics namespace Monorail.Generics
{ {
internal class SetGeneric<T> internal class SetGeneric<T>
where T : class where T : class
{ {
private readonly T?[] _places; private readonly List<T?> _places;
public int Count => _places.Length; public int Count => _places.Count;
public SetGeneric(int count) private readonly int _maxCount;
{ public SetGeneric(int count)
_places = new T?[count]; {
} _maxCount = count;
public int Insert(T monorail) _places = new List<T?>(count);
{ }
if (monorail == null) public int Insert(T monorail)
{ {
return -1; return Insert(monorail, 0);
} }
public int Insert(T monorail, int position)
for (int i = Count-1; i != 0; i--) {
{ if (Count == _maxCount)
_places[i] = _places[i - 1]; return -1;
}
_places[0] = monorail; if (position < 0 || monorail == null)
return -1;
return 0;
} if (position >= _maxCount)
public bool Insert(T monorail, int position) return -1;
{
// TODO проверка позиции
if (position >= Count) if (Count == 0)
{ {
return false; _places.Add(monorail);
} }
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то else
// проверка, что после вставляемого элемента в массиве есть пустой элемент {
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента _places.Insert(position, monorail);
if (_places[position] != null) }
{ return Count;
for(int i = position + 1; i<Count; i++) }
{ public bool Remove(int position)
if (_places[i] == null) {
{ // TODO проверка позиции
for (int j = i; j != position; j--) if (position >= Count)
{ {
_places[j] = _places[j - 1]; return false;
} }
// TODO вставка по позиции // TODO удаление объекта из массива, присвоив элементу массива значение null
_places[position] = monorail; if (_places[position] != null)
return true; {
} _places[position] = null;
} return true;
return false; }
} else
else {
{ return false;
_places[position] = monorail; }
return true; }
} public T? this[int position]
} {
public bool Remove(int position) get {
{ // TODO проверка позиции
// TODO проверка позиции if (position >= Count)
if (position >= Count) {
{ return null;
return false; }
} return _places[position];
// TODO удаление объекта из массива, присвоив элементу массива значение null }
if (_places[position] != null) set
{ {
_places[position] = null; if(position >= Count)
return true; {
} return;
else }
{ if (_places[position] != null)
return false; {
} return;
} }
public T? Get(int position) else
{ {
// TODO проверка позиции _places[position] = this[position];
if(position >= Count) }
{ }
return null; }
} public IEnumerable<T?> GetMonorails(int? maxMonorails = null)
return _places[position]; {
} for (int i = 0; i < _places.Count; ++i)
{
} yield return _places[i];
} if (maxMonorails.HasValue && i == maxMonorails.Value)
{
yield break;
}
}
}
}
}