Example #1
0
        public Local()
        {
            InitializeComponent();

            this.cbcBoard.Board.GameEnded += (b, r) =>
            {
                MessageBox.Show((r == ChessWinner.StaleMate ? "Stalemate" : r.ToString() + " wins") + "!", "Game Over");
            };

            this.cbcBoard.Board.Promotion = b =>
                {
                    Promotion p = new Promotion();
                    p.ShowDialog();

                    return p.Choise;
                };

            this.cbcBoard.Board.NextTurn += b =>
                {
                    this.cbcBoard.Repaint();

                    if (this.TurnEffect.IsChecked)
                    {
                        IEnumerable<int> turn = b.Turn == ChessColor.White ? 180.To(360, 10) : 0.To(180, 10);

                        foreach (int i in turn)
                        {
                            this.cbcBoard.LayoutTransform = new RotateTransform((double)i);

                            for (int rank = 0; rank < 8; rank++)
                            {
                                for (int file = 0; file < 8; file++)
                                {
                                    if (this.cbcBoard.Squares[rank, file].Square.Piece != null)
                                    {
                                        Image img = (Image)(this.cbcBoard.Squares[rank, file].Children.Count == 1 ? this.cbcBoard.Squares[rank, file].Children[0] : this.cbcBoard.Squares[rank, file].Children[1]); //.LayoutTransform = new RotateTransform((double)i);
                                        img.LayoutTransform = new RotateTransform((double)(360 - i) + (b.Turn == ChessColor.Black ? 0 : 180));
                                    }
                                }
                            }

                            this.cbcBoard.Dispatcher.Invoke(DispatcherPriority.Render, new Action(() => { }));
                            System.Threading.Thread.Sleep(20);
                        }
                    }

                    this.cbcBoard.Player = b.Turn;
                };
        }
Example #2
0
        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");
        }
Example #3
0
 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;
     }
 }