Редактирования по 5 лабораторной

This commit is contained in:
Даниил Путинцев 2023-11-09 17:11:55 +04:00
parent 129ed2e33c
commit f711ae5b81
6 changed files with 38 additions and 23 deletions

View File

@ -17,11 +17,11 @@ namespace RoadTrain.DrawningObjects
/// <summary> /// <summary>
/// Ширина окна /// Ширина окна
/// </summary> /// </summary>
protected int _pictureWidth; public int _pictureWidth;
/// <summary> /// <summary>
/// Высота окна /// Высота окна
/// </summary> /// </summary>
protected int _pictureHeight; public int _pictureHeight;
/// <summary> /// <summary>
/// Левая координата прорисовки автомобиля /// Левая координата прорисовки автомобиля
/// </summary> /// </summary>
@ -178,5 +178,9 @@ DrawningObjectTrain(this);
g.FillEllipse(br, _startPosX + 60, _startPosY + 20, 10, 10); g.FillEllipse(br, _startPosX + 60, _startPosY + 20, 10, 10);
g.FillRectangle(br, _startPosX + 60, _startPosY, 10, 20); g.FillRectangle(br, _startPosX + 60, _startPosY, 10, 20);
} }
public void SetBodyColor(Color color)
{
EntityRoadTrain.SetBodyColor(color);
}
} }
} }

View File

@ -50,7 +50,10 @@ namespace RoadTrain.DrawningObjects
g.DrawLine(pen, _startPosX + 20, _startPosY + 10, _startPosX + 10, _startPosY + 30); g.DrawLine(pen, _startPosX + 20, _startPosY + 10, _startPosX + 10, _startPosY + 30);
g.DrawLine(pen, _startPosX + 17, _startPosY + 30, _startPosX + 3, _startPosY + 30); g.DrawLine(pen, _startPosX + 17, _startPosY + 30, _startPosX + 3, _startPosY + 30);
} }
} }
} public void SetAdditionalColor(Color color)
{
(EntityRoadTrain as EntityTrain).SetAdditionalColor(color);
}
}
} }

View File

@ -20,9 +20,10 @@ namespace RoadTrain.Entities
/// Основной цвет /// Основной цвет
/// </summary> /// </summary>
public Color BodyColor { get; protected set; } public Color BodyColor { get; protected set; }
/// <summary> public void SetBodyColor(Color color)
/// Дополнительный цвет (для опциональных элементов) {
/// </summary> BodyColor = color;
}
public double Step => (double)Speed * 100 / Weight; public double Step => (double)Speed * 100 / Weight;
/// <summary> /// <summary>
/// Инициализация полей объекта-класса поезда /// Инициализация полей объекта-класса поезда

View File

@ -15,6 +15,10 @@ namespace RoadTrain.Entities
/// Дополнительный цвет (для опциональных элементов) /// Дополнительный цвет (для опциональных элементов)
/// </summary> /// </summary>
public Color AdditionalColor { get; private set; } public Color AdditionalColor { get; private set; }
public void SetAdditionalColor(Color color)
{
AdditionalColor = color;
}
/// <summary> /// <summary>
/// Признак (опция) наличия обвеса /// Признак (опция) наличия обвеса
/// </summary> /// </summary>

View File

@ -44,33 +44,34 @@ pictureBoxCollection.Height);
listBoxStorages.SelectedIndex = index; listBoxStorages.SelectedIndex = index;
} }
} }
private void AddTrain(DrawningRoadTrain train)
private void ButtonAddTrain_Click(object sender, EventArgs e)
{ {
train._pictureWidth = pictureBoxCollection.Width;
train._pictureHeight = pictureBoxCollection.Height;
if (listBoxStorages.SelectedIndex == -1) if (listBoxStorages.SelectedIndex == -1)
{ {
return; return;
} }
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
string.Empty];
if (obj == null) if (obj == null)
{ {
return; return;
} }
FormRoadTrain form = new(); if (obj + train != -1)
if (form.ShowDialog() == DialogResult.OK)
{ {
if (obj + form.SelectedTrain != -1) MessageBox.Show("Объект добавлен");
{ pictureBoxCollection.Image = obj.ShowTrains();
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowTrains();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
} }
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
private void ButtonAddTrain_Click(object sender, EventArgs e)
{
var formTrainConfig = new FormTrainConfig();
formTrainConfig.AddEvent(AddTrain);
formTrainConfig.Show();
} }
private void ButtonRemoveTrain_Click(object sender, EventArgs e) private void ButtonRemoveTrain_Click(object sender, EventArgs e)

View File

@ -9,6 +9,7 @@ using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using RoadTrain.MovementStrategy; using RoadTrain.MovementStrategy;
using RoadTrain.DrawningObjects; using RoadTrain.DrawningObjects;
using RoadTrain.Entities;
namespace RoadTrain namespace RoadTrain
{ {
@ -110,6 +111,7 @@ namespace RoadTrain
pictureBoxObject.Height); pictureBoxObject.Height);
break; break;
} }
DrawTrain();
} }
private void ButtonOk_Click(object sender, EventArgs e) private void ButtonOk_Click(object sender, EventArgs e)