Lab3 Готово

This commit is contained in:
Артём Яшин 2023-10-12 22:32:09 +04:00
parent e7bc34adb6
commit c3868c326c
4 changed files with 27 additions and 27 deletions

View File

@ -141,6 +141,7 @@
//
// buttonSelectPlane
//
buttonSelectPlane.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonSelectPlane.Location = new Point(890, 81);
buttonSelectPlane.Name = "buttonSelectPlane";
buttonSelectPlane.Size = new Size(108, 43);

View File

@ -40,23 +40,23 @@
//
// pictureBoxCollection
//
pictureBoxCollection.Dock = DockStyle.Left;
pictureBoxCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
pictureBoxCollection.Location = new Point(0, 0);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(669, 667);
pictureBoxCollection.Size = new Size(950, 667);
pictureBoxCollection.TabIndex = 0;
pictureBoxCollection.TabStop = false;
//
// groupBox1
//
groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Right;
groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
groupBox1.Controls.Add(ButtonRefreshCollection);
groupBox1.Controls.Add(ButtonRemovePlane);
groupBox1.Controls.Add(maskedTextBoxNumber);
groupBox1.Controls.Add(ButtonAddPlane);
groupBox1.Location = new Point(669, 9);
groupBox1.Location = new Point(956, 9);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(213, 477);
groupBox1.Size = new Size(213, 646);
groupBox1.TabIndex = 1;
groupBox1.TabStop = false;
groupBox1.Text = "Инструменты";
@ -102,7 +102,7 @@
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(882, 667);
ClientSize = new Size(1169, 667);
Controls.Add(groupBox1);
Controls.Add(pictureBoxCollection);
Name = "FormPlaneCollection";

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace ProjectAirBomber.Generics
{
@ -24,7 +25,7 @@ namespace ProjectAirBomber.Generics
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 210;
private readonly int _placeSizeWidth = 170;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
@ -52,13 +53,13 @@ namespace ProjectAirBomber.Generics
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static T? operator +(PlanesGenericCollection<T, U> collect, T? obj)
public static PlanesGenericCollection<T, U>? operator +(PlanesGenericCollection<T, U>? collect, T? obj)
{
if (obj == null)
if (obj != null)
{
return null;
collect?._collection.Insert(obj);
}
return collect?._collection.Insert(obj) ?? null;
return collect;
}
/// <summary>
/// Перегрузка оператора вычитания
@ -66,15 +67,14 @@ namespace ProjectAirBomber.Generics
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static T? operator -(PlanesGenericCollection<T, U> collect, int
pos)
public static PlanesGenericCollection<T, U>? operator -(PlanesGenericCollection<T, U>? collect, int pos)
{
T? obj = collect._collection.Get(pos);
T? obj = collect?._collection.Get(pos);
if (obj != null)
{
collect._collection.Remove(pos);
collect?._collection.Remove(pos);
}
return obj;
return collect;
}
/// <summary>
/// Получение объекта IMoveableObject
@ -108,9 +108,9 @@ namespace ProjectAirBomber.Generics
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
{//линия рамзетки места
{//линия разметки места
g.DrawLine(pen, i * _placeSizeWidth + 10, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2 + 10, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2 + 50, j *
_placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth + 10, 0, i *
@ -130,11 +130,10 @@ namespace ProjectAirBomber.Generics
if (plane != null)
{
int inRow = _pictureWidth / _placeSizeWidth;
plane.SetPosition(i % inRow * _placeSizeWidth + 10, (_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight + 40);
plane.SetPosition(_pictureWidth - _placeSizeWidth - (i % inRow * _placeSizeWidth) - _placeSizeHeight / 2 + 10, i / inRow * _placeSizeHeight + 20);
plane.DrawTransport(g);
}
}
}
}
}

View File

@ -18,29 +18,29 @@ namespace ProjectAirBomber.Generics
_places = new T?[count];
}
public T? Insert(T plane)
public bool Insert(T plane)
{
if (_places[Count - 1] != null)
return null;
return Insert(plane, 0); ;
return false;
return Insert(plane, 0);
}
public T? Insert(T plane, int position)
public bool Insert(T plane, int position)
{
if (!(position >= 0 && position < Count))
return null;
return false;
if (_places[position] != null)
{
int ind = position;
while (ind < Count && _places[ind] != null)
ind++;
if (ind == Count)
return null;
return false;
for (int i = ind - 1; i >= position; i--)
_places[i + 1] = _places[i];
}
_places[position] = plane;
return plane;
return true;
}
public bool Remove(int position)
{