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

69 lines
2.4 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;
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-10-22 20:53:46 +04:00
2022-09-25 11:25:29 +04:00
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new Random();
2022-10-01 20:41:57 +04:00
_catamaran = new DrawingBoat(rnd.Next(100, 300), rnd.Next(1000, 2000),
2022-09-25 11:25:29 +04:00
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();
}
}
}