Фикс 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.Drawnings;
using Battleship.Exceptions;
namespace Battleship.CollectionGenericObjects; namespace Battleship.CollectionGenericObjects;
/// <summary> /// <summary>
@ -93,10 +94,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
{ {
DrawningShip? obj = _collection?.Get(i); DrawningShip? obj = _collection?.Get(i);
obj?.DrawTransport(graphics); obj?.DrawTransport(graphics);
} }
catch (ObjectNotFoundException) { };
}
return bitmap; return bitmap;
} }

View File

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