Lab3 Done

This commit is contained in:
Артём Яшин 2023-10-18 19:50:10 +04:00
parent c3868c326c
commit 9cb8c3d5c4
4 changed files with 21 additions and 24 deletions

View File

@ -43,7 +43,7 @@
pictureBoxCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
pictureBoxCollection.Location = new Point(0, 0);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(950, 667);
pictureBoxCollection.Size = new Size(798, 667);
pictureBoxCollection.TabIndex = 0;
pictureBoxCollection.TabStop = false;
//
@ -54,7 +54,7 @@
groupBox1.Controls.Add(ButtonRemovePlane);
groupBox1.Controls.Add(maskedTextBoxNumber);
groupBox1.Controls.Add(ButtonAddPlane);
groupBox1.Location = new Point(956, 9);
groupBox1.Location = new Point(804, 9);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(213, 646);
groupBox1.TabIndex = 1;
@ -102,7 +102,7 @@
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1169, 667);
ClientSize = new Size(1017, 667);
Controls.Add(groupBox1);
Controls.Add(pictureBoxCollection);
Name = "FormPlaneCollection";

View File

@ -39,7 +39,7 @@ namespace ProjectAirBomber
FormAirBomber form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_planes + form.SelectedPlane != null)
if (_planes + form.SelectedPlane != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _planes.ShowPlanes();
@ -63,7 +63,7 @@ namespace ProjectAirBomber
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (_planes - pos != null)
if (_planes - pos)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = _planes.ShowPlanes();

View File

@ -53,13 +53,11 @@ namespace ProjectAirBomber.Generics
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static PlanesGenericCollection<T, U>? operator +(PlanesGenericCollection<T, U>? collect, T? obj)
public static int operator +(PlanesGenericCollection<T, U>? collect, T? obj)
{
if (obj != null)
{
collect?._collection.Insert(obj);
}
return collect;
if (obj == null || collect == null)
return -1;
return collect._collection.Insert(obj);
}
/// <summary>
/// Перегрузка оператора вычитания
@ -67,14 +65,12 @@ namespace ProjectAirBomber.Generics
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static PlanesGenericCollection<T, U>? operator -(PlanesGenericCollection<T, U>? collect, int pos)
public static bool operator -(PlanesGenericCollection<T, U> collect, int pos)
{
T? obj = collect?._collection.Get(pos);
if (obj != null)
{
collect?._collection.Remove(pos);
}
return collect;
if (obj == null || collect == null)
return false;
return collect._collection.Remove(pos);
}
/// <summary>
/// Получение объекта IMoveableObject
@ -130,7 +126,7 @@ namespace ProjectAirBomber.Generics
if (plane != null)
{
int inRow = _pictureWidth / _placeSizeWidth;
plane.SetPosition(_pictureWidth - _placeSizeWidth - (i % inRow * _placeSizeWidth) - _placeSizeHeight / 2 + 10, i / inRow * _placeSizeHeight + 20);
plane.SetPosition(_pictureWidth - _placeSizeWidth - (i % inRow * _placeSizeWidth) - _placeSizeHeight / 2 - 8, i / inRow * _placeSizeHeight + 20);
plane.DrawTransport(g);
}
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -18,29 +19,29 @@ namespace ProjectAirBomber.Generics
_places = new T?[count];
}
public bool Insert(T plane)
public int Insert(T plane)
{
if (_places[Count - 1] != null)
return false;
return -1;
return Insert(plane, 0);
}
public bool Insert(T plane, int position)
public int Insert(T plane, int position)
{
if (!(position >= 0 && position < Count))
return false;
return -1;
if (_places[position] != null)
{
int ind = position;
while (ind < Count && _places[ind] != null)
ind++;
if (ind == Count)
return false;
return -1;
for (int i = ind - 1; i >= position; i--)
_places[i + 1] = _places[i];
}
_places[position] = plane;
return true;
return position;
}
public bool Remove(int position)
{