Exemple #1
0
    // This message is sent by a GridCellScript if the cell has been changed.
    // It tells us we need to update the scoring arrays.

    public void RefreshScores()
    {
        int [] board = GetBoardAsInts();                                        // This also works out who's turn it is now.

        int winningPiece = HasGameBeenWon(ref board);                           // returns EMPTYCELL if neither side has won yet.



        // First check if the game has been drawn. If so, set game states accordingly.

        int playableCells = 0;

        foreach (int c in board)
        {
            if (c == EMPTYCELL)
            {
                ++playableCells;
            }
        }
        // Note that we need to be careful with this check, because it's possible
        //  for a player to win by playing the last empty cell on the board.
        // Hence the two tests here:
        if ((playableCells <= 0) && (winningPiece == EMPTYCELL))                                // it's a draw...
        {
            gHandler.GameDrawn();
        }

        if (winningPiece == EMPTYCELL)
        {
            // nobody has won, we're still playing, so continue with scoring process...

            for (int i = 0; i < BOARDDIMENSIONS; ++i)
            {
                scoreBoard [i] = GetScoreFor(pieceToPlayNext, i, ref board);
            }
        }
        else
        {
            gHandler.GameWon();
        }
    }