using Liner.Drawing; using Liner.Entities; using Liner.MovingStrategies; using System.Drawing; namespace Liner { public partial class MainScreen : Form { /// /// Поле-объект для прорисовки объекта /// private DrawingLiner? _drawingLiner; private Bitmap bmp; /// /// Стратегия перемещения /// private AbstractStrategy? _abstractStrategy; /// /// Выбранный лайнер /// public DrawingLiner? SelectedLiner { get; private set; } /// /// Инициализация формы /// public MainScreen() { InitializeComponent(); bmp = new(pictureBoxLiner.Width, pictureBoxLiner.Height); SelectedLiner = null; _abstractStrategy = null; } /// /// Метод прорисовки лайнера /// private void Draw() { if (_drawingLiner == null) { return; } Graphics gr = Graphics.FromImage(bmp); gr.Clear(Color.White); _drawingLiner.DrawTransport(gr); pictureBoxLiner.Image = bmp; } private void buttonCreateLiner_Click(object sender, EventArgs e) { Random random = new(); 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; } _drawingLiner = new DrawingLiner(random.Next(100, 300), random.Next(1000, 3000), mainColor, pictureBoxLiner.Width, pictureBoxLiner.Height); _drawingLiner.SetPosition(random.Next(10, 100), random.Next(10, 100)); 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(); } private void buttonCreateBigLiner_Click(object sender, EventArgs e) { Random random = new(); 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; } if (dialog.ShowDialog() == DialogResult.OK) { mainColor = dialog.Color; } _drawingLiner = new DrawingBigLiner(random.Next(100, 300), random.Next(1000, 3000), mainColor, addColor, 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(); } 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; } } private void buttonSelectLiner_Click(object sender, EventArgs e) { SelectedLiner = _drawingLiner; DialogResult = DialogResult.OK; } } }