// проверка на 3 подряд влево и вверх private bool CheckThrees(int row, int column) { bool hasThrees = false; TileImage curImage = (TileImage)GetElement(row, column); if (row > 1) { TileImage imageMinusRow = (TileImage)GetElement(row - 1, column); TileImage imageMinus2Row = (TileImage)GetElement(row - 2, column); if (curImage.ColorName == imageMinusRow.ColorName && curImage.ColorName == imageMinus2Row.ColorName) { return(true); } } if (column > 1) { TileImage imageMinusColumn = (TileImage)GetElement(row, column - 1); TileImage imageMinus2Column = (TileImage)GetElement(row, column - 2); if (curImage.ColorName == imageMinusColumn.ColorName && curImage.ColorName == imageMinus2Column.ColorName) { return(true); } } return(hasThrees); }
// удаление по ссылке (полиморфизм) private void RemoveTImage(TileImage tile) { if (tile != null) { Children.Remove(tile); } }
public void MatchAndClear() { CopyBoard(); currentTile = null; collector.Clear(); for (int y = 0; y < dimension; y++) { for (int x = 0; x < dimension; x++) { TestTile(x, y); if (collector.Count >= 3 && (tripleX >= 3 || tripleY >= 3)) { foreach (TileImage tile in collector) { RemoveTImage(tile); AddPoints(1); } } currentTile = null; collector.Clear(); tripleY = tripleX = 0; } } FillEmptyTiles(); }
// добавление тайла по индексам private TileImage PlaceTImage(int x, int y, string color) { RemoveTImage(x, y); var timage = new TileImage(color); SetRow(timage, x); SetColumn(timage, y); timage.MouseDown += OnMouseClick; timage.Drop += TargetDrop; Children.Add(timage); return(timage); }
private void TestTile(int x, int y) { if (tileImagesArr[x, y] == null) { return; } if (currentTile == null) { currentTile = tileImagesArr[x, y]; tileImagesArr[x, y] = null; collector.Add(currentTile); } else if (currentTile.ColorName != tileImagesArr[x, y].ColorName) { return; } else { collector.Add(tileImagesArr[x, y]); tileImagesArr[x, y] = null; } if (x > 0) { tripleX++; TestTile(x - 1, y); } if (y > 0) { tripleY++; TestTile(x, y - 1); } if (x < dimension - 1) { tripleX++; TestTile(x + 1, y); } if (y < dimension - 1) { tripleY++; TestTile(x, y + 1); } }