ПИ-21: практические примеры
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.0 KiB

using System;
using System.Collections.Generic;
using System.Linq;
namespace WorkField.Model
{
/// <summary>
/// Тип блока
/// </summary>
public enum EBlockType
{
Unknown = 0,
Wall = 1,
Field = 2,
}
/// <summary>
/// БлокСписок
/// </summary>
public class CBlockList
{
public List<CBlock> List;
/// <summary>Initializes a new instance of the <see cref="T:System.Object" /> class.</summary>
public CBlockList()
{
List = new List<CBlock>();
}
public int GetWidth()
{
int iMaxX = 0;
foreach (var pB in List) {
if (pB.X > iMaxX) {
iMaxX = pB.X;
}
}
return iMaxX;
}
public int GetHeight()
{
int iMaxY = 0;
foreach (var pB in List) {
if (pB.Y > iMaxY) {
iMaxY = pB.Y;
}
}
return iMaxY;
}
/// <summary>
/// Ищет элемент в позиции
/// </summary>
/// <param name="iX"></param>
/// <param name="iY"></param>
/// <returns></returns>
public CBlock Find(int iX, int iY)
{
CBlock el = List
.FirstOrDefault(block =>
block.X == iX && block.Y == iY);
//CBlock el = null;
//foreach (CBlock block in List) {
// if (block.X == iX && block.Y == iY) {
// el = block;
// break;
// }
//}
return el;
}
public bool Add(int iX, int iY, EBlockType enType)
{
CBlock pp = Find(iX, iY);
if (pp != null) {
return false;
}
switch (enType) {
case EBlockType.Field:
List.Add(new CFieldBlock() { X = iX, Y = iY });
break;
case EBlockType.Wall:
List.Add(new CWallBlock() { X = iX, Y = iY });
break;
case EBlockType.Unknown:
throw new ArgumentOutOfRangeException(nameof(enType), enType, null);
}
return true;
}
}
}