LabWork07

This commit is contained in:
Сафия Мухамадиева 2024-05-16 01:38:01 +03:00
parent d4b74a7d92
commit 1641bff131
3 changed files with 42 additions and 43 deletions

View File

@ -1,4 +1,5 @@
using ProjectBattleship.DrawingObject;
using ProjectBattleship.Exceptions;
namespace ProjectBattleship.CollectionGenericObjects;
/// <summary>
@ -12,8 +13,8 @@ public class Docks : AbstractCompany
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="collection"></param>
public Docks(int picWidth, int picHeight,
ICollectionGenericObjects<DrawingWarship> collection) :
public Docks(int picWidth, int picHeight,
ICollectionGenericObjects<DrawingWarship> collection) :
base(picWidth, picHeight, collection)
{
}
@ -26,48 +27,47 @@ public class Docks : AbstractCompany
{
for (int j = 0; j < height; ++j)
{
g.FillRectangle(brush, i * _placeSizeWidth,
g.FillRectangle(brush, i * _placeSizeWidth,
j * _placeSizeHeight, 200, 5);
g.FillRectangle(brush, i * _placeSizeWidth,
g.FillRectangle(brush, i * _placeSizeWidth,
j * _placeSizeHeight, 5, 80);
}
}
for (int j = 0; j < height - 4; ++j)
{
g.FillRectangle(brush, j * _placeSizeWidth,
g.FillRectangle(brush, j * _placeSizeWidth,
height * _placeSizeHeight, 200, 5);
}
}
protected override void SetObjectsPosition()
{
if (_collection == null) return;
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int curWidth = width - 1;
int curHeight = 0;
for (int i = 0; i < _collection.Count; i++)
for (int i = 0; i < (_collection?.Count ?? 0); i++)
{
DrawingWarship? _warship = _collection.Get(i);
if (_warship != null)
try
{
if (_warship.SetPictureSize(_pictureWidth, _pictureHeight))
{
_warship.SetPosition(_placeSizeWidth * curWidth + 20,
curHeight * _placeSizeHeight + 15);
}
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
_collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 10, curHeight * _placeSizeHeight + 10);
}
curWidth--;
if (curWidth < 0)
catch (ObjectNotFoundException) { }
catch (PositionOutOfCollectionException e) { }
if (curWidth > 0)
curWidth--;
else
{
curHeight++;
curWidth = width - 1;
curHeight++;
}
if (curHeight >= height)
{
return;
}
}
}
}
}

View File

@ -142,29 +142,29 @@ public partial class FormWarshipCollection : Form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveWarship_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)
|| _company == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_company - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
//private void ButtonRemoveWarship_Click(object sender, EventArgs e)
//{
// if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)
// || _company == null)
// {
// return;
// }
// if (MessageBox.Show("Удалить объект?", "Удаление",
// MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
// {
// return;
// }
// int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
// if (_company - pos != null)
// {
// MessageBox.Show("Объект удален");
// pictureBox.Image = _company.Show();
// }
// else
// {
// MessageBox.Show("Не удалось удалить объект");
// }
//}
/// <summary>
/// Передача объекта в другую форму
/// </summary>

View File

@ -9,8 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.11" />