using ProjectTank.DrawningObjects; using ProjectTank.Entities; using ProjectTank.MovementStrategy; using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace ProjectTank { public partial class FormTank : Form { private DrawningTankBase? DrawningTank; private AbstractStrategy? AbstractStrategy; public FormTank() { InitializeComponent(); } private void Draw() { if (DrawningTank == null) return; Bitmap bmp = new(pictureBoxTank.Width, pictureBoxTank.Height); Graphics gr = Graphics.FromImage(bmp); DrawningTank.DrawTransport(gr); pictureBoxTank.Image = bmp; } private void ButtonCreateTank_Click(object sender, EventArgs e) { Random random = new(); DrawningTank = new DrawningTank(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)), true, true, pictureBoxTank.Width, pictureBoxTank.Height); DrawningTank.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } private void ButtonCreateTankBase_Click(object sender, EventArgs e) { Random random = new(); DrawningTank = new DrawningTankBase(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), pictureBoxTank.Width, pictureBoxTank.Height); DrawningTank.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } private void moveButton_Click(object sender, EventArgs e) { if (DrawningTank == null) return; string name = ((System.Windows.Forms.Button)sender)?.Name ?? string.Empty; switch (name) { case "buttonUp": DrawningTank.MoveTransport(DirectionType.Up); break; case "buttonDown": DrawningTank.MoveTransport(DirectionType.Down); break; case "buttonLeft": DrawningTank.MoveTransport(DirectionType.Left); break; case "buttonRight": DrawningTank.MoveTransport(DirectionType.Right); break; } Draw(); } private void ButtonStep_Click(object sender, EventArgs e) { if (DrawningTank == null) return; if (comboBoxStrategy.Enabled) { AbstractStrategy = comboBoxStrategy.SelectedIndex switch { 0 => new MoveToCenter(), 1 => new MoveToRightBottomCorner(), _ => null, }; if (AbstractStrategy == null) return; AbstractStrategy.SetData(new DrawningObjectTank(DrawningTank), pictureBoxTank.Width, pictureBoxTank.Height); comboBoxStrategy.Enabled = false; } if (AbstractStrategy == null) return; AbstractStrategy.MakeStep(); Draw(); if (AbstractStrategy.GetStatus() == MovementStrategy.Status.Finish) { comboBoxStrategy.Enabled = true; AbstractStrategy = null; } } } }