138 lines
3.4 KiB
C#
138 lines
3.4 KiB
C#
using ProjectHoistingCrane.Drawnings;
|
|
using ProjectHoistingCrane.MovementStrategy;
|
|
namespace ProjectHoistingCrane;
|
|
|
|
public partial class FormHoistingCrane : Form
|
|
{
|
|
/// <summary>
|
|
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
|
/// </summary>
|
|
private DrawningCrane? _drawningCrane;
|
|
/// <summary>
|
|
/// Êîíñòðóêòîð ôîðìû
|
|
/// </summary>
|
|
|
|
///<summary>
|
|
///Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
|
/// </summary>
|
|
private AbstractStrategy? _strategy;
|
|
|
|
/// <summary>
|
|
/// Ïîëó÷åíèå îáúåêòà
|
|
/// </summary>
|
|
public DrawningCrane SetCrane
|
|
{
|
|
set
|
|
{
|
|
_drawningCrane = value;
|
|
_drawningCrane.SetPictureSize(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
|
|
comboBoxStrategy.Enabled = true;
|
|
_strategy = null;
|
|
Draw();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Êîíñòðóêòîð ôîðìû
|
|
/// </summary>
|
|
public FormHoistingCrane()
|
|
{
|
|
InitializeComponent();
|
|
_strategy = null;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Ìåòîä ïðîðèñîâêè êðàíà
|
|
/// </summary>
|
|
private void Draw()
|
|
{
|
|
if (_drawningCrane == null)
|
|
{
|
|
return;
|
|
}
|
|
Bitmap bmp = new(pictureBoxHoistingCrane.Width,
|
|
pictureBoxHoistingCrane.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawningCrane.DrawTransport(gr);
|
|
pictureBoxHoistingCrane.Image = bmp;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ïåðåìåùåíèå îáúåêòà ïî ôîðìå (íàæàòèå êíîïîê íàâèãàöèè)
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void buttonMove_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawningCrane == null)
|
|
{
|
|
return;
|
|
}
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
bool result = false;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
result =
|
|
_drawningCrane.MoveTransport(DirectionType.Up);
|
|
break;
|
|
case "buttonDown":
|
|
result =
|
|
_drawningCrane.MoveTransport(DirectionType.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
result =
|
|
_drawningCrane.MoveTransport(DirectionType.Left);
|
|
break;
|
|
case "buttonRight":
|
|
result =
|
|
_drawningCrane.MoveTransport(DirectionType.Right);
|
|
break;
|
|
}
|
|
if (result)
|
|
{
|
|
Draw();
|
|
}
|
|
}
|
|
|
|
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawningCrane == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (comboBoxStrategy.Enabled)
|
|
{
|
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
|
{
|
|
0 => new MoveToCenter(),
|
|
1 => new MoveToBorder(),
|
|
_ => null,
|
|
};
|
|
if (_strategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_strategy.SetData(new MoveableCrane(_drawningCrane), pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
|
|
}
|
|
|
|
if (_strategy == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
comboBoxStrategy.Enabled = false;
|
|
_strategy.MakeStep();
|
|
Draw();
|
|
|
|
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
|
{
|
|
comboBoxStrategy.Enabled = true;
|
|
_strategy = null;
|
|
}
|
|
}
|
|
}
|
|
|