PIbd-22. Fedorenko G.Y. Lab Work 3 #4

Closed
fedorenko wants to merge 3 commits from lab3 into lab2
3 changed files with 36 additions and 50 deletions
Showing only changes of commit a87e9d0fe5 - Show all commits

View File

@ -47,16 +47,18 @@
panel1.Controls.Add(InputNum);
panel1.Controls.Add(label1);
panel1.Dock = DockStyle.Right;
panel1.Location = new Point(550, 0);
panel1.Location = new Point(577, 0);
panel1.Margin = new Padding(3, 2, 3, 2);
panel1.Name = "panel1";
panel1.Size = new Size(250, 450);
panel1.Size = new Size(219, 338);
panel1.TabIndex = 0;
//
// UpdateButton
//
UpdateButton.Location = new Point(10, 241);
UpdateButton.Location = new Point(9, 181);
UpdateButton.Margin = new Padding(3, 2, 3, 2);
UpdateButton.Name = "UpdateButton";
UpdateButton.Size = new Size(228, 37);
UpdateButton.Size = new Size(200, 28);
UpdateButton.TabIndex = 4;
UpdateButton.Text = "Обновить коллекцию";
UpdateButton.UseVisualStyleBackColor = true;
@ -64,9 +66,10 @@
//
// DeleteButton
//
DeleteButton.Location = new Point(10, 176);
DeleteButton.Location = new Point(9, 132);
DeleteButton.Margin = new Padding(3, 2, 3, 2);
DeleteButton.Name = "DeleteButton";
DeleteButton.Size = new Size(228, 37);
DeleteButton.Size = new Size(200, 28);
DeleteButton.TabIndex = 3;
DeleteButton.Text = "Удалить самолёт";
DeleteButton.UseVisualStyleBackColor = true;
@ -74,9 +77,10 @@
//
// AddButton
//
AddButton.Location = new Point(10, 53);
AddButton.Location = new Point(9, 40);
AddButton.Margin = new Padding(3, 2, 3, 2);
AddButton.Name = "AddButton";
AddButton.Size = new Size(228, 37);
AddButton.Size = new Size(200, 28);
AddButton.TabIndex = 2;
AddButton.Text = "Добавить самолёт";
AddButton.UseVisualStyleBackColor = true;
@ -84,9 +88,10 @@
//
// InputNum
//
InputNum.Location = new Point(10, 133);
InputNum.Location = new Point(9, 100);
InputNum.Margin = new Padding(3, 2, 3, 2);
InputNum.Name = "InputNum";
InputNum.Size = new Size(228, 27);
InputNum.Size = new Size(200, 23);
InputNum.TabIndex = 1;
//
// label1
@ -94,7 +99,7 @@
label1.AutoSize = true;
label1.Location = new Point(2, 2);
label1.Name = "label1";
label1.Size = new Size(103, 20);
label1.Size = new Size(83, 15);
label1.TabIndex = 0;
label1.Text = "Инструменты";
//
@ -102,19 +107,21 @@
//
DrawPlane.Dock = DockStyle.Fill;
DrawPlane.Location = new Point(0, 0);
DrawPlane.Margin = new Padding(3, 2, 3, 2);
DrawPlane.Name = "DrawPlane";
DrawPlane.Size = new Size(550, 450);
DrawPlane.Size = new Size(577, 338);
DrawPlane.TabIndex = 1;
DrawPlane.TabStop = false;
//
// CollectionsFrame
// FormHydroplaneCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
ClientSize = new Size(796, 338);
Controls.Add(DrawPlane);
Controls.Add(panel1);
Name = "CollectionsFrame";
Margin = new Padding(3, 2, 3, 2);
Name = "FormHydroplaneCollection";
Text = "Form1";
panel1.ResumeLayout(false);
panel1.PerformLayout();

View File

@ -15,7 +15,7 @@ namespace Hydroplane.Generics
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 175;
private readonly int _placeSizeHeight = 80;
private readonly int _placeSizeHeight = 85;
private readonly SetGeneric<T> _collection;
public PlanesGenericCollection(int picWidth, int picHeight)
@ -80,7 +80,7 @@ namespace Hydroplane.Generics
{
for (int i = 0; i < _collection.Count; i++)
{
T t = _collection.Get(i);
T? t = _collection.Get(i);
if (t != null)
{
t.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);

View File

@ -19,48 +19,27 @@ namespace Hydroplane.Generics
public int Insert(T plane)
{
int index = -1;
for (int i = 0; i < _places.Length; i++)
{
if (_places[i] == null)
{
index = i; break;
}
}
if (index < 0)
{
if (_places[Count - 1] != null)
return -1;
}
for (int i = index; i > 0; i--)
{
_places[i] = _places[i - 1];
}
_places[0] = plane;
return 0;
return Insert(plane, 0);
}
public int Insert(T plane, int position)
{
if (position < 0 || position >= Count)
return -1;
if (_places[position] == null)
if (_places[position] != null)
{
_places[position] = plane;
return position;
}
int index = -1;
for (int i = position; i < Count; i++)
{
if (_places[i] == null)
int indexEnd = position + 1;
while (_places[indexEnd] != null)
{
index = i; break;
indexEnd++;
}
}
if (index < 0)
return -1;
for (int i = index; index > position; i--)
{
_places[i] = _places[i - 1];
for (int i = indexEnd + 1; i > position; i--)
{
_places[i] = _places[i - 1];
}
}
_places[position] = plane;
return position;