141 lines
4.8 KiB
C#
141 lines
4.8 KiB
C#
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;
|
|
|
|
namespace Hydroplane
|
|
{
|
|
public partial class FormHydroplane : Form
|
|
{
|
|
private DrawningPlane? _drawingPlane;
|
|
private AbstractStrategy? _abstractStrategy;
|
|
public DrawningPlane? SelectedPlane { get; private set; }
|
|
|
|
public FormHydroplane()
|
|
{
|
|
InitializeComponent();
|
|
_abstractStrategy = null;
|
|
SelectedPlane = null;
|
|
}
|
|
private void Draw()
|
|
{
|
|
if (_drawingPlane == null)
|
|
{
|
|
return;
|
|
}
|
|
Bitmap bmp = new(pictureBoxHydroplane.Width,
|
|
pictureBoxHydroplane.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawingPlane.DrawTransport(gr);
|
|
pictureBoxHydroplane.Image = bmp;
|
|
}
|
|
private void buttonCreatePlane_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;
|
|
}
|
|
_drawingPlane = new DrawningPlane(random.Next(100, 300), random.Next(1000, 3000), color, 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();
|
|
Color mainColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
ColorDialog dialog = new();
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
mainColor = dialog.Color;
|
|
}
|
|
Color addColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
addColor = dialog.Color;
|
|
}
|
|
_drawingPlane = new DrawningHydroplane(random.Next(100, 300), random.Next(1000, 3000), mainColor, addColor,
|
|
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));
|
|
Draw();
|
|
}
|
|
private void buttonMove_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawingPlane == null)
|
|
{
|
|
return;
|
|
}
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
_drawingPlane.MoveTransport(DirectionType.Up);
|
|
break;
|
|
case "buttonDown":
|
|
_drawingPlane.MoveTransport(DirectionType.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
_drawingPlane.MoveTransport(DirectionType.Left);
|
|
break;
|
|
case "buttonRight":
|
|
_drawingPlane.MoveTransport(DirectionType.Right);
|
|
break;
|
|
}
|
|
Draw();
|
|
}
|
|
|
|
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(_drawingPlane.GetMoveableObject, pictureBoxHydroplane.Width, pictureBoxHydroplane.Height);
|
|
comboBoxStrategy.Enabled = false;
|
|
}
|
|
if (_abstractStrategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_abstractStrategy.MakeStep();
|
|
Draw();
|
|
if (_abstractStrategy.GetStatus() == Status.Finish)
|
|
{
|
|
comboBoxStrategy.Enabled = true;
|
|
_abstractStrategy = null;
|
|
}
|
|
}
|
|
|
|
private void ButtonSelectPLane_Click(object sender, EventArgs e)
|
|
{
|
|
SelectedPlane = _drawingPlane;
|
|
DialogResult = DialogResult.OK;
|
|
}
|
|
|
|
}
|
|
} |