diff --git a/ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs b/ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs index e4a7e64..036d62c 100644 --- a/ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs +++ b/ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs @@ -176,8 +176,8 @@ namespace ArmoredCar int k = 0; foreach (var armoredCar in _setCars.GetCars()) { - armoredCar.SetObject(k % width * _placeSizeWidth + 5, k / width * _placeSizeHeight + 10, _pictureWidth, _pictureHeight); - armoredCar.DrawningObject(g); + armoredCar?.SetObject(k % width * _placeSizeWidth + 5, k / width * _placeSizeHeight + 10, _pictureWidth, _pictureHeight); + armoredCar?.DrawningObject(g); k++; } } @@ -191,7 +191,10 @@ namespace ArmoredCar string data = $"{_map.GetType().Name}{separatorType}"; foreach (var armoredCar in _setCars.GetCars()) { - data += $"{armoredCar.GetInfo()}{separatorData}"; + if (armoredCar != null) + data += $"{armoredCar.GetInfo()}{separatorData}"; + else + data += $"null{separatorData}"; } return data; } @@ -203,7 +206,10 @@ namespace ArmoredCar { foreach (var rec in records) { - _setCars.Insert(DrawningObjectArmCar.Create(rec) as T); + if (rec != "null") + _setCars.Insert(DrawningObjectArmCar.Create(rec) as T); + else + _setCars.Insert(null); } } } diff --git a/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs b/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs index 6d63325..fabb0b3 100644 --- a/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs +++ b/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs @@ -65,7 +65,7 @@ namespace ArmoredCar T armoredCar = _places[position]; if (armoredCar == null) throw new ArmoredCarNotFoundException(position); - _places.RemoveAt(position); + _places[position] = null; return armoredCar; } /// @@ -98,14 +98,15 @@ namespace ArmoredCar { foreach (var car in _places) { - if (car != null) + yield return car; + /*if (car != null) { yield return car; } else { yield break; - } + }*/ } }