192 lines
7.0 KiB
C#
192 lines
7.0 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
using WarmlyLocomotive.DrawningObjects;
|
|
|
|
using WarmlyLocomotive.MovementStrategy;
|
|
|
|
namespace WarmlyLocomotive
|
|
{
|
|
/// <summary>
|
|
/// Ôîðìà ðàáîòû ñ îáúåêòîì "Òåïëîâîç ñ òðóáîé è ïðèöåïîì"
|
|
/// </summary>
|
|
public partial class WarmlyLocomotiveForm : Form
|
|
{
|
|
private DrawningWarmlyLocomotive? _drawningWarmlyLocomotive;
|
|
private AbstractStrategy? _strategy;
|
|
public DrawningWarmlyLocomotive? SelectedWarmlyLocomotive { get; private set; }
|
|
public WarmlyLocomotiveForm()
|
|
{
|
|
InitializeComponent();
|
|
_strategy = null;
|
|
SelectedWarmlyLocomotive = null;
|
|
}
|
|
/// <summary>
|
|
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
|
/// </summary>
|
|
private void Draw()
|
|
{
|
|
if (_drawningWarmlyLocomotive == null)
|
|
{
|
|
return;
|
|
}
|
|
Bitmap bmp = new(pictureBoxWarmlyLocomotive.Width,
|
|
pictureBoxWarmlyLocomotive.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawningWarmlyLocomotive.DrawTransport(gr);
|
|
pictureBoxWarmlyLocomotive.Image = bmp;
|
|
}
|
|
/// <summary>
|
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü òåïëîâîç"
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
|
|
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
ColorDialog dialog = new();
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
color = dialog.Color;
|
|
}
|
|
_drawningWarmlyLocomotive = new DrawningWarmlyLocomotive(random.Next(100, 300),
|
|
random.Next(1000, 3000),
|
|
color,
|
|
pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
|
|
_drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10,
|
|
100));
|
|
Draw();
|
|
}
|
|
private void buttonMove_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
if (_drawningWarmlyLocomotive == null)
|
|
{
|
|
return;
|
|
}
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
_drawningWarmlyLocomotive.MoveTransport(Direction.Up);
|
|
break;
|
|
case "buttonDown":
|
|
_drawningWarmlyLocomotive.MoveTransport(Direction.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
_drawningWarmlyLocomotive.MoveTransport(Direction.Left);
|
|
break;
|
|
case "buttonRight":
|
|
_drawningWarmlyLocomotive.MoveTransport(Direction.Right);
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
/// <summary>
|
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void buttonStep_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawningWarmlyLocomotive == null)
|
|
{
|
|
return;
|
|
}
|
|
if (comboBoxWarmlyLocomotive.Enabled)
|
|
{
|
|
_strategy = comboBoxWarmlyLocomotive.SelectedIndex
|
|
switch
|
|
{
|
|
0 => new MoveToCenter(),
|
|
1 => new MoveToBorder(),
|
|
_ => null,
|
|
};
|
|
if (_strategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_strategy.SetData(new
|
|
DrawningObjectWarmlyLocomotive(_drawningWarmlyLocomotive), pictureBoxWarmlyLocomotive.Width,
|
|
pictureBoxWarmlyLocomotive.Height);
|
|
comboBoxWarmlyLocomotive.Enabled = false;
|
|
}
|
|
if (_strategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_strategy.MakeStep();
|
|
Draw();
|
|
if (_strategy.GetStatus() == Status.Finish)
|
|
{
|
|
comboBoxWarmlyLocomotive.Enabled = true;
|
|
_strategy = null;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü ïðîäâèíóòûé òåïëîâîç"
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void buttonCreate_WarmlyLocomotivePro_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
ColorDialog dialog = new();
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
color = dialog.Color;
|
|
}
|
|
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
ColorDialog dopDialog = new();
|
|
if (dopDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
dopColor = dopDialog.Color;
|
|
}
|
|
_drawningWarmlyLocomotive = new DrawningWarmlyLocomotiveWithTrumpet(random.Next(100, 300),
|
|
random.Next(1000, 3000),
|
|
color,
|
|
dopColor,
|
|
Convert.ToBoolean(random.Next(0, 2)),
|
|
Convert.ToBoolean(random.Next(0, 2)),
|
|
pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
|
|
_drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10,
|
|
100));
|
|
Draw();
|
|
}
|
|
private void buttonSelectWarmlyLocomotive_Click(object sender, EventArgs e)
|
|
{
|
|
SelectedWarmlyLocomotive = _drawningWarmlyLocomotive;
|
|
DialogResult = DialogResult.OK;
|
|
}
|
|
private void buttonCreate_Pro_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new();
|
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
ColorDialog dialog = new();
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
color = dialog.Color;
|
|
}
|
|
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
ColorDialog dopDialog = new();
|
|
if (dopDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
dopColor = dopDialog.Color;
|
|
}
|
|
_drawningWarmlyLocomotive = new DrawningWarmlyLocomotiveWithTrumpet(random.Next(100, 300),
|
|
random.Next(1000, 3000),
|
|
color,
|
|
dopColor,
|
|
Convert.ToBoolean(random.Next(0, 2)),
|
|
Convert.ToBoolean(random.Next(0, 2)),
|
|
pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
|
|
_drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10,
|
|
100));
|
|
Draw();
|
|
}
|
|
}
|
|
}
|