123 lines
4.4 KiB
C#
123 lines
4.4 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 Airbus
|
||
{
|
||
public partial class FormAirplaneWithParam : Form
|
||
{
|
||
private DrawningAirplane airplane;
|
||
public DrawningAirplane SelectedAirplane { get; private set; }
|
||
private SetRandomPieceAirplane<EntityAirplane, IPorthole> allPieceAirplane;
|
||
public FormAirplaneWithParam()
|
||
{
|
||
allPieceAirplane = new(100, 100);
|
||
InitializeComponent();
|
||
}
|
||
|
||
private void Draw()
|
||
{
|
||
Bitmap bmp = new(pictureBox.Width, pictureBox.Height);
|
||
Graphics g = Graphics.FromImage(bmp);
|
||
airplane.DrawTransport(g);
|
||
pictureBox.Image = bmp;
|
||
}
|
||
private void SetData()
|
||
{
|
||
Random random = new Random();
|
||
airplane.SetPosition(random.Next(300, 400), random.Next(200, 300), pictureBox.Width, pictureBox.Height);
|
||
airplane.Upd_count_Porthole(count_porthole);
|
||
}
|
||
private void buttonCreate_Click(object sender, EventArgs e)
|
||
{
|
||
airplane = allPieceAirplane.Generate();
|
||
if (airplane == null)
|
||
{
|
||
MessageBox.Show("Не удалось сгенерировать самолет. Добавьте свойства для генерации"
|
||
, "Генерация самолета");
|
||
return;
|
||
}
|
||
airplane.Upd_count_Porthole(count_porthole);
|
||
SetData();
|
||
Draw();
|
||
}
|
||
|
||
private void ButtonMove_Click(object sender, EventArgs e)
|
||
{
|
||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||
switch (name)
|
||
{
|
||
case "buttonLeft":
|
||
Console.WriteLine("");
|
||
airplane?.MoveTransport(Direction.Left);
|
||
break;
|
||
case "buttonUp":
|
||
airplane?.MoveTransport(Direction.Up);
|
||
break;
|
||
case "buttonRight":
|
||
airplane?.MoveTransport(Direction.Right);
|
||
break;
|
||
case "buttonDown":
|
||
airplane?.MoveTransport(Direction.Down);
|
||
break;
|
||
}
|
||
Draw();
|
||
}
|
||
CountPorthole count_porthole = CountPorthole.Ten;
|
||
private void PictureBox_Resize(object sender, EventArgs e)
|
||
{
|
||
airplane?.ChangeBorders(pictureBox.Width, pictureBox.Height);
|
||
Draw();
|
||
}
|
||
private void buttonSelectAirplane_Click(object sender, EventArgs e)
|
||
{
|
||
SelectedAirplane = airplane;
|
||
DialogResult = DialogResult.OK;
|
||
}
|
||
|
||
private void buttonAddEntity_Click(object sender, EventArgs e)
|
||
{
|
||
Random rnd = new();
|
||
Color colorBody = Color.FromArgb(rnd.Next() % 256, rnd.Next() % 256, rnd.Next() % 256);
|
||
ColorDialog dialog = new();
|
||
if (dialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
colorBody = dialog.Color;
|
||
}
|
||
var entity = new EntityAirplane((int)numericSpeed.Value, (int)numericWieght.Value, colorBody);
|
||
allPieceAirplane.AddPiece(entity);
|
||
MessageBox.Show($"Добавлены свойства самолета:\n" +
|
||
$"Вес: {entity.Weight}\n" +
|
||
$"Скорость: {entity.Speed}\n" +
|
||
$"Цвет: {colorBody.Name}",
|
||
"Успешно добавлены свойства");
|
||
}
|
||
|
||
private void buttonAddPorthole_Click(object sender, EventArgs e)
|
||
{
|
||
IPorthole formPorthole = new DrawningPorthole();
|
||
string formname = "";
|
||
switch (comboBoxFormPorthole.Text)
|
||
{
|
||
case "Обычные":
|
||
formPorthole = new DrawningPorthole();
|
||
break;
|
||
case "Крадратные":
|
||
formPorthole = new DrawingSquarePorthole();
|
||
break;
|
||
case "Ромбом":
|
||
formPorthole = new DrawingRhombPorthole();
|
||
break;
|
||
}
|
||
allPieceAirplane.AddPiece(formPorthole);
|
||
MessageBox.Show($"Добавлена выбранная форма иллюминаторов");
|
||
}
|
||
}
|
||
}
|