2023-11-25 14:55:27 +04:00
|
|
|
using DoubleDeckerbus.Drawing;
|
|
|
|
using DoubleDeckerbus.Entities;
|
|
|
|
using DoubleDeckerbus.Move_Strategy;
|
2023-11-14 14:11:54 +04:00
|
|
|
|
|
|
|
namespace DoubleDeckerbus
|
2023-11-14 13:52:50 +04:00
|
|
|
{
|
2023-11-25 14:13:49 +04:00
|
|
|
public partial class FormDoubleDeckerbus : Form
|
2023-11-14 13:52:50 +04:00
|
|
|
{
|
|
|
|
private DrawingBus? _drawingBus;
|
2023-11-14 14:11:54 +04:00
|
|
|
private AbstractStrategy? _abstractStrategy;
|
2023-11-25 14:13:49 +04:00
|
|
|
public DrawingBus? SelectedBus { get; private set; }
|
2023-11-25 14:55:27 +04:00
|
|
|
|
2023-11-25 14:13:49 +04:00
|
|
|
public FormDoubleDeckerbus()
|
2023-11-14 13:52:50 +04:00
|
|
|
{
|
|
|
|
InitializeComponent();
|
2023-11-25 14:13:49 +04:00
|
|
|
_abstractStrategy = null;
|
|
|
|
SelectedBus = null;
|
2023-11-14 13:52:50 +04:00
|
|
|
}
|
|
|
|
private void Draw()
|
|
|
|
{
|
|
|
|
if (_drawingBus == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-11-14 14:11:54 +04:00
|
|
|
Bitmap bmp = new(pictureBoxDoubleDeckerbus.Width, pictureBoxDoubleDeckerbus.Height);
|
2023-11-14 13:52:50 +04:00
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
_drawingBus.DrawTransport(gr);
|
2023-11-14 14:11:54 +04:00
|
|
|
pictureBoxDoubleDeckerbus.Image = bmp;
|
2023-11-25 14:55:27 +04:00
|
|
|
|
2023-11-14 13:52:50 +04:00
|
|
|
}
|
2023-11-14 14:11:54 +04:00
|
|
|
private void buttonCreateDoubleDeckerbus_Click(object sender, EventArgs e)
|
2023-11-14 13:52:50 +04:00
|
|
|
{
|
|
|
|
Random random = new();
|
2023-11-25 14:13:49 +04:00
|
|
|
Color color = Color.FromArgb(random.Next(0, 256),
|
|
|
|
random.Next(0, 256), random.Next(0, 256));
|
|
|
|
Color color1 = Color.FromArgb(random.Next(0, 256),
|
|
|
|
random.Next(0, 256), random.Next(0, 256));
|
|
|
|
ColorDialog dialog = new();
|
|
|
|
ColorDialog dialog1 = new();
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK && dialog1.ShowDialog() == DialogResult.OK)
|
|
|
|
{
|
|
|
|
color = dialog.Color;
|
|
|
|
color1 = dialog1.Color;
|
|
|
|
}
|
2023-11-14 14:11:54 +04:00
|
|
|
_drawingBus = new DrawingDoubleDeckerbus(random.Next(100, 300),
|
2023-11-25 14:13:49 +04:00
|
|
|
random.Next(1000, 3000), color, color1, true, true,
|
2023-11-14 14:11:54 +04:00
|
|
|
pictureBoxDoubleDeckerbus.Width, pictureBoxDoubleDeckerbus.Height);
|
2023-11-25 14:13:49 +04:00
|
|
|
_drawingBus.SetPosition(random.Next(10, 100), random.Next(10,
|
|
|
|
100));
|
2023-11-14 13:52:50 +04:00
|
|
|
Draw();
|
2023-11-25 14:55:27 +04:00
|
|
|
|
2023-11-14 13:52:50 +04:00
|
|
|
}
|
2023-11-14 14:11:54 +04:00
|
|
|
private void buttonCreateBus_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
Random random = new();
|
2023-11-25 14:13:49 +04:00
|
|
|
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;
|
|
|
|
}
|
2023-11-25 15:23:25 +04:00
|
|
|
|
2023-11-14 14:11:54 +04:00
|
|
|
_drawingBus = new DrawingBus(random.Next(100, 300),
|
2023-11-25 14:13:49 +04:00
|
|
|
random.Next(1000, 3000), color,
|
2023-11-14 14:11:54 +04:00
|
|
|
pictureBoxDoubleDeckerbus.Width, pictureBoxDoubleDeckerbus.Height);
|
2023-11-25 14:55:27 +04:00
|
|
|
_drawingBus.SetPosition(random.Next(10, 100), random.Next(10,100));
|
2023-11-14 14:11:54 +04:00
|
|
|
Draw();
|
2023-11-25 15:23:25 +04:00
|
|
|
|
|
|
|
|
2023-11-14 14:11:54 +04:00
|
|
|
}
|
|
|
|
private void buttonMove_Click(object sender, EventArgs e)
|
2023-11-14 13:52:50 +04:00
|
|
|
{
|
|
|
|
if (_drawingBus == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
|
|
switch (name)
|
|
|
|
{
|
|
|
|
case "buttonUp":
|
2023-11-14 14:11:54 +04:00
|
|
|
_drawingBus.MoveTransport(DirectionType.Up);
|
2023-11-14 13:52:50 +04:00
|
|
|
break;
|
|
|
|
case "buttonDown":
|
2023-11-14 14:11:54 +04:00
|
|
|
_drawingBus.MoveTransport(DirectionType.Down);
|
2023-11-14 13:52:50 +04:00
|
|
|
break;
|
|
|
|
case "buttonLeft":
|
2023-11-14 14:11:54 +04:00
|
|
|
_drawingBus.MoveTransport(DirectionType.Left);
|
2023-11-14 13:52:50 +04:00
|
|
|
break;
|
|
|
|
case "buttonRight":
|
2023-11-14 14:11:54 +04:00
|
|
|
_drawingBus.MoveTransport(DirectionType.Right);
|
2023-11-14 13:52:50 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
Draw();
|
|
|
|
}
|
2023-11-14 14:11:54 +04:00
|
|
|
private void buttonStep_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (_drawingBus == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (comboBoxStrategy.Enabled)
|
|
|
|
{
|
|
|
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
|
|
|
switch
|
|
|
|
{
|
|
|
|
0 => new MoveToCenter(),
|
|
|
|
1 => new MoveToBorder(),
|
|
|
|
_ => null,
|
|
|
|
};
|
|
|
|
if (_abstractStrategy == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_abstractStrategy.SetData(new DrawingObjectBus(_drawingBus), pictureBoxDoubleDeckerbus.Width, pictureBoxDoubleDeckerbus.Height);
|
|
|
|
comboBoxStrategy.Enabled = false;
|
|
|
|
}
|
|
|
|
if (_abstractStrategy == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_abstractStrategy.MakeStep();
|
|
|
|
Draw();
|
|
|
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
|
|
|
{
|
|
|
|
comboBoxStrategy.Enabled = true;
|
|
|
|
_abstractStrategy = null;
|
|
|
|
}
|
|
|
|
}
|
2023-11-25 14:13:49 +04:00
|
|
|
private void ButtonSelectBus_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
SelectedBus = _drawingBus;
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
}
|
2023-11-14 13:52:50 +04:00
|
|
|
}
|
|
|
|
}
|