From 5f39e71615a889ffe0d8affb4d35c22b8dba1d4f Mon Sep 17 00:00:00 2001 From: Saanechkaa Date: Tue, 13 Dec 2022 17:24:29 +0400 Subject: [PATCH] Lab7 fix --- RoadTrain/RoadTrain/MapWithSetRoadTrainsGeneric.cs | 2 +- RoadTrain/RoadTrain/RoadTrain.csproj | 1 + RoadTrain/RoadTrain/SetRoadTrainsGeneric.cs | 8 ++++++-- 3 files changed, 8 insertions(+), 3 deletions(-) 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);