private void LogGrid(Direction direction) { if (lastLoggedGrid != null) { bool flag = true; // dumbass tile check. wrote this when i was drunk or something and dont feel like making it not bad for (int y = 0; y < Size; y++) { for (int x = 0; x < Size; x++) { if (grid.Cells[y, x] == null && lastLoggedGrid[y, x] != null || grid.Cells[y, x] != null && lastLoggedGrid[y, x] == null || grid.Cells[y, x] != null && lastLoggedGrid[y, x] != null && grid.Cells[y, x].Value != lastLoggedGrid[y, x].Value) { flag = false; } } } if (flag) { return; } } lastLoggedGrid = new DigTile[Size, Size]; for (int y = 0; y < Size; y++) { for (int x = 0; x < Size; x++) { lastLoggedGrid[y, x] = grid.Cells[y, x] ?? null; } } GridLog log = new GridLog(CurrentScore, direction); grid.EachCell(delegate(int x, int y, DigTile tile) { if (tile != null) { log.tiles.Add(new GridLog.GridLogTile(tile)); } }); Log("Current grid: {0}", JsonConvert.SerializeObject(log, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })); }
public Grid2048(Grid2048 grid) { Size = grid.Size; Cells = new DigTile[Size, Size]; grid.EachCell((x, y, tile) => Cells[y, x] = tile == null ? null : new DigTile(tile)); }