готовая лаба 3

This commit is contained in:
spacyboy 2023-12-11 12:01:01 +04:00
parent 5ed8caf82c
commit 68d1b76596
18 changed files with 546 additions and 34 deletions

View File

@ -30,4 +30,4 @@ namespace RoadTrain.MovementStrategy
public bool CheckCanMove(DirectionType direction) => _drawingRoadTrain?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) => _drawingRoadTrain?.MoveTransport(direction);
}
}
}

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RoadTrain.Entities;
using RoadTrain.MovementStrategy;
namespace RoadTrain.DrawingObjects
{
@ -21,6 +21,7 @@ namespace RoadTrain.DrawingObjects
public int GetPosY => _startPosY;
public int GetWidth => _roadTrainWidth;
public int GetHeight => _roadTrainHeight;
public IMoveableObject GetMoveableObject => new DrawingObjectTrain(this);
public DrawingRoadTrain(int speed, double weight, Color bodyColor, int width, int height)
{
if (width < _roadTrainWidth || height < _roadTrainHeight)
@ -30,11 +31,10 @@ namespace RoadTrain.DrawingObjects
_pictureWidth = width;
_pictureHeight = height;
EntityRoadTrain = new EntityRoadTrain(speed, weight, bodyColor);
}
protected DrawingRoadTrain(int speed, double weight, Color bodyColor, int width, int height, int roadTrainWidth, int roadTrainHeight)
{
if (width < _roadTrainWidth || height < _roadTrainHeight)
if (width <= _roadTrainWidth || height <= _roadTrainHeight)
{
return;
}
@ -46,13 +46,10 @@ namespace RoadTrain.DrawingObjects
}
public void SetPosition(int x, int y)
{
_startPosX = x;
_startPosY = y;
if (_startPosX < 0 || _startPosY < 0 || _startPosX > (_pictureWidth - _roadTrainWidth) || _startPosY > (_pictureHeight - _roadTrainHeight))
if (x >= 0 && x + _roadTrainWidth <= _pictureWidth && y >= 0 && y + _roadTrainHeight <= _pictureHeight)
{
_startPosX = 50;
_startPosY = 50;
_startPosX = x;
_startPosY = y;
}
}
public void MoveTransport(DirectionType direction)
@ -87,8 +84,8 @@ namespace RoadTrain.DrawingObjects
{
DirectionType.Left => _startPosX - EntityRoadTrain.Step > 0,
DirectionType.Up => _startPosY - EntityRoadTrain.Step > 0,
DirectionType.Right => _startPosX + _roadTrainWidth + EntityRoadTrain.Step < _pictureWidth,
DirectionType.Down => _startPosY + _roadTrainHeight + EntityRoadTrain.Step < _pictureHeight,
DirectionType.Right => _startPosX + EntityRoadTrain.Step + _roadTrainWidth < _pictureWidth,
DirectionType.Down => _startPosY + EntityRoadTrain.Step + _roadTrainHeight < _pictureHeight,
_ => false,
};
}

View File

@ -28,8 +28,6 @@ namespace RoadTrain.DrawingObjects
Pen pen = new(Color.Black, 2);
Brush additionalBrush = new SolidBrush(roadTrain.AdditionalColor);
base.DrawTransport(g);
//щетка
Brush brGray = new SolidBrush(Color.Gray);
if (roadTrain.Brush)
@ -46,4 +44,4 @@ namespace RoadTrain.DrawingObjects
}
}
}
}
}

View File

@ -19,4 +19,4 @@ namespace RoadTrain.Entities
BodyColor = bodyColor;
}
}
}
}

View File

@ -20,4 +20,4 @@ namespace RoadTrain.Entities
Brush = brush;
}
}
}
}

View File

@ -15,4 +15,4 @@ namespace RoadTrain.MovementStrategy
bool CheckCanMove(DirectionType direction);
void MoveObject(DirectionType direction);
}
}
}

View File

@ -53,4 +53,4 @@ namespace RoadTrain.MovementStrategy
}
}
}
}
}

View File

@ -53,4 +53,4 @@ namespace RoadTrain.MovementStrategy
}
}
}
}
}

View File

@ -26,4 +26,4 @@ namespace RoadTrain.MovementStrategy
_height = height;
}
}
}
}

View File

@ -6,7 +6,7 @@ namespace RoadTrain
static void Main()
{
ApplicationConfiguration.Initialize();
Application.Run(new RoadTrain());
Application.Run(new TrainCollection());
}
}
}

View File

@ -37,6 +37,7 @@
comboBoxStrategy = new ComboBox();
button1 = new Button();
buttonCreateRoadTrain = new Button();
buttonSelectTrain = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxRoadTrain).BeginInit();
SuspendLayout();
//
@ -109,9 +110,9 @@
//
// buttonStep
//
buttonStep.Location = new Point(650, 41);
buttonStep.Location = new Point(624, 41);
buttonStep.Name = "buttonStep";
buttonStep.Size = new Size(94, 29);
buttonStep.Size = new Size(151, 29);
buttonStep.TabIndex = 16;
buttonStep.Text = "Шаг";
buttonStep.UseVisualStyleBackColor = true;
@ -149,11 +150,22 @@
buttonCreateRoadTrain.UseVisualStyleBackColor = true;
buttonCreateRoadTrain.Click += buttonCreateRoadTrain_Click;
//
// buttonSelectTrain
//
buttonSelectTrain.Location = new Point(624, 76);
buttonSelectTrain.Name = "buttonSelectTrain";
buttonSelectTrain.Size = new Size(151, 29);
buttonSelectTrain.TabIndex = 17;
buttonSelectTrain.Text = "Выбрать машину";
buttonSelectTrain.UseVisualStyleBackColor = true;
buttonSelectTrain.Click += ButtonSelectTrain_Click;
//
// RoadTrain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(buttonSelectTrain);
Controls.Add(buttonStep);
Controls.Add(comboBoxStrategy);
Controls.Add(button1);
@ -181,5 +193,6 @@
private ComboBox comboBoxStrategy;
private Button button1;
private Button buttonCreateRoadTrain;
private Button buttonSelectTrain;
}
}

View File

@ -9,10 +9,12 @@ namespace RoadTrain
{
private DrawingRoadTrain? _drawingRoadTrain;
private AbstractStrategy? _abstractStrategy;
public DrawingRoadTrain? SelectedTrain { get; private set; }
public RoadTrain()
{
InitializeComponent();
_abstractStrategy = null;
SelectedTrain = null;
}
private void Draw()
{
@ -29,10 +31,15 @@ namespace RoadTrain
private void buttonCreate_Click(object sender, EventArgs e)
{
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;
}
_drawingRoadTrain = new DrawingRoadTrain(random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
random.Next(0, 256)),
color,
pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height);
_drawingRoadTrain.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
@ -40,12 +47,24 @@ namespace RoadTrain
private void buttonCreateRoadTrain_Click(object sender, EventArgs e)
{
Random random = new();
Color color = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
ColorDialog dialogColor = new();
if (dialogColor.ShowDialog() == DialogResult.OK)
{
color = dialogColor.Color;
}
Color addColor = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
ColorDialog dialogDopColor = new();
if (dialogDopColor.ShowDialog() == DialogResult.OK)
{
addColor = dialogDopColor.Color;
}
_drawingRoadTrain = new DrawingRoadTrainWithTank(random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
random.Next(0, 256)),
color, addColor,
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height);
@ -96,8 +115,7 @@ namespace RoadTrain
{
return;
}
_abstractStrategy.SetData(new
DrawingObjectTrain(_drawingRoadTrain), pictureBoxRoadTrain.Width,
_abstractStrategy.SetData(_drawingRoadTrain.GetMoveableObject, pictureBoxRoadTrain.Width,
pictureBoxRoadTrain.Height);
comboBoxStrategy.Enabled = false;
}
@ -113,5 +131,10 @@ namespace RoadTrain
_abstractStrategy = null;
}
}
private void ButtonSelectTrain_Click(object sender, EventArgs e)
{
SelectedTrain = _drawingRoadTrain;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RoadTrain.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 roadtrain)
{
return Insert(roadtrain, 0);
}
public int Insert(T roadtrain, int position)
{
int nullIndex = -1;
int i;
if (position < 0 || position >= Count)
return -1;
for (i = position; i < Count; i++)
{
if (_places[i] == null)
{
nullIndex = i;
break;
}
}
if (nullIndex < 0)
return -1;
for (i = nullIndex; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = roadtrain;
return position;
}
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];
}
}
}

View File

@ -12,4 +12,4 @@ namespace RoadTrain.MovementStrategy
InProgress,
Finish
}
}
}

View File

@ -0,0 +1,139 @@
namespace RoadTrain
{
partial class TrainCollection
{
/// <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()
{
panelCollection = new Panel();
maskedTextBoxNumber = new MaskedTextBox();
labelCollection = new Label();
buttonRefreshCollection = new Button();
buttonRemoveTrain = new Button();
buttonAddTrain = new Button();
pictureBoxCollection = new PictureBox();
panelCollection.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
SuspendLayout();
//
// panelCollection
//
panelCollection.Controls.Add(maskedTextBoxNumber);
panelCollection.Controls.Add(labelCollection);
panelCollection.Controls.Add(buttonRefreshCollection);
panelCollection.Controls.Add(buttonRemoveTrain);
panelCollection.Controls.Add(buttonAddTrain);
panelCollection.Location = new Point(611, -1);
panelCollection.Margin = new Padding(3, 2, 3, 2);
panelCollection.Name = "panelCollection";
panelCollection.Size = new Size(191, 451);
panelCollection.TabIndex = 3;
//
// maskedTextBoxNumber
//
maskedTextBoxNumber.Location = new Point(14, 88);
maskedTextBoxNumber.Margin = new Padding(3, 2, 3, 2);
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(150, 23);
maskedTextBoxNumber.TabIndex = 6;
//
// labelCollection
//
labelCollection.AutoSize = true;
labelCollection.Location = new Point(3, 7);
labelCollection.Name = "labelCollection";
labelCollection.Size = new Size(83, 15);
labelCollection.TabIndex = 2;
labelCollection.Text = "Инструменты";
//
// buttonRefreshCollection
//
buttonRefreshCollection.Location = new Point(14, 179);
buttonRefreshCollection.Margin = new Padding(3, 2, 3, 2);
buttonRefreshCollection.Name = "buttonRefreshCollection";
buttonRefreshCollection.Size = new Size(150, 30);
buttonRefreshCollection.TabIndex = 5;
buttonRefreshCollection.Text = "Обновить коллекцию";
buttonRefreshCollection.UseVisualStyleBackColor = true;
buttonRefreshCollection.Click += ButtonRefreshCollection_Click;
//
// buttonRemoveTrain
//
buttonRemoveTrain.Location = new Point(14, 124);
buttonRemoveTrain.Margin = new Padding(3, 2, 3, 2);
buttonRemoveTrain.Name = "buttonRemoveTrain";
buttonRemoveTrain.Size = new Size(150, 30);
buttonRemoveTrain.TabIndex = 4;
buttonRemoveTrain.Text = "Удалить машину";
buttonRemoveTrain.UseVisualStyleBackColor = true;
buttonRemoveTrain.Click += ButtonRemoveTrain_Click;
//
// buttonAddTrain
//
buttonAddTrain.Location = new Point(14, 28);
buttonAddTrain.Margin = new Padding(3, 2, 3, 2);
buttonAddTrain.Name = "buttonAddTrain";
buttonAddTrain.Size = new Size(150, 30);
buttonAddTrain.TabIndex = 2;
buttonAddTrain.Text = "Добавить машину";
buttonAddTrain.UseVisualStyleBackColor = true;
buttonAddTrain.Click += ButtonAddTrain_Click;
//
// pictureBoxCollection
//
pictureBoxCollection.Location = new Point(-1, -1);
pictureBoxCollection.Margin = new Padding(3, 2, 3, 2);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(609, 451);
pictureBoxCollection.TabIndex = 2;
pictureBoxCollection.TabStop = false;
//
// TrainCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(panelCollection);
Controls.Add(pictureBoxCollection);
Name = "TrainCollection";
Text = "TrainCollection";
panelCollection.ResumeLayout(false);
panelCollection.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panelCollection;
private MaskedTextBox maskedTextBoxNumber;
private Label labelCollection;
private Button buttonRefreshCollection;
private Button buttonRemoveTrain;
private Button buttonAddTrain;
private PictureBox pictureBoxCollection;
}
}

View File

@ -0,0 +1,67 @@
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 RoadTrain.DrawingObjects;
using RoadTrain.Generics;
using RoadTrain.MovementStrategy;
namespace RoadTrain
{
public partial class TrainCollection : Form
{
private readonly TrainsGenericCollection<DrawingRoadTrain,
DrawingObjectTrain> _trains;
public TrainCollection()
{
InitializeComponent();
_trains = new TrainsGenericCollection<DrawingRoadTrain, DrawingObjectTrain>
(pictureBoxCollection.Width, pictureBoxCollection.Height);
}
private void ButtonAddTrain_Click(object sender, EventArgs e)
{
RoadTrain form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_trains + form.SelectedTrain != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _trains.ShowTrains();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void ButtonRemoveTrain_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (_trains - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = _trains.ShowTrains();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
pictureBoxCollection.Image = _trains.ShowTrains();
}
}
}

View 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>

View File

@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using RoadTrain.DrawingObjects;
using RoadTrain.MovementStrategy;
namespace RoadTrain.Generics
{
internal class TrainsGenericCollection<T, U>
where T : DrawingRoadTrain
where U : IMoveableObject
{
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 220;
private readonly int _placeSizeHeight = 100;
private readonly SetGeneric<T> _collection;
public TrainsGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
public static int operator +(TrainsGenericCollection<T, U> collect, T?
obj)
{
if (obj == null)
{
return -1;
}
return collect._collection.Insert(obj);
}
public static bool operator -(TrainsGenericCollection<T, U> collect, int
pos)
{
T? obj = collect._collection.Get(pos);
if (obj != null)
{
return collect._collection.Remove(pos);
}
return false;
}
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
}
public Bitmap ShowTrains()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
{
g.DrawLine(pen, i * _placeSizeWidth, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
_placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
private void DrawObjects(Graphics g)
{
for (int i = 0; i < _collection.Count; i++)
{
DrawingRoadTrain train = _collection.Get(i);
if (train != null)
{
int width = _pictureWidth / _placeSizeWidth;
train.SetPosition(i % width * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
train.DrawTransport(g);
}
}
}
}
}