Done
This commit is contained in:
parent
e3729a0365
commit
881edef5a4
@ -67,7 +67,8 @@ namespace Monorail.DrawningObjects
|
||||
_startPosY = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public IMoveableObject GetMoveableObject => new
|
||||
DrawningObjectMonorail(this);
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityMonorail == null)
|
||||
|
123
Monorail/Monorail/FormMonorailCollection.Designer.cs
generated
Normal file
123
Monorail/Monorail/FormMonorailCollection.Designer.cs
generated
Normal file
@ -0,0 +1,123 @@
|
||||
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()
|
||||
{
|
||||
toolGroupBox = new System.Windows.Forms.GroupBox();
|
||||
maskedTextBox = new System.Windows.Forms.MaskedTextBox();
|
||||
updateCollectionButton = new System.Windows.Forms.Button();
|
||||
deleteMonorailButton = new System.Windows.Forms.Button();
|
||||
addMonorailButton = new System.Windows.Forms.Button();
|
||||
pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
toolGroupBox.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// toolGroupBox
|
||||
//
|
||||
toolGroupBox.Controls.Add(maskedTextBox);
|
||||
toolGroupBox.Controls.Add(updateCollectionButton);
|
||||
toolGroupBox.Controls.Add(deleteMonorailButton);
|
||||
toolGroupBox.Controls.Add(addMonorailButton);
|
||||
toolGroupBox.Location = new System.Drawing.Point(623, 12);
|
||||
toolGroupBox.Name = "toolGroupBox";
|
||||
toolGroupBox.Size = new System.Drawing.Size(227, 426);
|
||||
toolGroupBox.TabIndex = 0;
|
||||
toolGroupBox.TabStop = false;
|
||||
toolGroupBox.Text = "Инструменты";
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new System.Drawing.Point(6, 72);
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new System.Drawing.Size(125, 27);
|
||||
maskedTextBox.TabIndex = 4;
|
||||
//
|
||||
// updateCollectionButton
|
||||
//
|
||||
updateCollectionButton.Location = new System.Drawing.Point(6, 151);
|
||||
updateCollectionButton.Name = "updateCollectionButton";
|
||||
updateCollectionButton.Size = new System.Drawing.Size(215, 40);
|
||||
updateCollectionButton.TabIndex = 3;
|
||||
updateCollectionButton.Text = "Обновить коллекцию";
|
||||
updateCollectionButton.UseVisualStyleBackColor = true;
|
||||
updateCollectionButton.Click += updateCollectionButton_Click;
|
||||
//
|
||||
// deleteMonorailButton
|
||||
//
|
||||
deleteMonorailButton.Location = new System.Drawing.Point(6, 105);
|
||||
deleteMonorailButton.Name = "deleteMonorailButton";
|
||||
deleteMonorailButton.Size = new System.Drawing.Size(215, 40);
|
||||
deleteMonorailButton.TabIndex = 2;
|
||||
deleteMonorailButton.Text = "Удалить";
|
||||
deleteMonorailButton.UseVisualStyleBackColor = true;
|
||||
deleteMonorailButton.Click += deleteMonorailButton_Click;
|
||||
//
|
||||
// addMonorailButton
|
||||
//
|
||||
addMonorailButton.Location = new System.Drawing.Point(6, 26);
|
||||
addMonorailButton.Name = "addMonorailButton";
|
||||
addMonorailButton.Size = new System.Drawing.Size(215, 40);
|
||||
addMonorailButton.TabIndex = 0;
|
||||
addMonorailButton.Text = "Добавить";
|
||||
addMonorailButton.UseVisualStyleBackColor = true;
|
||||
addMonorailButton.Click += addMonorailButton_Click;
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Location = new System.Drawing.Point(12, 12);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new System.Drawing.Size(605, 426);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// FormMonorailCollection
|
||||
//
|
||||
AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
ClientSize = new System.Drawing.Size(862, 450);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(toolGroupBox);
|
||||
Name = "FormMonorailCollection";
|
||||
Text = "FormMonorailCollection";
|
||||
toolGroupBox.ResumeLayout(false);
|
||||
toolGroupBox.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.GroupBox toolGroupBox;
|
||||
private System.Windows.Forms.Button updateCollectionButton;
|
||||
private System.Windows.Forms.Button deleteMonorailButton;
|
||||
private System.Windows.Forms.Button addMonorailButton;
|
||||
private System.Windows.Forms.PictureBox pictureBoxCollection;
|
||||
private System.Windows.Forms.MaskedTextBox maskedTextBox;
|
||||
}
|
||||
}
|
70
Monorail/Monorail/FormMonorailCollection.cs
Normal file
70
Monorail/Monorail/FormMonorailCollection.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using Monorail.DrawningObjects;
|
||||
using Monorail.Generics;
|
||||
using Monorail.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Monorail
|
||||
{
|
||||
public partial class FormMonorailCollection : Form
|
||||
{
|
||||
private readonly MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail> _monorails;
|
||||
|
||||
public FormMonorailCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_monorails = new MonorailGenericCollection<DrawningMonorail,
|
||||
DrawningObjectMonorail>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
|
||||
private void addMonorailButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
MonorailForm form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_monorails + form.SelectedMonorail)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _monorails.ShowMonorails();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteMonorailButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (_monorails - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _monorails.ShowMonorails();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCollectionButton_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>
|
13
Monorail/Monorail/MonorailForm.Designer.cs
generated
13
Monorail/Monorail/MonorailForm.Designer.cs
generated
@ -39,6 +39,7 @@ namespace Monorail
|
||||
comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
buttonStep = new System.Windows.Forms.Button();
|
||||
buttonCreateAdvanced = new System.Windows.Forms.Button();
|
||||
buttonSelectMonorail = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -141,11 +142,22 @@ namespace Monorail
|
||||
buttonCreateAdvanced.UseVisualStyleBackColor = true;
|
||||
buttonCreateAdvanced.Click += buttonCreateAdvanced_Click;
|
||||
//
|
||||
// buttonSelectMonorail
|
||||
//
|
||||
buttonSelectMonorail.Location = new System.Drawing.Point(384, 401);
|
||||
buttonSelectMonorail.Name = "buttonSelectMonorail";
|
||||
buttonSelectMonorail.Size = new System.Drawing.Size(180, 40);
|
||||
buttonSelectMonorail.TabIndex = 9;
|
||||
buttonSelectMonorail.Text = "Выбрать";
|
||||
buttonSelectMonorail.UseVisualStyleBackColor = true;
|
||||
buttonSelectMonorail.Click += buttonSelectMonorail_Click;
|
||||
//
|
||||
// MonorailForm
|
||||
//
|
||||
AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
ClientSize = new System.Drawing.Size(882, 453);
|
||||
Controls.Add(buttonSelectMonorail);
|
||||
Controls.Add(buttonCreateAdvanced);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
@ -173,6 +185,7 @@ namespace Monorail
|
||||
public System.Windows.Forms.ComboBox comboBoxStrategy;
|
||||
private System.Windows.Forms.Button buttonStep;
|
||||
private System.Windows.Forms.Button buttonCreateAdvanced;
|
||||
private System.Windows.Forms.Button buttonSelectMonorail;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,13 @@ namespace Monorail
|
||||
private DrawningMonorail? _drawningMonorail;
|
||||
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
|
||||
public DrawningMonorail? SelectedMonorail { get; private set; }
|
||||
public MonorailForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedMonorail = null;
|
||||
}
|
||||
|
||||
private void Draw()
|
||||
@ -37,10 +41,16 @@ namespace Monorail
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color wheelColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color tireColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
bodyColor = dialog.Color;
|
||||
}
|
||||
_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)),
|
||||
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)),
|
||||
bodyColor, wheelColor, tireColor,
|
||||
pictureBoxMonorail.Width, pictureBoxMonorail.Height);
|
||||
Draw();
|
||||
}
|
||||
@ -72,13 +82,20 @@ namespace Monorail
|
||||
private void buttonCreateAdvanced_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color wheelColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color tireColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
bodyColor = dialog.Color;
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
additionalColor = dialog.Color;
|
||||
int addWheelNumb = random.Next(3, 5);
|
||||
_drawningMonorail = new DrawningAdvancedMonorail(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)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
pictureBoxMonorail.Width, pictureBoxMonorail.Height, random.Next(3, 5),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), random.Next(0,2) > 0,
|
||||
random.Next(0, 2) > 0);
|
||||
bodyColor, wheelColor, tireColor,
|
||||
pictureBoxMonorail.Width, pictureBoxMonorail.Height, addWheelNumb,
|
||||
additionalColor, random.Next(0, 2) > 0, random.Next(0, 2) > 0);
|
||||
Draw();
|
||||
}
|
||||
|
||||
@ -116,5 +133,11 @@ namespace Monorail
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSelectMonorail_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedMonorail = _drawningMonorail;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
98
Monorail/Monorail/MonorailGenericCollection.cs
Normal file
98
Monorail/Monorail/MonorailGenericCollection.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using Monorail.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Monorail.DrawningObjects;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Monorail.Generics
|
||||
{
|
||||
internal class MonorailGenericCollection<T,U>
|
||||
where T :DrawningMonorail
|
||||
where U: IMoveableObject
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
private readonly int _placeSizeWidth = 133;
|
||||
|
||||
private readonly int _placeSizeHeight = 50;
|
||||
|
||||
private readonly SetGeneric<T> _collection;
|
||||
|
||||
public MonorailGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
|
||||
public static bool operator +(MonorailGenericCollection<T,U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return false;
|
||||
return collect?._collection.Insert(obj) ?? false;
|
||||
}
|
||||
|
||||
public static T? operator -(MonorailGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
if (obj != null)
|
||||
collect._collection.Remove(pos);
|
||||
return obj;
|
||||
}
|
||||
|
||||
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, j *
|
||||
_placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
DrawningMonorail monorail = _collection.Get(i);
|
||||
if (monorail != null)
|
||||
{
|
||||
int inRow = _pictureWidth / _placeSizeWidth;
|
||||
monorail.SetPosition(i % inRow * _placeSizeWidth, (_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight );
|
||||
monorail.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ namespace Monorail
|
||||
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new MonorailForm());
|
||||
Application.Run(new FormMonorailCollection());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
60
Monorail/Monorail/SetGeneric.cs
Normal file
60
Monorail/Monorail/SetGeneric.cs
Normal file
@ -0,0 +1,60 @@
|
||||
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 bool Insert(T monorail)
|
||||
{
|
||||
if (_places[Count-1] != null)
|
||||
return false;
|
||||
return Insert(monorail, 0);
|
||||
}
|
||||
|
||||
public bool Insert(T monorail, int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return false;
|
||||
if (_places[position] != null)
|
||||
{
|
||||
int ind = position;
|
||||
while (ind < Count && _places[ind] != null)
|
||||
ind++;
|
||||
if (ind == Count)
|
||||
return false;
|
||||
for (int i = ind - 1; i >= position; i--)
|
||||
_places[i + 1] = _places[i];
|
||||
}
|
||||
_places[position] = monorail;
|
||||
return true;
|
||||
}
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count) || _places[position] == null)
|
||||
return false;
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user