コード例 #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 TicTacToeWindow()
        {
            InitializeComponent();

            List <Button> buttonCollection = new List <Button>(GridPlayingField.Children.OfType <Button>());

            _tictactoe = new Tictactoe(buttonCollection);

            // Update the user interface
            _tictactoe.UpdateUi();
            UpdateStatusLabel();
        }