80 lines
2.5 KiB
C#
Raw Normal View History

2022-09-20 10:04:55 +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 PIbd_21_Potapov_N.S._Catamaran_Base
{
public partial class FormBoat : System.Windows.Forms.Form
2022-09-20 10:04:55 +04:00
{
DrawingBoat boatDrawObj;
2022-09-20 10:04:55 +04:00
public FormBoat()
2022-09-20 10:04:55 +04:00
{
InitializeComponent();
pictureBox.Image = new Bitmap(pictureBox.Width, pictureBox.Height);
}
private void btn_new_Click(object sender, EventArgs e)
{
2022-10-12 12:40:12 +04:00
Random rnd = new Random();
2022-09-20 10:04:55 +04:00
boatDrawObj = new DrawingBoat();
boatDrawObj.Init(rnd.Next(50, 100), rnd.Next(50, 100), Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)));
boatDrawObj.SetPosition(rnd.Next(10, 50), rnd.Next(10, 50), pictureBox.Width, pictureBox.Height - statusStrip.Height);
toolStripStatusLabelSpeed.Text = $"Скорость: {boatDrawObj.Boat.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {boatDrawObj.Boat.Weight}";
toolStripStatusLabelColor.Text = $"Цвет: {boatDrawObj.Boat.BodyColor.Name}";
2022-09-20 10:04:55 +04:00
RedrawCatamaran();
}
private void btn_move_Click(object sender, EventArgs e)
{
if (boatDrawObj == null)
2022-09-20 10:04:55 +04:00
return;
string btnName = ((Button)sender).Name;
switch (btnName)
{
case "btn_up":
{
boatDrawObj.MoveTransport(Direction.Up);
2022-09-20 10:04:55 +04:00
}
break;
case "btn_down":
{
boatDrawObj.MoveTransport(Direction.Down);
2022-09-20 10:04:55 +04:00
}
break;
case "btn_left":
{
boatDrawObj.MoveTransport(Direction.Left);
2022-09-20 10:04:55 +04:00
}
break;
case "btn_right":
{
boatDrawObj.MoveTransport(Direction.Right);
2022-09-20 10:04:55 +04:00
}
break;
default:
break;
}
RedrawCatamaran();
}
private void RedrawCatamaran()
{
Graphics g = Graphics.FromImage(pictureBox.Image);
g.Clear(Color.White);
boatDrawObj.DrawTransport(g);
2022-09-20 10:04:55 +04:00
pictureBox.Invalidate();
}
}
}