Exemple #1
0
        private void HighlightWinner(CompleteResult result)
        {
            switch (result.Type)
            {
            case CompleteType.Column:
                _currentBoard[result.Sequence, 0].Background
                        = _currentBoard[result.Sequence, 1].Background
                        = _currentBoard[result.Sequence, 2].Background
                        = CurrentPlayer.Color;
                _currentBoard[result.Sequence, 0].Foreground
                        = _currentBoard[result.Sequence, 1].Foreground
                        = _currentBoard[result.Sequence, 2].Foreground
                        = WinnerForeground;
                break;

            case CompleteType.Row:
                _currentBoard[0, result.Sequence].Background
                        = _currentBoard[1, result.Sequence].Background
                        = _currentBoard[2, result.Sequence].Background
                        = CurrentPlayer.Color;
                _currentBoard[0, result.Sequence].Foreground
                        = _currentBoard[1, result.Sequence].Foreground
                        = _currentBoard[2, result.Sequence].Foreground
                        = WinnerForeground;
                break;

            case CompleteType.Diagonal:
                _currentBoard[1, 1].Foreground = WinnerForeground;
                _currentBoard[1, 1].Background = CurrentPlayer.Color;

                if (result.Sequence == 0)
                {
                    _currentBoard[0, 0].Background
                        = _currentBoard[2, 2].Background = CurrentPlayer.Color;
                    _currentBoard[0, 0].Foreground
                        = _currentBoard[2, 2].Foreground = WinnerForeground;
                }
                else
                {
                    _currentBoard[2, 0].Background
                        = _currentBoard[0, 2].Background = CurrentPlayer.Color;
                    _currentBoard[2, 0].Foreground
                        = _currentBoard[0, 2].Foreground = WinnerForeground;
                }
                break;
            }
        }
Exemple #2
0
        public CompleteResult IsComplete()
        {
            for (var rowIndex = 0; rowIndex < 3; rowIndex++)
            {
                if (AreEqual(0, rowIndex, 1, rowIndex, 2, rowIndex))
                {
                    return(CompleteResult.Row(rowIndex));
                }
            }

            for (var columnIndex = 0; columnIndex < 3; columnIndex++)
            {
                if (AreEqual(columnIndex, 0, columnIndex, 1, columnIndex, 2))
                {
                    return(CompleteResult.Column(columnIndex));
                }
            }

            if (AreEqual(0, 0, 1, 1, 2, 2))
            {
                return(CompleteResult.Diagonal(0));
            }

            if (AreEqual(0, 2, 1, 1, 2, 0))
            {
                return(CompleteResult.Diagonal(1));
            }

            for (var rowIndex = 0; rowIndex < 3; rowIndex++)
            {
                for (var columnIndex = 0; columnIndex < 3; columnIndex++)
                {
                    if (!_values[columnIndex, rowIndex].IsSet)
                    {
                        return(CompleteResult.NotComplete);
                    }
                }
            }

            return(CompleteResult.Draw);
        }