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

78 lines
2.6 KiB
C#
Raw Permalink 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
{
public partial class CatamaranForm : Form
{
private DrawingCatamaran _catamaran;
public CatamaranForm()
{
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 CatamaranForm_Load(object sender, EventArgs e)
{
}
private void toolStripStatusLabel3_Click(object sender, EventArgs e)
{
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new Random();
_catamaran = new DrawingCatamaran();
_catamaran.Init(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();
}
}
}