Лабораторная работа №3

This commit is contained in:
Stranni15k 2022-11-19 21:59:35 +04:00
parent 84be2f6a1c
commit 5879f21e46
6 changed files with 32 additions and 81 deletions

View File

@ -13,12 +13,6 @@ namespace ElectricLocomotive
{ {
_locomotive = locomotive; _locomotive = locomotive;
} }
public void Metod(int x)
{
x = 150;
Console.WriteLine(x);
}
public float Step => _locomotive?.Locomotive?.Step ?? 0; public float Step => _locomotive?.Locomotive?.Step ?? 0;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()

View File

@ -168,7 +168,7 @@
this.buttonselectlocomotive.TabIndex = 8; this.buttonselectlocomotive.TabIndex = 8;
this.buttonselectlocomotive.Text = "Выбрать"; this.buttonselectlocomotive.Text = "Выбрать";
this.buttonselectlocomotive.UseVisualStyleBackColor = true; this.buttonselectlocomotive.UseVisualStyleBackColor = true;
this.buttonselectlocomotive.Click += new System.EventHandler(this.ButtonSelectCar_Click); this.buttonselectlocomotive.Click += new System.EventHandler(this.ButtonSelectLocomotive_Click);
// //
// FormLocomotive // FormLocomotive
// //

View File

@ -18,9 +18,6 @@ namespace ElectricLocomotive
{ {
InitializeComponent(); InitializeComponent();
} }
/// <summary>
/// Метод прорисовки машины
/// </summary>
private void Draw() private void Draw()
{ {
Bitmap bmp = new(pictureBox1.Width, pictureBox1.Height); Bitmap bmp = new(pictureBox1.Width, pictureBox1.Height);
@ -28,9 +25,6 @@ namespace ElectricLocomotive
_locomotive?.DrawTransport(gr); _locomotive?.DrawTransport(gr);
pictureBox1.Image = bmp; pictureBox1.Image = bmp;
} }
/// <summary>
/// Метод установки данных
/// </summary>
private void SetData() private void SetData()
{ {
Random rnd = new(); Random rnd = new();
@ -40,7 +34,6 @@ namespace ElectricLocomotive
toolStripStatusLabelWeight.Text = $"Вес: {_locomotive.Locomotive.Weight}"; toolStripStatusLabelWeight.Text = $"Вес: {_locomotive.Locomotive.Weight}";
toolStripStatusLabelColor.Text = $"Цвет: { _locomotive.Locomotive.BodyColor.Name} "; toolStripStatusLabelColor.Text = $"Цвет: { _locomotive.Locomotive.BodyColor.Name} ";
} }
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
@ -79,7 +72,7 @@ namespace ElectricLocomotive
Draw(); Draw();
} }
private void PictureBoxCar_Resize(object sender, EventArgs e) private void PictureBoxLocomotive_Resize(object sender, EventArgs e)
{ {
_locomotive?.ChangeBorders(pictureBox1.Width, pictureBox1.Height); _locomotive?.ChangeBorders(pictureBox1.Width, pictureBox1.Height);
Draw(); Draw();
@ -110,7 +103,7 @@ namespace ElectricLocomotive
Draw(); Draw();
} }
private void ButtonSelectCar_Click(object sender, EventArgs e) private void ButtonSelectLocomotive_Click(object sender, EventArgs e)
{ {
SelectedLocomotive = _locomotive; SelectedLocomotive = _locomotive;
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;

View File

@ -123,7 +123,7 @@
this.buttonAddLocomotive.TabIndex = 17; this.buttonAddLocomotive.TabIndex = 17;
this.buttonAddLocomotive.Text = "Добавить локомотив"; this.buttonAddLocomotive.Text = "Добавить локомотив";
this.buttonAddLocomotive.UseVisualStyleBackColor = true; this.buttonAddLocomotive.UseVisualStyleBackColor = true;
this.buttonAddLocomotive.Click += new System.EventHandler(this.ButtonAddCar_Click); this.buttonAddLocomotive.Click += new System.EventHandler(this.ButtonAddLocomotive_Click);
// //
// comboBoxSelectorMap // comboBoxSelectorMap
// //
@ -156,7 +156,7 @@
this.buttonRemoveCar.TabIndex = 24; this.buttonRemoveCar.TabIndex = 24;
this.buttonRemoveCar.Text = "Удалить локомотив"; this.buttonRemoveCar.Text = "Удалить локомотив";
this.buttonRemoveCar.UseVisualStyleBackColor = true; this.buttonRemoveCar.UseVisualStyleBackColor = true;
this.buttonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveCar_Click); this.buttonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveLocomotive_Click);
// //
// buttonShowStorage // buttonShowStorage
// //

View File

@ -12,22 +12,11 @@ namespace ElectricLocomotive
{ {
public partial class FormMapWithSetLocomotive : Form public partial class FormMapWithSetLocomotive : Form
{ {
/// <summary> private MapWithSetLocomotivGeneric<DrawningObjectLocomotive, AbstractMap> _mapLocomotivesCollectionGeneric;
/// Объект от класса карты с набором объектов
/// </summary>
private MapWithSetLocomotivGeneric<DrawningObjectLocomotive, AbstractMap> _mapCarsCollectionGeneric;
/// <summary>
/// Конструктор
/// </summary>
public FormMapWithSetLocomotive() public FormMapWithSetLocomotive()
{ {
InitializeComponent(); InitializeComponent();
} }
/// <summary>
/// Выбор карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, private void ComboBoxSelectorMap_SelectedIndexChanged(object sender,
EventArgs e) EventArgs e)
{ {
@ -46,32 +35,27 @@ namespace ElectricLocomotive
} }
if (map != null) if (map != null)
{ {
_mapCarsCollectionGeneric = new MapWithSetLocomotivGeneric<DrawningObjectLocomotive, AbstractMap>(pictureBox1.Width, pictureBox1.Height, map); _mapLocomotivesCollectionGeneric = new MapWithSetLocomotivGeneric<DrawningObjectLocomotive, AbstractMap>(pictureBox1.Width, pictureBox1.Height, map);
} }
else else
{ {
_mapCarsCollectionGeneric = null; _mapLocomotivesCollectionGeneric = null;
} }
} }
/// <summary> private void ButtonAddLocomotive_Click(object sender, EventArgs e)
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddCar_Click(object sender, EventArgs e)
{ {
if (_mapCarsCollectionGeneric == null) if (_mapLocomotivesCollectionGeneric == null)
{ {
return; return;
} }
FormLocomotive form = new(); FormLocomotive form = new();
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
DrawningObjectLocomotive ship = new(form.SelectedLocomotive); DrawningObjectLocomotive Locomotive = new(form.SelectedLocomotive);
if (_mapCarsCollectionGeneric + ship != -1) if (_mapLocomotivesCollectionGeneric + Locomotive != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox1.Image = _mapCarsCollectionGeneric.ShowSet(); pictureBox1.Image = _mapLocomotivesCollectionGeneric.ShowSet();
} }
else else
{ {
@ -79,12 +63,7 @@ namespace ElectricLocomotive
} }
} }
} }
/// <summary> private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveCar_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{ {
@ -96,50 +75,35 @@ namespace ElectricLocomotive
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapCarsCollectionGeneric - pos != null) if (_mapLocomotivesCollectionGeneric - pos != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBox1.Image = _mapCarsCollectionGeneric.ShowSet(); pictureBox1.Image = _mapLocomotivesCollectionGeneric.ShowSet();
} }
else else
{ {
MessageBox.Show("Не удалось удалить объект"); MessageBox.Show("Не удалось удалить объект");
} }
} }
/// <summary>
/// Вывод набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e) private void ButtonShowStorage_Click(object sender, EventArgs e)
{ {
if (_mapCarsCollectionGeneric == null) if (_mapLocomotivesCollectionGeneric == null)
{ {
return; return;
} }
pictureBox1.Image = _mapCarsCollectionGeneric.ShowSet(); pictureBox1.Image = _mapLocomotivesCollectionGeneric.ShowSet();
} }
/// <summary>
/// Вывод карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e) private void ButtonShowOnMap_Click(object sender, EventArgs e)
{ {
if (_mapCarsCollectionGeneric == null) if (_mapLocomotivesCollectionGeneric == null)
{ {
return; return;
} }
pictureBox1.Image = _mapCarsCollectionGeneric.ShowOnMap(); pictureBox1.Image = _mapLocomotivesCollectionGeneric.ShowOnMap();
} }
/// <summary>
/// Перемещение
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
if (_mapCarsCollectionGeneric == null) if (_mapLocomotivesCollectionGeneric == null)
{ {
return; return;
} }
@ -161,7 +125,7 @@ namespace ElectricLocomotive
dir = Direction.Right; dir = Direction.Right;
break; break;
} }
pictureBox1.Image = _mapCarsCollectionGeneric.MoveObject(dir); pictureBox1.Image = _mapLocomotivesCollectionGeneric.MoveObject(dir);
} }
} }
} }

View File

@ -35,9 +35,9 @@ namespace ElectricLocomotive
_map = map; _map = map;
} }
// Перегрузка оператора сложения // Перегрузка оператора сложения
public static int operator +(MapWithSetLocomotivGeneric<T, U> map, T Ship) public static int operator +(MapWithSetLocomotivGeneric<T, U> map, T Locomotive)
{ {
return map._setLocomotive.Insert(Ship); return map._setLocomotive.Insert(Locomotive);
} }
// Перегрузка оператора вычитания // Перегрузка оператора вычитания
public static T operator -(MapWithSetLocomotivGeneric<T, U> map, int position) public static T operator -(MapWithSetLocomotivGeneric<T, U> map, int position)
@ -62,7 +62,7 @@ namespace ElectricLocomotive
Bitmap bmp = new(_pictureWidth, _pictureHeight); Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr); DrawBackground(gr);
DrawShip(gr); DrawLocomotive(gr);
return bmp; return bmp;
} }
// Просмотр объекта на карте // Просмотр объекта на карте
@ -71,10 +71,10 @@ namespace ElectricLocomotive
Shaking(); Shaking();
for (int i = 0; i < _setLocomotive.Count; i++) for (int i = 0; i < _setLocomotive.Count; i++)
{ {
var Ship = _setLocomotive.Get(i); var Locomotive = _setLocomotive.Get(i);
if (Ship != null) if (Locomotive != null)
{ {
return _map.CreateMap(_pictureWidth, _pictureHeight, Ship); return _map.CreateMap(_pictureWidth, _pictureHeight, Locomotive);
} }
} }
return new(_pictureWidth, _pictureHeight); return new(_pictureWidth, _pictureHeight);
@ -98,10 +98,10 @@ namespace ElectricLocomotive
{ {
for (; j > i; j--) for (; j > i; j--)
{ {
var Ship = _setLocomotive.Get(j); var Locomotive = _setLocomotive.Get(j);
if (Ship != null) if (Locomotive != null)
{ {
_setLocomotive.Insert(Ship, i); _setLocomotive.Insert(Locomotive, i);
_setLocomotive.Remove(j); _setLocomotive.Remove(j);
break; break;
} }
@ -130,7 +130,7 @@ namespace ElectricLocomotive
} }
} }
// Метод прорисовки объектов // Метод прорисовки объектов
private void DrawShip(Graphics g) private void DrawLocomotive(Graphics g)
{ {
int widthEl = _pictureWidth / _placeSizeWidth; int widthEl = _pictureWidth / _placeSizeWidth;
int heightEl = _pictureHeight / _placeSizeHeight; int heightEl = _pictureHeight / _placeSizeHeight;