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

View File

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

View File

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

View File

@ -20,7 +20,7 @@ public class DrawingStormtrooper: DrawningStormtrooperBase
/// <param name="rockets"></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);
@ -62,7 +62,7 @@ public class DrawingStormtrooper: DrawningStormtrooperBase
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 40, 10, 10);
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 90, 10, 10);
}
}

View File

@ -36,7 +36,7 @@ public class DrawningStormtrooperBase
/// Высота прорисовки
/// </summary>
private readonly int _drawningStormtooperHeight = 140;
private readonly int _drawningStormtooperHeight = 135;
/// <summary>
/// Координата Х объекта
@ -215,7 +215,7 @@ public class DrawningStormtrooperBase
Pen pen = new(Color.Black);
Brush bodyColorBrush = new SolidBrush(EntityStormtrooperBase.BodyColor);
//нос штурмовика
Brush brBlack = new SolidBrush(Color.Black);

View File

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

View File

@ -100,7 +100,7 @@ public partial class FormStormtrooperCollection : Form
/// <param name="e"></param>
private void ButtonRemoveStormtrooper_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
{
return;
@ -110,6 +110,7 @@ public partial class FormStormtrooperCollection : Form
return;
}
int pos = Convert.ToInt32(maskedTextBox.Text);
int tempSize = StormtrooperSharingService.getAmountOfObjects();
try
{
if (_company - pos != null)
@ -119,7 +120,7 @@ public partial class FormStormtrooperCollection : Form
_logger.LogInformation("Удален объект по позиции" + pos);
}
}
catch(Exception ex)
catch (Exception ex)
{
MessageBox.Show("Не удалось удалить объект");
_logger.LogError("Ошибка: {Message}", ex.Message);
@ -140,22 +141,23 @@ public partial class FormStormtrooperCollection : Form
int counter = 100;
try
{
while (stormtrooper == null)
{
stormtrooper = _company.GetRandomObject();
counter--;
if (counter < -0)
if (counter <= 0)
{
break;
}
}
FormStormtrooper form = new()
FormStormtrooper form = new();
{
SetStormtrooper = stormtrooper
SetStormtrooper(stormtrooper);
};
form.ShowDialog();
}
catch(Exception ex)
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
@ -200,7 +202,7 @@ public partial class FormStormtrooperCollection : Form
RerfreshListBoxItems();
_logger.LogInformation("Коллекция добавлена" + textBoxCollectionName.Text);
}
catch(Exception ex)
catch (Exception ex)
{
_logger.LogError("Ошибка: {Message}", ex.Message);
}
@ -231,11 +233,11 @@ public partial class FormStormtrooperCollection : Form
RerfreshListBoxItems();
_logger.LogInformation("Коллекция:" + listBoxCollection.SelectedItem.ToString() + "удалена");
}
catch(Exception ex)
catch (Exception ex)
{
_logger.LogError("Ошибка: {Message}", ex.Message);
}
}
/// <summary>
/// Добавление списка в listBoxCollection
@ -302,7 +304,7 @@ public partial class FormStormtrooperCollection : Form
MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogError("Ошибка: {Message}", ex.Message);
}
}
}
/// <summary>
@ -323,20 +325,20 @@ public partial class FormStormtrooperCollection : Form
RerfreshListBoxItems();
_logger.LogInformation("Загрузка из файла: {filename}", openFileDialog.FileName);
}
catch(Exception ex)
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogError("Ошибка: {Message}", ex.Message);
}
}
}
}

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">
<value>261, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>25</value>
</metadata>
</root>