до логики формы
This commit is contained in:
parent
24f96b5ae0
commit
1883c5f919
197
Monorail/Monorail/FormMapWithSetLocomotive.Designer.cs
generated
Normal file
197
Monorail/Monorail/FormMapWithSetLocomotive.Designer.cs
generated
Normal file
@ -0,0 +1,197 @@
|
||||
namespace Monorail
|
||||
{
|
||||
partial class FormMapWithSetLocomotive
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
pictureBoxLocomotive = new PictureBox();
|
||||
comboBoxSelectorMap = new ComboBox();
|
||||
buttonAddCar = new Button();
|
||||
buttonRemoveCar = new Button();
|
||||
buttonShowStorage = new Button();
|
||||
buttonShowOnMap = new Button();
|
||||
maskedTextBoxPosition = new MaskedTextBox();
|
||||
buttonUp = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
groupBoxTools = new GroupBox();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxLocomotive).BeginInit();
|
||||
groupBoxTools.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxLocomotive
|
||||
//
|
||||
pictureBoxLocomotive.Dock = DockStyle.Left;
|
||||
pictureBoxLocomotive.Location = new Point(0, 0);
|
||||
pictureBoxLocomotive.Name = "pictureBoxLocomotive";
|
||||
pictureBoxLocomotive.Size = new Size(579, 450);
|
||||
pictureBoxLocomotive.TabIndex = 0;
|
||||
pictureBoxLocomotive.TabStop = false;
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
comboBoxSelectorMap.FormattingEnabled = true;
|
||||
comboBoxSelectorMap.Location = new Point(26, 22);
|
||||
comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
comboBoxSelectorMap.Size = new Size(168, 23);
|
||||
comboBoxSelectorMap.TabIndex = 2;
|
||||
//
|
||||
// buttonAddCar
|
||||
//
|
||||
buttonAddCar.Location = new Point(26, 70);
|
||||
buttonAddCar.Name = "buttonAddCar";
|
||||
buttonAddCar.Size = new Size(168, 28);
|
||||
buttonAddCar.TabIndex = 3;
|
||||
buttonAddCar.Text = "Добавить автомобиль";
|
||||
buttonAddCar.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonRemoveCar
|
||||
//
|
||||
buttonRemoveCar.Location = new Point(26, 151);
|
||||
buttonRemoveCar.Name = "buttonRemoveCar";
|
||||
buttonRemoveCar.Size = new Size(169, 30);
|
||||
buttonRemoveCar.TabIndex = 4;
|
||||
buttonRemoveCar.Text = "Удалить автомобиль";
|
||||
buttonRemoveCar.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
buttonShowStorage.Location = new Point(26, 222);
|
||||
buttonShowStorage.Name = "buttonShowStorage";
|
||||
buttonShowStorage.Size = new Size(168, 39);
|
||||
buttonShowStorage.TabIndex = 5;
|
||||
buttonShowStorage.Text = "Посмотреть хранилище";
|
||||
buttonShowStorage.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
buttonShowOnMap.Location = new Point(26, 307);
|
||||
buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
buttonShowOnMap.Size = new Size(169, 34);
|
||||
buttonShowOnMap.TabIndex = 6;
|
||||
buttonShowOnMap.Text = "Посмотреть карту";
|
||||
buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
maskedTextBoxPosition.Location = new Point(26, 193);
|
||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
maskedTextBoxPosition.Size = new Size(168, 23);
|
||||
maskedTextBoxPosition.TabIndex = 7;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(98, 366);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(30, 30);
|
||||
buttonUp.TabIndex = 8;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Location = new Point(62, 402);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(30, 30);
|
||||
buttonLeft.TabIndex = 9;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(98, 402);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(30, 30);
|
||||
buttonDown.TabIndex = 10;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Location = new Point(134, 402);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(30, 30);
|
||||
buttonRight.TabIndex = 11;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
groupBoxTools.Controls.Add(buttonRight);
|
||||
groupBoxTools.Controls.Add(buttonDown);
|
||||
groupBoxTools.Controls.Add(buttonLeft);
|
||||
groupBoxTools.Controls.Add(buttonUp);
|
||||
groupBoxTools.Controls.Add(maskedTextBoxPosition);
|
||||
groupBoxTools.Controls.Add(buttonShowOnMap);
|
||||
groupBoxTools.Controls.Add(buttonShowStorage);
|
||||
groupBoxTools.Controls.Add(buttonRemoveCar);
|
||||
groupBoxTools.Controls.Add(buttonAddCar);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorMap);
|
||||
groupBoxTools.Location = new Point(585, -2);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(212, 451);
|
||||
groupBoxTools.TabIndex = 12;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// FormMapWithSetLocomotive
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(pictureBoxLocomotive);
|
||||
Name = "FormMapWithSetLocomotive";
|
||||
Text = "Карта с набором объектов";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxLocomotive).EndInit();
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxLocomotive;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
private Button buttonAddCar;
|
||||
private Button buttonRemoveCar;
|
||||
private Button buttonShowStorage;
|
||||
private Button buttonShowOnMap;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private Button buttonUp;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private GroupBox groupBoxTools;
|
||||
}
|
||||
}
|
20
Monorail/Monorail/FormMapWithSetLocomotive.cs
Normal file
20
Monorail/Monorail/FormMapWithSetLocomotive.cs
Normal file
@ -0,0 +1,20 @@
|
||||
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 FormMapWithSetLocomotive : Form
|
||||
{
|
||||
public FormMapWithSetLocomotive()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
60
Monorail/Monorail/FormMapWithSetLocomotive.resx
Normal file
60
Monorail/Monorail/FormMapWithSetLocomotive.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<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>
|
151
Monorail/Monorail/MapWithSetLocomotiveGeneric.cs
Normal file
151
Monorail/Monorail/MapWithSetLocomotiveGeneric.cs
Normal file
@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Monorail
|
||||
{
|
||||
internal class MapWithSetLocomotivGeneric<T, U>
|
||||
where T : class, IDrawingObject
|
||||
where U : AbstractMap
|
||||
{
|
||||
// Ширина окна отрисовки
|
||||
private readonly int _pictureWidth;
|
||||
// Высота окна отрисовки
|
||||
private readonly int _pictureHeight;
|
||||
// Размер занимаемого объектом места (ширина)
|
||||
private readonly int _placeSizeWidth = 180;
|
||||
// Размер занимаемого объектом места (высота)
|
||||
private readonly int _placeSizeHeight = 150;
|
||||
// Набор объектов
|
||||
private readonly SetLocomotivGeneric<T> _setLocomotive;
|
||||
// Карта
|
||||
private readonly U _map;
|
||||
|
||||
private readonly T[] _places;
|
||||
// Конструктор
|
||||
public MapWithSetLocomotivGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setLocomotive = new SetLocomotivGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
// Перегрузка оператора сложения
|
||||
public static int operator +(MapWithSetLocomotivGeneric<T, U> map, T Locomotive)
|
||||
{
|
||||
return map._setLocomotive.Insert(Locomotive);
|
||||
}
|
||||
// Перегрузка оператора вычитания
|
||||
public static T operator -(MapWithSetLocomotivGeneric<T, U> map, int position)
|
||||
{
|
||||
|
||||
return map._setLocomotive.Remove(position);
|
||||
}
|
||||
// Вывод всего набора объектов
|
||||
public Bitmap ShowSet()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawLocomotive(gr);
|
||||
return bmp;
|
||||
}
|
||||
// Просмотр объекта на карте
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setLocomotive.Count; i++)
|
||||
{
|
||||
var Locomotive = _setLocomotive.Get(i);
|
||||
if (Locomotive != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, Locomotive);
|
||||
}
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
// Перемещение объекта по карте
|
||||
public Bitmap MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
// "Взбалтываем" набор, чтобы все элементы оказались в начале
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setLocomotive.Count - 1;
|
||||
for (int i = 0; i < _setLocomotive.Count; i++)
|
||||
{
|
||||
if (_setLocomotive.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var Locomotive = _setLocomotive.Get(j);
|
||||
if (Locomotive != null)
|
||||
{
|
||||
_setLocomotive.Insert(Locomotive, i);
|
||||
_setLocomotive.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Метод отрисовки фона
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Sienna, 3);
|
||||
Brush brush = new SolidBrush(Color.DodgerBlue);
|
||||
g.FillRectangle(brush, 0, 0, _pictureWidth, _pictureHeight);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight + 2, i * _placeSizeWidth + _placeSizeWidth / 2 + 40, j * _placeSizeHeight + 2);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth + 7, 2, i * _placeSizeWidth + 7, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
g.DrawLine(pen, i * _placeSizeWidth + 3, 2, i * _placeSizeWidth + 3, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
// Метод прорисовки объектов
|
||||
private void DrawLocomotive(Graphics g)
|
||||
{
|
||||
int widthEl = _pictureWidth / _placeSizeWidth;
|
||||
int heightEl = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
int curWidth = 0;
|
||||
int curHeight = 0;
|
||||
|
||||
for (int i = _setLocomotive.Count; i >= 0; i--)
|
||||
{
|
||||
_setLocomotive.Get(i)?.SetObject(_pictureWidth - _placeSizeWidth * curWidth - 85,
|
||||
curHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
_setLocomotive.Get(i)?.DrawingObject(g);
|
||||
|
||||
if (curWidth < widthEl)
|
||||
curWidth++;
|
||||
else
|
||||
{
|
||||
curWidth = 1;
|
||||
curHeight++;
|
||||
}
|
||||
if (curHeight > heightEl)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
80
Monorail/Monorail/SetLocomotiveGeneric.cs
Normal file
80
Monorail/Monorail/SetLocomotiveGeneric.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Monorail
|
||||
{
|
||||
internal class SetLocomotivGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
// Массив объектов, которые храним
|
||||
private readonly T[] _places;
|
||||
// Количество объектов в массиве
|
||||
public int Count => _places.Length;
|
||||
// Конструктор
|
||||
public SetLocomotivGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
// Добавление объекта в набор
|
||||
public int Insert(T Locomotive)
|
||||
{
|
||||
// вставка в начало набора
|
||||
return Insert(Locomotive, 0);
|
||||
}
|
||||
// Добавление объекта в набор на конкретную позицию
|
||||
public int Insert(T Locomotive, int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (position >= _places.Length || position < 0)
|
||||
return -1;
|
||||
//проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = Locomotive;
|
||||
return position;
|
||||
}
|
||||
//проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
int findEmptyPos = -1;
|
||||
|
||||
for (int i = position + 1; i < Count; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
findEmptyPos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (findEmptyPos < 0) return -1;
|
||||
|
||||
//сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
for (int i = findEmptyPos; i > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
// вставка по позиции
|
||||
_places[position] = Locomotive;
|
||||
return position;
|
||||
}
|
||||
// Удаление объекта из набора с конкретной позиции
|
||||
public T Remove(int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (position >= _places.Length || position < 0) return null;
|
||||
// удаление объекта из массива, присовив элементу массива значение null
|
||||
T temp = _places[position];
|
||||
_places[position] = null;
|
||||
return temp;
|
||||
}
|
||||
// Получение объекта из набора по позиции
|
||||
public T Get(int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (position >= _places.Length || position < 0)
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user