123 lines
4.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 Airbus
{
public partial class Form1 : Form
{
private DrawningAirbus _airbus;
//выбранный объект
public DrawningAirbus SelectedPlane { get; set; }
public Form1()
{
InitializeComponent();
}
//метод прорисовки самолёта
private void Draw()
{
Bitmap bmp = new(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
Graphics gr = Graphics.FromImage(bmp);
_airbus?.DrawTransport(gr);
pictureBoxAirbus.Image = bmp;
}
//метод установки данных
private void SetData()
{
Random rnd = new();
toolStripStatusLabelSpeed.Text = $"Скорость: {_airbus.Airbus?.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_airbus.Airbus?.Weight}";
toolStripStatusLabelCorpusColor.Text = $"Цвет: {_airbus.Airbus?.CorpusColor.Name}";
_airbus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirbus.Width, pictureBoxAirbus.Height);
}
//обработка нажатия кнопки "Создать"
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_airbus = new DrawningAirbus(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData();
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
//Получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_airbus?.MoveTransport(Direction.Up);
break;
case "buttonDown":
_airbus?.MoveTransport(Direction.Down);
break;
case "buttonLeft":
_airbus?.MoveTransport(Direction.Left);
break;
case "buttonRight":
_airbus?.MoveTransport(Direction.Right);
break;
}
Draw();
}
//изменение размеров формы
private void PictureBoxCar_Resize(object sender, EventArgs e)
{
_airbus?.ChangeBorders(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
Draw();
}
//обработка нажития кнопки "Модификация"
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if(dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color addColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialogAdd = new();
if(dialogAdd.ShowDialog() == DialogResult.OK)
{
addColor = dialogAdd.Color;
}
_airbus = new DrawningSuperAirbus(rnd.Next(100, 300), rnd.Next(1000, 2000), color, addColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
private void buttonSelectPlane_Click(object sender, EventArgs e)
{
SelectedPlane = _airbus;
DialogResult = DialogResult.OK;
}
}
}