diff --git a/RoadTrain/RoadTrain/DrawingObjectTrain.cs b/RoadTrain/RoadTrain/DrawingObjectTrain.cs index 2b1eb18..dd4b4b1 100644 --- a/RoadTrain/RoadTrain/DrawingObjectTrain.cs +++ b/RoadTrain/RoadTrain/DrawingObjectTrain.cs @@ -30,4 +30,4 @@ namespace RoadTrain.MovementStrategy public bool CheckCanMove(DirectionType direction) => _drawingRoadTrain?.CanMove(direction) ?? false; public void MoveObject(DirectionType direction) => _drawingRoadTrain?.MoveTransport(direction); } -} +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/DrawingRoadTrain.cs b/RoadTrain/RoadTrain/DrawingRoadTrain.cs index d9a9e52..60a946f 100644 --- a/RoadTrain/RoadTrain/DrawingRoadTrain.cs +++ b/RoadTrain/RoadTrain/DrawingRoadTrain.cs @@ -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, }; } diff --git a/RoadTrain/RoadTrain/DrawingRoadTrainWithTank.cs b/RoadTrain/RoadTrain/DrawingRoadTrainWithTank.cs index de32d6a..9ad989e 100644 --- a/RoadTrain/RoadTrain/DrawingRoadTrainWithTank.cs +++ b/RoadTrain/RoadTrain/DrawingRoadTrainWithTank.cs @@ -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 } } } -} +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/EntityRoadTrain.cs b/RoadTrain/RoadTrain/EntityRoadTrain.cs index e73b415..00affdb 100644 --- a/RoadTrain/RoadTrain/EntityRoadTrain.cs +++ b/RoadTrain/RoadTrain/EntityRoadTrain.cs @@ -19,4 +19,4 @@ namespace RoadTrain.Entities BodyColor = bodyColor; } } -} +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/EntityRoadTrainWithTank.cs b/RoadTrain/RoadTrain/EntityRoadTrainWithTank.cs index 0a4f943..448eb41 100644 --- a/RoadTrain/RoadTrain/EntityRoadTrainWithTank.cs +++ b/RoadTrain/RoadTrain/EntityRoadTrainWithTank.cs @@ -20,4 +20,4 @@ namespace RoadTrain.Entities Brush = brush; } } -} +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/IMoveableObject.cs b/RoadTrain/RoadTrain/IMoveableObject.cs index 4cc5d30..87439ba 100644 --- a/RoadTrain/RoadTrain/IMoveableObject.cs +++ b/RoadTrain/RoadTrain/IMoveableObject.cs @@ -15,4 +15,4 @@ namespace RoadTrain.MovementStrategy bool CheckCanMove(DirectionType direction); void MoveObject(DirectionType direction); } -} +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/MoveToBorder.cs b/RoadTrain/RoadTrain/MoveToBorder.cs index 120bac0..c983282 100644 --- a/RoadTrain/RoadTrain/MoveToBorder.cs +++ b/RoadTrain/RoadTrain/MoveToBorder.cs @@ -53,4 +53,4 @@ namespace RoadTrain.MovementStrategy } } } -} +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/MoveToCenter.cs b/RoadTrain/RoadTrain/MoveToCenter.cs index 1e7be9a..fe66f85 100644 --- a/RoadTrain/RoadTrain/MoveToCenter.cs +++ b/RoadTrain/RoadTrain/MoveToCenter.cs @@ -53,4 +53,4 @@ namespace RoadTrain.MovementStrategy } } } -} +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/ObjectParameters.cs b/RoadTrain/RoadTrain/ObjectParameters.cs index 5691830..d3c6ad8 100644 --- a/RoadTrain/RoadTrain/ObjectParameters.cs +++ b/RoadTrain/RoadTrain/ObjectParameters.cs @@ -26,4 +26,4 @@ namespace RoadTrain.MovementStrategy _height = height; } } -} +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/Program.cs b/RoadTrain/RoadTrain/Program.cs index c6803b9..dc724be 100644 --- a/RoadTrain/RoadTrain/Program.cs +++ b/RoadTrain/RoadTrain/Program.cs @@ -6,7 +6,7 @@ namespace RoadTrain static void Main() { ApplicationConfiguration.Initialize(); - Application.Run(new RoadTrain()); + Application.Run(new TrainCollection()); } } } \ No newline at end of file diff --git a/RoadTrain/RoadTrain/RoadTrain.Designer.cs b/RoadTrain/RoadTrain/RoadTrain.Designer.cs index 9487c1d..52990ad 100644 --- a/RoadTrain/RoadTrain/RoadTrain.Designer.cs +++ b/RoadTrain/RoadTrain/RoadTrain.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/RoadTrain/RoadTrain/RoadTrain.cs b/RoadTrain/RoadTrain/RoadTrain.cs index 22fa028..3246f9e 100644 --- a/RoadTrain/RoadTrain/RoadTrain.cs +++ b/RoadTrain/RoadTrain/RoadTrain.cs @@ -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; + } } } \ No newline at end of file diff --git a/RoadTrain/RoadTrain/SetGeneric.cs b/RoadTrain/RoadTrain/SetGeneric.cs new file mode 100644 index 0000000..961eece --- /dev/null +++ b/RoadTrain/RoadTrain/SetGeneric.cs @@ -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 + 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]; + } + } +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/Status.cs b/RoadTrain/RoadTrain/Status.cs index 702be08..bf1d49f 100644 --- a/RoadTrain/RoadTrain/Status.cs +++ b/RoadTrain/RoadTrain/Status.cs @@ -12,4 +12,4 @@ namespace RoadTrain.MovementStrategy InProgress, Finish } -} +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/TrainCollection.Designer.cs b/RoadTrain/RoadTrain/TrainCollection.Designer.cs new file mode 100644 index 0000000..620c01e --- /dev/null +++ b/RoadTrain/RoadTrain/TrainCollection.Designer.cs @@ -0,0 +1,139 @@ +namespace RoadTrain +{ + partial class TrainCollection + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/TrainCollection.cs b/RoadTrain/RoadTrain/TrainCollection.cs new file mode 100644 index 0000000..a5d4e4e --- /dev/null +++ b/RoadTrain/RoadTrain/TrainCollection.cs @@ -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 _trains; + public TrainCollection() + { + InitializeComponent(); + _trains = new TrainsGenericCollection + (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(); + } + } +} \ No newline at end of file diff --git a/RoadTrain/RoadTrain/TrainCollection.resx b/RoadTrain/RoadTrain/TrainCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RoadTrain/RoadTrain/TrainCollection.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/RoadTrain/RoadTrain/TrainsGenericCollection.cs b/RoadTrain/RoadTrain/TrainsGenericCollection.cs new file mode 100644 index 0000000..1185645 --- /dev/null +++ b/RoadTrain/RoadTrain/TrainsGenericCollection.cs @@ -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 + 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 _collection; + public TrainsGenericCollection(int picWidth, int picHeight) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = new SetGeneric(width * height); + } + public static int operator +(TrainsGenericCollection collect, T? + obj) + { + if (obj == null) + { + return -1; + } + return collect._collection.Insert(obj); + } + public static bool operator -(TrainsGenericCollection 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); + } + } + } + } +} \ No newline at end of file