PIbd-21_Krasnikov_Lab1.base/WinFormsApp1/FormTractor.cs
2022-11-14 21:25:33 +04:00

94 lines
2.9 KiB
C#
Raw Permalink 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 WinFormsApp1
{
public partial class FormTractor : Form
{
private TractorDraw _Tractor;
public FormTractor()
{
InitializeComponent();
}
private void Draw()
{
Bitmap bmp = new Bitmap(pictureBoxTractor.Width, pictureBoxTractor.Height);
Graphics gr = Graphics.FromImage(bmp);
_Tractor?.DrawEntity(gr);
pictureBoxTractor.Image = bmp;
}
private void SetData()
{
Random random = new();
_Tractor.SetPosition(random.Next(10, 50), random.Next(10, 50), pictureBoxTractor.Width, pictureBoxTractor.Height);
toolStripStatusLabelSpeed.Text = $"Скорость: {_Tractor.Tractor.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_Tractor.Tractor.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет кузова: {_Tractor.Tractor.BodyColor.Name}";
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random random = new Random();
_Tractor = new TractorDraw(random.Next(100, 200), random.Next(2500, 5000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
SetData();
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_Tractor?.MoveTransport(Direction.Up);
break;
case "buttonDown":
_Tractor?.MoveTransport(Direction.Down);
break;
case "buttonLeft":
_Tractor?.MoveTransport(Direction.Left);
break;
case "buttonRight":
_Tractor?.MoveTransport(Direction.Right);
break;
}
Draw();
}
private void pictureBoxTractor_Resize(object sender, EventArgs e)
{
_Tractor?.ChangeBorders(pictureBoxTractor.Width, pictureBoxTractor.Height);
Draw();
}
private void buttonCreateModif_Click(object sender, EventArgs e)
{
Random random = new Random();
_Tractor = new MultiTraktorDraw(random.Next(100, 200), random.Next(2500, 5000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
SetData();
Draw();
}
}
}