Пример #1
0
        private void ButtonClick(object sender, RoutedEventArgs e)
        {
            // Players turn
            _tictactoe.PlaceMarker(sender as Button);
            _tictactoe.UpdateUi();
            UpdateStatusLabel();

            // Check if the game state has changed
            if (_tictactoe.HasGameStateChanged())
            {
                UpdateStatusLabel();
                return;
            }

            // Computers turn
            // Skip when the computer oponent is disabled
            if (!Settings.Default.ComputerOponentEnabled)
            {
                return;
            }

            // Compute the AIs move and place the marker
            var computerMove = _tictactoe.ComputerPlayerAi.GetMove(_tictactoe.GetCurrentTurnPlayerMark(), Settings.Default.AiDifficultySetting);

            _tictactoe.PlaceMarker(computerMove.X, computerMove.Y);

            // Check for the game state and update user interface
            _tictactoe.UpdateUi();
            _tictactoe.HasGameStateChanged();
            UpdateStatusLabel();
        }
Пример #2
0
        public void GetCurrentTurnPlayerMark_ValidUse_Success()
        {
            // Arrange
            var ticTacToe = new Tictactoe(GetBoardButtons());

            ticTacToe.StartNewGame(true, false, 0);

            // Act
            string shouldBeCrossMark = ticTacToe.GetCurrentTurnPlayerMark();

            ticTacToe.NextTurn();

            string shouldBeCircleMark = ticTacToe.GetCurrentTurnPlayerMark();

            ticTacToe.NextTurn();

            string shouldBeCrossMarkAgain = ticTacToe.GetCurrentTurnPlayerMark();

            // Assert
            Assert.AreEqual(Resources.BoardCrossMark, shouldBeCrossMark);
            Assert.AreEqual(Resources.BoardCircleMark, shouldBeCircleMark);
            Assert.AreEqual(Resources.BoardCrossMark, shouldBeCrossMarkAgain);
        }