90 lines
2.9 KiB
C#
90 lines
2.9 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 OceanForm1 : Form
|
|
{
|
|
// Поле-объект для прорисовки объекта
|
|
private DrawningBase? _drawningCruiser;
|
|
|
|
public OceanForm1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
// Метод прорисовки transport
|
|
private void Draw()
|
|
{
|
|
if (_drawningCruiser == null)
|
|
{
|
|
return;
|
|
}
|
|
Bitmap bmp = new(pictureBoxCr.Width,
|
|
pictureBoxCr.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawningCruiser.DrawTransport(gr);
|
|
pictureBoxCr.Image = bmp;
|
|
}
|
|
|
|
// Обработка нажатия кнопки "Create"
|
|
private void ButtonCreateBase_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
_drawningCruiser = new DrawningBase();
|
|
|
|
_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(pictureBoxCr.Width, pictureBoxCr.Height);
|
|
_drawningCruiser.SetPosition(random.Next(10, 100),
|
|
pictureBoxCr.Height - random.Next(10, 100) - _drawningCruiser.getHeight());
|
|
Draw();
|
|
}
|
|
|
|
|
|
private void BtnMove_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawningCruiser == null)
|
|
{
|
|
return;
|
|
}
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
bool result = false;
|
|
switch (name)
|
|
{
|
|
case "btnUpArrow":
|
|
result =
|
|
_drawningCruiser.MoveTransport(DirectionType.Up);
|
|
break;
|
|
case "btnDownArrow":
|
|
result =
|
|
_drawningCruiser.MoveTransport(DirectionType.Down);
|
|
break;
|
|
case "btnLeftArrow":
|
|
result =
|
|
_drawningCruiser.MoveTransport(DirectionType.Left);
|
|
break;
|
|
case "btnRightArrow":
|
|
result =
|
|
_drawningCruiser.MoveTransport(DirectionType.Right);
|
|
break;
|
|
}
|
|
if (result)
|
|
{
|
|
Draw();
|
|
}
|
|
}
|
|
}
|
|
}
|