Лабораторная работа №3
This commit is contained in:
parent
84be2f6a1c
commit
5879f21e46
@ -13,12 +13,6 @@ namespace ElectricLocomotive
|
||||
{
|
||||
_locomotive = locomotive;
|
||||
}
|
||||
|
||||
public void Metod(int x)
|
||||
{
|
||||
x = 150;
|
||||
Console.WriteLine(x);
|
||||
}
|
||||
public float Step => _locomotive?.Locomotive?.Step ?? 0;
|
||||
|
||||
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
||||
|
@ -168,7 +168,7 @@
|
||||
this.buttonselectlocomotive.TabIndex = 8;
|
||||
this.buttonselectlocomotive.Text = "Выбрать";
|
||||
this.buttonselectlocomotive.UseVisualStyleBackColor = true;
|
||||
this.buttonselectlocomotive.Click += new System.EventHandler(this.ButtonSelectCar_Click);
|
||||
this.buttonselectlocomotive.Click += new System.EventHandler(this.ButtonSelectLocomotive_Click);
|
||||
//
|
||||
// FormLocomotive
|
||||
//
|
||||
|
@ -18,9 +18,6 @@ namespace ElectricLocomotive
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки машины
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
Bitmap bmp = new(pictureBox1.Width, pictureBox1.Height);
|
||||
@ -28,9 +25,6 @@ namespace ElectricLocomotive
|
||||
_locomotive?.DrawTransport(gr);
|
||||
pictureBox1.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод установки данных
|
||||
/// </summary>
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
@ -40,7 +34,6 @@ namespace ElectricLocomotive
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {_locomotive.Locomotive.Weight}";
|
||||
toolStripStatusLabelColor.Text = $"Цвет: { _locomotive.Locomotive.BodyColor.Name} ";
|
||||
}
|
||||
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
@ -79,7 +72,7 @@ namespace ElectricLocomotive
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void PictureBoxCar_Resize(object sender, EventArgs e)
|
||||
private void PictureBoxLocomotive_Resize(object sender, EventArgs e)
|
||||
{
|
||||
_locomotive?.ChangeBorders(pictureBox1.Width, pictureBox1.Height);
|
||||
Draw();
|
||||
@ -110,7 +103,7 @@ namespace ElectricLocomotive
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonSelectCar_Click(object sender, EventArgs e)
|
||||
private void ButtonSelectLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedLocomotive = _locomotive;
|
||||
DialogResult = DialogResult.OK;
|
||||
|
@ -123,7 +123,7 @@
|
||||
this.buttonAddLocomotive.TabIndex = 17;
|
||||
this.buttonAddLocomotive.Text = "Добавить локомотив";
|
||||
this.buttonAddLocomotive.UseVisualStyleBackColor = true;
|
||||
this.buttonAddLocomotive.Click += new System.EventHandler(this.ButtonAddCar_Click);
|
||||
this.buttonAddLocomotive.Click += new System.EventHandler(this.ButtonAddLocomotive_Click);
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
@ -156,7 +156,7 @@
|
||||
this.buttonRemoveCar.TabIndex = 24;
|
||||
this.buttonRemoveCar.Text = "Удалить локомотив";
|
||||
this.buttonRemoveCar.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveCar_Click);
|
||||
this.buttonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveLocomotive_Click);
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
|
@ -12,22 +12,11 @@ namespace ElectricLocomotive
|
||||
{
|
||||
public partial class FormMapWithSetLocomotive : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Объект от класса карты с набором объектов
|
||||
/// </summary>
|
||||
private MapWithSetLocomotivGeneric<DrawningObjectLocomotive, AbstractMap> _mapCarsCollectionGeneric;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
private MapWithSetLocomotivGeneric<DrawningObjectLocomotive, AbstractMap> _mapLocomotivesCollectionGeneric;
|
||||
public FormMapWithSetLocomotive()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор карты
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender,
|
||||
EventArgs e)
|
||||
{
|
||||
@ -46,32 +35,27 @@ namespace ElectricLocomotive
|
||||
}
|
||||
if (map != null)
|
||||
{
|
||||
_mapCarsCollectionGeneric = new MapWithSetLocomotivGeneric<DrawningObjectLocomotive, AbstractMap>(pictureBox1.Width, pictureBox1.Height, map);
|
||||
_mapLocomotivesCollectionGeneric = new MapWithSetLocomotivGeneric<DrawningObjectLocomotive, AbstractMap>(pictureBox1.Width, pictureBox1.Height, map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapCarsCollectionGeneric = null;
|
||||
_mapLocomotivesCollectionGeneric = null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddCar_Click(object sender, EventArgs e)
|
||||
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapCarsCollectionGeneric == null)
|
||||
if (_mapLocomotivesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormLocomotive form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawningObjectLocomotive ship = new(form.SelectedLocomotive);
|
||||
if (_mapCarsCollectionGeneric + ship != -1)
|
||||
DrawningObjectLocomotive Locomotive = new(form.SelectedLocomotive);
|
||||
if (_mapLocomotivesCollectionGeneric + Locomotive != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox1.Image = _mapCarsCollectionGeneric.ShowSet();
|
||||
pictureBox1.Image = _mapLocomotivesCollectionGeneric.ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -79,12 +63,7 @@ namespace ElectricLocomotive
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveCar_Click(object sender, EventArgs e)
|
||||
private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
@ -96,50 +75,35 @@ namespace ElectricLocomotive
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapCarsCollectionGeneric - pos != null)
|
||||
if (_mapLocomotivesCollectionGeneric - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox1.Image = _mapCarsCollectionGeneric.ShowSet();
|
||||
pictureBox1.Image = _mapLocomotivesCollectionGeneric.ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapCarsCollectionGeneric == null)
|
||||
if (_mapLocomotivesCollectionGeneric == null)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (_mapCarsCollectionGeneric == null)
|
||||
if (_mapLocomotivesCollectionGeneric == null)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (_mapCarsCollectionGeneric == null)
|
||||
if (_mapLocomotivesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -161,7 +125,7 @@ namespace ElectricLocomotive
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBox1.Image = _mapCarsCollectionGeneric.MoveObject(dir);
|
||||
pictureBox1.Image = _mapLocomotivesCollectionGeneric.MoveObject(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,9 +35,9 @@ namespace ElectricLocomotive
|
||||
_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)
|
||||
@ -62,7 +62,7 @@ namespace ElectricLocomotive
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawShip(gr);
|
||||
DrawLocomotive(gr);
|
||||
return bmp;
|
||||
}
|
||||
// Просмотр объекта на карте
|
||||
@ -71,10 +71,10 @@ namespace ElectricLocomotive
|
||||
Shaking();
|
||||
for (int i = 0; i < _setLocomotive.Count; i++)
|
||||
{
|
||||
var Ship = _setLocomotive.Get(i);
|
||||
if (Ship != null)
|
||||
var Locomotive = _setLocomotive.Get(i);
|
||||
if (Locomotive != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, Ship);
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, Locomotive);
|
||||
}
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
@ -98,10 +98,10 @@ namespace ElectricLocomotive
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var Ship = _setLocomotive.Get(j);
|
||||
if (Ship != null)
|
||||
var Locomotive = _setLocomotive.Get(j);
|
||||
if (Locomotive != null)
|
||||
{
|
||||
_setLocomotive.Insert(Ship, i);
|
||||
_setLocomotive.Insert(Locomotive, i);
|
||||
_setLocomotive.Remove(j);
|
||||
break;
|
||||
}
|
||||
@ -130,7 +130,7 @@ namespace ElectricLocomotive
|
||||
}
|
||||
}
|
||||
// Метод прорисовки объектов
|
||||
private void DrawShip(Graphics g)
|
||||
private void DrawLocomotive(Graphics g)
|
||||
{
|
||||
int widthEl = _pictureWidth / _placeSizeWidth;
|
||||
int heightEl = _pictureHeight / _placeSizeHeight;
|
||||
|
Loading…
Reference in New Issue
Block a user