public void PutValue(int x, int y, int value) { var target = cellBoard[x, y]; if (target.Value > 0) { var from = new CellData(target); target.Value = value; CellMoved?.Invoke(this, new CellMovedEventArgs(from, new CellData(target), null)); } else { target.Value = value; CellCreated?.Invoke(this, new CellCreatedEventArgs(new CellData(target))); } SaveUndo(); }
public void PullDown() { SaveUndo(); for (var x = 0; x < sizeX; x++) { var values = new List <CellData>(); for (var y = maxY; y >= 0; y--) { var cell = cellBoard[x, y]; if (cell.Value > 0) { values.Add(new CellData(cell)); } } var merged = TruncateList(values); var n = 0; for (var y = maxY; y >= 0; y--) { var to = cellBoard[x, y]; if (n < merged.Count) { var from = merged[n]; n++; to.Value = from.Data.Value; if (from.Merged.HasValue) { CellMoved?.Invoke(this, new CellMovedEventArgs(from.Data, new CellData(to), from.Merged.Value)); } else if (from.Data.Y != y) { CellMoved?.Invoke(this, new CellMovedEventArgs(from.Data, new CellData(to), null)); } } else { to.Value = 0; } } } CalculatePoints(); }