using ProjectLainer.DrawningObjects; using ProjectLainer.MovementStrategy; namespace ProjectLainer { public partial class LainerForm : Form { private DrawingLainer? _drawningLainer; private AbstractStrategy? _abstractStrategy; public LainerForm() { InitializeComponent(); } private void Draw() { if (_drawningLainer == null) { return; } Bitmap bmp = new(pictureBoxLainer.Width, pictureBoxLainer.Height); Graphics gr = Graphics.FromImage(bmp); _drawningLainer.DrawTransport(gr); pictureBoxLainer.Image = bmp; } private void ButtonCreateSuperLainer_Click(object sender, EventArgs e) { Random random = new(); _drawningLainer = new DrawningSuperLainer(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxLainer.Width, pictureBoxLainer.Height); _drawningLainer.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } private void ButtonCreate_Click(object sender, EventArgs e) { Random random = new(); _drawningLainer = new DrawingLainer(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), pictureBoxLainer.Width, pictureBoxLainer.Height); _drawningLainer.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } private void ButtonMove_Click(object sender, EventArgs e) { if (_drawningLainer == null) { return; } string name = ((Button)sender)?.Name ?? string.Empty; switch (name) { case "buttonUp": _drawningLainer.MoveTransport(DirectionType.Up); break; case "buttonDown": _drawningLainer.MoveTransport(DirectionType.Down); break; case "buttonLeft": _drawningLainer.MoveTransport(DirectionType.Left); break; case "buttonRight": _drawningLainer.MoveTransport(DirectionType.Right); break; } Draw(); } private void ButtonStep_Click(object sender, EventArgs e) { if (_drawningLainer == null) { return; } if (comboBoxStrategy.Enabled) { _abstractStrategy = comboBoxStrategy.SelectedIndex switch { 0 => new MoveToCenter(), 1 => new MoveToBorder(), _ => null, }; if (_abstractStrategy == null) { return; } _abstractStrategy.SetData(new DrawningObjectLainer(_drawningLainer), pictureBoxLainer.Width, pictureBoxLainer.Height); comboBoxStrategy.Enabled = false; } if (_abstractStrategy == null) { return; } _abstractStrategy.MakeStep(); Draw(); if (_abstractStrategy.GetStatus() == Status.Finish) { comboBoxStrategy.Enabled = true; _abstractStrategy = null; } } } }