ПИбд-21 Кувшинов Тимур 3Лаба простая #6
@ -10,6 +10,7 @@ namespace Laba1Loco
|
||||
{
|
||||
internal class DrawingTrain
|
||||
{
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectTrain(this);
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
@ -64,6 +65,7 @@ namespace Laba1Loco
|
||||
{
|
||||
_startPosX = Math.Min(x, _pictureWidth - _locoWidth);
|
||||
_startPosY = Math.Min(y, _pictureHeight - _locoHeight);
|
||||
clouds = new List<cloud>();
|
||||
}
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
|
17
Laba1Loco/Laba1Loco/FormLocomotive.Designer.cs
generated
17
Laba1Loco/Laba1Loco/FormLocomotive.Designer.cs
generated
@ -39,6 +39,8 @@
|
||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
this.strategysstep = new System.Windows.Forms.Button();
|
||||
this.createLocomotive = new System.Windows.Forms.Button();
|
||||
this.SelectTrain = new System.Windows.Forms.Button();
|
||||
this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -143,11 +145,22 @@
|
||||
this.createLocomotive.UseVisualStyleBackColor = true;
|
||||
this.createLocomotive.Click += new System.EventHandler(this.createLocomotive_Click);
|
||||
//
|
||||
// SelectTrain
|
||||
//
|
||||
this.SelectTrain.Location = new System.Drawing.Point(346, 415);
|
||||
this.SelectTrain.Name = "SelectTrain";
|
||||
this.SelectTrain.Size = new System.Drawing.Size(75, 23);
|
||||
this.SelectTrain.TabIndex = 11;
|
||||
this.SelectTrain.Text = "Select Train";
|
||||
this.SelectTrain.UseVisualStyleBackColor = true;
|
||||
this.SelectTrain.Click += new System.EventHandler(this.ButtonSelectTrain_Click);
|
||||
//
|
||||
// FormLocomotive
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.SelectTrain);
|
||||
this.Controls.Add(this.createLocomotive);
|
||||
this.Controls.Add(this.strategysstep);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
@ -172,10 +185,12 @@
|
||||
private System.Windows.Forms.Button up;
|
||||
private System.Windows.Forms.Button down;
|
||||
private System.Windows.Forms.Button right;
|
||||
private System.Windows.Forms.Timer timer1;
|
||||
public System.Windows.Forms.Timer timer1;
|
||||
private System.Windows.Forms.ComboBox comboBoxStrategy;
|
||||
private System.Windows.Forms.Button strategysstep;
|
||||
private System.Windows.Forms.Button createLocomotive;
|
||||
private System.Windows.Forms.Button SelectTrain;
|
||||
private System.ComponentModel.BackgroundWorker backgroundWorker1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,8 @@ namespace Laba1Loco
|
||||
{
|
||||
public partial class FormLocomotive : Form
|
||||
{
|
||||
AbstractStrategy abstractStrategy;
|
||||
internal DrawingTrain SelectedTrain { get; private set; }
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
@ -23,6 +25,8 @@ namespace Laba1Loco
|
||||
public FormLocomotive()
|
||||
{
|
||||
InitializeComponent();
|
||||
abstractStrategy = null;
|
||||
SelectedTrain = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -50,9 +54,16 @@ namespace Laba1Loco
|
||||
private void create_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
Color color = Color.FromArgb(random.Next(0, 256),
|
||||
random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new ColorDialog();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_drawingTrain = new DrawingTrain(
|
||||
random.Next(100, 300), random.Next(2000, 4000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
color,
|
||||
pictureBox.Width, pictureBox.Height
|
||||
);
|
||||
_drawingTrain.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
@ -108,10 +119,24 @@ namespace Laba1Loco
|
||||
private void createLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
Color color1 = Color.FromArgb(random.Next(0, 256),
|
||||
random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog1 = new ColorDialog();
|
||||
if (dialog1.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color1 = dialog1.Color;
|
||||
}
|
||||
Color color2 = Color.FromArgb(random.Next(0, 256),
|
||||
random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog2 = new ColorDialog();
|
||||
if (dialog2.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color2 = dialog2.Color;
|
||||
}
|
||||
_drawingTrain = new DrawingLoco(
|
||||
random.Next(100, 300), random.Next(2000, 4000),
|
||||
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)),
|
||||
color1,
|
||||
color2,
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBox.Width, pictureBox.Height
|
||||
);
|
||||
@ -119,7 +144,6 @@ namespace Laba1Loco
|
||||
Draw();
|
||||
|
||||
}
|
||||
AbstractStrategy abstractStrategy;
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Шаг"
|
||||
/// </summary>
|
||||
@ -168,5 +192,17 @@ namespace Laba1Loco
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Выбор автомобиля
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSelectTrain_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedTrain = _drawingTrain;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -120,4 +120,7 @@
|
||||
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>104, 17</value>
|
||||
</metadata>
|
||||
</root>
|
124
Laba1Loco/Laba1Loco/FormTrainCollection.Designer.cs
generated
Normal file
124
Laba1Loco/Laba1Loco/FormTrainCollection.Designer.cs
generated
Normal file
@ -0,0 +1,124 @@
|
||||
namespace Laba1Loco
|
||||
{
|
||||
partial class FormTrainCollection
|
||||
{
|
||||
/// <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.panel1 = new System.Windows.Forms.Panel();
|
||||
this.maskedTextBoxNumber = new System.Windows.Forms.TextBox();
|
||||
this.ButtonAddTrain = new System.Windows.Forms.Button();
|
||||
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
|
||||
this.ButtonRemoveTrain = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.panel1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(633, 473);
|
||||
this.pictureBoxCollection.TabIndex = 0;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.Controls.Add(this.maskedTextBoxNumber);
|
||||
this.panel1.Controls.Add(this.ButtonAddTrain);
|
||||
this.panel1.Controls.Add(this.ButtonRefreshCollection);
|
||||
this.panel1.Controls.Add(this.ButtonRemoveTrain);
|
||||
this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.panel1.Location = new System.Drawing.Point(639, 0);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(166, 473);
|
||||
this.panel1.TabIndex = 1;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(59, 170);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(100, 20);
|
||||
this.maskedTextBoxNumber.TabIndex = 4;
|
||||
//
|
||||
// ButtonAddTrain
|
||||
//
|
||||
this.ButtonAddTrain.Location = new System.Drawing.Point(71, 31);
|
||||
this.ButtonAddTrain.Name = "ButtonAddTrain";
|
||||
this.ButtonAddTrain.Size = new System.Drawing.Size(75, 23);
|
||||
this.ButtonAddTrain.TabIndex = 3;
|
||||
this.ButtonAddTrain.Text = "Add Train";
|
||||
this.ButtonAddTrain.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddTrain.Click += new System.EventHandler(this.ButtonAddTrain_Click);
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(71, 320);
|
||||
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(75, 23);
|
||||
this.ButtonRefreshCollection.TabIndex = 2;
|
||||
this.ButtonRefreshCollection.Text = "Refresh Collection";
|
||||
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
|
||||
//
|
||||
// ButtonRemoveTrain
|
||||
//
|
||||
this.ButtonRemoveTrain.Location = new System.Drawing.Point(71, 196);
|
||||
this.ButtonRemoveTrain.Name = "ButtonRemoveTrain";
|
||||
this.ButtonRemoveTrain.Size = new System.Drawing.Size(75, 23);
|
||||
this.ButtonRemoveTrain.TabIndex = 0;
|
||||
this.ButtonRemoveTrain.Text = "Remove Train";
|
||||
this.ButtonRemoveTrain.UseVisualStyleBackColor = true;
|
||||
this.ButtonRemoveTrain.Click += new System.EventHandler(this.ButtonRemoveTrain_Click);
|
||||
//
|
||||
// FormTrainCollection
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(805, 473);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.Name = "FormTrainCollection";
|
||||
this.Text = "FormTrainCollection";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.panel1.ResumeLayout(false);
|
||||
this.panel1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.PictureBox pictureBoxCollection;
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
private System.Windows.Forms.Button ButtonRefreshCollection;
|
||||
private System.Windows.Forms.Button ButtonRemoveTrain;
|
||||
private System.Windows.Forms.Button ButtonAddTrain;
|
||||
private System.Windows.Forms.TextBox maskedTextBoxNumber;
|
||||
}
|
||||
}
|
88
Laba1Loco/Laba1Loco/FormTrainCollection.cs
Normal file
88
Laba1Loco/Laba1Loco/FormTrainCollection.cs
Normal file
@ -0,0 +1,88 @@
|
||||
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 Laba1Loco
|
||||
{
|
||||
public partial class FormTrainCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly TrainsGenericCollection<DrawingTrain, DrawningObjectTrain> _trains;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormTrainCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_trains = new TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddTrain_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormLocomotive form = new FormLocomotive();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if ((_trains + form.SelectedTrain) != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _trains.ShowTrains();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
form.timer1.Stop();
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveTrain_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (var it in maskedTextBoxNumber.Text)
|
||||
if (it < '0' || it > '9')
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (_trains - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _trains.ShowTrains();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обновление рисунка по набору
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _trains.ShowTrains();
|
||||
}
|
||||
}
|
||||
}
|
120
Laba1Loco/Laba1Loco/FormTrainCollection.resx
Normal file
120
Laba1Loco/Laba1Loco/FormTrainCollection.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>
|
@ -47,6 +47,13 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AbstractStrategy.cs" />
|
||||
<Compile Include="FormTrainCollection.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FormTrainCollection.Designer.cs">
|
||||
<DependentUpon>FormTrainCollection.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="TrainsGenericCollection.cs" />
|
||||
<Compile Include="Direction.cs" />
|
||||
<Compile Include="DrawingLoco.cs" />
|
||||
<Compile Include="DrawingTrain.cs" />
|
||||
@ -65,10 +72,14 @@
|
||||
<Compile Include="ObjectParameters.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SetGeneric.cs" />
|
||||
<Compile Include="Status.cs" />
|
||||
<EmbeddedResource Include="FormLocomotive.resx">
|
||||
<DependentUpon>FormLocomotive.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="FormTrainCollection.resx">
|
||||
<DependentUpon>FormTrainCollection.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
|
@ -16,7 +16,7 @@ namespace Laba1Loco
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new FormLocomotive());
|
||||
Application.Run(new FormTrainCollection());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
103
Laba1Loco/Laba1Loco/SetGeneric.cs
Normal file
103
Laba1Loco/Laba1Loco/SetGeneric.cs
Normal file
@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T[] _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="train">Добавляемый поезд</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T train)
|
||||
{
|
||||
int i = 0;
|
||||
TImourka marked this conversation as resolved
|
||||
for (;i < _places.Length; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
break;
|
||||
}
|
||||
if (i == _places.Length)
|
||||
return -1;
|
||||
for (; i > 0; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[i] = train;
|
||||
return i;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="train">Добавляемый поезд</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T train, int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.Length)
|
||||
return false;
|
||||
for (; position < _places.Length; position++)
|
||||
{
|
||||
if (_places[position] == null)
|
||||
break;
|
||||
}
|
||||
if (position == _places.Length)
|
||||
return false;
|
||||
for (; position > 0; position--)
|
||||
{
|
||||
_places[position] = _places[position - 1];
|
||||
}
|
||||
_places[position] = train;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.Length)
|
||||
return false;
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.Length)
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
135
Laba1Loco/Laba1Loco/TrainsGenericCollection.cs
Normal file
135
Laba1Loco/Laba1Loco/TrainsGenericCollection.cs
Normal file
@ -0,0 +1,135 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal class TrainsGenericCollection<T, U>
|
||||
where T : DrawingTrain
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 210;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetGeneric<T> _collection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
public TrainsGenericCollection(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 +(TrainsGenericCollection<T, U> collect, T obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return collect?._collection.Insert(obj) ?? -1;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static T operator -(TrainsGenericCollection<T, U> collect, int pos)
|
||||
eegov
commented
Требовалось поменять тип возвращаемого значения Требовалось поменять тип возвращаемого значения
|
||||
{
|
||||
T obj = collect._collection.Get(pos);
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
/// <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 ShowTrains()
|
||||
{
|
||||
Bitmap bmp = new Bitmap(_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 Pen(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++)
|
||||
{
|
||||
T t = _collection.Get(i);
|
||||
if (t != null)
|
||||
{
|
||||
t.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
|
||||
if (t is DrawingLoco)
|
||||
(t as DrawingLoco).DrawTransport(g);
|
||||
else
|
||||
t.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user
Правильнее было вызвать Insert(T obj, 0);