129 lines
3.3 KiB
C#
129 lines
3.3 KiB
C#
using ProjectShip.MovementStrategy;
|
|
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 WarmlyShip.Drawnings;
|
|
using WarmlyShip.MovementStrategy;
|
|
|
|
namespace WarmlyShip
|
|
{
|
|
public partial class FormShips : Form
|
|
{
|
|
private DrawningShip? _drawningShip;
|
|
|
|
private AbstractStrategy? _strategy;
|
|
|
|
public DrawningShip SetShip
|
|
{
|
|
set
|
|
{
|
|
_drawningShip = value;
|
|
_drawningShip.SetPictureSize(pictureBoxShips.Width, pictureBoxShips.Height);
|
|
comboBoxStrategy.Enabled = true;
|
|
_strategy = null;
|
|
Draw();
|
|
}
|
|
}
|
|
|
|
public FormShips()
|
|
{
|
|
InitializeComponent();
|
|
_strategy = null;
|
|
}
|
|
|
|
private void Draw()
|
|
{
|
|
|
|
if (_drawningShip == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Bitmap bmp = new(pictureBoxShips.Width, pictureBoxShips.Height);
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
_drawningShip.DrawTransport(gr);
|
|
pictureBoxShips.Image = bmp;
|
|
}
|
|
|
|
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawningShip == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
bool result = false;
|
|
switch (name)
|
|
{
|
|
case "buttonUp":
|
|
result = _drawningShip.MoveTransport(DirectionType.Up);
|
|
break;
|
|
case "buttonDown":
|
|
result = _drawningShip.MoveTransport(DirectionType.Down);
|
|
break;
|
|
case "buttonLeft":
|
|
result = _drawningShip.MoveTransport(DirectionType.Left);
|
|
break;
|
|
case "buttonRight":
|
|
result = _drawningShip.MoveTransport(DirectionType.Right);
|
|
break;
|
|
}
|
|
|
|
if (result)
|
|
{
|
|
Draw();
|
|
}
|
|
}
|
|
|
|
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
|
{
|
|
if (_drawningShip == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (comboBoxStrategy.Enabled)
|
|
{
|
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
|
{
|
|
0 => new MoveToCenter(),
|
|
1 => new MoveToBorder(),
|
|
_ => null,
|
|
};
|
|
|
|
if (_strategy == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_strategy.SetData(new MoveableShip(_drawningShip), pictureBoxShips.Width, pictureBoxShips.Height);
|
|
}
|
|
|
|
if (_strategy == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
comboBoxStrategy.Enabled = false;
|
|
_strategy.MakeStep();
|
|
Draw();
|
|
|
|
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
|
{
|
|
comboBoxStrategy.Enabled = true;
|
|
_strategy = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|