185 lines
6.0 KiB
C#
185 lines
6.0 KiB
C#
using System;
|
|
using Cruiser.Drawing;
|
|
using Cruiser.Entities;
|
|
using Cruiser.MovementStrategy;
|
|
|
|
namespace Cruiser
|
|
{
|
|
public partial class FormCruiser : Form
|
|
{
|
|
Bitmap bmp;
|
|
/// <summary>
|
|
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
|
/// </summary>
|
|
private DrawingCruiser? _drawningCruiser;
|
|
/// <summary>
|
|
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
|
/// </summary>
|
|
private AbstractStrategy? _abstractStrategy;
|
|
/// <summary>
|
|
/// Âûáðàííûé ëàéíåð
|
|
/// </summary>
|
|
public DrawingCruiser? SelectedCruiser { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Èíèöèàëèçàöèÿ ôîðìû
|
|
/// </summary>
|
|
public FormCruiser()
|
|
{
|
|
InitializeComponent();
|
|
bmp = new(pictureBoxCruiser.Width, pictureBoxCruiser.Width);
|
|
_abstractStrategy = null;
|
|
SelectedCruiser = null;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Ìåòîä ïðîðèñîâêè êðåéñåðà
|
|
/// </summary>
|
|
private void Draw()
|
|
{
|
|
if (_drawningCruiser == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
gr.Clear(Color.White);
|
|
_drawningCruiser.DrawTransport(gr);
|
|
pictureBoxCruiser.Image = bmp;
|
|
|
|
}
|
|
|
|
/// <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;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
_drawningCruiser.MoveTransport(Direction.Up);
|
|
break;
|
|
case "buttonDown":
|
|
_drawningCruiser.MoveTransport(Direction.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
_drawningCruiser.MoveTransport(Direction.Left);
|
|
break;
|
|
case "buttonRight":
|
|
_drawningCruiser.MoveTransport(Direction.Right);
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
/// <summary>
|
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ButtonStep_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawningCruiser == null)
|
|
{
|
|
return;
|
|
}
|
|
if (comboBoxStrategy.Enabled)
|
|
{
|
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
|
switch
|
|
{
|
|
0 => new MoveToCenter(),
|
|
1 => new MoveToBorder(),
|
|
_ => null,
|
|
};
|
|
if (_abstractStrategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_abstractStrategy.SetData(new
|
|
DrawningObjectCar(_drawningCruiser), pictureBoxCruiser.Width,
|
|
pictureBoxCruiser.Height);
|
|
comboBoxStrategy.Enabled = false;
|
|
}
|
|
if (_abstractStrategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_abstractStrategy.MakeStep();
|
|
Draw();
|
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
|
{
|
|
comboBoxStrategy.Enabled = true;
|
|
_abstractStrategy = null;
|
|
}
|
|
}
|
|
private void buttonCreateLiner_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
Color colorFirst = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
ColorDialog dialog = new();
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
colorFirst = dialog.Color;
|
|
}
|
|
|
|
_drawningCruiser = new DrawingCruiser(random.Next(100, 300),
|
|
random.Next(1000, 3000),
|
|
colorFirst,
|
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
pictureBoxCruiser.Width,
|
|
pictureBoxCruiser.Height);
|
|
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
Draw();
|
|
}
|
|
|
|
private void buttonCreateProLiner_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
Color colorFirst = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
ColorDialog dialog = new();
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
colorFirst = dialog.Color;
|
|
}
|
|
Color colorSecond = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
colorSecond = dialog.Color;
|
|
}
|
|
_drawningCruiser = new DrawingProCruiser(random.Next(100, 300),
|
|
random.Next(1000, 3000),
|
|
colorFirst,
|
|
colorSecond,
|
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
|
Convert.ToBoolean(random.Next(1, 2)),
|
|
Convert.ToBoolean(random.Next(1, 2)),
|
|
pictureBoxCruiser.Width,
|
|
pictureBoxCruiser.Height);
|
|
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
Draw();
|
|
}
|
|
/// <summary>
|
|
/// Âûáîð ëàéíåð
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void ButtonSelectCruiser_Click(object sender, EventArgs e)
|
|
{
|
|
SelectedCruiser = _drawningCruiser;
|
|
DialogResult = DialogResult.OK;
|
|
}
|
|
|
|
private void FormCruiser_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
} |