using lab1; 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; namespace lab1 { public partial class FormFighter : Form { private DrawningEntityFighter? _drawningFighter; public FormFighter() { InitializeComponent(); } private void Draw() { if (_drawningFighter == null) { return; } Bitmap bmp = new(pictureBoxFighter.Width, pictureBoxFighter.Height); Graphics gr = Graphics.FromImage(bmp); _drawningFighter.DrawTransport(gr); pictureBoxFighter.Image = bmp; } private void buttonMove_Click(object sender, EventArgs e) { if (_drawningFighter == null) { return; } string name = ((Button)sender)?.Name ?? string.Empty; bool result = false; switch (name) { case "buttonUp": result = _drawningFighter.MoveTransport(DirectionType.Up); break; case "buttonDown": result = _drawningFighter.MoveTransport(DirectionType.Down); break; case "buttonLeft": result = _drawningFighter.MoveTransport(DirectionType.Left); break; case "buttonRight": result = _drawningFighter.MoveTransport(DirectionType.Right); break; } if (result) { Draw(); } } private void buttonCreate_Click_1(object sender, EventArgs e) { { Random random = new(); _drawningFighter = new DrawningEntityFighter(); _drawningFighter.Init(random.Next(100, 300), random.Next(1200, 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))); _drawningFighter.SetPictureSize(pictureBoxFighter.Width, pictureBoxFighter.Height); _drawningFighter.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } } private void FormFighter_Load(object sender, EventArgs e) { } } }