예제 #1
0
        /// <summary>
        /// This method inits some data for the first game turn.
        /// It looks for the possible moves and starts the timer.
        /// </summary>
        public void StartGame()
        {
            currentPossibleMoves = LogicalBoard.GetPossibleMoves(logicalBoard.BoardArray, whitePlayerTurn, BOARD_DIMENSIONS);

            UpdateHintsDisplay();
            if (windowView != null)
            {
                windowView.DisplayPlayerTurnHighlight(whitePlayerTurn);
            }

            GetPlayerStopwatch(whitePlayerTurn).Start();
            refreshTimer.Start();
        }
예제 #2
0
        /// <summary>
        /// This function changes the variables to change turn, calculates the possible moves for the current player and checks for game over.
        /// </summary>
        private void ChangeTurn()
        {
            GetPlayerStopwatch(whitePlayerTurn).Stop();
            whitePlayerTurn = !whitePlayerTurn;
            if (windowView != null)
            {
                windowView.DisplayPlayerTurnHighlight(whitePlayerTurn);
            }

            UpdateHintsDisplay(false);

            var nextPossibleMoves = LogicalBoard.GetPossibleMoves(logicalBoard.BoardArray, whitePlayerTurn, BOARD_DIMENSIONS);

            if (!nextPossibleMoves.Any())
            {
                // if the possible moves for the previous player and the current one are empty nobody can play anymore, it's the end of the game
                if (!currentPossibleMoves.Any())
                {
                    string playerName = ScoreWhite >= ScoreBlack ? "White player" : "Black player";
                    if (windowView != null && windowView.DisplayReplayDialog(playerName))
                    {
                        ResetGame();
                    }
                }
                // if only the current ones are empty it's to the other play again
                else
                {
                    currentPossibleMoves = nextPossibleMoves;
                    UpdateHintsDisplay();
                    ChangeTurn();
                    return;
                }
            }
            // otherwise we switch player turns regularly
            else
            {
                GetPlayerStopwatch(whitePlayerTurn).Start();
                currentPossibleMoves = nextPossibleMoves;
                UpdateHintsDisplay();
            }

            if (AI && whitePlayerTurn == false)
            {
                Tuple <int, int> movePos = GetNextMove(logicalBoard.BoardArray, 5, whitePlayerTurn);
                PlayMove(movePos.Item1, movePos.Item2, whitePlayerTurn);
                return;
            }
        }