закончена лабораторная 7
This commit is contained in:
parent
668d6a7a7f
commit
9688585e32
@ -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>
|
||||||
@ -85,8 +90,12 @@ public abstract class AbstractCompany
|
|||||||
SetObjectsPosition();
|
SetObjectsPosition();
|
||||||
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||||
{
|
{
|
||||||
DrawningStormtrooperBase? obj = _collection?.Get(i);
|
try
|
||||||
obj?.DrawTransport(graphics);
|
{
|
||||||
|
DrawningStormtrooperBase? obj = _collection?.Get(i);
|
||||||
|
obj?.DrawTransport(graphics);
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
}
|
}
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
@ -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()
|
||||||
|
@ -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];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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);
|
||||||
|
|
||||||
@ -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 + 40, 10, 10);
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 90, 10, 10);
|
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 90, 10, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ public class DrawningStormtrooperBase
|
|||||||
/// Высота прорисовки
|
/// Высота прорисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
private readonly int _drawningStormtooperHeight = 140;
|
private readonly int _drawningStormtooperHeight = 135;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Координата Х объекта
|
/// Координата Х объекта
|
||||||
@ -215,7 +215,7 @@ public class DrawningStormtrooperBase
|
|||||||
|
|
||||||
Pen pen = new(Color.Black);
|
Pen pen = new(Color.Black);
|
||||||
Brush bodyColorBrush = new SolidBrush(EntityStormtrooperBase.BodyColor);
|
Brush bodyColorBrush = new SolidBrush(EntityStormtrooperBase.BodyColor);
|
||||||
|
|
||||||
|
|
||||||
//нос штурмовика
|
//нос штурмовика
|
||||||
Brush brBlack = new SolidBrush(Color.Black);
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
|
@ -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);
|
||||||
|
@ -100,7 +100,7 @@ public partial class FormStormtrooperCollection : Form
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonRemoveStormtrooper_Click(object sender, EventArgs e)
|
private void ButtonRemoveStormtrooper_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -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)
|
||||||
@ -119,7 +120,7 @@ public partial class FormStormtrooperCollection : Form
|
|||||||
_logger.LogInformation("Удален объект по позиции" + pos);
|
_logger.LogInformation("Удален объект по позиции" + pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
@ -140,22 +141,23 @@ 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();
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
@ -200,7 +202,7 @@ public partial class FormStormtrooperCollection : Form
|
|||||||
RerfreshListBoxItems();
|
RerfreshListBoxItems();
|
||||||
_logger.LogInformation("Коллекция добавлена" + textBoxCollectionName.Text);
|
_logger.LogInformation("Коллекция добавлена" + textBoxCollectionName.Text);
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
}
|
}
|
||||||
@ -231,11 +233,11 @@ public partial class FormStormtrooperCollection : Form
|
|||||||
RerfreshListBoxItems();
|
RerfreshListBoxItems();
|
||||||
_logger.LogInformation("Коллекция:" + listBoxCollection.SelectedItem.ToString() + "удалена");
|
_logger.LogInformation("Коллекция:" + listBoxCollection.SelectedItem.ToString() + "удалена");
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление списка в listBoxCollection
|
/// Добавление списка в listBoxCollection
|
||||||
@ -302,7 +304,7 @@ public partial class FormStormtrooperCollection : Form
|
|||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -323,20 +325,20 @@ public partial class FormStormtrooperCollection : Form
|
|||||||
RerfreshListBoxItems();
|
RerfreshListBoxItems();
|
||||||
_logger.LogInformation("Загрузка из файла: {filename}", openFileDialog.FileName);
|
_logger.LogInformation("Загрузка из файла: {filename}", openFileDialog.FileName);
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Результат",
|
MessageBox.Show(ex.Message, "Результат",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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>
|
Loading…
Reference in New Issue
Block a user