public Cell AddCell(Cell cell) { if (_lstCell.Count > Rule.ROWS * Rule.COLUMNS / 3) { return(null); } while (_lstCell.Select(cl => cl.Position).Contains(cell.Position)) { cell.RandomPosition(); } cell.No = _lstCell.Count; cell.ParentWorldMapPanel = this; while (!cell.GetAbility()) { ; } cell.Dead += (sender, e) => { _lstCell.Remove(cell); this.Controls.Remove(cell); }; cell.PositionChanged += (sender, e) => { cell.Location = GetLocation(e.TargetPosition); }; _lstCell.Add(cell); this.Controls.Add(cell); this.Invalidate(cell.ClientRectangle); return(cell); }
public Cell AddCell(Cell cell) { if (_lstCell.Count > Rule.ROWS * Rule.COLUMNS / 3) { return null; } while (_lstCell.Select(cl => cl.Position).Contains(cell.Position)) { cell.RandomPosition(); } cell.No = _lstCell.Count; cell.ParentWorldMapPanel = this; while (!cell.GetAbility()) ; cell.Dead += (sender, e) => { _lstCell.Remove(cell); this.Controls.Remove(cell); }; cell.PositionChanged += (sender, e) => { cell.Location = GetLocation(e.TargetPosition); }; _lstCell.Add(cell); this.Controls.Add(cell); this.Invalidate(cell.ClientRectangle); return cell; }