Третья лабораторная работа

This commit is contained in:
10Г Егор Романов 2022-10-10 19:53:02 +03:00
parent 755078a597
commit 72344e2aa5
2 changed files with 22 additions and 41 deletions

View File

@ -12,19 +12,9 @@ namespace HoistingCrane
{ {
public partial class FormMapWithSetHoistingCrane : Form public partial class FormMapWithSetHoistingCrane : Form
{ {
/// Словарь для выпадающего списка
/// </summary>
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Простая карта", new SimpleMap() },
{ "Вторая карта", new SecondMap() },
};
/// <summary>
/// Объект от коллекции карт
/// </summary>
private readonly MapsCollection _mapsCollection;
/// <summary>
private MapWithSetHoistingCraneGeneric<DrawingObjectHoistingCrane, AbstractMap> _mapHoistingCraneCollectionGeneric; private MapWithSetHoistingCraneGeneric<DrawingObjectHoistingCrane, AbstractMap> _mapHoistingCraneCollectionGeneric;
public FormMapWithSetHoistingCrane() public FormMapWithSetHoistingCrane()
{ {
InitializeComponent(); InitializeComponent();
@ -62,7 +52,6 @@ namespace HoistingCrane
AbstractMap map = null; AbstractMap map = null;
switch (comboBoxSelectorMap.Text) switch (comboBoxSelectorMap.Text)
{ {
case "Простая карта":
map = new SimpleMap(); map = new SimpleMap();
break; break;
case "Вторая карта": case "Вторая карта":
@ -123,30 +112,22 @@ namespace HoistingCrane
} }
private void ButtonAddHoistingCrane_Click(object sender, EventArgs e) private void ButtonAddHoistingCrane_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
var formHoistingCraneConfig = new FormHoistingCraneConfig();
formHoistingCraneConfig.AddEvent(AddHoistingCrane);
formHoistingCraneConfig.Show();
}
private void AddHoistingCrane(DrawingHoistingCrane drawingHoistingCrane)
{ {
DrawingObjectHoistingCrane hoistingCrane = new DrawingObjectHoistingCrane(drawingHoistingCrane);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + hoistingCrane != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show("Не удалось добавить объект");
} }
} }
}
private void ButtonRemoveHoistingCrane_Click(object sender, EventArgs e) private void ButtonRemoveHoistingCrane_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
@ -155,35 +136,31 @@ namespace HoistingCrane
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
MessageBox.Show("Не удалось удалить объект"); MessageBox.Show("Не удалось удалить объект");
} }
} }
private void ButtonShowStorage_Click(object sender, EventArgs e) private void ButtonShowStorage_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
private void ButtonShowOnMap_Click(object sender, EventArgs e) private void ButtonShowOnMap_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
} }
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
@ -206,5 +183,10 @@ namespace HoistingCrane
} }
pictureBox.Image = _mapHoistingCraneCollectionGeneric.MoveObject(enums); pictureBox.Image = _mapHoistingCraneCollectionGeneric.MoveObject(enums);
} }
private void pictureBox_Click(object sender, EventArgs e)
{
}
} }
} }

View File

@ -42,7 +42,7 @@ namespace HoistingCrane
Bitmap bmp = new(_pictureWidth, _pictureWidth); Bitmap bmp = new(_pictureWidth, _pictureWidth);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr); DrawBackground(gr);
DrawHoistingCranes(gr); DrawBulldozers(gr);
return bmp; return bmp;
} }
@ -107,7 +107,6 @@ namespace HoistingCrane
} }
} }
private void DrawHoistingCranes(Graphics gr)
{ {
int heightEl = _pictureHeight / _placeSizeHeight; int heightEl = _pictureHeight / _placeSizeHeight;
int widthEl = _pictureWidth / _placeSizeWidth; int widthEl = _pictureWidth / _placeSizeWidth;