Pibd-22_Presnyakova.V.V_Cat.../Catamaran/FormBoat.cs
2022-10-22 20:53:46 +04:00

69 lines
2.4 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 Catamaran
{
public partial class FormBoat : Form
{
private DrawingBoat _catamaran;
public FormBoat()
{
InitializeComponent();
}
private void Draw()
{
Bitmap bmp = new Bitmap(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
Graphics gr = Graphics.FromImage(bmp);
_catamaran?.DrawTransport(gr);
pictureBoxCatamaran.Image = bmp;
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new Random();
_catamaran = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_catamaran.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
toolStripStatusLabelSpeed.Text = $"Скорость: {_catamaran.Catamaran.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_catamaran.Catamaran.Weight}";
toolStripStatusLabelColor.Text = $"Цвет:{ _catamaran.Catamaran.BodyColor.Name}";
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();
}
}
}