2023-09-25 11:15:05 +04:00
|
|
|
|
using System;
|
2023-09-25 14:09:42 +04:00
|
|
|
|
using Cruiser.Drawing;
|
|
|
|
|
using Cruiser.Entities;
|
|
|
|
|
using Cruiser.MovementStrategy;
|
2023-09-25 11:15:05 +04:00
|
|
|
|
|
|
|
|
|
namespace Cruiser
|
|
|
|
|
{
|
|
|
|
|
public partial class FormCruiser : Form
|
|
|
|
|
{
|
|
|
|
|
Bitmap bmp;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
private DrawingCruiser? _drawningCruiser;
|
|
|
|
|
/// <summary>
|
2023-09-25 14:09:42 +04:00
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
private AbstractStrategy? _abstractStrategy;
|
2023-10-21 14:10:32 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public DrawingCruiser? SelectedCruiser { get; private set; }
|
|
|
|
|
|
2023-09-25 14:09:42 +04:00
|
|
|
|
/// <summary>
|
2023-09-25 11:15:05 +04:00
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormCruiser()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
bmp = new(pictureBoxCruiser.Width, pictureBoxCruiser.Width);
|
2023-10-21 14:10:32 +04:00
|
|
|
|
_abstractStrategy = null;
|
|
|
|
|
SelectedCruiser = null;
|
2023-09-25 11:15:05 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void Draw()
|
|
|
|
|
{
|
|
|
|
|
if (_drawningCruiser == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
|
gr.Clear(Color.White);
|
|
|
|
|
_drawningCruiser.DrawTransport(gr);
|
|
|
|
|
pictureBoxCruiser.Image = bmp;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-25 14:09:42 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2023-09-25 11:15:05 +04:00
|
|
|
|
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();
|
|
|
|
|
}
|
2023-09-25 14:09:42 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "<22><><EFBFBD>"
|
|
|
|
|
/// </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();
|
2023-10-21 14:10:32 +04:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-25 14:09:42 +04:00
|
|
|
|
_drawningCruiser = new DrawingCruiser(random.Next(100, 300),
|
|
|
|
|
random.Next(1000, 3000),
|
2023-10-21 14:10:32 +04:00
|
|
|
|
colorFirst,
|
2023-09-25 14:09:42 +04:00
|
|
|
|
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)
|
2023-09-25 11:15:05 +04:00
|
|
|
|
{
|
|
|
|
|
Random random = new();
|
2023-10-21 14:10:32 +04:00
|
|
|
|
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;
|
|
|
|
|
}
|
2023-09-25 14:09:42 +04:00
|
|
|
|
_drawningCruiser = new DrawingProCruiser(random.Next(100, 300),
|
2023-09-25 11:15:05 +04:00
|
|
|
|
random.Next(1000, 3000),
|
2023-10-21 14:10:32 +04:00
|
|
|
|
colorFirst,
|
|
|
|
|
colorSecond,
|
2023-09-25 11:15:05 +04:00
|
|
|
|
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
2023-09-25 14:09:42 +04:00
|
|
|
|
Convert.ToBoolean(random.Next(1, 2)),
|
|
|
|
|
Convert.ToBoolean(random.Next(1, 2)),
|
2023-09-25 11:15:05 +04:00
|
|
|
|
pictureBoxCruiser.Width,
|
|
|
|
|
pictureBoxCruiser.Height);
|
|
|
|
|
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
2023-10-21 14:10:32 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
/// </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)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2023-09-25 11:15:05 +04:00
|
|
|
|
}
|
|
|
|
|
}
|