private void MouseDownHandler(object sender, MouseButtonEventArgs e) { int col = Grid.GetColumn((Image)sender); int row = Grid.GetRow((Image)sender); List<int[]> moveable = new List<int[]>(); List<int[]> threatened = new List<int[]>(); List<int[]> enPassant = new List<int[]>(); bool promote = false; cvm.SelectOrMove(row, col, moveable, threatened, enPassant, ref promote); if (promote) { Piece.Type promoteTo = new Piece.Type(); while (promoteTo == Piece.Type.Empty) { Promotion promo = new Promotion(row, ref promoteTo); promo.ShowDialog(); promoteTo = promo.PromoteTo(); } mf.Promote(promoteTo, row, col, cvm.Playfield); } drawPieces(); //draw borders for moveable squares foreach (int[] pair in moveable) drawBorder(pair[0], pair[1], "yellow"); foreach (int[] pair in threatened) //only show red if there's a piece to take if (cvm.Playfield[pair[0], pair[1]].Exists && cvm.Highlight.Contains(pair)) drawBorder(pair[0], pair[1], "red"); foreach (int[] pair in enPassant) drawBorder(pair[0], pair[1], "red"); }
private void MouseDownHandler(object sender, MouseButtonEventArgs e) { bool moved = false; int col = Grid.GetColumn((Image)sender); int row = Grid.GetRow((Image)sender); List<int[]> moveable = new List<int[]>(); List<int[]> threatened = new List<int[]>(); List<int[]> enPassant = new List<int[]>(); bool promote = false; cvm.SelectOrMove(row, col, moveable, threatened, enPassant, ref promote, ref moved); if (promote) { string promoteTo = null; while (string.IsNullOrEmpty(promoteTo)) { Promotion promo = new Promotion(row, ref promoteTo); promo.ShowDialog(); promoteTo = promo.PromoteTo(); } mf.Promote(promoteTo, row, col, cvm.Playfield); } drawPieces(); //draw borders for moveable squares foreach (int[] pair in moveable) drawBorder(pair[0], pair[1], "yellow"); foreach (int[] pair in threatened) //only show red if there's a piece to take if (cvm.Playfield[pair[0], pair[1]].Exists && cvm.Highlight.Contains(pair)) drawBorder(pair[0], pair[1], "red"); foreach (int[] pair in enPassant) drawBorder(pair[0], pair[1], "red"); if (moved) { ai.TakeTurn(cvm.Playfield, cvm.WhiteTaken, cvm.BlackTaken, cvm.whiteTakenIndeces, cvm.blackTakenIndeces, 0); drawPieces(); cvm.WhiteTurn = !cvm.WhiteTurn; } }