Exemple #1
0
        // Redraw the visible board from the internal chess board
        public void RedrawBoard()
        {
            foreach (Squar ChessSquar in Squars)
            {
                if (ChessSquar.BackgroundImage == null)               // background image doesn't exists
                {
                    ChessSquar.SetBackgroundSquar(ChessImages);
                }

                if (ChessGame.Board[ChessSquar.Name] != null)                                                   // Valid board squar
                {
                    ChessSquar.DrawPiece(ChessImages.GetImageForPiece(ChessGame.Board[ChessSquar.Name].piece)); // draw the chess piece image
                }
                if (ChessSquar.Name == SelectedSquar && ShowMoveHelp == true)                                   // selected check box
                {
                    ChessSquar.BackgroundImage = null;
                    ChessSquar.BackColor       = System.Drawing.Color.Thistle;
                }
            }


            // Check if need to show the possible legal moves for the current selected piece
            if (SelectedSquar != null && SelectedSquar != "" && ShowMoveHelp == true && ChessGame.Board[SelectedSquar].piece != null && !ChessGame.Board[SelectedSquar].piece.IsEmpty() && ChessGame.Board[SelectedSquar].piece.Side.type == ChessGame.GameTurn)
            {
                ArrayList moves = ChessGame.GetLegalMoves(ChessGame.Board[SelectedSquar]);                      // Get all legal moves for the current selected item

                // Hightlight all the possible moves for the current player
                foreach (Cell cell in moves)
                {
                    Squar sqr = GetBoardSquar(cell.ToString());                         // get the board by cell position
                    sqr.BackgroundImage = null;
                    // Show a semi-transparent, saddle color
                    sqr.BackColor = System.Drawing.Color.FromArgb(200, System.Drawing.Color.SaddleBrown);
                }
            }
            SelectedSquar = "";                 // Reset the selected squar position
        }
Exemple #2
0
        // Redraw the visible board from the internal chess board
        public void RedrawBoard()
        {
            foreach (Squar ChessSquar in Squars)
            {
                if (ChessSquar.BackgroundImage == null)               // if background image doesn't exist
                {
                    ChessSquar.SetBackgroundSquar(ChessImages);
                }

                if (ChessGame.Board[ChessSquar.Name] != null)                                                   // Valid board square
                {
                    ChessSquar.DrawPiece(ChessImages.GetImageForPiece(ChessGame.Board[ChessSquar.Name].piece)); // draw the chess piece image
                }
                if (ChessSquar.Name == SelectedSquar && ShowMoveHelp == true)                                   // selected check box
                {
                    ChessSquar.BackgroundImage = null;
                    ChessSquar.BackColor       = System.Drawing.Color.Thistle;
                }
            }

            if (SelectedSquar != null && SelectedSquar != "" && ChessGame.Board[SelectedSquar].piece != null && !ChessGame.Board[SelectedSquar].piece.IsEmpty())
            {
                if (ChessGame.Board[SelectedSquar].piece.Side.isWhite())
                {
                    sSynth.SpeakAsync("player");
                }
                if (ChessGame.Board[SelectedSquar].piece.Side.isBlack())
                {
                    sSynth.SpeakAsync("computer");
                }

                if (ChessGame.Board[SelectedSquar].piece.IsPawn())
                {
                    style.AppendTextWithPronunciation("pawn", "ˈpːɒɳ");
                }
                else
                {
                    style.AppendText(ChessGame.Board[SelectedSquar].piece.ToString(), PromptEmphasis.Strong);   // identify piece at selected square
                }
                sSynth.SpeakAsync(style);
                style.ClearContent();
            }

            // Check if need to show the possible legal moves for the current selected piece
            if (SelectedSquar != null && SelectedSquar != "" && ShowMoveHelp == true && ChessGame.Board[SelectedSquar].piece != null && !ChessGame.Board[SelectedSquar].piece.IsEmpty() && ChessGame.Board[SelectedSquar].piece.Side.type == ChessGame.GameTurn)
            {
                ArrayList moves = ChessGame.GetLegalMoves(ChessGame.Board[SelectedSquar]);    // Get all legal moves for the current selected item

                // highlight all the possible moves for the current player
                if (moves.Count != 0)
                {
                    sSynth.SpeakAsync("Available moves are ");                   // speak coordinates of clicked square
                }
                foreach (Cell cell in moves)
                {
                    Squar sqr = GetBoardSquar(cell.ToString());   // get the board by cell position
//                  sqr.BackgroundImage = null;
                    // Show a semi-transparent, saddle color
//                     sqr.BackColor = System.Drawing.Color.FromArgb(200, System.Drawing.Color.SteelBlue);
                }
            }
            SelectedSquar = "";                 // Reset the selected square position
        }