コード例 #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
ファイル: TictactoeTests.cs プロジェクト: lzrp/c-_tictactoe
        public void PlaceMarker_VerticalParameterOutOfRange_ThrowsException()
        {
            // Arrange
            var ticTacToe = new Tictactoe(GetBoardButtons());

            // Act
            ticTacToe.PlaceMarker(1, 5);
            ticTacToe.PlaceMarker(1, -1);

            // Assert
            Assert.Fail("No exception was thrown.");
        }
コード例 #3
0
ファイル: TictactoeTests.cs プロジェクト: lzrp/c-_tictactoe
        public void PlaceMarker_ValidUse_Success()
        {
            // Arrange
            var ticTacToe = new Tictactoe(GetBoardButtons());

            ticTacToe.StartNewGame(true, false, 0);
            var buttonForCrossMarkPlacement  = GetBoardButtons().First(x => x.Tag.ToString() == "00");
            var buttonForCircleMarkPlacement = GetBoardButtons().First(x => x.Tag.ToString() == "01");

            // Act
            ticTacToe.PlaceMarker(buttonForCrossMarkPlacement);
            ticTacToe.NextTurn();
            ticTacToe.PlaceMarker(buttonForCircleMarkPlacement);

            var buttonWithCrossMark  = buttonForCrossMarkPlacement.Content.ToString();
            var buttonWithCircleMark = buttonForCircleMarkPlacement.Content.ToString();

            // Assert
            Assert.AreEqual(Resources.BoardCrossMark, buttonWithCrossMark);
            Assert.AreEqual(Resources.BoardCircleMark, buttonWithCircleMark);
        }
コード例 #4
0
ファイル: TictactoeTests.cs プロジェクト: lzrp/c-_tictactoe
        public void PlaceMarker_ButtonParameterIsNull_ThrowsException()
        {
            // Arrange
            var ticTacToe = new Tictactoe(GetBoardButtons());

            ticTacToe.StartNewGame(true, false, 0);

            // Act
            ticTacToe.PlaceMarker(null);

            // Assert
            Assert.Fail("No exception was thrown.");
        }
コード例 #5
0
ファイル: TictactoeTests.cs プロジェクト: lzrp/c-_tictactoe
        public void IsBoardFieldEmpty2_ValidUse_Success()
        {
            // Arrange
            var ticTacToe = new Tictactoe(GetBoardButtons());

            ticTacToe.StartNewGame(true, false, 0);

            // Act
            ticTacToe.PlaceMarker(1, 0);

            bool fieldShouldBeEmpty    = ticTacToe.IsBoardFieldEmpty(0, 0);
            bool fieldShouldNotBeEmpty = ticTacToe.IsBoardFieldEmpty(1, 0);

            // Assert
            Assert.AreEqual(true, fieldShouldBeEmpty);
            Assert.AreEqual(false, fieldShouldNotBeEmpty);
        }