private int ProcessQueue(ref Queue <WaveElement> wave, CellDomain waveDomain) { int count = 0; var tmpQ = new Queue <WaveElement>(); while (wave.Count > 0) { var startElem = wave.Dequeue(); if ((startElem.HPLeft <= 0) || (Map[startElem.Position.X, startElem.Position.Y].CellState != CellDomain.Free)) { continue; } count++; Map[startElem.Position.X, startElem.Position.Y].CellState = waveDomain; var delta = new int[] { -1, 1 }; foreach (var tmp in delta .SelectMany(d => new Point[] { new Point(startElem.Position.X + d, startElem.Position.Y), new Point(startElem.Position.X, startElem.Position.Y + d) }) .Where(x => (InBounds(x) && IsCellAvabForStep(CellDomain.Player, x)))) { tmpQ.Enqueue(new WaveElement(startElem.HPLeft - 1, tmp)); } } wave = tmpQ; return(count); }
private bool IsCellAvabForStep(CellDomain dom, Point p) { if ((Map[p.X, p.Y]).CellState == CellDomain.Free) { return(true); } if ((Map[p.X, p.Y]).CellState == dom) { return(true); } return(false); }
public Cell(CellDomain dom) { CellState = dom; }