закончена лабораторная 7

This commit is contained in:
Adelina888 2024-05-13 21:19:14 +04:00
parent 668d6a7a7f
commit 9688585e32
9 changed files with 45 additions and 31 deletions

View File

@ -9,7 +9,7 @@ public abstract class AbstractCompany
/// <summary> /// <summary>
/// Размер места (ширина) /// Размер места (ширина)
/// </summary> /// </summary>
protected readonly int _placeSizeWidth = 210; protected readonly int _placeSizeWidth = 220;
/// <summary> /// <summary>
/// Размер места (высота) /// Размер места (высота)
/// </summary> /// </summary>
@ -22,10 +22,15 @@ public abstract class AbstractCompany
/// Высота окна /// Высота окна
/// </summary> /// </summary>
protected readonly int _pictureHeight; protected readonly int _pictureHeight;
protected static int amountOfObjects = 0;
/// <summary> /// <summary>
/// Коллекция штурмовика /// Коллекция штурмовика
/// </summary> /// </summary>
protected ICollectionGenericObjects<DrawningStormtrooperBase>? _collection = null; protected ICollectionGenericObjects<DrawningStormtrooperBase>? _collection = null;
public static int getAmountOfObjects()
{
return amountOfObjects;
}
/// <summary> /// <summary>
/// Вычисление максимального количества элементов, который можно разместить в окне /// Вычисление максимального количества элементов, который можно разместить в окне
/// </summary> /// </summary>
@ -84,10 +89,14 @@ public abstract class AbstractCompany
SetObjectsPosition(); SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i) for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
try
{ {
DrawningStormtrooperBase? obj = _collection?.Get(i); DrawningStormtrooperBase? obj = _collection?.Get(i);
obj?.DrawTransport(graphics); obj?.DrawTransport(graphics);
} }
catch (Exception) { }
}
return bitmap; return bitmap;
} }
/// <summary> /// <summary>

View File

@ -79,9 +79,9 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
// TODO проверка позиции // TODO проверка позиции
// TODO удаление объекта из списка // TODO удаление объекта из списка
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position); if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
T obj = _collection[position]; T temp = _collection[position];
_collection.RemoveAt(position); _collection.RemoveAt(position);
return obj; return temp;
} }
public IEnumerable<T?> GetItems() public IEnumerable<T?> GetItems()

View File

@ -54,7 +54,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
{ {
// проверка позиции // проверка позиции
if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position); if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
//if (_collection[position] == null) throw new ObjectNotFoundException(position); if (_collection[position] == null) throw new ObjectNotFoundException(position);
return _collection[position]; return _collection[position];
} }

View File

@ -46,15 +46,15 @@ public class StormtrooperSharingService : AbstractCompany
{ {
try try
{ {
if (_collection.Get(i) != null)
{
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
_collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 15, curHeight * _placeSizeHeight + 3); _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 15, curHeight * _placeSizeHeight + 3);
}
} }
catch (Exception) { } catch (Exception) { }
if (curWidth > 0) if (curWidth > 0)
curWidth--; curWidth--;
else else
{ {
curWidth = width - 1; curWidth = width - 1;

View File

@ -20,7 +20,7 @@ public class DrawingStormtrooper: DrawningStormtrooperBase
/// <param name="rockets"></param> /// <param name="rockets"></param>
/// <param name="bombs"></param> /// <param name="bombs"></param>
public DrawingStormtrooper(int speed,double weight, Color bodyColor,Color additionalColor, bool rockets, bool bombs):base(140,140) public DrawingStormtrooper(int speed,double weight, Color bodyColor,Color additionalColor, bool rockets, bool bombs):base(140,135)
{ {
EntityStormtrooperBase = new EntityStormtrooper(speed, weight, bodyColor, additionalColor, rockets, bombs); EntityStormtrooperBase = new EntityStormtrooper(speed, weight, bodyColor, additionalColor, rockets, bombs);

View File

@ -36,7 +36,7 @@ public class DrawningStormtrooperBase
/// Высота прорисовки /// Высота прорисовки
/// </summary> /// </summary>
private readonly int _drawningStormtooperHeight = 140; private readonly int _drawningStormtooperHeight = 135;
/// <summary> /// <summary>
/// Координата Х объекта /// Координата Х объекта

View File

@ -68,7 +68,7 @@
groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(911, 24); groupBoxTools.Location = new Point(911, 24);
groupBoxTools.Name = "groupBoxTools"; groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(173, 604); groupBoxTools.Size = new Size(173, 646);
groupBoxTools.TabIndex = 0; groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false; groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты"; groupBoxTools.Text = "Инструменты";
@ -248,7 +248,7 @@
pictureBox.Dock = DockStyle.Fill; pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 24); pictureBox.Location = new Point(0, 24);
pictureBox.Name = "pictureBox"; pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(911, 604); pictureBox.Size = new Size(911, 646);
pictureBox.TabIndex = 3; pictureBox.TabIndex = 3;
pictureBox.TabStop = false; pictureBox.TabStop = false;
// //
@ -296,7 +296,7 @@
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1084, 628); ClientSize = new Size(1084, 670);
Controls.Add(pictureBox); Controls.Add(pictureBox);
Controls.Add(groupBoxTools); Controls.Add(groupBoxTools);
Controls.Add(menuStrip); Controls.Add(menuStrip);

View File

@ -110,6 +110,7 @@ public partial class FormStormtrooperCollection : Form
return; return;
} }
int pos = Convert.ToInt32(maskedTextBox.Text); int pos = Convert.ToInt32(maskedTextBox.Text);
int tempSize = StormtrooperSharingService.getAmountOfObjects();
try try
{ {
if (_company - pos != null) if (_company - pos != null)
@ -140,18 +141,19 @@ public partial class FormStormtrooperCollection : Form
int counter = 100; int counter = 100;
try try
{ {
while (stormtrooper == null) while (stormtrooper == null)
{ {
stormtrooper = _company.GetRandomObject(); stormtrooper = _company.GetRandomObject();
counter--; counter--;
if (counter < -0) if (counter <= 0)
{ {
break; break;
} }
} }
FormStormtrooper form = new() FormStormtrooper form = new();
{ {
SetStormtrooper = stormtrooper SetStormtrooper(stormtrooper);
}; };
form.ShowDialog(); form.ShowDialog();
} }

View File

@ -126,4 +126,7 @@
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>261, 17</value> <value>261, 17</value>
</metadata> </metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>25</value>
</metadata>
</root> </root>