<pre>public bool CapturePieces(object p) { var piece = GameBoard.First(t => t.Id == (int)p); PieceColor currentColor = CurrentPlayer.TypeOfColor; int x = piece.Coordinates.Item1; int y = piece.Coordinates.Item2; for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { if (dx == 0 && dy == 0) continue; if (x + dx < 0 || x + dx > 7 || y + dy < 0 || y + dy > 7) continue; if (GameBoard.Any(square => square.Coordinates == (x + dx, y + dy) && square.TypeOfColor != oppositeColor)) continue; int i = 2; while (i <= 7) { if (x + i * dx < 0 || x + i * dx > 7 || y + i * dy < 0 || y + i * dy > 7) break; if (GameBoard.Any(square => square.Coordinates == (x + i * dx, y + i * dy) && square.TypeOfColor == PieceColor.Empty)) break; if (GameBoard.Any(square => square.Coordinates == (x + i * dx, y + i * dy) && piece.TypeOfColor == currentColor)) { return true; } i++; } } } return false; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)