151 lines
4.7 KiB
C#
151 lines
4.7 KiB
C#
|
using ProjectTank.CollectionGenericObjects;
|
|||
|
using ProjectTank.Drawnings;
|
|||
|
using System.Windows.Forms;
|
|||
|
|
|||
|
namespace ProjectTank
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public partial class FormTankCollection : Form
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
private AbstractCompany? _company = null;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Конструктор
|
|||
|
/// </summary>
|
|||
|
public FormTankCollection()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
switch (comboBoxSelectorCompany.Text)
|
|||
|
{
|
|||
|
case "Хранилище":
|
|||
|
_company = new TankBase(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningTank2>());
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Создание объекта класса-перемещения
|
|||
|
/// </summary>
|
|||
|
/// <param name="type">Тип создоваемого объекта</param>
|
|||
|
private void CreateObject(string type)
|
|||
|
{
|
|||
|
if (_company == null) return;
|
|||
|
|
|||
|
Random random = new();
|
|||
|
DrawningTank2 drawningTank;
|
|||
|
switch (type)
|
|||
|
{
|
|||
|
case nameof(DrawningTank2):
|
|||
|
drawningTank = new DrawningTank2(random.Next(100, 300), random.Next(1000, 3000),
|
|||
|
GetColor(random));
|
|||
|
break;
|
|||
|
case nameof(DrawningTank1):
|
|||
|
bool randomTrack = Convert.ToBoolean(random.Next(0, 2));
|
|||
|
drawningTank = new DrawningTank1(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), randomTrack, (randomTrack ? Convert.ToBoolean(random.Next(0, 2)) : true));
|
|||
|
break;
|
|||
|
default:
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (_company + drawningTank != -1)
|
|||
|
{
|
|||
|
MessageBox.Show("Объект добавлен");
|
|||
|
pictureBox.Image = _company.Show();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
MessageBox.Show("Не удалось добавить объект");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Получение цвета
|
|||
|
/// </summary>
|
|||
|
/// <param name="random">Генератор случайных чесел</param>
|
|||
|
/// <returns></returns>
|
|||
|
private static Color GetColor(Random random)
|
|||
|
{
|
|||
|
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
|||
|
ColorDialog dialog = new ColorDialog();
|
|||
|
|
|||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|||
|
{
|
|||
|
color = dialog.Color;
|
|||
|
}
|
|||
|
|
|||
|
return color;
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonAddTank_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
CreateObject(nameof(DrawningTank2));
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonAddBattleTank_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
CreateObject(nameof(DrawningTank1));
|
|||
|
}
|
|||
|
|
|||
|
private void buttonRemoveTank_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) return;
|
|||
|
|
|||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
|
|||
|
|
|||
|
int position = Convert.ToInt32(maskedTextBox.Text);
|
|||
|
|
|||
|
if (_company - position != null)
|
|||
|
{
|
|||
|
MessageBox.Show("Объект удален");
|
|||
|
pictureBox.Image = _company.Show();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
MessageBox.Show("Не удалось удалить объект");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonGoToCheck_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (_company == null) return;
|
|||
|
|
|||
|
DrawningTank2? tank = null;
|
|||
|
int coutner = 100;
|
|||
|
|
|||
|
while (tank == null)
|
|||
|
{
|
|||
|
tank = _company.GetRandomObject();
|
|||
|
coutner--;
|
|||
|
if (coutner <= 0) break;
|
|||
|
}
|
|||
|
|
|||
|
if (tank == null) return;
|
|||
|
|
|||
|
FormTank form = new()
|
|||
|
{
|
|||
|
SetTank = tank
|
|||
|
};
|
|||
|
form.ShowDialog();
|
|||
|
}
|
|||
|
|
|||
|
private void ButtonRefresh_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (_company == null) return;
|
|||
|
pictureBox.Image = _company.Show();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|