121 lines
4.0 KiB
C#
121 lines
4.0 KiB
C#
using ProjectBulldozer;
|
|
using ProjectBulldozer.Drawings;
|
|
using ProjectBulldozer.Generics;
|
|
using ProjectBulldozer.MovementStrategy;
|
|
using System;
|
|
|
|
namespace Bulldozer
|
|
{
|
|
public partial class Bulldozer : Form
|
|
{
|
|
|
|
private DrawingTractor? _drawingTractor;
|
|
|
|
private AbstractStrategy? _abstractStrategy;
|
|
|
|
public Bulldozer()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Draw()
|
|
{
|
|
if (_drawingTractor == null)
|
|
{
|
|
return;
|
|
}
|
|
Bitmap bmp = new(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawingTractor.DrawTransport(gr);
|
|
pictureBoxBulldozer.Image = bmp;
|
|
}
|
|
|
|
private void buttonCreateBulldozer_Click(object sender, EventArgs e)
|
|
{
|
|
Random random = new Random();
|
|
_drawingTractor = new DrawingBulldozer(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)),
|
|
pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
|
_drawingTractor.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
|
Draw();
|
|
}
|
|
|
|
private void buttonCreateTractor_Click(object sender, EventArgs e)
|
|
{
|
|
Random rnd = new Random();
|
|
_drawingTractor = new DrawingTractor(rnd.Next(100, 300), rnd.Next(1000, 3000),
|
|
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
|
pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
|
|
_drawingTractor.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
|
|
Draw();
|
|
}
|
|
|
|
private void buttonMove_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawingTractor == null)
|
|
{
|
|
return;
|
|
}
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
_drawingTractor.MoveTransport(DirectionType.Up);
|
|
break;
|
|
case "buttonDown":
|
|
_drawingTractor.MoveTransport(DirectionType.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
_drawingTractor.MoveTransport(DirectionType.Left);
|
|
break;
|
|
case "buttonRight":
|
|
_drawingTractor.MoveTransport(DirectionType.Right);
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
|
|
private void buttonStep_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawingTractor == null)
|
|
{
|
|
return;
|
|
}
|
|
if (comboBoxStrategy.Enabled)
|
|
{
|
|
_abstractStrategy = comboBoxStrategy.SelectedIndex switch
|
|
{
|
|
0 => new MoveToCenter(),
|
|
1 => new MoveToRightCorner(),
|
|
_ => null,
|
|
};
|
|
if (_abstractStrategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_abstractStrategy.SetData(new
|
|
DrawingObjectTractor(_drawingTractor), pictureBoxBulldozer.Width,
|
|
pictureBoxBulldozer.Height);
|
|
comboBoxStrategy.Enabled = false;
|
|
}
|
|
if (_abstractStrategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_abstractStrategy.MakeStep();
|
|
Draw();
|
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
|
{
|
|
comboBoxStrategy.Enabled = true;
|
|
_abstractStrategy = null;
|
|
}
|
|
}
|
|
|
|
private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
} |