Abazov A. A. LabWork04 #4

Merged
eegov merged 5 commits from LabWork04 into LabWork03 2022-10-28 09:46:46 +04:00
3 changed files with 103 additions and 9 deletions
Showing only changes of commit 3a0b45fdff - Show all commits

View File

@ -88,13 +88,9 @@ namespace AirBomber
public Bitmap ShowOnMap()
{
Shaking();
for (int i = 0; i < _setAirBombers.Count; i++)
foreach (var airBomber in _setAirBombers.GetAirBombers())
{
var airBomber = _setAirBombers[i];
if (airBomber != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, airBomber);
}
return _map.CreateMap(_pictureWidth, _pictureHeight, airBomber);
}
return new(_pictureWidth, _pictureHeight);
}
@ -163,10 +159,12 @@ namespace AirBomber
private void DrawAirBombers(Graphics g)
{
int numOfObjectsInRow = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _setAirBombers.Count; i++)
int i = 0;
foreach (var airBomber in _setAirBombers.GetAirBombers())
{
_setAirBombers[i]?.SetObject((numOfObjectsInRow - (i % numOfObjectsInRow) - 1) * _placeSizeWidth, (i / numOfObjectsInRow) * _placeSizeHeight, _pictureWidth, _pictureHeight);
_setAirBombers[i]?.DrawingObject(g);
airBomber.SetObject((numOfObjectsInRow - (i % numOfObjectsInRow) - 1) * _placeSizeWidth, (i / numOfObjectsInRow) * _placeSizeHeight, _pictureWidth, _pictureHeight);
airBomber.DrawingObject(g);
i++;
}
}
}

View File

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber
{
internal class MapsCollection
{
/// <summary>
/// Словарь (хранилище) с картами
/// </summary>
readonly Dictionary<string, MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>> _mapStorages;
/// <summary>
/// Возвращение списка названий карт
/// </summary>
public List<string> Keys => _mapStorages.Keys.ToList();
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="pictureWidth"></param>
/// <param name="pictureHeight"></param>
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new Dictionary<string, MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// <summary>
/// Добавление карты
/// </summary>
/// <param name="name">Название карты</param>
/// <param name="map">Карта</param>
public void AddMap(string name, AbstractMap map)
{
if (_mapStorages.ContainsKey(name))
{
MessageBox.Show("Карта с таким названием уже существует!");
Review

В классе с логикой не выводят сообщения

В классе с логикой не выводят сообщения
return;
}
_mapStorages.Add(name, new MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>(_pictureWidth, _pictureHeight, map));
}
/// <summary>
/// Удаление карты
/// </summary>
/// <param name="name">Название карты</param>
public void DelMap(string name)
{
if (_mapStorages.ContainsKey(name))
{
_mapStorages.Remove(name);
}
}
/// <summary>
/// Доступ к парковке
/// </summary>
/// <param name="ind"></param>
/// <returns></returns>
public MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap> this[string ind]
{
get
{
if (_mapStorages.ContainsKey(ind)) return _mapStorages[ind];
return null;
}
}
}
}

View File

@ -82,5 +82,24 @@ namespace AirBomber
if (position < 0 || position >= _maxCount) Insert(value, position);
}
}
/// <summary>
/// Проход по набору до первого пустого
/// </summary>
/// <returns></returns>
public IEnumerable<T> GetAirBombers()
{
foreach (var airBomber in _places)
{
if (airBomber != null)
{
yield return airBomber;
}
else
{
yield break;
}
}
}
}
}