diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs index 2febce7..8624783 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs @@ -117,6 +117,8 @@ namespace AirPlaneWithRadar { return; } + if (maskedTextBoxPosition.Text == null) + return; int pos = Convert.ToInt32(maskedTextBoxPosition.Text); if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - (pos - 1)) != null) { diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs index 457fbe3..37316eb 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs @@ -113,44 +113,33 @@ namespace AirPlaneWithRadar } private void DrawPlains(Graphics g) { - - int CountWidth = _pictureWidth / _placeSizeWidth; int x = _pictureWidth - _placeSizeWidth; int y = _placeSizeHeight / 4; - - for (int k = 0; k < _setPlains.Count; k++) + int k = 0; + foreach(var plain in _setPlains.GetPlains()) { - if (_setPlains[k] != null) - { + if ((k + 1) % CountWidth != 0 || k == 0) { - _setPlains[k]?.SetObject(x, y, _pictureWidth, _pictureHeight); - _setPlains[k]?.DrawningObject(g); + plain?.SetObject(x, y, _pictureWidth, _pictureHeight); + plain?.DrawningObject(g); x -= _placeSizeWidth; } else { - _setPlains[k]?.SetObject(x, y, _pictureWidth, _pictureHeight); - _setPlains[k]?.DrawningObject(g); - x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4; + plain?.SetObject(x, y, _pictureWidth, _pictureHeight); + plain?.DrawningObject(g); + x = _pictureWidth - _placeSizeWidth ; y += _placeSizeHeight; } - } - if (_setPlains[k] == null) - { - if ((k + 1) % CountWidth != 0 || k == 0) - x -= _placeSizeWidth; - else - { - x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4; - y += _placeSizeHeight; - } - } + + k++; } + } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/MapsCollection.cs b/AirPlaneWithRadar/AirPlaneWithRadar/MapsCollection.cs index 0dfb5ea..abbd72a 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/MapsCollection.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/MapsCollection.cs @@ -25,13 +25,19 @@ namespace AirPlaneWithRadar public void AddMap(string name, AbstractMap map) { - + if (_mapStorages.ContainsKey(name)) + return; + Keys.Add(name); + _mapStorages.Add(name, new MapWithSetPlainGeneric(_pictureWidth, _pictureHeight, map)); } public void DelMap(string name) { - + if (!_mapStorages.ContainsKey(name)) + return; + Keys.Remove(name); + _mapStorages.Remove(name); } public MapWithSetPlainGeneric this[string ind] @@ -39,7 +45,9 @@ namespace AirPlaneWithRadar get { - + if (!_mapStorages.ContainsKey(ind)) + return null; + else return _mapStorages[ind]; } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs index 4e83bdd..45b9dc2 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs @@ -20,31 +20,57 @@ namespace AirPlaneWithRadar } public int Insert(T plain) { - + if (_places.Count == _maxCount) + { + return -1; + } + _places.Insert(0, plain); - return 1; + return _places.Count; } - public bool Insert(T plain, int position) + public int Insert(T plain, int position) { - - return true; + if (position < 0 || _places.Count < position||position > _maxCount) + return -1; + else if (plain == null) + return -1; + _places.Insert(position, plain); + return position; } public T Remove(int position) { - - return _places[position]; + T mid; + if (position < 0 || _places.Count < position || position > _maxCount) + return null; + else if (_places[position] == null) + return null; + else + { + mid = _places[position]; + _places.RemoveAt(position); + } + return mid; } public T this[int position] { get { - + if (position < 0 || _places.Count < position || position > _maxCount) + return null; + else if (_places[position] == null) + return null; + else return _places[position]; } set { - + if (position < 0 || _places.Count < position || position > _maxCount) + return; + else if (_places.Count == _maxCount) + return; + else + _places[position] = value; } } public IEnumerable GetPlains()