Kashin M.I. Lab work 3 #3
@ -82,6 +82,7 @@
|
||||
this.keyRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.keyRight.TabIndex = 10;
|
||||
this.keyRight.UseVisualStyleBackColor = true;
|
||||
this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// keyLeft
|
||||
//
|
||||
@ -93,6 +94,7 @@
|
||||
this.keyLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.keyLeft.TabIndex = 9;
|
||||
this.keyLeft.UseVisualStyleBackColor = true;
|
||||
this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// keyUp
|
||||
//
|
||||
@ -104,6 +106,7 @@
|
||||
this.keyUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.keyUp.TabIndex = 8;
|
||||
this.keyUp.UseVisualStyleBackColor = true;
|
||||
this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// keyDown
|
||||
//
|
||||
@ -115,6 +118,7 @@
|
||||
this.keyDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.keyDown.TabIndex = 7;
|
||||
this.keyDown.UseVisualStyleBackColor = true;
|
||||
this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
|
@ -29,7 +29,7 @@ namespace GasolineTanker
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawingObjectGasolineTanker GasolineTanker = new(form.SelectedGasolineTanker);
|
||||
if (_mapGasolineTankerCollectionGeneric + GasolineTanker)
|
||||
if (_mapGasolineTankerCollectionGeneric + GasolineTanker >= 0)
|
||||
{
|
||||
MessageBox.Show("Object added");
|
||||
pictureBox.Image = _mapGasolineTankerCollectionGeneric.ShowSet();
|
||||
@ -52,7 +52,7 @@ namespace GasolineTanker
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapGasolineTankerCollectionGeneric - pos)
|
||||
if (_mapGasolineTankerCollectionGeneric - pos != null)
|
||||
{
|
||||
MessageBox.Show("Object deleted");
|
||||
pictureBox.Image = _mapGasolineTankerCollectionGeneric.ShowSet();
|
||||
@ -91,16 +91,16 @@ namespace GasolineTanker
|
||||
Direction dir = Direction.None;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
case "keyUp":
|
||||
dir = Direction.Up;
|
||||
break;
|
||||
case "buttonDown":
|
||||
case "keyDown":
|
||||
dir = Direction.Down;
|
||||
break;
|
||||
case "buttonLeft":
|
||||
case "keyLeft":
|
||||
dir = Direction.Left;
|
||||
break;
|
||||
case "buttonRight":
|
||||
case "keyRight":
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
|
@ -26,12 +26,12 @@ namespace GasolineTanker
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public static bool operator +(MapWithSetGasolienTankerGeneric<T, U> map, T GasolineTanker)
|
||||
public static int operator +(MapWithSetGasolienTankerGeneric<T, U> map, T GasolineTanker)
|
||||
{
|
||||
return map._setGasolineTanker.Insert(GasolineTanker);
|
||||
}
|
||||
|
||||
public static bool operator -(MapWithSetGasolienTankerGeneric<T, U> map, int position)
|
||||
public static T operator -(MapWithSetGasolienTankerGeneric<T, U> map, int position)
|
||||
{
|
||||
return map._setGasolineTanker.Remove(position);
|
||||
}
|
||||
@ -95,23 +95,30 @@ namespace GasolineTanker
|
||||
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
Pen pen = new(Color.Black, 5);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight + 2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2);
|
||||
g.DrawLine(pen, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20);
|
||||
g.DrawLine(pen, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawGasolineTanker(Graphics g)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
for (int i = 0; i < _setGasolineTanker.Count; i++)
|
||||
{
|
||||
// TODO установка позиции
|
||||
_setGasolineTanker.Get(i)?.DrawningObject(g);
|
||||
if (_setGasolineTanker.Get(i) != null)
|
||||
{
|
||||
_setGasolineTanker.Get(i).SetObject(i % width * _placeSizeWidth + 10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
|
||||
_setGasolineTanker.Get(i)?.DrawningObject(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,30 +15,65 @@ namespace GasolineTanker
|
||||
{
|
||||
_places = new T[count];
|
||||
}
|
||||
public bool Insert(T GasolineTanker)
|
||||
public int Insert(T GasolineTanker)
|
||||
{
|
||||
// TODO вставка в начало набора
|
||||
return true;
|
||||
if (_places[Count - 1] == null)
|
||||
|
||||
{
|
||||
for (int i = Count - 1; i > 0; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[0] = GasolineTanker;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public bool Insert(T GasolineTanker, int position)
|
||||
public int Insert(T GasolineTanker, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||
// TODO вставка по позиции
|
||||
_places[position] = GasolineTanker;
|
||||
return true;
|
||||
if (position < 0 || position >= Count) return -1;
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = GasolineTanker;
|
||||
return position;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_places[Count - 1] == null)
|
||||
{
|
||||
for (int i = Count - 1; i > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[position] = GasolineTanker;
|
||||
return position;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
public bool Remove(int position)
|
||||
public T Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присовив элементу массива значение null
|
||||
return true;
|
||||
if (position < 0 || position >= Count)
|
||||
return null;
|
||||
if (_places[position] != null)
|
||||
{
|
||||
T removed = _places[position];
|
||||
_places[position] = null;
|
||||
if (position < Count - 1)
|
||||
eegov
commented
Выполнять операцию сдивга не требовалось Выполнять операцию сдивга не требовалось
|
||||
{
|
||||
for (int k = position; k < Count - 1; k++)
|
||||
{
|
||||
_places[k] = _places[k + 1];
|
||||
}
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public T Get(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position >= Count || position < 0)
|
||||
return null;
|
||||
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user
Правильнее было вызвать Insert(T obj, 0);