137 lines
3.7 KiB
C#
137 lines
3.7 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 ProjectLinkor.Drawnings;
|
|
using ProjectLinkor.MovementStrategy;
|
|
|
|
namespace ProjectLinkor
|
|
{
|
|
public partial class FormLinkor : Form
|
|
{
|
|
private DrawingShip? _drawingShip;
|
|
|
|
/// <summary>
|
|
/// Стратегия перемещения
|
|
/// </summary>
|
|
private AbstractStrategy? _strategy;
|
|
|
|
/// <summary>
|
|
/// Получение объекта
|
|
/// </summary>
|
|
public DrawingShip SetShip
|
|
{
|
|
set
|
|
{
|
|
_drawingShip = value;
|
|
_drawingShip.SetPictureSize(pictureBoxLinkor.Width, pictureBoxLinkor.Height);
|
|
comboBoxStrategy.Enabled = true;
|
|
_strategy = null;
|
|
Draw();
|
|
}
|
|
}
|
|
|
|
public FormLinkor()
|
|
{
|
|
InitializeComponent();
|
|
_strategy = null;
|
|
}
|
|
|
|
|
|
private void Draw()
|
|
{
|
|
if (_drawingShip == null)
|
|
{
|
|
return;
|
|
}
|
|
Bitmap bmp = new(pictureBoxLinkor.Width, pictureBoxLinkor.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawingShip.DrawTransport(gr);
|
|
pictureBoxLinkor.Image = bmp;
|
|
}
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawingShip == null)
|
|
{
|
|
return;
|
|
}
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
bool result = false;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
result = _drawingShip.MoveTransport(DirectionType.Up);
|
|
break;
|
|
case "buttonDown":
|
|
result = _drawingShip.MoveTransport(DirectionType.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
result = _drawingShip.MoveTransport(DirectionType.Left);
|
|
break;
|
|
case "buttonRight":
|
|
result = _drawingShip.MoveTransport(DirectionType.Right);
|
|
break;
|
|
}
|
|
if (result)
|
|
{
|
|
Draw();
|
|
}
|
|
|
|
}
|
|
|
|
private void FormLinkor_SizeChanged(object sender, EventArgs e)
|
|
{
|
|
if (_drawingShip == null)
|
|
{
|
|
return;
|
|
}
|
|
if (_drawingShip.SetPictureSize(pictureBoxLinkor.Width, pictureBoxLinkor.Height))
|
|
{
|
|
Draw();
|
|
}
|
|
}
|
|
|
|
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawingShip == null)
|
|
{
|
|
return;
|
|
}
|
|
if (comboBoxStrategy.Enabled)
|
|
{
|
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
|
{
|
|
0 => new MoveToCenter(),
|
|
1 => new MoveToBorder(),
|
|
_ => null,
|
|
};
|
|
if (_strategy == null)
|
|
{
|
|
return;
|
|
}
|
|
_strategy.SetData(new MoveableShip(_drawingShip),
|
|
pictureBoxLinkor.Width, pictureBoxLinkor.Height);
|
|
}
|
|
if (_strategy == null)
|
|
{
|
|
return;
|
|
}
|
|
comboBoxStrategy.Enabled = false;
|
|
_strategy.MakeStep();
|
|
Draw();
|
|
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
|
{
|
|
comboBoxStrategy.Enabled = true;
|
|
_strategy = null;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|