PIbd-21_Valitov_D.F_Sailboa.../Sailboat/BoatForm.cs

99 lines
3.4 KiB
C#
Raw Permalink Normal View History

2023-03-17 19:30:05 +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 Sailboat
{
public partial class BoatForm : Form
{
2023-03-18 02:05:18 +04:00
private DrawingBoat _boat;
2023-03-17 19:30:05 +04:00
public BoatForm()
{
InitializeComponent();
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_create_Click(object sender, EventArgs e)
{
Random rnd = new();
2023-03-18 02:05:18 +04:00
_boat = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000),
2023-03-17 19:30:05 +04:00
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_boat.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
pictureBoxBoat.Width, pictureBoxBoat.Height);
2023-03-18 02:05:18 +04:00
SetData();
2023-03-17 19:30:05 +04:00
Draw();
}
/// <summary>
2023-03-18 02:05:18 +04:00
/// Обработка нажатия кнопки "Создать парусник"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_create_sailboat_Click(object sender, EventArgs e)
{
Random rnd = new();
_boat = new DrawingSailboat(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
_boat.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
pictureBoxBoat.Width, pictureBoxBoat.Height);
SetData();
Draw();
}
/// <summary>
/// Обработка нажатия стрелок
2023-03-17 19:30:05 +04:00
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_move_Click(object sender, EventArgs e)
{
//получаем имя кнопки
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "btn_up":
_boat?.MoveTransport(Direction.Up);
break;
case "btn_down":
_boat?.MoveTransport(Direction.Down);
break;
case "btn_left":
_boat?.MoveTransport(Direction.Left);
break;
case "btn_right":
_boat?.MoveTransport(Direction.Right);
break;
}
Draw();
}
/// <summary>
/// Метод прорисовки машины
/// </summary>
private void Draw()
{
Bitmap bmp = new(pictureBoxBoat.Width, pictureBoxBoat.Height);
Graphics gr = Graphics.FromImage(bmp);
_boat?.DrawTransport(gr);
pictureBoxBoat.Image = bmp;
}
2023-03-18 02:05:18 +04:00
/// <summary>
/// Метод прорисовки машины
/// </summary>
private void SetData()
{
Random rnd = new();
toolStripLabel_color.Text = $"Скорость: {_boat.Boat.Speed}";
toolStripLabel_weight.Text = $"Вес: {_boat.Boat.Weight}";
2023-04-13 16:43:46 +04:00
toolStripLabel_color.Text = $"Цвет: { _boat.Boat.BodyColor.Name}";
2023-03-18 02:05:18 +04:00
}
2023-03-17 19:30:05 +04:00
}
}