PIbd-23-Mamadosimov-Z-Sh-Se.../Lab1/SelfPropelledArtilleryUnit/Form1.cs

118 lines
3.2 KiB
C#
Raw Normal View History

2023-10-13 10:51:06 +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;
using SelfPropelledArtilleryUnit;
namespace SelfPropelledArtilleryUnit
{
public partial class FormTank : Form
{
// <summary>
/// Поле-объект для прорисовки объекта
/// </summary>
private DrawningTank? _drawningTank;
public FormTank()
{
InitializeComponent();
}
/// <summary>
/// Метод прорисовки машины
/// </summary>
private void Draw()
{
if (_drawningTank == null)
{
return;
}
Bitmap bmp = new(pictureboxTankk.Width, pictureboxTankk.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningTank.DrawTransport(gr);
pictureboxTankk.Image = bmp;
}
/// <summary>
/// Изменение размеров формы
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningTank == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawningTank.MoveTransport(Direction.Up);
break;
case "buttonDown":
_drawningTank.MoveTransport(Direction.Down);
break;
case "buttonLeft":
_drawningTank.MoveTransport(Direction.Left);
break;
case "buttonRight":
_drawningTank.MoveTransport(Direction.Right);
break;
}
Draw();
}
private void buttonUp_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawningTank = new DrawningTank();
_drawningTank.Init(random.Next(100, 300),
random.Next(1000, 3000),
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)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureboxTankk.Width, pictureboxTankk.Height);
_drawningTank.SetPosition(random.Next(10, 100),
random.Next(10, 100));
Draw();
}
private void pictureBox1_Click_1(object sender, EventArgs e)
{
}
}
}