Lab4
This commit is contained in:
parent
5c2d3d0465
commit
5befb89c6b
349
Monorail/Monorail/FormMonorailCollection.Designer.cs
generated
349
Monorail/Monorail/FormMonorailCollection.Designer.cs
generated
@ -1,138 +1,213 @@
|
||||
namespace Monorail
|
||||
{
|
||||
partial class FormMonorailCollection
|
||||
{
|
||||
/// <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();
|
||||
panel1 = new Panel();
|
||||
maskedTextBoxNumber = new TextBox();
|
||||
buttonRefreshCol = new Button();
|
||||
buttonDelMonorail = new Button();
|
||||
buttonAddMonorail = new Button();
|
||||
label1 = new Label();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
panel1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Location = new Point(5, -1);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(931, 454);
|
||||
pictureBoxCollection.TabIndex = 5;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
panel1.BackColor = SystemColors.Info;
|
||||
panel1.Controls.Add(maskedTextBoxNumber);
|
||||
panel1.Controls.Add(buttonRefreshCol);
|
||||
panel1.Controls.Add(buttonDelMonorail);
|
||||
panel1.Controls.Add(buttonAddMonorail);
|
||||
panel1.Controls.Add(label1);
|
||||
panel1.Location = new Point(942, 12);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(190, 429);
|
||||
panel1.TabIndex = 4;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(29, 109);
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(125, 27);
|
||||
maskedTextBoxNumber.TabIndex = 4;
|
||||
//
|
||||
// buttonRefreshCol
|
||||
//
|
||||
buttonRefreshCol.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
buttonRefreshCol.Location = new Point(12, 237);
|
||||
buttonRefreshCol.Name = "buttonRefreshCol";
|
||||
buttonRefreshCol.Size = new Size(166, 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, 174);
|
||||
buttonDelMonorail.Name = "buttonDelMonorail";
|
||||
buttonDelMonorail.Size = new Size(166, 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, 29);
|
||||
buttonAddMonorail.Name = "buttonAddMonorail";
|
||||
buttonAddMonorail.Size = new Size(166, 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(1144, 453);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(panel1);
|
||||
Name = "FormMonorailCollection";
|
||||
Text = "Набор Монорельсов";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
panel1.ResumeLayout(false);
|
||||
panel1.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;
|
||||
}
|
||||
namespace Monorail
|
||||
{
|
||||
partial class FormMonorailCollection
|
||||
{
|
||||
/// <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();
|
||||
panel1 = new Panel();
|
||||
panel2 = new Panel();
|
||||
label2 = new Label();
|
||||
listBoxStorages = new ListBox();
|
||||
textBoxStorageName = new TextBox();
|
||||
button1 = new Button();
|
||||
ButtonAddObject = new Button();
|
||||
maskedTextBoxNumber = new TextBox();
|
||||
buttonRefreshCol = new Button();
|
||||
buttonDelMonorail = new Button();
|
||||
buttonAddMonorail = new Button();
|
||||
label1 = new Label();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
panel1.SuspendLayout();
|
||||
panel2.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Location = new Point(5, -1);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(1017, 517);
|
||||
pictureBoxCollection.TabIndex = 5;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
panel1.BackColor = SystemColors.Info;
|
||||
panel1.Controls.Add(panel2);
|
||||
panel1.Controls.Add(maskedTextBoxNumber);
|
||||
panel1.Controls.Add(buttonRefreshCol);
|
||||
panel1.Controls.Add(buttonDelMonorail);
|
||||
panel1.Controls.Add(buttonAddMonorail);
|
||||
panel1.Controls.Add(label1);
|
||||
panel1.Location = new Point(1025, -1);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(204, 517);
|
||||
panel1.TabIndex = 4;
|
||||
//
|
||||
// panel2
|
||||
//
|
||||
panel2.Controls.Add(label2);
|
||||
panel2.Controls.Add(listBoxStorages);
|
||||
panel2.Controls.Add(textBoxStorageName);
|
||||
panel2.Controls.Add(button1);
|
||||
panel2.Controls.Add(ButtonAddObject);
|
||||
panel2.Location = new Point(12, 20);
|
||||
panel2.Name = "panel2";
|
||||
panel2.Size = new Size(179, 263);
|
||||
panel2.TabIndex = 7;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(3, -3);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(66, 20);
|
||||
label2.TabIndex = 8;
|
||||
label2.Text = "Наборы";
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
listBoxStorages.FormattingEnabled = true;
|
||||
listBoxStorages.ItemHeight = 20;
|
||||
listBoxStorages.Location = new Point(17, 109);
|
||||
listBoxStorages.Name = "listBoxStorages";
|
||||
listBoxStorages.Size = new Size(144, 104);
|
||||
listBoxStorages.TabIndex = 9;
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
textBoxStorageName.Location = new Point(18, 29);
|
||||
textBoxStorageName.Name = "textBoxStorageName";
|
||||
textBoxStorageName.Size = new Size(143, 27);
|
||||
textBoxStorageName.TabIndex = 8;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
button1.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
button1.Location = new Point(18, 219);
|
||||
button1.Name = "button1";
|
||||
button1.Size = new Size(143, 41);
|
||||
button1.TabIndex = 5;
|
||||
button1.Text = "Удалить набор";
|
||||
button1.UseVisualStyleBackColor = true;
|
||||
button1.Click += ButtonDelObject_Click;
|
||||
//
|
||||
// ButtonAddObject
|
||||
//
|
||||
ButtonAddObject.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
ButtonAddObject.Location = new Point(18, 62);
|
||||
ButtonAddObject.Name = "ButtonAddObject";
|
||||
ButtonAddObject.Size = new Size(143, 41);
|
||||
ButtonAddObject.TabIndex = 6;
|
||||
ButtonAddObject.Text = "Добавить набор";
|
||||
ButtonAddObject.UseVisualStyleBackColor = true;
|
||||
ButtonAddObject.Click += ButtonAddObject_Click;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(30, 336);
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(125, 27);
|
||||
maskedTextBoxNumber.TabIndex = 4;
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
@ -1,75 +1,161 @@
|
||||
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 Monorail.DrawningObjects;
|
||||
using Monorail.Generics;
|
||||
using Monorail.MovementStrategy;
|
||||
|
||||
namespace Monorail
|
||||
{
|
||||
public partial class FormMonorailCollection : Form
|
||||
{
|
||||
private readonly MonorailsGenericCollection<DrawningMonorail, DrawningObjectMonorail> _monorails;
|
||||
|
||||
public FormMonorailCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_monorails = new MonorailsGenericCollection<DrawningMonorail, DrawningObjectMonorail>
|
||||
(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
private void ButtonAddMonorail_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormMonorail form = new();
|
||||
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_monorails + form.SelectedMonorail != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _monorails.ShowMonorails();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonRemoveMonorail_Click(object sender, EventArgs e)
|
||||
{
|
||||
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 (_monorails - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _monorails.ShowMonorails();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _monorails.ShowMonorails();
|
||||
}
|
||||
}
|
||||
}
|
||||
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 Monorail.DrawningObjects;
|
||||
using Monorail.Generics;
|
||||
using Monorail.MovementStrategy;
|
||||
|
||||
namespace Monorail
|
||||
{
|
||||
|
||||
public partial class FormMonorailCollection : Form
|
||||
{
|
||||
private readonly MonorailsGenericStorage _storage;
|
||||
|
||||
public FormMonorailCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new MonorailsGenericStorage
|
||||
(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxStorages.SelectedIndex;
|
||||
listBoxStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
|
||||
>= listBoxStorages.Items.Count))
|
||||
{
|
||||
listBoxStorages.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
|
||||
index < listBoxStorages.Items.Count)
|
||||
{
|
||||
listBoxStorages.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
private void ButtonAddObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
}
|
||||
private void ListBoxObjects_SelectedIndexChanged(object sender,
|
||||
EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image =
|
||||
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowMonorails();
|
||||
}
|
||||
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?",
|
||||
"Удаление", MessageBoxButtons.YesNo,
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,120 +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>
|
||||
<?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>
|
@ -33,18 +33,18 @@ namespace Monorail.Generics
|
||||
}
|
||||
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)
|
||||
{
|
||||
return collect._collection.Remove(pos);
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return false;
|
||||
return obj;
|
||||
}
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
public Bitmap ShowMonorails()
|
||||
{
|
||||
@ -78,7 +78,7 @@ namespace Monorail.Generics
|
||||
{
|
||||
|
||||
// TODO получение объекта
|
||||
DrawningMonorail? _monorail = _collection.Get(indexPlaces);
|
||||
DrawningMonorail? _monorail = _collection[indexPlaces];
|
||||
indexPlaces++;
|
||||
|
||||
if (_monorail != null)
|
||||
|
52
Monorail/Monorail/Generics/MonorailsGenericStorage.cs
Normal file
52
Monorail/Monorail/Generics/MonorailsGenericStorage.cs
Normal 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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,95 +1,104 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Monorail.Generics
|
||||
{
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
private readonly T?[] _places;
|
||||
public int Count => _places.Length;
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
}
|
||||
public int Insert(T monorail)
|
||||
{
|
||||
if (monorail == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = Count-1; i != 0; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[0] = monorail;
|
||||
|
||||
return 0;
|
||||
}
|
||||
public bool Insert(T monorail, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position >= Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
if (_places[position] != null)
|
||||
{
|
||||
for(int i = position + 1; i<Count; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
for (int j = i; j != position; j--)
|
||||
{
|
||||
_places[j] = _places[j - 1];
|
||||
}
|
||||
// TODO вставка по позиции
|
||||
_places[position] = monorail;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_places[position] = monorail;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public bool Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position >= Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||
if (_places[position] != null)
|
||||
{
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public T? Get(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if(position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Monorail.Generics
|
||||
{
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
private readonly List<T?> _places;
|
||||
public int Count => _places.Count;
|
||||
private readonly int _maxCount;
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
public int Insert(T monorail)
|
||||
{
|
||||
return Insert(monorail, 0);
|
||||
}
|
||||
public int Insert(T monorail, int position)
|
||||
{
|
||||
if (Count == _maxCount)
|
||||
return -1;
|
||||
|
||||
if (position < 0 || monorail == null)
|
||||
return -1;
|
||||
|
||||
if (position >= _maxCount)
|
||||
return -1;
|
||||
|
||||
|
||||
if (Count == 0)
|
||||
{
|
||||
_places.Add(monorail);
|
||||
}
|
||||
else
|
||||
{
|
||||
_places.Insert(position, monorail);
|
||||
}
|
||||
return Count;
|
||||
}
|
||||
public bool Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position >= Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||
if (_places[position] != null)
|
||||
{
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public T? this[int position]
|
||||
{
|
||||
get {
|
||||
// TODO проверка позиции
|
||||
if (position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if(position >= Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_places[position] != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
_places[position] = this[position];
|
||||
}
|
||||
}
|
||||
}
|
||||
public IEnumerable<T?> GetMonorails(int? maxMonorails = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxMonorails.HasValue && i == maxMonorails.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user