2024-04-18 14:03:03 +04:00
|
|
|
|
using ProjectBus.Drawnings;
|
|
|
|
|
using ProjectBus.MovementStrategy;
|
2024-04-11 11:18:53 +04:00
|
|
|
|
using System;
|
2024-02-29 10:45:00 +04:00
|
|
|
|
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;
|
|
|
|
|
|
2024-04-18 14:03:03 +04:00
|
|
|
|
namespace ProjectBus;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// форма работы с объектом "Автобус"
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class FormBus : Form
|
2024-02-29 10:45:00 +04:00
|
|
|
|
{
|
2024-04-18 14:03:03 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// поле-объект для прорисовки объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
private DrawningSimpleBus? _drawningSimpleBus;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Стратегия перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
private AbstractStrategy? _strategy;
|
|
|
|
|
|
2024-04-25 10:17:26 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public DrawningSimpleBus SetSimpleBus
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_drawningSimpleBus = value;
|
|
|
|
|
_drawningSimpleBus.SetPictureSize(pictureBoxBus.Width, pictureBoxBus.Height);
|
|
|
|
|
comboBoxStrategy.Enabled = true;
|
|
|
|
|
_strategy = null;
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-04-18 14:03:03 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// конструктор формы
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormBus()
|
2024-02-29 10:45:00 +04:00
|
|
|
|
{
|
2024-04-18 14:03:03 +04:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
_strategy = null;
|
|
|
|
|
}
|
2024-02-29 10:45:00 +04:00
|
|
|
|
|
2024-04-18 14:03:03 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// метод прорисовки машины
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void Draw()
|
|
|
|
|
{
|
|
|
|
|
if (_drawningSimpleBus == null)
|
2024-02-29 10:45:00 +04:00
|
|
|
|
{
|
2024-04-18 14:03:03 +04:00
|
|
|
|
return;
|
2024-02-29 10:45:00 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-18 14:03:03 +04:00
|
|
|
|
Bitmap bmp = new(pictureBoxBus.Width, pictureBoxBus.Height);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
|
_drawningSimpleBus.DrawTransport(gr);
|
|
|
|
|
pictureBoxBus.Image = bmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_drawningSimpleBus == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
2024-02-29 10:45:00 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-18 14:03:03 +04:00
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
|
|
|
bool result = false;
|
|
|
|
|
switch (name)
|
|
|
|
|
{
|
|
|
|
|
case "buttonUp":
|
|
|
|
|
result =
|
|
|
|
|
_drawningSimpleBus.MoveTransport(DirectionType.Up);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonDown":
|
|
|
|
|
result =
|
|
|
|
|
_drawningSimpleBus.MoveTransport(DirectionType.Down);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonLeft":
|
|
|
|
|
result =
|
|
|
|
|
_drawningSimpleBus.MoveTransport(DirectionType.Left);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonRight":
|
|
|
|
|
result =
|
|
|
|
|
_drawningSimpleBus.MoveTransport(DirectionType.Right);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-04-11 11:18:53 +04:00
|
|
|
|
|
2024-04-18 14:03:03 +04:00
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-11 11:18:53 +04:00
|
|
|
|
|
2024-04-18 14:03:03 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_drawningSimpleBus == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-04-11 11:18:53 +04:00
|
|
|
|
|
2024-04-18 14:03:03 +04:00
|
|
|
|
if (comboBoxStrategy.Enabled)
|
2024-02-29 10:45:00 +04:00
|
|
|
|
{
|
2024-04-18 14:03:03 +04:00
|
|
|
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
|
|
|
|
{
|
|
|
|
|
0 => new MoveToCenter(),
|
|
|
|
|
1 => new MoveToBorder(),
|
|
|
|
|
_ => null,
|
|
|
|
|
};
|
|
|
|
|
if (_strategy == null)
|
2024-02-29 10:45:00 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-04-18 14:03:03 +04:00
|
|
|
|
_strategy.SetData(new MoveableSimpleBus(_drawningSimpleBus), pictureBoxBus.Width, pictureBoxBus.Height);
|
|
|
|
|
}
|
2024-02-29 10:45:00 +04:00
|
|
|
|
|
2024-04-18 14:03:03 +04:00
|
|
|
|
if (_strategy == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-02-29 10:45:00 +04:00
|
|
|
|
|
2024-04-18 14:03:03 +04:00
|
|
|
|
comboBoxStrategy.Enabled = false;
|
|
|
|
|
_strategy.MakeStep();
|
|
|
|
|
Draw();
|
|
|
|
|
|
|
|
|
|
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
|
|
|
|
{
|
|
|
|
|
comboBoxStrategy.Enabled = true;
|
|
|
|
|
_strategy = null;
|
2024-02-29 10:45:00 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-18 14:03:03 +04:00
|
|
|
|
|
2024-04-25 10:17:26 +04:00
|
|
|
|
|