PIbd-21_Valitov_D.F_Sailboa.../Sailboat/BoatForm.cs
2023-04-13 16:43:46 +04:00

99 lines
3.4 KiB
C#
Raw Permalink 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 Sailboat
{
public partial class BoatForm : Form
{
private DrawingBoat _boat;
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();
_boat = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000),
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);
SetData();
Draw();
}
/// <summary>
/// Обработка нажатия кнопки "Создать парусник"
/// </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>
/// Обработка нажатия стрелок
/// </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;
}
/// <summary>
/// Метод прорисовки машины
/// </summary>
private void SetData()
{
Random rnd = new();
toolStripLabel_color.Text = $"Скорость: {_boat.Boat.Speed}";
toolStripLabel_weight.Text = $"Вес: {_boat.Boat.Weight}";
toolStripLabel_color.Text = $"Цвет: { _boat.Boat.BodyColor.Name}";
}
}
}