Beispiel #1
0
 private void InitializeGame()
 {
     gameBoxes = new BOX_VALUE[3, 3] {
         { BOX_VALUE.EMPTY, BOX_VALUE.EMPTY, BOX_VALUE.EMPTY }, { BOX_VALUE.EMPTY, BOX_VALUE.EMPTY, BOX_VALUE.EMPTY }, { BOX_VALUE.EMPTY, BOX_VALUE.EMPTY, BOX_VALUE.EMPTY }
     };
     whoseTurn = BOX_VALUE.X;
     reportTurn();
     resetButtons();
 }
Beispiel #2
0
        private bool isWinner()
        {
            // rows
            for (int row = 0; row < 3; row++)
            {
                BOX_VALUE val = gameBoxes[row, 0];

                if (val == BOX_VALUE.EMPTY)
                {
                    continue;
                }

                bool sameInRow = true;
                for (int col = 0; col < 3; col++)
                {
                    if (gameBoxes[row, col] != val)
                    {
                        sameInRow = false;
                    }
                }

                if (sameInRow)
                {
                    return(true);
                }
            }

            // columns
            for (int col = 0; col < 3; col++)
            {
                BOX_VALUE val = gameBoxes[0, col];

                if (val == BOX_VALUE.EMPTY)
                {
                    continue;
                }

                bool sameInCol = true;
                for (int row = 0; row < 3; row++)
                {
                    if (gameBoxes[row, col] != val)
                    {
                        sameInCol = false;
                    }
                }

                if (sameInCol)
                {
                    return(true);
                }
            }

            // only thing left is diagonals
            return(gameBoxes[0, 0] != BOX_VALUE.EMPTY && gameBoxes[0, 0] == gameBoxes[1, 1] && gameBoxes[0, 0] == gameBoxes[2, 2] ||
                   gameBoxes[0, 2] != BOX_VALUE.EMPTY && gameBoxes[0, 2] == gameBoxes[1, 1] && gameBoxes[0, 2] == gameBoxes[2, 0]);
        }
Beispiel #3
0
        private void changeTurn()
        {
            if (whoseTurn == BOX_VALUE.X)
            {
                whoseTurn = BOX_VALUE.O;
            }
            else
            {
                whoseTurn = BOX_VALUE.X;
            }

            reportTurn();
        }