using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Hydroplane.Entities; using Hydroplane.DrawningObjects; using Hydroplane.MovementStrategy; namespace Hydroplane { public partial class FormHydroplane : Form { private DrawningPlane? _drawingPlane; private AbstractStrategy? _abstractStrategy; public FormHydroplane() { InitializeComponent(); } private void Draw() { if (_drawingPlane == null) { return; } Bitmap bmp = new(pictureBoxHydroplane.Width, pictureBoxHydroplane.Height); Graphics gr = Graphics.FromImage(bmp); _drawingPlane.DrawTransport(gr); pictureBoxHydroplane.Image = bmp; } private void buttonCreatePlane_Click(object sender, EventArgs e) { Random random = new(); _drawingPlane = new DrawningPlane(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), pictureBoxHydroplane.Width, pictureBoxHydroplane.Height); _drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } private void buttonCreateHydroplane_Click(object sender, EventArgs e) { Random random = new(); _drawingPlane = new DrawningHydroplane(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)), pictureBoxHydroplane.Width, pictureBoxHydroplane.Height); _drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } private void buttonMove_Click(object sender, EventArgs e) { if (_drawingPlane == null) { return; } string name = ((Button)sender)?.Name ?? string.Empty; switch (name) { case "buttonUp": _drawingPlane.MoveTransport(DirectionType.Up); break; case "buttonDown": _drawingPlane.MoveTransport(DirectionType.Down); break; case "buttonLeft": _drawingPlane.MoveTransport(DirectionType.Left); break; case "buttonRight": _drawingPlane.MoveTransport(DirectionType.Right); break; } Draw(); } private void buttonStep_Click(object sender, EventArgs e) { if (_drawingPlane == null) { return; } if (comboBoxStrategy.Enabled) { _abstractStrategy = comboBoxStrategy.SelectedIndex switch { 0 => new MoveToCenter(), 1 => new MoveToBorder(), _ => null, }; if (_abstractStrategy == null) { return; } _abstractStrategy.SetData(new DrawningObjectPlane(_drawingPlane), pictureBoxHydroplane.Width, pictureBoxHydroplane.Height); comboBoxStrategy.Enabled = false; } if (_abstractStrategy == null) { return; } _abstractStrategy.MakeStep(); Draw(); if (_abstractStrategy.GetStatus() == Status.Finish) { comboBoxStrategy.Enabled = true; _abstractStrategy = null; } } } }