Example #1
0
        // A move is made by the player
        public bool UserMove(string source, string dest)
        {
            bool success    = true;
            int  MoveResult = ChessGame.DoMove(source, dest);

            RedrawBoard();              // Refresh the board


            switch (MoveResult)
            {
            case 0:                                  // move was successfull;
                                                     // check if the last move was promo move
                Move move = ChessGame.GetLastMove(); // get the last move



                // If last move was a pawn promotion move, get the new selected piece from user
                if (move.IsPromoMove() && !ChessGame.ActivePlay.IsComputer())
                {
                    ChessGame.SetPromoPiece(GetPromoPiece(move.EndCell.piece.Side));                                    // Set the promo piece as selected by user
                }
                // check for the check mate situation
                if (ChessGame.IsCheckMate(ChessGame.GameTurn))
                {
                    if (ChessGame.GameTurn.ToString() == "White")
                    {
                        this.WhoWins = false;
                    }
                    IsOver = true;
                    MessageBox.Show(ChessGame.GetPlayerBySide(ChessGame.GameTurn).Name + " is checkmate.", "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);


                    Result resultform = new Result(this);
                    resultform.Show();
                    ParentForm.Hide();
                }
                // check for the statemate situation
                if (ChessGame.IsStaleMate(ChessGame.GameTurn))
                {
                    IsOver = true;
                    MessageBox.Show(ChessGame.GetPlayerBySide(ChessGame.GameTurn).Name + " is stalmate.", "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                LogUserMove(move.ToString());                           // Log the user action

                break;

            default:
                success = false;
                break;
            }

            return(success);
        }
Example #2
0
        // A move is made by the player
        public bool UserMove(string source, string dest)
        {
            bool success    = true;
            int  MoveResult = ChessGame.DoMove(source, dest);

            RedrawBoard();              // Refresh the board

            switch (MoveResult)
            {
            case 0:                                  // move was successfull;
                                                     // check if the last move was promo move
                Move move = ChessGame.GetLastMove(); // get the last move

                // Play the sound
                if (ChessGame.IsUnderCheck())
                {
                    Sounds.PlayCheck();                                 // Player is under check
                }
                else if (move.Type == Move.MoveType.NormalMove || move.Type == Move.MoveType.TowerMove)
                {
                    Sounds.PlayNormalMove();
                }
                else
                {
                    Sounds.PlayCaptureMove();
                }

                // Add to the capture list
                if (move.IsCaptureMove())
                {
                    ParentForm.ChessCaptureBar.Add(ChessImages.GetImageForPiece(move.CapturedPiece));
                }

                // If last move was a pawn promotion move, get the new selected piece from user
                if (move.IsPromoMove() && !ChessGame.ActivePlay.IsComputer())
                {
                    ChessGame.SetPromoPiece(GetPromoPiece(move.EndCell.piece.Side));                                    // Set the promo piece as selected by user
                }
                // check for the check mate situation
                if (ChessGame.IsCheckMate(ChessGame.GameTurn))
                {
                    Sounds.PlayGameOver();
                    IsOver = true;
                    MessageBox.Show(ChessGame.GetPlayerBySide(ChessGame.GameTurn).Name + " is checkmate.", "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                // check for the statemate situation
                if (ChessGame.IsStaleMate(ChessGame.GameTurn))
                {
                    Sounds.PlayGameOver();
                    IsOver = true;
                    MessageBox.Show(ChessGame.GetPlayerBySide(ChessGame.GameTurn).Name + " is stalmate.", "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                LogUserMove(move.ToString());                           // Log the user action
                NextPlayerTurn();
                break;

            default:
                success = false;
                break;
            }

            return(success);
        }
Example #3
0
        // A move is made by the player
        public bool UserMove(string source, string dest)
        {
            sr.RecognizeAsyncStop();

            bool success    = true;
            int  MoveResult = ChessGame.DoMove(source, dest);

            Console.Write(" --- MoveResult:: " + MoveResult + " --- ");
            RedrawBoard();              // Refresh the board

            switch (MoveResult)
            {
            case 0:                                  // move was successful;
                                                     // check if the last move was promo move
                Move move = ChessGame.GetLastMove(); // get the last move

                // Play the sound
                if (ChessGame.IsUnderCheck())
                {
                    Sounds.PlayCheck();          // Player is under check
                    sSynth.SpeakAsync("Check."); // Speech indication of player being under check
                }
                else if (move.Type == Move.MoveType.NormalMove || move.Type == Move.MoveType.TowerMove)
                {
                    Sounds.PlayNormalMove();
                }
                else
                {
                    Sounds.PlayCaptureMove();
                }

                // Add to the capture list
                if (move.IsCaptureMove())
                {
                    ParentForm.ChessCaptureBar.Add(ChessImages.GetImageForPiece(move.CapturedPiece));
                }

                // If last move was a pawn promotion move, get the new selected piece from user
                if (move.IsPromoMove() && !ChessGame.ActivePlay.IsComputer())
                {
                    ChessGame.SetPromoPiece(GetPromoPiece(move.EndCell.piece.Side));                                    // Set the promo piece as selected by user
                }
                // check for the check mate situation
                if (ChessGame.IsCheckMate(ChessGame.GameTurn))
                {
                    Sounds.PlayGameOver();
                    sSynth.SpeakAsync("Check mate.");
                    sSynth.SpeakAsync("Game over.");
                    IsOver = true;
                    MessageBox.Show(ChessGame.GetPlayerBySide(ChessGame.GameTurn).Name + " is checkmate.", "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                // check for the stalemate situation
                if (ChessGame.IsStaleMate(ChessGame.GameTurn))
                {
                    Sounds.PlayGameOver();
                    sSynth.SpeakAsync("Stale mate.");
                    sSynth.SpeakAsync("Game over.");
                    IsOver = true;
                    MessageBox.Show(ChessGame.GetPlayerBySide(ChessGame.GameTurn).Name + " is stalemate.", "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }

                String        output = move.ToString();
                StringBuilder bar    = new StringBuilder();
                foreach (char c in output)
                {
                    if (Char.IsDigit(c))
                    {
                        int val    = (int)Char.GetNumericValue(c);
                        int newVal = 8 - val + 1;
                        bar.Append(newVal);
                    }
                    else
                    {
                        bar.Append(c);
                    }
                }

                LogUserMove(bar.ToString());
                Console.Write("---------");
                Console.Write(move.ToString());                                    // Log the user action
                Console.Write(bar.ToString());
                Console.Write("---------");

                sSynth.SpeakAsync(bar.ToString());      // Speech indicates piece taken
                NextPlayerTurn();
                break;

            default:
                success = false;
                break;
            }

            return(success);
        }