using ProjectAirFighter.Drawnings; using ProjectAirFighter.MovementStrategy; namespace ProjectAirFighter; public partial class FormAirFighter : Form { private DrawningMilitaryAircraft? _drawningMilitaryAircraft; private AbstractStrategy? _strategy; public FormAirFighter() { InitializeComponent(); _strategy = null; } public DrawningMilitaryAircraft SetAir { set { _drawningMilitaryAircraft = value; _drawningMilitaryAircraft.SetPictureSize(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); comboBoxStrategy.Enabled = true; _strategy = null; Draw(); } } private void Draw() { if (_drawningMilitaryAircraft == null) { return; } Bitmap bmp = new(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); Graphics gr = Graphics.FromImage(bmp); _drawningMilitaryAircraft.DrawTransport(gr); pictureBoxAirFighter.Image = bmp; } private void ButtonMove_Click(object sender, EventArgs e) { if (_drawningMilitaryAircraft == null) { return; } string name = ((Button)sender)?.Name ?? string.Empty; bool result = false; switch (name) { case "buttonUp": result = _drawningMilitaryAircraft.MoveTransport(DirectionType.Up); break; case "buttonDown": result = _drawningMilitaryAircraft.MoveTransport(DirectionType.Down); break; case "buttonLeft": result = _drawningMilitaryAircraft.MoveTransport(DirectionType.Left); break; case "buttonRight": result = _drawningMilitaryAircraft.MoveTransport(DirectionType.Right); break; } if (result) { Draw(); } } private void ButtonStrategyStep_Click(object sender, EventArgs e) { if (_drawningMilitaryAircraft == null) { return; } if (comboBoxStrategy.Enabled) { _strategy = comboBoxStrategy.SelectedIndex switch { 0 => new MoveToCenter(), 1 => new MoveToBorder(), _ => null, }; if (_strategy == null) { return; } _strategy.SetData(new MoveableMilitaryAircraft(_drawningMilitaryAircraft), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); } if (_strategy == null) { return; } comboBoxStrategy.Enabled = false; _strategy.MakeStep(); Draw(); if (_strategy.GetStatus() == StrategyStatus.Finish) { comboBoxStrategy.Enabled = true; _strategy = null; } } }