Лабораторная работа №3
This commit is contained in:
parent
6ffb60938c
commit
131e58dc88
@ -53,9 +53,9 @@ public abstract class AbstractCompany
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="car">Добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(AbstractCompany company, DrawningTrack car)
|
||||
public static int operator +(AbstractCompany company, DrawningTrack car)
|
||||
{
|
||||
return company._collection?.Insert(car) ?? false;
|
||||
return company._collection.Insert(car);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -64,9 +64,9 @@ public abstract class AbstractCompany
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">Номер удаляемого объекта</param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(AbstractCompany company, int position)
|
||||
public static DrawningTrack operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection?.Remove(position) ?? false;
|
||||
return company._collection.Remove(position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -24,7 +24,7 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
bool Insert(T obj);
|
||||
int Insert(T obj);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
@ -32,14 +32,14 @@ public interface ICollectionGenericObjects<T>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
bool Insert(T obj, int position);
|
||||
int Insert(T obj, int position);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||
bool Remove(int position);
|
||||
T? Remove(int position);
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта по позиции
|
||||
|
@ -44,7 +44,7 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public bool Insert(T obj)
|
||||
public int Insert(T obj)
|
||||
{
|
||||
// TODO вставка в свободное место набора
|
||||
int index = 0;
|
||||
@ -53,25 +53,25 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return true;
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// ищется свободное место после этой позиции и идет вставка туда
|
||||
// если нет после, ищем до
|
||||
// TODO вставка
|
||||
if (position >= _collection.Length || position < 0) return false;
|
||||
if (position >= _collection.Length || position < 0) return -1;
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return true;
|
||||
return position;
|
||||
}
|
||||
int index = position + 1;
|
||||
while (index < _collection.Length)
|
||||
@ -79,7 +79,7 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return true;
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
@ -89,20 +89,21 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return true;
|
||||
return index;
|
||||
}
|
||||
index--;
|
||||
}
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
public T? Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||
if (position >= _collection.Length || position < 0) return false;
|
||||
if (position >= _collection.Length || position < 0) return null;
|
||||
T removeObj = _collection[position];
|
||||
_collection[position] = null;
|
||||
return true;
|
||||
return removeObj;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,9 +53,6 @@ public class DrawningDumpTrack : DrawningTrack
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value, 3, 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value, 3, 40);
|
||||
}
|
||||
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ public class EntityDumpTrack : EntityTrack
|
||||
/// <param name="bodywork">Признак наличия кузова</param>
|
||||
/// <param name="awning">Признак наличия тента</param>
|
||||
|
||||
public EntityDumpTrack(int speed, double weight, Color bodyColor, Color additionalColor, Color additional2Color, bool bodywork, bool awning) : base(5, 45, Color.Black)
|
||||
public EntityDumpTrack(int speed, double weight, Color bodyColor, Color additionalColor, Color additional2Color, bool bodywork, bool awning) : base(5, 45, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Additional2Color = additional2Color;
|
||||
|
@ -148,7 +148,7 @@
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(961, 493);
|
||||
ClientSize = new Size(961, 100);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Name = "FormTrackCollection";
|
||||
|
@ -70,14 +70,14 @@ public partial class FormTrackCollection : Form
|
||||
drawningTrack = new DrawningTrack(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||||
break;
|
||||
case nameof(DrawningDumpTrack):
|
||||
drawningTrack = new DrawningDumpTrack(random.Next(100, 300), random.Next(1000, 3000), Color.Black, GetColor(random), GetColor(random),
|
||||
drawningTrack = new DrawningDumpTrack(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), GetColor(random),
|
||||
Convert.ToBoolean(random.Next(2, 2)), Convert.ToBoolean(random.Next(1, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (_company + drawningTrack)
|
||||
if (_company + drawningTrack != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
@ -125,7 +125,7 @@ public partial class FormTrackCollection : Form
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (_company - pos)
|
||||
if (_company - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
|
Loading…
x
Reference in New Issue
Block a user