96 lines
3.0 KiB
C#
96 lines
3.0 KiB
C#
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 Tank
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
private DrawningTank? _drawningTank;
|
|
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
/// Метод прорисовки машины
|
|
/// </summary>
|
|
private void Draw()
|
|
{
|
|
if (_drawningTank == null)
|
|
{
|
|
return;
|
|
}
|
|
Bitmap bmp = new(pictureBox1.Width,
|
|
pictureBox1.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawningTank.DrawTransport(gr);
|
|
pictureBox1.Image = bmp;
|
|
}
|
|
/// <summary>
|
|
/// Обработка нажатия кнопки "Создать"
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ButtonCreateTank_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)));
|
|
_drawningTank.SetPictureSize(pictureBox1.Width,
|
|
pictureBox1.Height);
|
|
_drawningTank.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
Draw();
|
|
}
|
|
/// <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;
|
|
bool result = false;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
result = _drawningTank.MoveTransport(DirectionType.Up);
|
|
break;
|
|
case "buttonDown":
|
|
result = _drawningTank.MoveTransport(DirectionType.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
result = _drawningTank.MoveTransport(DirectionType.Left);
|
|
break;
|
|
case "buttonRight":
|
|
result = _drawningTank.MoveTransport(DirectionType.Right);
|
|
break;
|
|
}
|
|
if (result)
|
|
{
|
|
Draw();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|