Фикс ObjNotFndEx в компании

This commit is contained in:
grishazagidulin 2024-04-28 17:02:12 +04:00
parent 3cac227c53
commit 7baa0393e0
2 changed files with 14 additions and 4 deletions

View File

@ -1,4 +1,5 @@
using Battleship.Drawnings;
using Battleship.Exceptions;
namespace Battleship.CollectionGenericObjects;
/// <summary>
@ -94,8 +95,12 @@ public abstract class AbstractCompany
SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
DrawningShip? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
try
{
DrawningShip? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
}
catch (ObjectNotFoundException) { };
}
return bitmap;
}

View File

@ -1,4 +1,5 @@
using Battleship.Drawnings;
using Battleship.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
@ -50,8 +51,12 @@ public class ShipDocks : AbstractCompany
{
if (count < _collection.Count)
{
_collection?.Get(count)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection?.Get(count)?.SetPosition(ix, iy);
try
{
_collection?.Get(count)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection?.Get(count)?.SetPosition(ix, iy);
}
catch (ObjectNotFoundException){}
}
count++;
}