PIbd22_Kamcharova_K.A._lab4 #12
@ -5,9 +5,9 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using DoubleDeckerbus.Entities;
|
||||
using DoubleDeckerbus.MovementStrategy;
|
||||
using DoubleDeckerbus.Move_Strategy;
|
||||
|
||||
namespace DoubleDeckerbus.DrawingObjects
|
||||
namespace DoubleDeckerbus.Drawing
|
||||
{
|
||||
public class DrawingBus
|
||||
{
|
||||
@ -17,8 +17,8 @@ namespace DoubleDeckerbus.DrawingObjects
|
||||
public int _pictureHeight;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
protected readonly int _busWidth = 175;
|
||||
protected readonly int _busHeight = 115;
|
||||
protected readonly int _busWidth = 175;
|
||||
protected readonly int _busHeight = 115;
|
||||
public int GetPosX => _startPosX;
|
||||
public int GetPosY => _startPosY;
|
||||
public int GetWidth => _busWidth;
|
||||
@ -55,7 +55,7 @@ namespace DoubleDeckerbus.DrawingObjects
|
||||
_startPosY = y;
|
||||
}
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
{
|
||||
if (!CanMove(direction) || EntityBus == null)
|
||||
{
|
||||
return;
|
||||
@ -91,10 +91,8 @@ namespace DoubleDeckerbus.DrawingObjects
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black);
|
||||
|
||||
Brush additionalBrush = new
|
||||
SolidBrush(EntityBus.BodyColor);
|
||||
|
||||
g.FillRectangle(additionalBrush, _startPosX + 147, _startPosY + 52, 21, 20);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 147, _startPosY + 71, 30, 27);
|
||||
g.FillRectangle(additionalBrush, _startPosX + 10, _startPosY + 52, 137, 46);
|
||||
@ -106,7 +104,6 @@ namespace DoubleDeckerbus.DrawingObjects
|
||||
g.FillRectangle(brBlue, _startPosX + 123, _startPosY + 55, 15, 15);
|
||||
g.DrawLine(pen, _startPosX + 30, _startPosY + 52, _startPosX + 30, _startPosY + 98);
|
||||
g.DrawLine(pen, _startPosX + 35, _startPosY + 52, _startPosX + 35, _startPosY + 98);
|
||||
|
||||
Brush gr = new SolidBrush(Color.Gray);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 23, _startPosY + 88, 25, 25);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 123, _startPosY + 88, 25, 25);
|
@ -1,5 +1,4 @@
|
||||
using DoubleDeckerbus.DrawingObjects;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -7,7 +6,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using DoubleDeckerbus.Entities;
|
||||
|
||||
namespace DoubleDeckerbus
|
||||
namespace DoubleDeckerbus.Drawing
|
||||
{
|
||||
public class DrawingDoubleDeckerbus : DrawingBus
|
||||
{
|
||||
@ -17,7 +16,6 @@ namespace DoubleDeckerbus
|
||||
{
|
||||
EntityBus = new EntityDoubleDeckerBus(speed, weight, bodyColor, additionalColor, secondfloor, stairs);
|
||||
}
|
||||
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
@ -25,16 +23,20 @@ namespace DoubleDeckerbus
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Pen additionalPen = new(doubleDeckerBus.Body);
|
||||
Brush additionalBrush = new SolidBrush(doubleDeckerBus.Body);
|
||||
Pen pen = new(Color.Black); //чёрный цвет для колёс
|
||||
Pen additionalPen = new(doubleDeckerBus.AddColor);
|
||||
Brush additionalBrush = new SolidBrush(doubleDeckerBus.AddColor);
|
||||
base.DrawTransport(g);
|
||||
|
||||
if (doubleDeckerBus.Secondfloor)
|
||||
{
|
||||
Brush additionalBrush2 = new SolidBrush(doubleDeckerBus.Body);
|
||||
Brush additionalBrush2 = new SolidBrush(doubleDeckerBus.AddColor);
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
g.FillRectangle(additionalBrush2, _startPosX + 7, _startPosY + 12, 172, 40);
|
||||
|
||||
g.FillRectangle(additionalBrush2, _startPosX + 7, _startPosY + 12, 172, 40); //большой прямоугольник
|
||||
|
||||
g.DrawLine(pen, _startPosX + 7, _startPosY + 36, _startPosX + 178, _startPosY + 36);
|
||||
|
||||
g.FillRectangle(brBlue, _startPosX + 15, _startPosY + 15, 15, 15);
|
||||
g.FillRectangle(brBlue, _startPosX + 42, _startPosY + 15, 15, 15);
|
||||
g.FillRectangle(brBlue, _startPosX + 69, _startPosY + 15, 15, 15);
|
||||
@ -42,6 +44,7 @@ namespace DoubleDeckerbus
|
||||
g.FillRectangle(brBlue, _startPosX + 123, _startPosY + 15, 15, 15);
|
||||
g.FillRectangle(brBlue, _startPosX + 150, _startPosY + 15, 15, 15);
|
||||
}
|
||||
|
||||
if (doubleDeckerBus.Stairs)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX + 10, _startPosY + 55, _startPosX + 34, _startPosY + 55);
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DoubleDeckerbus
|
||||
namespace DoubleDeckerbus.Entities
|
||||
{
|
||||
public enum DirectionType
|
||||
{
|
@ -9,12 +9,12 @@ namespace DoubleDeckerbus.Entities
|
||||
{
|
||||
public class EntityDoubleDeckerBus : EntityBus
|
||||
{
|
||||
public Color Body { get; private set; }
|
||||
public Color AddColor { get; private set; }
|
||||
public bool Secondfloor { get; private set; }
|
||||
public bool Stairs { get; private set; }
|
||||
public EntityDoubleDeckerBus(int speed, double weight, Color bodyColor, Color additionalColor, bool secondfloor, bool stairs) : base(speed, weight, bodyColor)
|
||||
{
|
||||
Body = additionalColor;
|
||||
AddColor = additionalColor;
|
||||
Secondfloor = secondfloor;
|
||||
Stairs = stairs;
|
||||
}
|
128
DoubleDeckerBus/FormBusCollection.Designer.cs
generated
128
DoubleDeckerBus/FormBusCollection.Designer.cs
generated
@ -1,128 +0,0 @@
|
||||
namespace DoubleDeckerbus
|
||||
{
|
||||
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()
|
||||
{
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.labelInstruments = new System.Windows.Forms.Label();
|
||||
this.buttonAdd = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxNumber = new System.Windows.Forms.TextBox();
|
||||
this.buttonDelete = new System.Windows.Forms.Button();
|
||||
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(1, -2);
|
||||
this.pictureBoxCollection.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(803, 924);
|
||||
this.pictureBoxCollection.TabIndex = 0;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// labelInstruments
|
||||
//
|
||||
this.labelInstruments.AutoSize = true;
|
||||
this.labelInstruments.Location = new System.Drawing.Point(852, 22);
|
||||
this.labelInstruments.Name = "labelInstruments";
|
||||
this.labelInstruments.Size = new System.Drawing.Size(83, 15);
|
||||
this.labelInstruments.TabIndex = 1;
|
||||
this.labelInstruments.Text = "Инструменты";
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
this.buttonAdd.Location = new System.Drawing.Point(823, 63);
|
||||
this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonAdd.Name = "buttonAdd";
|
||||
this.buttonAdd.Size = new System.Drawing.Size(161, 44);
|
||||
this.buttonAdd.TabIndex = 2;
|
||||
this.buttonAdd.Text = "Добавить автобус";
|
||||
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||
this.buttonAdd.Click += new System.EventHandler(this.ButtonAddBus_Click);
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(874, 140);
|
||||
this.maskedTextBoxNumber.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(110, 23);
|
||||
this.maskedTextBoxNumber.TabIndex = 3;
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
this.buttonDelete.Location = new System.Drawing.Point(840, 167);
|
||||
this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonDelete.Name = "buttonDelete";
|
||||
this.buttonDelete.Size = new System.Drawing.Size(165, 45);
|
||||
this.buttonDelete.TabIndex = 4;
|
||||
this.buttonDelete.Text = "Удалить автобус";
|
||||
this.buttonDelete.UseVisualStyleBackColor = true;
|
||||
this.buttonDelete.Click += new System.EventHandler(this.ButtonRemoveBus_Click);
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
this.buttonUpdate.Location = new System.Drawing.Point(840, 260);
|
||||
this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonUpdate.Name = "buttonUpdate";
|
||||
this.buttonUpdate.Size = new System.Drawing.Size(165, 45);
|
||||
this.buttonUpdate.TabIndex = 5;
|
||||
this.buttonUpdate.Text = "Обновить";
|
||||
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||
this.buttonUpdate.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
|
||||
//
|
||||
// FormBusCollection
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1152, 975);
|
||||
this.Controls.Add(this.buttonUpdate);
|
||||
this.Controls.Add(this.buttonDelete);
|
||||
this.Controls.Add(this.maskedTextBoxNumber);
|
||||
this.Controls.Add(this.buttonAdd);
|
||||
this.Controls.Add(this.labelInstruments);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.Name = "FormBusCollection";
|
||||
this.Text = "Автобус";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxCollection;
|
||||
private Label labelInstruments;
|
||||
private Button buttonAdd;
|
||||
private TextBox maskedTextBoxNumber;
|
||||
private Button buttonDelete;
|
||||
private Button buttonUpdate;
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
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 DoubleDeckerbus.DrawingObjects;
|
||||
using DoubleDeckerbus;
|
||||
using DoubleDeckerbus.MovementStrategy;
|
||||
|
||||
namespace DoubleDeckerbus
|
||||
{
|
||||
public partial class FormBusCollection : Form
|
||||
{
|
||||
private readonly BusGenericCollection<DrawingBus, DrawingObjectBus> _bus;
|
||||
public FormBusCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_bus = new BusGenericCollection<DrawingBus, DrawingObjectBus>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
|
||||
}
|
||||
private void ButtonAddBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormDoubleDeckerbus form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_bus + form.SelectedBus != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _bus.ShowBus();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonRemoveBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = 0;
|
||||
try
|
||||
{
|
||||
pos = Convert.ToInt32(maskedTextBoxNumber.Text) ;
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Ошибка ввода данных");
|
||||
return;
|
||||
}
|
||||
if (_bus - (_bus.ReturnLength() - pos))
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _bus.ShowBus();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _bus.ShowBus();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<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>
|
@ -1,13 +1,16 @@
|
||||
using DoubleDeckerbus.DrawingObjects;
|
||||
using DoubleDeckerbus.MovementStrategy;
|
||||
using DoubleDeckerbus.Drawing;
|
||||
using DoubleDeckerbus.Entities;
|
||||
using DoubleDeckerbus.Move_Strategy;
|
||||
|
||||
namespace DoubleDeckerbus
|
||||
{
|
||||
|
||||
public partial class FormDoubleDeckerbus : Form
|
||||
{
|
||||
private DrawingBus? _drawingBus;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawingBus? SelectedBus { get; private set; }
|
||||
|
||||
public FormDoubleDeckerbus()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -24,6 +27,7 @@ namespace DoubleDeckerbus
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawingBus.DrawTransport(gr);
|
||||
pictureBoxDoubleDeckerbus.Image = bmp;
|
||||
|
||||
}
|
||||
private void buttonCreateDoubleDeckerbus_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -45,6 +49,7 @@ namespace DoubleDeckerbus
|
||||
_drawingBus.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
|
||||
}
|
||||
private void buttonCreateBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -59,7 +64,7 @@ namespace DoubleDeckerbus
|
||||
_drawingBus = new DrawingBus(random.Next(100, 300),
|
||||
random.Next(1000, 3000), color,
|
||||
pictureBoxDoubleDeckerbus.Width, pictureBoxDoubleDeckerbus.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)
|
||||
|
197
DoubleDeckerBus/FormDoubleDeckerbusCollection.Designer.cs
generated
Normal file
197
DoubleDeckerBus/FormDoubleDeckerbusCollection.Designer.cs
generated
Normal file
@ -0,0 +1,197 @@
|
||||
namespace DoubleDeckerbus
|
||||
{
|
||||
partial class FormDoubleDeckerbusCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
buttonAddBus = new Button();
|
||||
pictureBoxCollection = new PictureBox();
|
||||
labelInstruments = new Label();
|
||||
buttonUpdate = new Button();
|
||||
buttonDeleteBus = new Button();
|
||||
colorDialog = new ColorDialog();
|
||||
maskedTextBoxNumber = new MaskedTextBox();
|
||||
label1 = new Label();
|
||||
listBoxStorages = new ListBox();
|
||||
buttonAddStorage = new Button();
|
||||
buttonDeleteStorage = new Button();
|
||||
textBoxStorageName = new TextBox();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonAddBus
|
||||
//
|
||||
buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonAddBus.Location = new Point(666, 331);
|
||||
buttonAddBus.Name = "buttonAddBus";
|
||||
buttonAddBus.Size = new Size(118, 28);
|
||||
buttonAddBus.TabIndex = 0;
|
||||
buttonAddBus.Text = "Добавить автобус";
|
||||
buttonAddBus.UseVisualStyleBackColor = true;
|
||||
buttonAddBus.Click += buttonAddBus_Click;
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Location = new Point(3, 0);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(639, 436);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// labelInstruments
|
||||
//
|
||||
labelInstruments.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
labelInstruments.AutoSize = true;
|
||||
labelInstruments.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
labelInstruments.Location = new Point(666, 0);
|
||||
labelInstruments.Name = "labelInstruments";
|
||||
labelInstruments.Size = new Size(108, 21);
|
||||
labelInstruments.TabIndex = 2;
|
||||
labelInstruments.Text = "Инструменты";
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
buttonUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonUpdate.Location = new Point(658, 130);
|
||||
buttonUpdate.Name = "buttonUpdate";
|
||||
buttonUpdate.Size = new Size(131, 25);
|
||||
buttonUpdate.TabIndex = 3;
|
||||
buttonUpdate.Text = "Обновить набор";
|
||||
buttonUpdate.UseVisualStyleBackColor = true;
|
||||
buttonUpdate.Click += buttonUpdate_Click;
|
||||
//
|
||||
// buttonDeleteBus
|
||||
//
|
||||
buttonDeleteBus.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonDeleteBus.Location = new Point(666, 394);
|
||||
buttonDeleteBus.Name = "buttonDeleteBus";
|
||||
buttonDeleteBus.Size = new Size(118, 28);
|
||||
buttonDeleteBus.TabIndex = 4;
|
||||
buttonDeleteBus.Text = "Удалить автобус";
|
||||
buttonDeleteBus.UseVisualStyleBackColor = true;
|
||||
buttonDeleteBus.Click += buttonDeleteBus_Click;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
maskedTextBoxNumber.Location = new Point(658, 365);
|
||||
maskedTextBoxNumber.Mask = "00";
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(138, 23);
|
||||
maskedTextBoxNumber.TabIndex = 5;
|
||||
maskedTextBoxNumber.ValidatingType = typeof(int);
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(658, 38);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(52, 15);
|
||||
label1.TabIndex = 7;
|
||||
label1.Text = "Наборы";
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
listBoxStorages.FormattingEnabled = true;
|
||||
listBoxStorages.ItemHeight = 15;
|
||||
listBoxStorages.Location = new Point(657, 159);
|
||||
listBoxStorages.Margin = new Padding(3, 2, 3, 2);
|
||||
listBoxStorages.Name = "listBoxStorages";
|
||||
listBoxStorages.Size = new Size(132, 109);
|
||||
listBoxStorages.TabIndex = 8;
|
||||
listBoxStorages.SelectedIndexChanged += listBoxObjects_SelectedIndexChanged;
|
||||
//
|
||||
// buttonAddStorage
|
||||
//
|
||||
buttonAddStorage.Location = new Point(657, 101);
|
||||
buttonAddStorage.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonAddStorage.Name = "buttonAddStorage";
|
||||
buttonAddStorage.Size = new Size(131, 25);
|
||||
buttonAddStorage.TabIndex = 9;
|
||||
buttonAddStorage.Text = "Добавить набор";
|
||||
buttonAddStorage.UseVisualStyleBackColor = true;
|
||||
buttonAddStorage.Click += buttonAddStorage_Click;
|
||||
//
|
||||
// buttonDeleteStorage
|
||||
//
|
||||
buttonDeleteStorage.Location = new Point(657, 272);
|
||||
buttonDeleteStorage.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonDeleteStorage.Name = "buttonDeleteStorage";
|
||||
buttonDeleteStorage.Size = new Size(131, 25);
|
||||
buttonDeleteStorage.TabIndex = 10;
|
||||
buttonDeleteStorage.Text = "Удалить набор";
|
||||
buttonDeleteStorage.UseVisualStyleBackColor = true;
|
||||
buttonDeleteStorage.Click += buttonDeleteStorage_Click;
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
textBoxStorageName.Location = new Point(657, 76);
|
||||
textBoxStorageName.Margin = new Padding(3, 2, 3, 2);
|
||||
textBoxStorageName.Name = "textBoxStorageName";
|
||||
textBoxStorageName.Size = new Size(132, 23);
|
||||
textBoxStorageName.TabIndex = 11;
|
||||
//
|
||||
// FormDoubleDeckerbusCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(810, 443);
|
||||
Controls.Add(textBoxStorageName);
|
||||
Controls.Add(buttonDeleteStorage);
|
||||
Controls.Add(buttonAddStorage);
|
||||
Controls.Add(listBoxStorages);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(buttonAddBus);
|
||||
Controls.Add(maskedTextBoxNumber);
|
||||
Controls.Add(buttonDeleteBus);
|
||||
Controls.Add(buttonUpdate);
|
||||
Controls.Add(labelInstruments);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Name = "FormDoubleDeckerbusCollection";
|
||||
Text = "Набор автобусов";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonAddBus;
|
||||
private PictureBox pictureBoxCollection;
|
||||
private Label labelInstruments;
|
||||
private Button buttonUpdate;
|
||||
private Button buttonDeleteBus;
|
||||
private ColorDialog colorDialog;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private Label label1;
|
||||
private ListBox listBoxStorages;
|
||||
private Button buttonAddStorage;
|
||||
private Button buttonDeleteStorage;
|
||||
private TextBox textBoxStorageName;
|
||||
}
|
||||
}
|
143
DoubleDeckerBus/FormDoubleDeckerbusCollection.cs
Normal file
143
DoubleDeckerBus/FormDoubleDeckerbusCollection.cs
Normal file
@ -0,0 +1,143 @@
|
||||
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 DoubleDeckerbus.Generic;
|
||||
using DoubleDeckerbus.Drawing;
|
||||
using DoubleDeckerbus.Move_Strategy;
|
||||
|
||||
namespace DoubleDeckerbus
|
||||
{
|
||||
public partial class FormDoubleDeckerbusCollection : Form
|
||||
{
|
||||
private readonly BusesGenericStorage _storage;
|
||||
public FormDoubleDeckerbusCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new BusesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxStorages.SelectedIndex;
|
||||
listBoxStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
|
||||
{
|
||||
listBoxStorages.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
|
||||
{
|
||||
listBoxStorages.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
private void buttonAddStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
}
|
||||
private void listBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowBus();
|
||||
}
|
||||
private void buttonDeleteStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
|
||||
ReloadObjects();
|
||||
}
|
||||
}
|
||||
private void buttonAddBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
MessageBox.Show("Не выбран набор");
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormDoubleDeckerbus form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (obj + form.SelectedBus != -1) //-1
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowBus();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void buttonDeleteBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = 0;
|
||||
try
|
||||
{
|
||||
pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (obj - pos) //!!
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = obj.ShowBus();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowBus();
|
||||
}
|
||||
}
|
||||
}
|
126
DoubleDeckerBus/FormDoubleDeckerbusCollection.resx
Normal file
126
DoubleDeckerBus/FormDoubleDeckerbusCollection.resx
Normal file
@ -0,0 +1,126 @@
|
||||
<?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>
|
||||
<metadata name="colorDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>36</value>
|
||||
</metadata>
|
||||
</root>
|
@ -3,10 +3,10 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DoubleDeckerbus.DrawingObjects;
|
||||
using DoubleDeckerbus.MovementStrategy;
|
||||
using DoubleDeckerbus.Drawing;
|
||||
using DoubleDeckerbus.Move_Strategy;
|
||||
|
||||
namespace DoubleDeckerbus
|
||||
namespace DoubleDeckerbus.Generic
|
||||
{
|
||||
internal class BusGenericCollection<T, U>
|
||||
where T : DrawingBus
|
||||
@ -17,7 +17,6 @@ namespace DoubleDeckerbus
|
||||
private readonly int _placeSizeWidth = 200;
|
||||
private readonly int _placeSizeHeight = 120;
|
||||
private readonly SetGeneric<T> _collection;
|
||||
|
||||
public BusGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
@ -37,20 +36,19 @@ namespace DoubleDeckerbus
|
||||
}
|
||||
public static bool operator -(BusGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
if (collect._collection.Get(pos) == null)
|
||||
if (collect._collection.GetBus(pos) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect?._collection.Remove(pos) ?? false;
|
||||
}
|
||||
|
||||
public int ReturnLength()
|
||||
{
|
||||
return _collection.Count;
|
||||
}
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
public int ReturnLength()
|
||||
{
|
||||
return _collection.Count;
|
||||
}
|
||||
public Bitmap ShowBus()
|
||||
{
|
||||
@ -74,30 +72,20 @@ namespace DoubleDeckerbus
|
||||
}
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int x = 0;
|
||||
int x = _pictureWidth / _placeSizeWidth - 1;
|
||||
int y = 0;
|
||||
int index = -1;
|
||||
for (int i = 0; i <= _collection.Count; ++i)
|
||||
foreach (var bus in _collection.GetBus())
|
||||
{
|
||||
DrawingBus _bus = _collection.Get(i);
|
||||
x = 0;
|
||||
y = 0;
|
||||
if (_bus != null)
|
||||
if (bus != null)
|
||||
{
|
||||
index = _collection.Count - i;
|
||||
while ((index - _pictureWidth / _placeSizeWidth) >= 0)
|
||||
{
|
||||
y++;
|
||||
index -= _pictureWidth / _placeSizeWidth;
|
||||
}
|
||||
if (index > 0)
|
||||
if (x < 0)
|
||||
{
|
||||
x += index;
|
||||
x = _pictureWidth / _placeSizeWidth - 1;
|
||||
++y;
|
||||
}
|
||||
x = _pictureWidth / _placeSizeWidth - 1 - x;
|
||||
_bus.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y);
|
||||
|
||||
_bus.DrawTransport(g);
|
||||
bus.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y);
|
||||
bus.DrawTransport(g);
|
||||
--x;
|
||||
}
|
||||
}
|
||||
}
|
56
DoubleDeckerBus/Generic/BusesGenericStorage.cs
Normal file
56
DoubleDeckerBus/Generic/BusesGenericStorage.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DoubleDeckerbus.Drawing;
|
||||
using DoubleDeckerbus.Move_Strategy;
|
||||
|
||||
namespace DoubleDeckerbus.Generic
|
||||
{
|
||||
internal class BusesGenericStorage
|
||||
{
|
||||
readonly Dictionary<string, BusGenericCollection<DrawingBus, DrawingObjectBus>> _busStorages;
|
||||
public List<string> Keys => _busStorages.Keys.ToList();
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
public BusesGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_busStorages = new Dictionary<string, BusGenericCollection<DrawingBus, DrawingObjectBus>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
public void AddSet(string name)
|
||||
{
|
||||
foreach (string nameStorage in Keys)
|
||||
{
|
||||
if (nameStorage == name)
|
||||
{
|
||||
MessageBox.Show("Набор с заданным именем уже есть", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
_busStorages.Add(name, new BusGenericCollection<DrawingBus, DrawingObjectBus>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (_busStorages.ContainsKey(name))
|
||||
{
|
||||
_busStorages.Remove(name);
|
||||
}
|
||||
|
||||
}
|
||||
public BusGenericCollection<DrawingBus, DrawingObjectBus>? this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_busStorages.ContainsKey(ind))
|
||||
{
|
||||
return _busStorages[ind];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
74
DoubleDeckerBus/Generic/SetGeneric.cs
Normal file
74
DoubleDeckerBus/Generic/SetGeneric.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DoubleDeckerbus.Generic
|
||||
{
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
private readonly List<T?> _places;
|
||||
public int Count => _places.Count;
|
||||
private readonly int _maxCount;
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
public int Insert(T bus)
|
||||
{
|
||||
_places.Insert(0, bus); //0
|
||||
return 0;
|
||||
}
|
||||
public bool Insert(T bus, int position)
|
||||
{
|
||||
if (position < 0 || position >= Count || Count >= _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_places.Insert(position, bus);
|
||||
return true;
|
||||
}
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
public T? this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position < 0 || position > Count || Count >= _maxCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.Insert(position, value);
|
||||
}
|
||||
}
|
||||
public IEnumerable<T?> GetBus(int? maxBus = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxBus.HasValue && i == maxBus.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,12 @@
|
||||
using DoubleDeckerbus.MovementStrategy;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DoubleDeckerbus.Entities;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
using DoubleDeckerbus.DrawingObjects;
|
||||
|
||||
namespace DoubleDeckerbus.MovementStrategy
|
||||
namespace DoubleDeckerbus.Move_Strategy
|
||||
{
|
||||
public abstract class AbstractStrategy
|
||||
{
|
@ -1,14 +1,14 @@
|
||||
using DoubleDeckerbus.MovementStrategy;
|
||||
using DoubleDeckerbus;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using DoubleDeckerbus.DrawingObjects;
|
||||
namespace DoubleDeckerbus.MovementStrategy
|
||||
using DoubleDeckerbus.Entities;
|
||||
using DoubleDeckerbus.Drawing;
|
||||
|
||||
namespace DoubleDeckerbus.Move_Strategy
|
||||
{
|
||||
public class DrawingObjectBus : IMoveableObject
|
||||
{
|
||||
@ -25,7 +25,7 @@ namespace DoubleDeckerbus.MovementStrategy
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawingBus.GetPosX,_drawingBus.GetPosY, _drawingBus.GetWidth, _drawingBus.GetHeight);
|
||||
return new ObjectParameters(_drawingBus.GetPosX, _drawingBus.GetPosY, _drawingBus.GetWidth, _drawingBus.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawingBus?.EntityBus?.Step ?? 0);
|
@ -4,9 +4,10 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using DoubleDeckerbus.DrawingObjects;
|
||||
using DoubleDeckerbus.Drawing;
|
||||
using DoubleDeckerbus.Entities;
|
||||
|
||||
namespace DoubleDeckerbus.MovementStrategy
|
||||
namespace DoubleDeckerbus.Move_Strategy
|
||||
{
|
||||
public interface IMoveableObject
|
||||
{
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DoubleDeckerbus.MovementStrategy
|
||||
namespace DoubleDeckerbus.Move_Strategy
|
||||
{
|
||||
internal class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
@ -18,7 +18,7 @@ namespace DoubleDeckerbus.MovementStrategy
|
||||
return objParams.RightBorder <= FieldWidth &&
|
||||
objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder <= FieldHeight &&
|
||||
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
@ -38,7 +38,6 @@ namespace DoubleDeckerbus.MovementStrategy
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
|
||||
}
|
||||
var diffY = objParams.ObjectMiddleVertical - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DoubleDeckerbus.MovementStrategy
|
||||
namespace DoubleDeckerbus.Move_Strategy
|
||||
{
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DoubleDeckerbus.MovementStrategy
|
||||
namespace DoubleDeckerbus.Move_Strategy
|
||||
{
|
||||
public class ObjectParameters
|
||||
{
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DoubleDeckerbus.MovementStrategy
|
||||
namespace DoubleDeckerbus.Move_Strategy
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
@ -12,4 +12,4 @@ namespace DoubleDeckerbus.MovementStrategy
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace DoubleDeckerbus
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormBusCollection());
|
||||
Application.Run(new FormDoubleDeckerbusCollection());
|
||||
}
|
||||
}
|
||||
}
|
18
DoubleDeckerBus/Properties/Resources.Designer.cs
generated
18
DoubleDeckerBus/Properties/Resources.Designer.cs
generated
@ -8,7 +8,7 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace DoubleDeckerBus.Properties {
|
||||
namespace DoubleDeckerbus.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ namespace DoubleDeckerBus.Properties {
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DoubleDeckerBus.Properties.Resources", typeof(Resources).Assembly);
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DoubleDeckerbus.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
@ -63,9 +63,9 @@ namespace DoubleDeckerBus.Properties {
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap ArrowDown {
|
||||
internal static System.Drawing.Bitmap стрелка_вверх {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("ArrowDown", resourceCulture);
|
||||
object obj = ResourceManager.GetObject("ArrowUp", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
@ -73,7 +73,7 @@ namespace DoubleDeckerBus.Properties {
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap ArrowLeft {
|
||||
internal static System.Drawing.Bitmap стрелка_влево {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("ArrowLeft", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
@ -83,9 +83,9 @@ namespace DoubleDeckerBus.Properties {
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap ArrowRight {
|
||||
internal static System.Drawing.Bitmap стрелка_вниз {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("ArrowRight", resourceCulture);
|
||||
object obj = ResourceManager.GetObject("ArrowDown", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
@ -93,9 +93,9 @@ namespace DoubleDeckerBus.Properties {
|
||||
/// <summary>
|
||||
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap ArrowUp {
|
||||
internal static System.Drawing.Bitmap стрелка_вправо {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("ArrowUp", resourceCulture);
|
||||
object obj = ResourceManager.GetObject("ArrowRight", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
@ -118,16 +118,16 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="ArrowLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\ArrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="ArrowRight" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\ArrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="ArrowUp" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\ArrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="ArrowLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\ArrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="ArrowDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\ArrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="ArrowRight" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\ArrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
@ -1,85 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DoubleDeckerbus
|
||||
{
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
|
||||
{
|
||||
private readonly T?[] _places;
|
||||
public int Count => _places.Length - 1;
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
}
|
||||
public int Insert(T bus)
|
||||
{
|
||||
int pos = Count - 1;
|
||||
if (_places[Count] != null)
|
||||
{
|
||||
for (int i = pos; i > 0; --i)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
pos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = pos + 1; i <= Count; ++i)
|
||||
{
|
||||
_places[i - 1] = _places[i];
|
||||
}
|
||||
}
|
||||
_places[Count] = bus;
|
||||
return pos;
|
||||
}
|
||||
public bool Insert(T bus, int position)
|
||||
{
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_places[Count] != null)
|
||||
{
|
||||
int pos = Count;
|
||||
for (int i = Count; i > 0; --i)
|
||||
{
|
||||
|
||||
if (_places[i] == null)
|
||||
{
|
||||
pos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = Count; i >= pos; --i)
|
||||
{
|
||||
_places[i - 1] = _places[i];
|
||||
}
|
||||
}
|
||||
_places[Count] = bus;
|
||||
return true;
|
||||
}
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
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