Пример #1
0
        private void Cell_Click(object sender, MouseButtonEventArgs e)
        {
            var cell = sender as Rectangle;

            var y = (int)cell.GetValue(Grid.RowProperty);
            var x = (int)cell.GetValue(Grid.ColumnProperty);

            var clickedPoint = new Point(x, y);

            if (_currentState.Board.IsPlayer(clickedPoint))
            {
                _clickedPoint = new Point(x, y);

                _currentState.PossibleMoves = _currentState.Board.PossibleMoves(_clickedPoint, Field.Player);
                SeePossibleMoves();

                _firstClick = true;
            }
            else
            {
                var move = new Move(_clickedPoint, new Point(x, y));

                if (!_firstClick || !_currentState.PossibleMoves.Any(m => m == move))
                {
                    return;
                }

                _currentState.Board.MovePawn(move);
                SeeMove(move, Field.Player);
                CleanSelected();

                //Player end move
                if (_currentState.Board.IsWin(Field.Player))
                {
                    NewGame();
                    ai.Update();
                    PlayerScore++;
                    StatsData.PlayerVictories++;
                    return;
                }

                //AI Move
                move = ai.GetMove(_currentState);

                _currentState.Board.MovePawn(move);
                SeeMove(move, Field.AI);

                if (_currentState.Board.IsWin(Field.AI))
                {
                    NewGame();
                    AiScore++;
                    StatsData.AiVictories++;
                    return;
                }

                _firstClick = false;
            }
        }
Пример #2
0
        private void Cell_MouseEnter(object sender, MouseEventArgs e)
        {
            var cell = sender as Rectangle;

            var y = (int)cell.GetValue(Grid.RowProperty);
            var x = (int)cell.GetValue(Grid.ColumnProperty);

            var enterPoint = new Point(x, y);

            if (_currentState.Board.IsPlayer(enterPoint) || _currentState.PossibleMoves.Any(m => m.To == enterPoint))
            {
                cell.Cursor = Cursors.Hand;
            }
        }