2023-10-11 09:42:48 +04:00
|
|
|
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;
|
|
|
|
using Hydroplane.Entities;
|
|
|
|
using Hydroplane.DrawningObjects;
|
|
|
|
using Hydroplane.MovementStrategy;
|
|
|
|
|
2023-09-22 18:54:14 +04:00
|
|
|
namespace Hydroplane
|
|
|
|
{
|
2023-09-23 12:02:28 +04:00
|
|
|
public partial class FormHydroplane : Form
|
2023-09-22 18:54:14 +04:00
|
|
|
{
|
2023-10-11 09:42:48 +04:00
|
|
|
private DrawningPlane? _drawingPlane;
|
|
|
|
private AbstractStrategy? _abstractStrategy;
|
2023-09-23 12:02:28 +04:00
|
|
|
public FormHydroplane()
|
2023-09-22 18:54:14 +04:00
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
}
|
2023-09-22 21:05:01 +04:00
|
|
|
private void Draw()
|
|
|
|
{
|
2023-10-11 09:42:48 +04:00
|
|
|
if (_drawingPlane == null)
|
2023-09-22 21:05:01 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Bitmap bmp = new(pictureBoxHydroplane.Width,
|
|
|
|
pictureBoxHydroplane.Height);
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
2023-10-11 09:42:48 +04:00
|
|
|
_drawingPlane.DrawTransport(gr);
|
2023-09-22 21:05:01 +04:00
|
|
|
pictureBoxHydroplane.Image = bmp;
|
|
|
|
}
|
2023-10-11 09:42:48 +04:00
|
|
|
private void buttonCreatePlane_Click(object sender, EventArgs e)
|
2023-09-22 21:05:01 +04:00
|
|
|
{
|
|
|
|
Random random = new();
|
2023-10-11 09:42:48 +04:00
|
|
|
_drawingPlane = new DrawningPlane(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), pictureBoxHydroplane.Width, pictureBoxHydroplane.Height);
|
|
|
|
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10,
|
|
|
|
100));
|
|
|
|
Draw();
|
|
|
|
}
|
|
|
|
private void buttonCreateHydroplane_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
Random random = new();
|
|
|
|
_drawingPlane = new DrawningHydroplane(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)), pictureBoxHydroplane.Width, pictureBoxHydroplane.Height);
|
|
|
|
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
2023-09-22 21:05:01 +04:00
|
|
|
Draw();
|
|
|
|
}
|
|
|
|
private void buttonMove_Click(object sender, EventArgs e)
|
|
|
|
{
|
2023-10-11 09:42:48 +04:00
|
|
|
if (_drawingPlane == null)
|
2023-09-22 21:05:01 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
|
|
switch (name)
|
|
|
|
{
|
|
|
|
case "buttonUp":
|
2023-10-11 09:42:48 +04:00
|
|
|
_drawingPlane.MoveTransport(DirectionType.Up);
|
2023-09-22 21:05:01 +04:00
|
|
|
break;
|
|
|
|
case "buttonDown":
|
2023-10-11 09:42:48 +04:00
|
|
|
_drawingPlane.MoveTransport(DirectionType.Down);
|
2023-09-22 21:05:01 +04:00
|
|
|
break;
|
|
|
|
case "buttonLeft":
|
2023-10-11 09:42:48 +04:00
|
|
|
_drawingPlane.MoveTransport(DirectionType.Left);
|
2023-09-22 21:05:01 +04:00
|
|
|
break;
|
|
|
|
case "buttonRight":
|
2023-10-11 09:42:48 +04:00
|
|
|
_drawingPlane.MoveTransport(DirectionType.Right);
|
2023-09-22 21:05:01 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
Draw();
|
|
|
|
}
|
2023-10-11 09:42:48 +04:00
|
|
|
|
|
|
|
private void buttonStep_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (_drawingPlane == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (comboBoxStrategy.Enabled)
|
|
|
|
{
|
|
|
|
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
|
|
|
switch
|
|
|
|
{
|
|
|
|
0 => new MoveToCenter(),
|
|
|
|
1 => new MoveToBorder(),
|
|
|
|
_ => null,
|
|
|
|
};
|
|
|
|
if (_abstractStrategy == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_abstractStrategy.SetData(new DrawningObjectPlane(_drawingPlane), pictureBoxHydroplane.Width,
|
|
|
|
pictureBoxHydroplane.Height);
|
|
|
|
comboBoxStrategy.Enabled = false;
|
|
|
|
}
|
|
|
|
if (_abstractStrategy == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_abstractStrategy.MakeStep();
|
|
|
|
Draw();
|
|
|
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
|
|
|
{
|
|
|
|
comboBoxStrategy.Enabled = true;
|
|
|
|
_abstractStrategy = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-22 18:54:14 +04:00
|
|
|
}
|
|
|
|
}
|