99 lines
3.3 KiB
C#
99 lines
3.3 KiB
C#
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 ProjectAirplaneWithRadar
|
|
{
|
|
public partial class FormAirplaneWithRadar : Form
|
|
{
|
|
private DrawingAirplaneWithRadar? _drawingAirplaneWithRadar;
|
|
public FormAirplaneWithRadar()
|
|
{
|
|
InitializeComponent();
|
|
MinimumSize = new Size(DrawingAirplaneWithRadar.PlaneWidth + 40, DrawingAirplaneWithRadar.PlaneHeight + 40 + DrawingAirplaneWithRadar.FormPadding);
|
|
}
|
|
|
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
_drawingAirplaneWithRadar = new DrawingAirplaneWithRadar();
|
|
_drawingAirplaneWithRadar.Init(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)), Convert.ToBoolean(random.Next(0, 2)));
|
|
_drawingAirplaneWithRadar.SetPictureSize(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
|
|
_drawingAirplaneWithRadar.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
|
|
UpdatePlane();
|
|
}
|
|
|
|
private void UpdatePlane()
|
|
{
|
|
Bitmap bmp = new(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawingAirplaneWithRadar?.DrawTransport(gr);
|
|
pictureBoxAirplaneWithRadar.Image = bmp;
|
|
}
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawingAirplaneWithRadar == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (sender is Button button)
|
|
{
|
|
string name = button.Name;
|
|
DirectionType result;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
result = DirectionType.Up;
|
|
break;
|
|
case "buttonDown":
|
|
result = DirectionType.Down;
|
|
break;
|
|
case "buttonLeft":
|
|
result = DirectionType.Left;
|
|
break;
|
|
case "buttonRight":
|
|
result = DirectionType.Right;
|
|
break;
|
|
|
|
default:
|
|
return;
|
|
|
|
}
|
|
_drawingAirplaneWithRadar.MoveTransport(result);
|
|
|
|
UpdatePlane();
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void FormAirplaneWithRadar_ResizeEnd(object sender, EventArgs e)
|
|
{
|
|
if (_drawingAirplaneWithRadar is null)
|
|
return;
|
|
bool outOfRange = _drawingAirplaneWithRadar.SetPictureSize(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
|
|
if (outOfRange)
|
|
{
|
|
UpdatePlane();
|
|
}
|
|
}
|
|
|
|
private void FormAirplaneWithRadar_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|