доработки
This commit is contained in:
parent
d53e5be32e
commit
47b268ae21
@ -177,10 +177,11 @@ namespace AircraftCarrier
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
try
|
||||
{
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
var deletedWarship = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos;
|
||||
if (deletedWarship != null)
|
||||
{
|
||||
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();
|
||||
}
|
||||
else
|
||||
|
@ -149,10 +149,10 @@ namespace AircraftCarrier
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var car = _setWarships[j];
|
||||
if (car != null)
|
||||
var warship = _setWarships[j];
|
||||
if (warship != null)
|
||||
{
|
||||
_setWarships.Insert(car, i);
|
||||
_setWarships.Insert(warship, i);
|
||||
_setWarships.Remove(j);
|
||||
break;
|
||||
}
|
||||
@ -189,14 +189,33 @@ namespace AircraftCarrier
|
||||
/// <param name="g"></param>
|
||||
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;
|
||||
for (int i = 0; i < _setWarships.Count; i++)
|
||||
{
|
||||
var warship = _setWarships[i];
|
||||
warship?.SetObject(i % _pictureWidth * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight + 4, _pictureWidth, _pictureHeight);
|
||||
warship?.DrawningObject(g);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,10 +52,16 @@ namespace AircraftCarrier
|
||||
if (Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
|
||||
if (position >= _maxCount || position < 0) return -1;
|
||||
if (!isCorrectPosition(position)) return -1;
|
||||
_places.Insert(position, warship);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private bool isCorrectPosition(int position)
|
||||
{
|
||||
return 0 <= position && position < _maxCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
@ -63,10 +69,9 @@ namespace AircraftCarrier
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position >= _maxCount || position < 0)
|
||||
if (!isCorrectPosition(position))
|
||||
return null;
|
||||
|
||||
var result = _places[position];
|
||||
var result = this[position];
|
||||
if (result == null)
|
||||
throw new WarshipNotFoundException(position);
|
||||
_places.RemoveAt(position);
|
||||
@ -81,8 +86,7 @@ namespace AircraftCarrier
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position >= _maxCount || position < 0) return null;
|
||||
return _places[position];
|
||||
return isCorrectPosition(position) && position < Count ? _places[position] : null;
|
||||
}
|
||||
set
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user