Pibd-22_Presnyakova.V.V_Cat.../Catamaran/FormBoat.cs

112 lines
4.0 KiB
C#
Raw Normal View History

2022-09-25 11:25:29 +04:00
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 Catamaran
{
2022-10-01 20:41:57 +04:00
public partial class FormBoat : Form
2022-09-25 11:25:29 +04:00
{
2022-10-01 20:41:57 +04:00
private DrawingBoat _catamaran;
2022-11-06 23:24:34 +04:00
public DrawingBoat SelectedBoat { get; private set; }
2022-10-01 20:41:57 +04:00
public FormBoat()
2022-09-25 11:25:29 +04:00
{
InitializeComponent();
}
private void Draw()
{
Bitmap bmp = new Bitmap(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
Graphics gr = Graphics.FromImage(bmp);
_catamaran?.DrawTransport(gr);
pictureBoxCatamaran.Image = bmp;
}
2022-11-06 23:24:34 +04:00
private void SetData()
2022-09-25 11:25:29 +04:00
{
Random rnd = new Random();
_catamaran.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
toolStripStatusLabelSpeed.Text = $"Скорость: {_catamaran.Catamaran.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_catamaran.Catamaran.Weight}";
2022-11-06 23:24:34 +04:00
toolStripStatusLabelColor.Text = $"Цвет: { _catamaran.Catamaran.BodyColor.Name}";
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new Random();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new ColorDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_catamaran = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData();
2022-09-25 11:25:29 +04:00
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
{
//получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_catamaran?.MoveTransport(Direction.Up);
break;
case "buttonDown":
_catamaran?.MoveTransport(Direction.Down);
break;
case "buttonLeft":
_catamaran?.MoveTransport(Direction.Left);
break;
case "buttonRight":
_catamaran?.MoveTransport(Direction.Right);
break;
}
Draw();
}
private void PictureBoxCatamaran_Resize(object sender, EventArgs e)
{
_catamaran?.ChangeBorders(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
Draw();
}
2022-11-06 23:24:34 +04:00
private void buttonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new Random();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new ColorDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),
rnd.Next(0, 256));
ColorDialog dialogDop = new ColorDialog();
if (dialogDop.ShowDialog() == DialogResult.OK)
{
dopColor = dialogDop.Color;
}
_catamaran = new DrawingCatamaran(rnd.Next(100, 300), rnd.Next(1000, 2000),
color, dopColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
/// <summary>
/// Обработка нажатия кнопки "Выбрать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSelectBoat_Click(object sender, EventArgs e)
{
SelectedBoat = _catamaran;
DialogResult = DialogResult.OK;
}
2022-09-25 11:25:29 +04:00
}
}