diff --git a/RoadTrain/RoadTrain/MapWithSetRoadTrainsGeneric.cs b/RoadTrain/RoadTrain/MapWithSetRoadTrainsGeneric.cs index d92ef94..78197e0 100644 --- a/RoadTrain/RoadTrain/MapWithSetRoadTrainsGeneric.cs +++ b/RoadTrain/RoadTrain/MapWithSetRoadTrainsGeneric.cs @@ -49,7 +49,7 @@ { int width = picWidth / _placeSizeWidth; int height = picHeight / _placeSizeHeight; - _setRoadTrains = new SetRoadTrainsGeneric(width * height - 2); + _setRoadTrains = new SetRoadTrainsGeneric(width * height - 1); _pictureWidth = picWidth; _pictureHeight = picHeight; _map = map; diff --git a/RoadTrain/RoadTrain/RoadTrain.csproj b/RoadTrain/RoadTrain/RoadTrain.csproj index 92b34c7..e0d9d40 100644 --- a/RoadTrain/RoadTrain/RoadTrain.csproj +++ b/RoadTrain/RoadTrain/RoadTrain.csproj @@ -27,6 +27,7 @@ + diff --git a/RoadTrain/RoadTrain/SetRoadTrainsGeneric.cs b/RoadTrain/RoadTrain/SetRoadTrainsGeneric.cs index 051cec2..13d3946 100644 --- a/RoadTrain/RoadTrain/SetRoadTrainsGeneric.cs +++ b/RoadTrain/RoadTrain/SetRoadTrainsGeneric.cs @@ -72,9 +72,13 @@ public T Remove(int position) { // проверка позиции - if (position < 0 || position >= _maxCount) + if (position < 0 || position >= _maxCount - 1) return null; - T delObj = _places[position]; + if (position >= _places.Count) + { + throw new RoadTrainNotFoundException(position); + } + var delObj = _places[position]; if (delObj == null) { throw new RoadTrainNotFoundException(position);