144 lines
4.7 KiB
C#
144 lines
4.7 KiB
C#
using ProjectGasolineTanker.Drawings;
|
|
using ProjectGasolineTanker.Entities;
|
|
using ProjectGasolineTanker.MovementStratg;
|
|
|
|
namespace ProjectGasolineTanker
|
|
{
|
|
|
|
public partial class FormGasolineTanker : Form
|
|
{
|
|
|
|
private DrawingTruck? _drawingTruck;
|
|
|
|
private AbstractStrategy? _abstractStrategy;
|
|
|
|
public DrawingTruck? SelectedTruck { get; private set; }
|
|
|
|
public FormGasolineTanker()
|
|
{
|
|
InitializeComponent();
|
|
_abstractStrategy = null;
|
|
SelectedTruck = null;
|
|
}
|
|
|
|
private void Draw()
|
|
{
|
|
if (_drawingTruck == null)
|
|
{
|
|
return;
|
|
}
|
|
Bitmap bmp = new(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawingTruck.DrawTransport(gr);
|
|
pictureBoxGasolineTanker.Image = bmp;
|
|
|
|
}
|
|
|
|
private void buttonCreateProjectGasolineTanker_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
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;
|
|
}
|
|
_drawingTruck = new DrawingGasolineTanker(random.Next(100, 300),
|
|
random.Next(1000, 3000),
|
|
color, color1,
|
|
true, true,
|
|
pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height);
|
|
_drawingTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
Draw();
|
|
}
|
|
|
|
private void buttonCreateTruck_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
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;
|
|
}
|
|
_drawingTruck = new DrawingTruck(random.Next(100, 300),
|
|
random.Next(1000, 3000),
|
|
color,
|
|
pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height);
|
|
_drawingTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
Draw();
|
|
|
|
}
|
|
|
|
private void buttonMove_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawingTruck == null)
|
|
{
|
|
return;
|
|
}
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
_drawingTruck.MoveTransport(DirectionType.Up);
|
|
break;
|
|
case "buttonDown":
|
|
_drawingTruck.MoveTransport(DirectionType.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
_drawingTruck.MoveTransport(DirectionType.Left);
|
|
break;
|
|
case "buttonRight":
|
|
_drawingTruck.MoveTransport(DirectionType.Right);
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
|
|
private void buttonStep_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawingTruck == null)
|
|
{
|
|
return;
|
|
}
|
|
if (comboBoxStrategy.Enabled)
|
|
{
|
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
|
switch
|
|
{
|
|
0 => new MoveToCenter(),
|
|
1 => new MoveToBorder(),
|
|
_ => null,
|
|
};
|
|
if (_abstractStrategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_abstractStrategy.SetData(new DrawingObjectTruck(_drawingTruck), pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height);
|
|
comboBoxStrategy.Enabled = false;
|
|
}
|
|
if (_abstractStrategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_abstractStrategy.MakeStep();
|
|
Draw();
|
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
|
{
|
|
comboBoxStrategy.Enabled = true;
|
|
_abstractStrategy = null;
|
|
}
|
|
}
|
|
private void ButtonSelectTruck_Click(object sender, EventArgs e)
|
|
{
|
|
SelectedTruck = _drawingTruck;
|
|
DialogResult = DialogResult.OK;
|
|
}
|
|
}
|
|
} |