154 lines
5.2 KiB
C#
Raw Permalink Normal View History

2023-09-25 14:04:52 +04:00
using Liner.Drawing;
using Liner.Entities;
using Liner.MovingStrategies;
2023-11-24 12:39:11 +04:00
using System.Drawing;
2023-09-25 14:04:52 +04:00
2023-09-25 09:27:40 +04:00
namespace Liner
{
public partial class MainScreen : Form
{
/// <summary>
/// <20><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
private DrawingLiner? _drawingLiner;
private Bitmap bmp;
/// <summary>
2023-09-25 14:04:52 +04:00
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
private AbstractStrategy? _abstractStrategy;
/// <summary>
2023-11-24 12:39:11 +04:00
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public DrawingLiner? SelectedLiner { get; private set; }
/// <summary>
2023-09-25 09:27:40 +04:00
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public MainScreen()
{
InitializeComponent();
bmp = new(pictureBoxLiner.Width, pictureBoxLiner.Height);
2023-11-24 12:39:11 +04:00
SelectedLiner = null;
_abstractStrategy = null;
2023-09-25 09:27:40 +04:00
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
private void Draw()
{
if (_drawingLiner == null)
{
return;
}
Graphics gr = Graphics.FromImage(bmp);
gr.Clear(Color.White);
_drawingLiner.DrawTransport(gr);
pictureBoxLiner.Image = bmp;
}
2023-09-25 14:04:52 +04:00
private void buttonCreateLiner_Click(object sender, EventArgs e)
2023-09-25 09:27:40 +04:00
{
Random random = new();
2023-11-24 12:39:11 +04:00
Color mainColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color addColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
2023-11-24 15:24:14 +04:00
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
addColor = dialog.Color;
}
2023-09-25 14:04:52 +04:00
_drawingLiner = new DrawingLiner(random.Next(100, 300),
random.Next(1000, 3000), mainColor,
2023-09-25 09:27:40 +04:00
pictureBoxLiner.Width, pictureBoxLiner.Height);
2023-09-25 14:04:52 +04:00
_drawingLiner.SetPosition(random.Next(10, 100), random.Next(10, 100));
2023-09-25 09:27:40 +04:00
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawingLiner == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawingLiner.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawingLiner.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawingLiner.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawingLiner.MoveTransport(DirectionType.Right);
break;
}
Draw();
2023-09-25 14:04:52 +04:00
}
private void buttonCreateBigLiner_Click(object sender, EventArgs e)
{
Random random = new();
2023-11-24 12:39:11 +04:00
Color mainColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
Color addColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
addColor = dialog.Color;
}
2023-11-24 15:24:14 +04:00
if (dialog.ShowDialog() == DialogResult.OK)
{
mainColor = dialog.Color;
}
2023-09-25 14:04:52 +04:00
_drawingLiner = new DrawingBigLiner(random.Next(100, 300),
2023-11-24 12:39:11 +04:00
random.Next(1000, 3000), mainColor, addColor,
2023-09-25 14:04:52 +04:00
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(1, 2)),
pictureBoxLiner.Width, pictureBoxLiner.Height);
_drawingLiner.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
2023-09-25 09:27:40 +04:00
2023-09-25 14:04:52 +04:00
private void buttonStep_Click(object sender, EventArgs e)
{
if (_drawingLiner == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new DrawingObjectLiner(_drawingLiner), pictureBoxLiner.Width,
pictureBoxLiner.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
2023-09-25 09:27:40 +04:00
}
2023-11-24 12:39:11 +04:00
private void buttonSelectLiner_Click(object sender, EventArgs e)
{
SelectedLiner = _drawingLiner;
DialogResult = DialogResult.OK;
}
2023-09-25 09:27:40 +04:00
}
}