Example #1
0
 public TicTacToeTurnEventArgs(TicTacToePlayerTurn whoseTurn, int nextMoveX, int nextMoveY, int moveXGrid, int moveYGrid, int moveX, int moveY)
 {
     WhoseTurn = whoseTurn;
     NextMoveX = nextMoveX;
     NextMoveY = nextMoveY;
     MoveXGrid = moveXGrid;
     MoveYGrid = moveYGrid;
     MoveX     = moveX;
     MoveY     = moveY;
 }
        public void AssertCantPlayInWonGrid()
        {
            SubgridWinVerticalTest();

            Debug.Assert(supergrid.CheckGridStatus(0, 0) != TicTacToeGridStatus.Contested, "recheck SubgridWinVerticalTest -- subgrid 0,0 should have been won");
            Debug.Assert(supergrid.NextMoveX != -1, "recheck SubgridWinVerticalTest -- last move should not point at a won subgrid");

            //
            supergrid.ClaimCell(supergrid.NextMoveX, supergrid.NextMoveY, 0, 0);

            TicTacToePlayerTurn whoseTurnBeforeClaimCellFailure = supergrid.WhoseTurn;

            //make sure that nobody can claim any cells in the 'won' subgrid
            TicTacToeException ex = Assert.ThrowsException <TicTacToeException>(() =>
            {
                supergrid.ClaimCell(0, 0, 0, 0);
            });

            StringAssert.Contains("Grid is already filled in", ex.Message);

            //Assert that it's still X's turn -- i.e. that the exception didn't forfeit X's turn
            Assert.AreEqual(whoseTurnBeforeClaimCellFailure, supergrid.WhoseTurn);
        }
Example #3
0
 private void DeclareWinner(TicTacToePlayerTurn whoWon)
 {
     Winner = whoWon == TicTacToePlayerTurn.X ? TicTacToeWinner.X : TicTacToeWinner.O;
     GameWon?.Invoke(this, new TicTacToeWinEventArgs(Winner));
 }