Pibd-13_Garifullin_F.M_LabWork04 #13
@ -1,4 +1,4 @@
|
||||
namespace ProjectTank.Drawning;
|
||||
namespace ProjectTank.Drawning;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
|
@ -1,4 +1,8 @@
|
||||
using ProjectTank.Drawning;
|
||||
using ProjectTank.Entities;
|
||||
using ProjectTank.MovementStrategy;
|
||||
|
||||
using ProjectTank.Drawning;
|
||||
using ProjectTank.MovementStrategy;
|
||||
|
||||
namespace ProjectTank
|
||||
@ -12,11 +16,14 @@ namespace ProjectTank
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningTank? _drawningTank;
|
||||
private DrawningTank? _drawningTank;
|
||||
|
||||
/// <summary>
|
||||
/// Стратегия перемещения
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
public DrawningTank SetTank
|
||||
{
|
||||
@ -36,12 +43,15 @@ namespace ProjectTank
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
_strategy = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки танка
|
||||
/// Метод прорисовки танка
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningTank == null)
|
||||
if (_drawningTank == null)
|
||||
{
|
||||
return;
|
||||
@ -49,6 +59,7 @@ namespace ProjectTank
|
||||
Bitmap bmp = new(pictureBoxBattleTank.Width, pictureBoxBattleTank.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningTank.DrawTransport(gr);
|
||||
_drawningTank.DrawTransport(gr);
|
||||
pictureBoxBattleTank.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
@ -79,6 +90,34 @@ namespace ProjectTank
|
||||
СomboBoxStrategy.Enabled = true;
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new Random();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningTank):
|
||||
_drawningTank = new DrawningTank(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||
break;
|
||||
case nameof(DrawningBattleTank):
|
||||
_drawningTank = new DrawningBattleTank(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)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
_drawningTank.SetPictureSize(pictureBoxBattleTank.Width, pictureBoxBattleTank.Height);
|
||||
_drawningTank.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_strategy = null;
|
||||
СomboBoxStrategy.Enabled = true;
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
@ -86,6 +125,10 @@ namespace ProjectTank
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
private void ButtonCreateButtleTank_Ckick(object sender, EventArgs e) => CreateObject(nameof(DrawningBattleTank));
|
||||
private void ButtonCreateTank_Ckick(object sender, EventArgs e) => CreateObject(nameof(DrawningTank));
|
||||
|
||||
|
||||
private void ButtonCreateButtleTank_Ckick(object sender, EventArgs e) => CreateObject(nameof(DrawningBattleTank));
|
||||
private void ButtonCreateTank_Ckick(object sender, EventArgs e) => CreateObject(nameof(DrawningTank));
|
||||
|
||||
@ -96,6 +139,7 @@ namespace ProjectTank
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningTank == null)
|
||||
if (_drawningTank == null)
|
||||
{
|
||||
return;
|
||||
@ -105,15 +149,19 @@ namespace ProjectTank
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningTank.MoveTransport(DirectionType.Up);
|
||||
result = _drawningTank.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningTank.MoveTransport(DirectionType.Left);
|
||||
result = _drawningTank.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningTank.MoveTransport(DirectionType.Right);
|
||||
result = _drawningTank.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningTank.MoveTransport(DirectionType.Down);
|
||||
result = _drawningTank.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
}
|
||||
@ -162,5 +210,45 @@ namespace ProjectTank
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Шаг"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonStrategyStep_Ckick(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningTank == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (СomboBoxStrategy.Enabled)
|
||||
{
|
||||
_strategy = СomboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableTank(_drawningTank),
|
||||
pictureBoxBattleTank.Width, pictureBoxBattleTank.Height);
|
||||
}
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
СomboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
СomboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user