доработки

This commit is contained in:
Hells Hound 2022-11-28 11:26:09 +04:00
parent d53e5be32e
commit 47b268ae21
3 changed files with 38 additions and 14 deletions

View File

@ -177,10 +177,11 @@ namespace AircraftCarrier
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
try try
{ {
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) var deletedWarship = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos;
if (deletedWarship != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
_logger.LogInformation("Из текущей карты удален объект {@ship}", (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos)); _logger.LogInformation("Из текущей карты удален объект {@ship}", deletedWarship);
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else

View File

@ -149,10 +149,10 @@ namespace AircraftCarrier
{ {
for (; j > i; j--) for (; j > i; j--)
{ {
var car = _setWarships[j]; var warship = _setWarships[j];
if (car != null) if (warship != null)
{ {
_setWarships.Insert(car, i); _setWarships.Insert(warship, i);
_setWarships.Remove(j); _setWarships.Remove(j);
break; break;
} }
@ -189,14 +189,33 @@ namespace AircraftCarrier
/// <param name="g"></param> /// <param name="g"></param>
private void DrawWarships(Graphics g) private void DrawWarships(Graphics g)
{ {
int width = _pictureWidth / _placeSizeWidth; int countInLine = _pictureWidth / _placeSizeWidth;
int countInColumn = _pictureHeight / _placeSizeHeight;
int maxLeft = (countInLine - 1) * _placeSizeWidth;
int maxDown = (countInColumn - 1) * _placeSizeHeight;
for (int i = 0; i < _setWarships.Count; i++)
{
var warship = _setWarships[i];
warship?.SetObject(i % countInLine * _placeSizeWidth, maxDown - i / countInLine * _placeSizeHeight + 7, _pictureWidth, _pictureHeight);
//warship?.SetObject(i % countInLine * _placeSizeWidth - 3, i / countInLine * _placeSizeHeight, _pictureWidth, _pictureHeight);
//warship?.SetObject(i % countInLine * _placeSizeWidth - 3, maxDown - i * countInColumn * _placeSizeHeight, _pictureWidth, _pictureHeight);
//warship?.SetObject(i % _pictureWidth * _placeSizeWidth, (countInColumn - 1 - i / countInLine) * _placeSizeHeight + 5, _pictureWidth, _pictureHeight);
warship?.DrawningObject(g);
}
/*int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight; int height = _pictureHeight / _placeSizeHeight;
for (int i = 0; i < _setWarships.Count; i++) for (int i = 0; i < _setWarships.Count; i++)
{ {
var warship = _setWarships[i]; var warship = _setWarships[i];
warship?.SetObject(i % _pictureWidth * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight + 4, _pictureWidth, _pictureHeight); warship?.SetObject(i % _pictureWidth * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight + 4, _pictureWidth, _pictureHeight);
warship?.DrawningObject(g); warship?.DrawningObject(g);
} }*/
} }
} }
} }

View File

@ -52,10 +52,16 @@ namespace AircraftCarrier
if (Count == _maxCount) if (Count == _maxCount)
throw new StorageOverflowException(_maxCount); throw new StorageOverflowException(_maxCount);
if (position >= _maxCount || position < 0) return -1; if (!isCorrectPosition(position)) return -1;
_places.Insert(position, warship); _places.Insert(position, warship);
return 1; return 1;
} }
private bool isCorrectPosition(int position)
{
return 0 <= position && position < _maxCount;
}
/// <summary> /// <summary>
/// Удаление объекта из набора с конкретной позиции /// Удаление объекта из набора с конкретной позиции
/// </summary> /// </summary>
@ -63,10 +69,9 @@ namespace AircraftCarrier
/// <returns></returns> /// <returns></returns>
public T Remove(int position) public T Remove(int position)
{ {
if (position >= _maxCount || position < 0) if (!isCorrectPosition(position))
return null; return null;
var result = this[position];
var result = _places[position];
if (result == null) if (result == null)
throw new WarshipNotFoundException(position); throw new WarshipNotFoundException(position);
_places.RemoveAt(position); _places.RemoveAt(position);
@ -81,8 +86,7 @@ namespace AircraftCarrier
{ {
get get
{ {
if (position >= _maxCount || position < 0) return null; return isCorrectPosition(position) && position < Count ? _places[position] : null;
return _places[position];
} }
set set
{ {