示例#1
0
        //Used to select and move White's pieces
        public void whiteTurn(string tile)
        {
            //IF the user tries to move to the same tile as their selected piece, (i.e double clicks the tile)
            //      Deselect the piece and re-enable the board
            if (selectedTile == tile)
            {
                setBoard(true);
                hasSelectedPiece = false;
                selectedTile = "";
            }

            //ELSE IF the user has not selected an empty tile OR has selected a piece,
            else if (board[Convert.ToInt32(tile.Substring(0, 1)), Convert.ToInt32(tile.Substring(1, 1))] != "" || hasSelectedPiece)
            {
                White accWhite = new White(hasSelectedPiece, tile, board, piece, selectedTile, takenBlackPieces);
                ScoreBoard accScore = new ScoreBoard();

                //Does:
                //  SETS integral variables that need to be accessed later
                //  Moves pieces
                //      Changes the appropriate values in the board array to simulate movement
                accWhite.action();

                //Used to hold the list of possible moves generated from the White class.
                ArrayList list = new ArrayList();

                //Generate a list of possible moves based on the selected piece and its location
                list = (ArrayList)accWhite.generateListOfPossibleMoves().Clone();

                //GET the selected tile
                selectedTile = accWhite.getSelectedTile();

                //IF the user has not already selected a piece,
                //      Enable all tiles that can be moved to and disable the rest
                //          SET hasSelectedPiece to true to reflect that a piece is now selected
                if (!hasSelectedPiece && accWhite.getTile() != "")
                {
                    setBoard(false);
                    activateButtons(list);
                    hasSelectedPiece = true;
                }

                //ELSE IF the user has already selected a piece,
                //      Enable all tiles
                //      Deselect the piece
                //      SET isWhiteTurn to false to allow for Black's turn.
                else
                {
                    setBoard(true);
                    hasSelectedPiece = false;
                    selectedTile = "";
                    isWhiteTurn = false;
                }

                //SET the local board array to the White class' updated board array
                updateBoard(accWhite.getBoard());

                //Check for and promote pawns that have reached the opposing side of the board
                checkForPawns();

                //UPDATE the visuals to reflect the changes in the board
                refreshBoard();

                //SET the local takenBlackPieces array to the White class' takenBlackPieces array
                takenBlackPieces = (string[])accWhite.getTakenBlackPieces().Clone();

                //IF White has taken Black's King,
                //      Reset the board
                //      Update the visuals
                //      Display a message stating White's victory
                //      Add one point to White's score
                //      Updatee the score label
                if (accScore.hasWon(takenBlackPieces, "bKing"))
                {
                    resetGame();
                    MessageBox.Show("White has won!");
                    whitePoints++;
                    updateScore();
                }
            }
        }
示例#2
0
        //Used to select and move White's pieces
        public void whiteTurn(string tile)
        {
            if (selectedTile == tile || board[Convert.ToInt32(tile.Substring(0, 1)), Convert.ToInt32(tile.Substring(1, 1))] == "" && !hasSelectedPiece)
            {
                setBoard(true);
                hasSelectedPiece = false;
                selectedTile = "";
                count = -1;
            }
            else if (board[Convert.ToInt32(tile.Substring(0, 1)), Convert.ToInt32(tile.Substring(1, 1))] != "" || hasSelectedPiece)
            {
                White accWhite = new White(hasSelectedPiece, tile, board, piece, selectedTile, takenBlackPieces);
                ScoreBoard accScore = new ScoreBoard();

                accWhite.action();

                ArrayList list = new ArrayList();

                list = (ArrayList)accWhite.generateListOfPossibleMoves().Clone();

                selectedTile = accWhite.getSelectedTile();

                if (!hasSelectedPiece && accWhite.getTile() != "")
                {
                    setBoard(false);
                    activateButtons(list);
                    hasSelectedPiece = true;
                }
                else
                {
                    setBoard(true);
                    hasSelectedPiece = false;
                    selectedTile = "";
                    isWhiteTurn = false;
                }

                updateBoard(accWhite.getBoard());

                checkForPawns();

                refreshBoard();

                takenBlackPieces = (string[])accWhite.getTakenBlackPieces().Clone();

                if (accScore.hasWon(takenBlackPieces, "bKing"))
                {
                    whitePoints++;
                    resetGame();
                    MessageBox.Show("White has won!");
                }

            }
        }