80 lines
2.5 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 PIbd_21_Potapov_N.S._Catamaran_Base
{
public partial class FormBoat : System.Windows.Forms.Form
{
DrawingBoat boatDrawObj;
public FormBoat()
{
InitializeComponent();
pictureBox.Image = new Bitmap(pictureBox.Width, pictureBox.Height);
}
private void btn_new_Click(object sender, EventArgs e)
{
Random rnd = new Random();
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}";
RedrawCatamaran();
}
private void btn_move_Click(object sender, EventArgs e)
{
if (boatDrawObj == null)
return;
string btnName = ((Button)sender).Name;
switch (btnName)
{
case "btn_up":
{
boatDrawObj.MoveTransport(Direction.Up);
}
break;
case "btn_down":
{
boatDrawObj.MoveTransport(Direction.Down);
}
break;
case "btn_left":
{
boatDrawObj.MoveTransport(Direction.Left);
}
break;
case "btn_right":
{
boatDrawObj.MoveTransport(Direction.Right);
}
break;
default:
break;
}
RedrawCatamaran();
}
private void RedrawCatamaran()
{
Graphics g = Graphics.FromImage(pictureBox.Image);
g.Clear(Color.White);
boatDrawObj.DrawTransport(g);
pictureBox.Invalidate();
}
}
}