101 lines
3.3 KiB
C#
101 lines
3.3 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 ProjectCruiser
|
|||
|
{
|
|||
|
public partial class FormCruiser : Form
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Поле-объект для прорисовки объекта
|
|||
|
/// </summary>
|
|||
|
private DrawningCruiser? _drawningCruiser;
|
|||
|
public FormCruiser()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Метод прорисовки машины
|
|||
|
/// </summary>
|
|||
|
private void Draw()
|
|||
|
{
|
|||
|
if (_drawningCruiser == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
Bitmap bmp = new(pictureBox1.Width,
|
|||
|
pictureBox1.Height);
|
|||
|
Graphics gr = Graphics.FromImage(bmp);
|
|||
|
_drawningCruiser.DrawTransport(gr);
|
|||
|
pictureBox1.Image = bmp;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Обработка нажатия кнопки "Создать"
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
private void ButtonCreateCruiser_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Random random = new();
|
|||
|
_drawningCruiser = new DrawningCruiser();
|
|||
|
_drawningCruiser.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)), Convert.ToBoolean(random.Next(0, 2)));
|
|||
|
_drawningCruiser.SetPictureSize(pictureBox1.Width,
|
|||
|
pictureBox1.Height);
|
|||
|
_drawningCruiser.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 (_drawningCruiser == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|||
|
bool result = false;
|
|||
|
switch (name)
|
|||
|
{
|
|||
|
case "buttonUp":
|
|||
|
result =
|
|||
|
_drawningCruiser.MoveTransport(DirectionType.Up);
|
|||
|
break;
|
|||
|
case "buttonDown":
|
|||
|
result =
|
|||
|
_drawningCruiser.MoveTransport(DirectionType.Down);
|
|||
|
break;
|
|||
|
case "buttonLeft":
|
|||
|
result =
|
|||
|
_drawningCruiser.MoveTransport(DirectionType.Left);
|
|||
|
break;
|
|||
|
case "buttonRight":
|
|||
|
result =
|
|||
|
_drawningCruiser.MoveTransport(DirectionType.Right);
|
|||
|
break;
|
|||
|
}
|
|||
|
if (result)
|
|||
|
{
|
|||
|
Draw();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|