PIbd-23. Yunusov N.N. Lab work 03 #3
@ -39,7 +39,7 @@ namespace ProjectTrolleybus.MovementStrategy
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||
protected bool MoveLeft() => MoveTo(DirectionType.Left);
|
||||
protected bool MoveRight() => MoveTo(DirectionType.Right);
|
||||
protected bool MoveUp() => MoveTo(DirectionType.Up);
|
||||
protected bool MoveDown() => MoveTo(DirectionType.Down);
|
||||
|
133
Trolleybus/Trolleybus/BusesGenericCollection.cs
Normal file
133
Trolleybus/Trolleybus/BusesGenericCollection.cs
Normal file
@ -0,0 +1,133 @@
|
||||
using ProjectTrolleybus.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectTrolleybus.DrawingObjects;
|
||||
using ProjectTrolleybus.Generics;
|
||||
|
||||
namespace ProjectTrolleybus.Generics
|
||||
{
|
||||
internal class BusesGenericCollection<T, U>
|
||||
where T : DrawingBus
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 170;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 124;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetGeneric<T> _collection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
public BusesGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(BusesGenericCollection<T, U>? collect, T? obj)
|
||||
{
|
||||
if (obj == null || collect == null)
|
||||
return -1;
|
||||
return collect._collection.Insert(obj);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(BusesGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T? obj = collect?._collection.Get(pos);
|
||||
if (obj == null || collect == null)
|
||||
return false;
|
||||
return collect._collection.Remove(pos);
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowBuses()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
DrawingBus? trolleybus = _collection.Get(i);
|
||||
if (trolleybus != null)
|
||||
{
|
||||
int inRow = _pictureWidth / _placeSizeWidth;
|
||||
trolleybus.SetPosition(_placeSizeWidth * (inRow - 1) - (i % inRow * _placeSizeWidth), i / inRow * _placeSizeHeight);
|
||||
trolleybus.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectTrolleybus.Entities;
|
||||
using ProjectTrolleybus.MovementStrategy;
|
||||
|
||||
namespace ProjectTrolleybus.DrawingObjects
|
||||
{
|
||||
@ -151,5 +152,6 @@ namespace ProjectTrolleybus.DrawingObjects
|
||||
g.DrawEllipse(pen, _startPosX + 95, _startPosY + 40, 20, 40);
|
||||
g.DrawEllipse(pen, _startPosX + 120, _startPosY + 40, 20, 40);
|
||||
}
|
||||
public IMoveableObject GetMoveableObject => new DrawingObjectBus(this);
|
||||
}
|
||||
}
|
||||
|
126
Trolleybus/Trolleybus/FormBusCollection.Designer.cs
generated
Normal file
126
Trolleybus/Trolleybus/FormBusCollection.Designer.cs
generated
Normal file
@ -0,0 +1,126 @@
|
||||
namespace ProjectTrolleybus
|
||||
{
|
||||
partial class FormBusCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
groupBoxTrolleybus = new GroupBox();
|
||||
buttonUpdateCollection = new Button();
|
||||
buttonDeleteBus = new Button();
|
||||
maskedTextBoxNumber = new MaskedTextBox();
|
||||
buttonAddBus = new Button();
|
||||
pictureBoxCollection = new PictureBox();
|
||||
groupBoxTrolleybus.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTrolleybus
|
||||
//
|
||||
groupBoxTrolleybus.Controls.Add(buttonUpdateCollection);
|
||||
groupBoxTrolleybus.Controls.Add(buttonDeleteBus);
|
||||
groupBoxTrolleybus.Controls.Add(maskedTextBoxNumber);
|
||||
groupBoxTrolleybus.Controls.Add(buttonAddBus);
|
||||
groupBoxTrolleybus.Location = new Point(538, 2);
|
||||
groupBoxTrolleybus.Name = "groupBoxTrolleybus";
|
||||
groupBoxTrolleybus.Size = new Size(262, 448);
|
||||
groupBoxTrolleybus.TabIndex = 0;
|
||||
groupBoxTrolleybus.TabStop = false;
|
||||
groupBoxTrolleybus.Text = "Инструменты";
|
||||
//
|
||||
// buttonUpdateCollection
|
||||
//
|
||||
buttonUpdateCollection.Location = new Point(10, 250);
|
||||
buttonUpdateCollection.Name = "buttonUpdateCollection";
|
||||
buttonUpdateCollection.Size = new Size(241, 28);
|
||||
buttonUpdateCollection.TabIndex = 3;
|
||||
buttonUpdateCollection.Text = "Обновить коллекцию";
|
||||
buttonUpdateCollection.UseVisualStyleBackColor = true;
|
||||
buttonUpdateCollection.Click += ButtonRefreshCollection_Click;
|
||||
//
|
||||
// buttonDeleteBus
|
||||
//
|
||||
buttonDeleteBus.Location = new Point(10, 198);
|
||||
buttonDeleteBus.Name = "buttonDeleteBus";
|
||||
buttonDeleteBus.Size = new Size(241, 29);
|
||||
buttonDeleteBus.TabIndex = 2;
|
||||
buttonDeleteBus.Text = "Удалить автобус";
|
||||
buttonDeleteBus.UseVisualStyleBackColor = true;
|
||||
buttonDeleteBus.Click += ButtonRemoveBus_Click;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(74, 86);
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(115, 23);
|
||||
maskedTextBoxNumber.TabIndex = 1;
|
||||
//
|
||||
// buttonAddBus
|
||||
//
|
||||
buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonAddBus.Location = new Point(10, 22);
|
||||
buttonAddBus.Name = "buttonAddBus";
|
||||
buttonAddBus.Size = new Size(241, 28);
|
||||
buttonAddBus.TabIndex = 0;
|
||||
buttonAddBus.Text = "Добавить автобус";
|
||||
buttonAddBus.UseVisualStyleBackColor = true;
|
||||
buttonAddBus.Click += ButtonAddBus_Click;
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
pictureBoxCollection.Location = new Point(0, 2);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(537, 448);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// FormBusCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(805, 450);
|
||||
Controls.Add(groupBoxTrolleybus);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Name = "FormBusCollection";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Набор автобусов";
|
||||
groupBoxTrolleybus.ResumeLayout(false);
|
||||
groupBoxTrolleybus.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxTrolleybus;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private Button buttonAddBus;
|
||||
private Button buttonUpdateCollection;
|
||||
private Button buttonDeleteBus;
|
||||
private PictureBox pictureBoxCollection;
|
||||
}
|
||||
}
|
80
Trolleybus/Trolleybus/FormBusCollection.cs
Normal file
80
Trolleybus/Trolleybus/FormBusCollection.cs
Normal file
@ -0,0 +1,80 @@
|
||||
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 ProjectTrolleybus.DrawingObjects;
|
||||
using ProjectTrolleybus.MovementStrategy;
|
||||
using ProjectTrolleybus.Generics;
|
||||
|
||||
namespace ProjectTrolleybus
|
||||
{
|
||||
public partial class FormBusCollection : Form
|
||||
{
|
||||
private readonly BusesGenericCollection<DrawingBus, DrawingObjectBus> _buses;
|
||||
|
||||
public FormBusCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_buses = new BusesGenericCollection<DrawingBus, DrawingObjectBus>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormTrolleybus form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_buses + form.SelectedBus != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _buses.ShowBuses();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (_buses - pos)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _buses.ShowBuses();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обновление рисунка по набору
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _buses.ShowBuses();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
120
Trolleybus/Trolleybus/FormBusCollection.resx
Normal file
120
Trolleybus/Trolleybus/FormBusCollection.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>
|
116
Trolleybus/Trolleybus/FormTrolleybus.Designer.cs
generated
116
Trolleybus/Trolleybus/FormTrolleybus.Designer.cs
generated
@ -28,38 +28,29 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxTrolleybus = new PictureBox();
|
||||
buttonCreateTrolleybus = new Button();
|
||||
ButtonCreateTrolleybus = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonCreateBus = new Button();
|
||||
buttonStep = new Button();
|
||||
ButtonCreateBus = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
ButtonStep = new Button();
|
||||
ButtonSelectBus = new Button();
|
||||
pictureBoxTrolleybus = new PictureBox();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxTrolleybus).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxTrolleybus
|
||||
// ButtonCreateTrolleybus
|
||||
//
|
||||
pictureBoxTrolleybus.Dock = DockStyle.Fill;
|
||||
pictureBoxTrolleybus.Location = new Point(0, 0);
|
||||
pictureBoxTrolleybus.Name = "pictureBoxTrolleybus";
|
||||
pictureBoxTrolleybus.Size = new Size(884, 461);
|
||||
pictureBoxTrolleybus.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxTrolleybus.TabIndex = 0;
|
||||
pictureBoxTrolleybus.TabStop = false;
|
||||
//
|
||||
// buttonCreateTrolleybus
|
||||
//
|
||||
buttonCreateTrolleybus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateTrolleybus.Location = new Point(12, 411);
|
||||
buttonCreateTrolleybus.Name = "buttonCreateTrolleybus";
|
||||
buttonCreateTrolleybus.Size = new Size(84, 38);
|
||||
buttonCreateTrolleybus.TabIndex = 1;
|
||||
buttonCreateTrolleybus.Text = "Создать троллейбус";
|
||||
buttonCreateTrolleybus.UseVisualStyleBackColor = true;
|
||||
buttonCreateTrolleybus.Click += ButtonCreateTrolleybus_Click;
|
||||
ButtonCreateTrolleybus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
ButtonCreateTrolleybus.Location = new Point(12, 411);
|
||||
ButtonCreateTrolleybus.Name = "ButtonCreateTrolleybus";
|
||||
ButtonCreateTrolleybus.Size = new Size(92, 38);
|
||||
ButtonCreateTrolleybus.TabIndex = 1;
|
||||
ButtonCreateTrolleybus.Text = "Создать троллейбус";
|
||||
ButtonCreateTrolleybus.UseVisualStyleBackColor = true;
|
||||
ButtonCreateTrolleybus.Click += ButtonCreateTrolleybus_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
@ -109,49 +100,72 @@
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateBus
|
||||
// ButtonCreateBus
|
||||
//
|
||||
buttonCreateBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateBus.Location = new Point(102, 411);
|
||||
buttonCreateBus.Name = "buttonCreateBus";
|
||||
buttonCreateBus.Size = new Size(78, 38);
|
||||
buttonCreateBus.TabIndex = 6;
|
||||
buttonCreateBus.Text = "Создать автобус";
|
||||
buttonCreateBus.UseVisualStyleBackColor = true;
|
||||
buttonCreateBus.Click += ButtonCreateBus_Click;
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
buttonStep.Location = new Point(797, 41);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(75, 23);
|
||||
buttonStep.TabIndex = 7;
|
||||
buttonStep.Text = "Шаг";
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += ButtonStep_Click;
|
||||
ButtonCreateBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
ButtonCreateBus.Location = new Point(110, 411);
|
||||
ButtonCreateBus.Name = "ButtonCreateBus";
|
||||
ButtonCreateBus.Size = new Size(75, 38);
|
||||
ButtonCreateBus.TabIndex = 6;
|
||||
ButtonCreateBus.Text = "Создать автобус";
|
||||
ButtonCreateBus.UseVisualStyleBackColor = true;
|
||||
ButtonCreateBus.Click += ButtonCreateBus_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "Движение в центр", "Движение в правый угол" });
|
||||
comboBoxStrategy.Location = new Point(751, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(121, 23);
|
||||
comboBoxStrategy.TabIndex = 8;
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// ButtonStep
|
||||
//
|
||||
ButtonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonStep.Location = new Point(797, 41);
|
||||
ButtonStep.Name = "ButtonStep";
|
||||
ButtonStep.Size = new Size(75, 23);
|
||||
ButtonStep.TabIndex = 8;
|
||||
ButtonStep.Text = "Шаг";
|
||||
ButtonStep.UseVisualStyleBackColor = true;
|
||||
ButtonStep.Click += ButtonStep_Click;
|
||||
//
|
||||
// ButtonSelectBus
|
||||
//
|
||||
ButtonSelectBus.Location = new Point(797, 95);
|
||||
ButtonSelectBus.Name = "ButtonSelectBus";
|
||||
ButtonSelectBus.Size = new Size(75, 25);
|
||||
ButtonSelectBus.TabIndex = 9;
|
||||
ButtonSelectBus.Text = "Создание";
|
||||
ButtonSelectBus.UseVisualStyleBackColor = true;
|
||||
ButtonSelectBus.Click += ButtonSelectBus_Click;
|
||||
//
|
||||
// pictureBoxTrolleybus
|
||||
//
|
||||
pictureBoxTrolleybus.Dock = DockStyle.Fill;
|
||||
pictureBoxTrolleybus.Location = new Point(0, 0);
|
||||
pictureBoxTrolleybus.Name = "pictureBoxTrolleybus";
|
||||
pictureBoxTrolleybus.Size = new Size(884, 461);
|
||||
pictureBoxTrolleybus.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxTrolleybus.TabIndex = 10;
|
||||
pictureBoxTrolleybus.TabStop = false;
|
||||
//
|
||||
// FormTrolleybus
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(884, 461);
|
||||
Controls.Add(ButtonSelectBus);
|
||||
Controls.Add(ButtonStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(buttonCreateBus);
|
||||
Controls.Add(ButtonCreateBus);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonCreateTrolleybus);
|
||||
Controls.Add(ButtonCreateTrolleybus);
|
||||
Controls.Add(pictureBoxTrolleybus);
|
||||
Name = "FormTrolleybus";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
@ -162,15 +176,15 @@
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxTrolleybus;
|
||||
private Button buttonCreateTrolleybus;
|
||||
private Button ButtonCreateTrolleybus;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonCreateBus;
|
||||
private Button buttonStep;
|
||||
private Button ButtonCreateBus;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button ButtonStep;
|
||||
private Button ButtonSelectBus;
|
||||
private PictureBox pictureBoxTrolleybus;
|
||||
}
|
||||
}
|
@ -6,12 +6,14 @@ namespace ProjectTrolleybus
|
||||
public partial class FormTrolleybus : Form
|
||||
{
|
||||
private DrawingBus? _drawingBus;
|
||||
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
private AbstractStrategy? _strategy;
|
||||
public DrawingBus? SelectedBus { get; private set; }
|
||||
|
||||
public FormTrolleybus()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
SelectedBus = null;
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
@ -26,22 +28,41 @@ namespace ProjectTrolleybus
|
||||
}
|
||||
private void ButtonCreateTrolleybus_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
_drawingBus = new DrawingTrolleybus(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)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
|
||||
Random random = new();
|
||||
Color mainColor = Color.FromArgb(random.Next(0, 256),
|
||||
random.Next(0, 256), random.Next(0, 256));
|
||||
Color additColor = Color.FromArgb(random.Next(0, 256),
|
||||
random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
mainColor = dialog.Color;
|
||||
}
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
additColor = dialog.Color;
|
||||
}
|
||||
_drawingBus = new DrawingTrolleybus(random.Next(100, 300),
|
||||
random.Next(1000, 3000), mainColor, additColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
|
||||
_drawingBus.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void ButtonCreateBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
_drawingBus = new DrawingBus(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Random random = new();
|
||||
Color color = Color.FromArgb(random.Next(0, 256),
|
||||
random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_drawingBus = new DrawingBus(random.Next(100, 300),
|
||||
random.Next(1000, 3000), color,
|
||||
pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
|
||||
_drawingBus.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_drawingBus.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
}
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
@ -76,33 +97,39 @@ namespace ProjectTrolleybus
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
_strategy = comboBoxStrategy.SelectedIndex
|
||||
switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
_strategy.SetData(new
|
||||
DrawingObjectBus(_drawingBus), pictureBoxTrolleybus.Width,
|
||||
pictureBoxTrolleybus.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
if (_strategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
private void ButtonSelectBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedBus = _drawingBus;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
//using ProjectTrolleybus.Drawings;
|
||||
|
||||
namespace ProjectTrolleybus.MovementStrategy
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ namespace ProjectTrolleybus
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormTrolleybus());
|
||||
Application.Run(new FormBusCollection());
|
||||
}
|
||||
}
|
||||
}
|
62
Trolleybus/Trolleybus/SetGeneric.cs
Normal file
62
Trolleybus/Trolleybus/SetGeneric.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectTrolleybus.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 trolleybus)
|
||||
{
|
||||
if (_places[Count - 1] != null)
|
||||
return -1;
|
||||
return Insert(trolleybus, 0);
|
||||
}
|
||||
|
||||
public int Insert(T trolleybus, int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return -1;
|
||||
if (_places[position] != null)
|
||||
{
|
||||
int ind = position;
|
||||
while (ind < Count && _places[ind] != null)
|
||||
ind++;
|
||||
if (ind == Count)
|
||||
return -1;
|
||||
for (int i = ind - 1; i >= position; i--)
|
||||
_places[i + 1] = _places[i];
|
||||
}
|
||||
_places[position] = trolleybus;
|
||||
return position;
|
||||
}
|
||||
|
||||
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…
x
Reference in New Issue
Block a user