PIbd-22. Stroev V.M. Lab Work 03 #5
@ -4,12 +4,16 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Monorail.Entities;
|
||||
using Monorail.MovementStrategy;
|
||||
|
||||
namespace Monorail.DrawningObjects
|
||||
{
|
||||
public class DrawningMonorail
|
||||
{
|
||||
public EntityMonorail? EntityMonorail { get; protected set; }
|
||||
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectMonorail(this);
|
||||
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
protected int _startPosX;
|
||||
|
@ -1,6 +1,6 @@
|
||||
namespace Monorail
|
||||
{
|
||||
partial class MonoRail
|
||||
partial class FormMonorail
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
@ -37,6 +37,7 @@
|
||||
ButtonCreateSecondMonorail = new Button();
|
||||
buttonStep = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
button1 = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -56,7 +57,7 @@
|
||||
buttonUp.BackColor = SystemColors.Info;
|
||||
buttonUp.BackgroundImage = Properties.Resources.upper_arrow;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(790, 355);
|
||||
buttonUp.Location = new Point(784, 355);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(40, 40);
|
||||
buttonUp.TabIndex = 6;
|
||||
@ -69,7 +70,7 @@
|
||||
buttonLeft.BackColor = SystemColors.Info;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.left_arrow;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Location = new Point(744, 401);
|
||||
buttonLeft.Location = new Point(738, 401);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(40, 40);
|
||||
buttonLeft.TabIndex = 10;
|
||||
@ -82,7 +83,7 @@
|
||||
buttonDown.BackColor = SystemColors.Info;
|
||||
buttonDown.BackgroundImage = Properties.Resources.down_arrow;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(790, 401);
|
||||
buttonDown.Location = new Point(784, 401);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(40, 40);
|
||||
buttonDown.TabIndex = 9;
|
||||
@ -95,7 +96,7 @@
|
||||
buttonRight.BackColor = SystemColors.Info;
|
||||
buttonRight.BackgroundImage = Properties.Resources.right_arrow;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Location = new Point(836, 401);
|
||||
buttonRight.Location = new Point(830, 401);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(40, 40);
|
||||
buttonRight.TabIndex = 8;
|
||||
@ -146,12 +147,24 @@
|
||||
comboBoxStrategy.Size = new Size(151, 28);
|
||||
comboBoxStrategy.TabIndex = 19;
|
||||
//
|
||||
// MonoRail
|
||||
// button1
|
||||
//
|
||||
button1.BackColor = SystemColors.Info;
|
||||
button1.Location = new Point(710, 88);
|
||||
button1.Name = "button1";
|
||||
button1.Size = new Size(166, 40);
|
||||
button1.TabIndex = 23;
|
||||
button1.Text = "Выбрать Монорельс";
|
||||
button1.UseVisualStyleBackColor = false;
|
||||
button1.Click += ButtonSelectMonorail_Click;
|
||||
//
|
||||
// FormMonorail
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
BackColor = SystemColors.ControlDarkDark;
|
||||
ClientSize = new Size(882, 453);
|
||||
Controls.Add(button1);
|
||||
Controls.Add(ButtonCreateMonorail);
|
||||
Controls.Add(ButtonCreateSecondMonorail);
|
||||
Controls.Add(buttonStep);
|
||||
@ -161,7 +174,7 @@
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(pictureBoxMonorail);
|
||||
Name = "MonoRail";
|
||||
Name = "FormMonorail";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Monorail";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).EndInit();
|
||||
@ -180,5 +193,6 @@
|
||||
private Button ButtonCreateSecondMonorail;
|
||||
private Button buttonStep;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button button1;
|
||||
}
|
||||
}
|
@ -1,17 +1,21 @@
|
||||
using Monorail.DrawningObjects;
|
||||
using Monorail.MovementStrategy;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Monorail
|
||||
{
|
||||
public partial class MonoRail : Form
|
||||
public partial class FormMonorail : Form
|
||||
{
|
||||
|
||||
private DrawningMonorail? _drawningMonorail;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawningMonorail? SelectedMonorail { get; private set; }
|
||||
|
||||
public MonoRail()
|
||||
public FormMonorail()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedMonorail = null;
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
@ -29,13 +33,24 @@ namespace Monorail
|
||||
private void ButtonCreateSecondMonorail_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256));
|
||||
ColorDialog dialog1 = new();
|
||||
if (dialog1.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog1.Color;
|
||||
}
|
||||
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256));
|
||||
ColorDialog dialog2 = new();
|
||||
if (dialog2.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialog2.Color;
|
||||
}
|
||||
|
||||
_drawningMonorail = new DrawningSecondMonorail(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
random.Next(1000, 3000), color, dopColor,
|
||||
true, true,
|
||||
pictureBoxMonorail.Width, pictureBoxMonorail.Height);
|
||||
_drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
@ -45,9 +60,16 @@ namespace Monorail
|
||||
private void ButtonCreateMonorail_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256));
|
||||
ColorDialog dialog1 = new();
|
||||
if (dialog1.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog1.Color;
|
||||
}
|
||||
|
||||
_drawningMonorail = new DrawningMonorail(random.Next(100, 300),
|
||||
random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)), pictureBoxMonorail.Width, pictureBoxMonorail.Height);
|
||||
random.Next(1000, 3000), color, pictureBoxMonorail.Width, pictureBoxMonorail.Height);
|
||||
_drawningMonorail.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
@ -97,7 +119,6 @@ namespace Monorail
|
||||
_abstractStrategy.SetData(new
|
||||
DrawningObjectMonorail(_drawningMonorail), pictureBoxMonorail.Width,
|
||||
pictureBoxMonorail.Height);
|
||||
//comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
@ -111,5 +132,10 @@ namespace Monorail
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
private void ButtonSelectMonorail_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedMonorail = _drawningMonorail;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
138
Monorail/Monorail/FormMonorailCollection.Designer.cs
generated
Normal file
138
Monorail/Monorail/FormMonorailCollection.Designer.cs
generated
Normal file
@ -0,0 +1,138 @@
|
||||
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;
|
||||
}
|
||||
}
|
75
Monorail/Monorail/FormMonorailCollection.cs
Normal file
75
Monorail/Monorail/FormMonorailCollection.cs
Normal file
@ -0,0 +1,75 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
120
Monorail/Monorail/FormMonorailCollection.resx
Normal file
120
Monorail/Monorail/FormMonorailCollection.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>
|
103
Monorail/Monorail/Generics/MonorailsGenericCollection.cs
Normal file
103
Monorail/Monorail/Generics/MonorailsGenericCollection.cs
Normal file
@ -0,0 +1,103 @@
|
||||
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 MonorailsGenericCollection<T, U>
|
||||
where T: DrawningMonorail
|
||||
where U : IMoveableObject
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly int _placeSizeWidth = 295;
|
||||
private readonly int _placeSizeHeight = 65;
|
||||
private readonly SetGeneric<T> _collection;
|
||||
public MonorailsGenericCollection(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 +(MonorailsGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect._collection.Insert(obj);
|
||||
}
|
||||
public static bool operator -(MonorailsGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
if (obj != null)
|
||||
{
|
||||
return collect._collection.Remove(pos);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
}
|
||||
public Bitmap ShowMonorails()
|
||||
{
|
||||
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 + 20, j *
|
||||
_placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int indexPlaces = 0;
|
||||
int j = _pictureHeight / _placeSizeHeight - 1;
|
||||
int ind = 0;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
|
||||
// TODO получение объекта
|
||||
DrawningMonorail? _monorail = _collection.Get(indexPlaces);
|
||||
indexPlaces++;
|
||||
|
||||
if (_monorail != null)
|
||||
{
|
||||
// TODO установка позиции
|
||||
_monorail.SetPosition(ind * _placeSizeWidth, j * _placeSizeHeight);
|
||||
// TODO прорисовка объекта
|
||||
_monorail.DrawTransport(g);
|
||||
}
|
||||
if(ind == _pictureWidth / _placeSizeWidth - 1)
|
||||
{
|
||||
ind = 0;
|
||||
j--;
|
||||
}
|
||||
else
|
||||
{
|
||||
ind++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
95
Monorail/Monorail/Generics/SetGeneric.cs
Normal file
95
Monorail/Monorail/Generics/SetGeneric.cs
Normal file
@ -0,0 +1,95 @@
|
||||
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];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace Monorail
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new MonoRail());
|
||||
Application.Run(new FormMonorailCollection());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user
Правильнее было вызвать Insert(T obj, 0);