using AntiAircraftGun.Drawnings; using AntiAircraftGun.MovementStrategy; namespace AntiAircraftGun; public partial class FormAntiAircraftGun : Form { /// /// Поле объект для прорисовки объекта /// private DrawningArmoredCar? _drawningAircraftGun; /// /// Стратегия перемещения /// private AbstractStrategy? _strategy; /// /// Получение объекта /// public DrawningArmoredCar SetArmoredCar { set { _drawningAircraftGun = value; _drawningAircraftGun.SetPictureSize(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); comboBoxStrategy.Enabled = true; _strategy = null; Draw(); } } /// /// конструктор формы /// public FormAntiAircraftGun() { InitializeComponent(); _strategy = null; } /// /// Метод прорисовки транспорта /// private void Draw() { if (_drawningAircraftGun == null) { return; } Bitmap bmp = new(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); Graphics gr = Graphics.FromImage(bmp); _drawningAircraftGun.DrawTransport(gr); pictureBoxAntiAircraftGun.Image = bmp; } /// /// Перемещение объекта по форме /// /// /// private void ButtonMove_Click(object sender, EventArgs e) { if (_drawningAircraftGun == null) { return; } string name = ((Button)sender)?.Name ?? string.Empty; bool result = false; switch (name) { case "buttonUp": result = _drawningAircraftGun.MoveTransport(DirectionType.Up); break; case "buttonDown": result = _drawningAircraftGun.MoveTransport(DirectionType.Down); break; case "buttonRight": result = _drawningAircraftGun.MoveTransport(DirectionType.Right); break; case "buttonLeft": result = _drawningAircraftGun.MoveTransport(DirectionType.Left); break; } if (result) { Draw(); } } /// /// Метод выбора стратегии /// /// /// private void buttonStrategyStep_Click(object sender, EventArgs e) { if (_drawningAircraftGun == null) { return; } if (comboBoxStrategy.Enabled) { _strategy = comboBoxStrategy.SelectedIndex switch { 0 => new MoveToCenter(), 1 => new MoveToBorder(), _ => null, }; if (_strategy == null) { return; } _strategy.SetData(new MoveableAircraftGun(_drawningAircraftGun), pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); } if (_strategy == null) { return; } comboBoxStrategy.Enabled = false; _strategy.MakeStep(); Draw(); if (_strategy.GetStatus() == StrategyStatus.Finish) { comboBoxStrategy.Enabled = true; _strategy = null; } } }