2024-04-18 13:11:34 +04:00
|
|
|
|
using lab1;
|
2024-04-24 09:28:37 +04:00
|
|
|
|
using lab1.Drawnings;
|
2024-04-24 13:04:56 +04:00
|
|
|
|
using lab1.MovementStrategy;
|
2024-04-18 13:11:34 +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;
|
|
|
|
|
|
2024-04-24 09:28:37 +04:00
|
|
|
|
namespace lab1;
|
|
|
|
|
|
2024-04-18 13:11:34 +04:00
|
|
|
|
|
|
|
|
|
|
2024-04-24 09:28:37 +04:00
|
|
|
|
public partial class FormFighter : Form
|
|
|
|
|
{
|
|
|
|
|
private DrawningTrackedVehicle? _drawningTrackedVehicle;
|
2024-04-24 13:04:56 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Стратегия перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
private AbstractSrategy? _strategy;
|
2024-04-24 09:28:37 +04:00
|
|
|
|
public FormFighter()
|
2024-04-18 13:11:34 +04:00
|
|
|
|
{
|
2024-04-24 09:28:37 +04:00
|
|
|
|
InitializeComponent();
|
2024-04-24 13:04:56 +04:00
|
|
|
|
_strategy = null;
|
|
|
|
|
comboBoxStrategy.Enabled = true;
|
2024-04-24 09:28:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Draw()
|
|
|
|
|
{
|
|
|
|
|
if (_drawningTrackedVehicle == null)
|
2024-04-18 13:11:34 +04:00
|
|
|
|
{
|
2024-04-24 09:28:37 +04:00
|
|
|
|
return;
|
2024-04-18 13:11:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-24 09:28:37 +04:00
|
|
|
|
Bitmap bmp = new(pictureBoxFighter.Width, pictureBoxFighter.Height);
|
|
|
|
|
Graphics gr = Graphics.FromImage(bmp);
|
|
|
|
|
_drawningTrackedVehicle.DrawTransport(gr);
|
|
|
|
|
pictureBoxFighter.Image = bmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создание объекта класса-перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
private void CreateObject(string type)
|
|
|
|
|
{
|
|
|
|
|
Random random = new();
|
|
|
|
|
switch (type)
|
2024-04-18 13:11:34 +04:00
|
|
|
|
{
|
2024-04-24 09:28:37 +04:00
|
|
|
|
case nameof(DrawningTrackedVehicle):
|
|
|
|
|
_drawningTrackedVehicle = new DrawningTrackedVehicle(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(DrawningEntityFighter):
|
|
|
|
|
_drawningTrackedVehicle = new DrawningEntityFighter(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:
|
2024-04-18 13:11:34 +04:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
}
|
2024-04-24 09:28:37 +04:00
|
|
|
|
_drawningTrackedVehicle.SetPictureSize(pictureBoxFighter.Width, pictureBoxFighter.Height);
|
|
|
|
|
_drawningTrackedVehicle.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
2024-04-24 13:04:56 +04:00
|
|
|
|
_strategy = null;
|
|
|
|
|
|
2024-04-24 09:28:37 +04:00
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка нажатия кнопки "Создать истребитель"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningEntityFighter));
|
|
|
|
|
|
2024-04-18 13:11:34 +04:00
|
|
|
|
|
2024-04-24 09:28:37 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка нажатия кнопки "Создать гусеничную машину"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonCreateTrackedVehicle_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedVehicle));
|
2024-04-18 13:11:34 +04:00
|
|
|
|
|
|
|
|
|
|
2024-04-24 09:28:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-04-24 13:04:56 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-04-24 09:28:37 +04:00
|
|
|
|
|
|
|
|
|
private void ButtonMove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_drawningTrackedVehicle == null)
|
2024-04-18 13:11:34 +04:00
|
|
|
|
{
|
2024-04-24 09:28:37 +04:00
|
|
|
|
return;
|
2024-04-18 13:11:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-24 09:28:37 +04:00
|
|
|
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
|
|
|
|
bool result = false;
|
|
|
|
|
switch (name)
|
2024-04-18 13:11:34 +04:00
|
|
|
|
{
|
2024-04-24 09:28:37 +04:00
|
|
|
|
case "buttonUp":
|
|
|
|
|
result = _drawningTrackedVehicle.MoveTransport(DirectionType.Up);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonDown":
|
|
|
|
|
result = _drawningTrackedVehicle.MoveTransport(DirectionType.Down);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonLeft":
|
|
|
|
|
result = _drawningTrackedVehicle.MoveTransport(DirectionType.Left);
|
|
|
|
|
break;
|
|
|
|
|
case "buttonRight":
|
|
|
|
|
result = _drawningTrackedVehicle.MoveTransport(DirectionType.Right);
|
|
|
|
|
break;
|
2024-04-18 13:11:34 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-24 09:28:37 +04:00
|
|
|
|
if (result)
|
2024-04-18 13:11:34 +04:00
|
|
|
|
{
|
2024-04-24 09:28:37 +04:00
|
|
|
|
Draw();
|
2024-04-18 13:11:34 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-24 09:28:37 +04:00
|
|
|
|
|
2024-04-24 13:04:56 +04:00
|
|
|
|
|
2024-04-24 09:28:37 +04:00
|
|
|
|
|
|
|
|
|
private void FormFighter_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-24 13:04:56 +04:00
|
|
|
|
private void checkBox1_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void pictureBoxFighter_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_drawningTrackedVehicle == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (comboBoxStrategy.Enabled)
|
|
|
|
|
{
|
|
|
|
|
_strategy = comboBoxStrategy.SelectedIndex switch
|
|
|
|
|
{
|
|
|
|
|
0 => new MoveToCenter(),
|
|
|
|
|
1 => new MoveToBorder(),
|
|
|
|
|
_ => null,
|
|
|
|
|
};
|
|
|
|
|
if (_strategy == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_strategy.SetData(new MoveableTrackedVehicle(_drawningTrackedVehicle), pictureBoxFighter.Width, pictureBoxFighter.Height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_strategy == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
comboBoxStrategy.Enabled = false;
|
|
|
|
|
_strategy.MakeStep();
|
|
|
|
|
Draw();
|
|
|
|
|
|
|
|
|
|
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
|
|
|
|
{
|
|
|
|
|
comboBoxStrategy.Enabled = true;
|
|
|
|
|
_strategy = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-18 13:11:34 +04:00
|
|
|
|
}
|
2024-04-24 13:04:56 +04:00
|
|
|
|
|