124 lines
5.6 KiB
C#
124 lines
5.6 KiB
C#
namespace WarmlyLocomotove
|
||
{
|
||
public partial class FormMap : Form
|
||
{
|
||
/// <summary>
|
||
/// Создание объекта от абстрактного класса карты
|
||
/// </summary>
|
||
private AbstractMap _abstractMap;
|
||
public FormMap()
|
||
{
|
||
InitializeComponent();
|
||
_abstractMap = new SimpleMap();
|
||
}
|
||
/// <summary>
|
||
/// Заполнение информации по объекту
|
||
/// </summary>
|
||
/// <param name="locomotive">Объект от класса отрисовки или его наследника</param>
|
||
private void SetData(DrawningLocomotive locomotive)
|
||
{
|
||
toolStripStatusLabelSpeed.Text = $"Скорость: {locomotive.Locomotive.Speed}";
|
||
toolStripStatusLabelWeight.Text = $"Вес: {locomotive.Locomotive.Weight}";
|
||
toolStripStatusLabelBodyColor.Text = $"Цвет: {locomotive.Locomotive.BodyColor.Name}";
|
||
toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: н/д";
|
||
toolStripStatusLabelHasPipe.Text = $"Наличие трубы: н/д";
|
||
toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: н/д";
|
||
pictureBoxLocomotive.Image = _abstractMap.CreateMap(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height,
|
||
new DrawningObjectLocomotive(locomotive));
|
||
}
|
||
/// <summary>
|
||
/// Заполнение дополнительной информации по объекту (только для усложнённого объекта)
|
||
/// </summary>
|
||
/// <param name="warmlylocomotive">Объект от наследника класса отрисовки</param>
|
||
private void SetAdditionalData(DrawningWarmlyLocomotive warmlylocomotive)
|
||
{
|
||
if (warmlylocomotive.Locomotive is EntityWarmlyLocomotive entityWarmlyLocomotive)
|
||
{
|
||
toolStripStatusLabelAdditionalColor.Text = $"Дополнительный цвет: {entityWarmlyLocomotive.AdditionalColor.Name}";
|
||
toolStripStatusLabelHasPipe.Text = $"Наличие трубы: {entityWarmlyLocomotive.HasPipe}";
|
||
toolStripStatusLabelHasFuelTank.Text = $"Наличие топливного бака: {entityWarmlyLocomotive.HasFuelTank}";
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// Обработка нажатия кнопки "Создать"
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||
{
|
||
Random rnd = new();
|
||
var locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||
locomotive.Wheels.WheelsNum = (int)numericUpDownWheelsNumber.Value;
|
||
SetData(locomotive);
|
||
}
|
||
/// <summary>
|
||
/// Перемещение объекта по форме
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonMove_Click(object sender, EventArgs e)
|
||
{
|
||
//получаем имя кнопки
|
||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||
Direction dir = Direction.None;
|
||
switch (name)
|
||
{
|
||
case "buttonUp":
|
||
dir = Direction.Up;
|
||
break;
|
||
case "buttonDown":
|
||
dir = Direction.Down;
|
||
break;
|
||
case "buttonLeft":
|
||
dir = Direction.Left;
|
||
break;
|
||
case "buttonRight":
|
||
dir = Direction.Right;
|
||
break;
|
||
}
|
||
pictureBoxLocomotive.Image = _abstractMap?.MoveObject(dir);
|
||
}
|
||
/// <summary>
|
||
/// Обработка нажатия кнопки "Модификация"
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonCreateModif_Click(object sender, EventArgs e)
|
||
{
|
||
Random rnd = new();
|
||
var locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||
160, 85,
|
||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||
Convert.ToBoolean(rnd.Next(0, 2)),
|
||
Convert.ToBoolean(rnd.Next(0, 2)));
|
||
locomotive.Wheels.WheelsNum = (int)numericUpDownWheelsNumber.Value;
|
||
SetData(locomotive);
|
||
SetAdditionalData(locomotive);
|
||
}
|
||
/// <summary>
|
||
/// Смена карты
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
switch (comboBoxSelectorMap.Text)
|
||
{
|
||
case "Простая карта":
|
||
_abstractMap = new SimpleMap();
|
||
break;
|
||
case "Карта с крестом":
|
||
_abstractMap = new CrossMap();
|
||
break;
|
||
case "Карта с дорожками":
|
||
_abstractMap = new RoadsMap();
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|