Пример #1
0
        private void OnAITurn()
        {
            var dllMap = logicMap.GetDLLMap();

            DecisionTreeDll.GetDecision(dllMap, out DecisionTreeDllDecision decision);
            var firstPosition = new Position
            {
                x = decision.fromX,
                y = decision.fromY,
            };
            var secondPosition = new Position
            {
                x = decision.desX,
                y = decision.desY,
            };

            this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                        (ThreadStart) delegate()
            {
                logicMap.MoveChess(firstPosition, secondPosition);
                isPlayerTurn             = true;
                Board.HighlightedPostion = secondPosition;
            });
        }
Пример #2
0
        private void OnBorderMouseUp(int x, int y)
        {
            if (!isPlayerTurn)
            {
                return;
            }
            var chess         = logicMap.GetChess(x, y);
            var mousePosition = new Position {
                x = x, y = y
            };

            if (lastSelectedChess == null)
            {
                if (chess == null)
                {// no thing to do
                }
                else
                {// select chess
                    Board.SelectedPostion = chess.Position;
                    //Board.HintedPosition = chess.GetAccessiblePosition();
                    Board.HintedPosition = DecisionTreeDll.GetAccessiblePosition(logicMap.GetDLLMap(), chess.Position.x, chess.Position.y);
                    lastSelectedChess    = chess;
                }
            }
            else
            {
                if (chess == null)
                {
                    //var positions = lastSelectedChess.GetAccessiblePosition();
                    var positions = DecisionTreeDll.GetAccessiblePosition(logicMap.GetDLLMap(), lastSelectedChess.Position.x, lastSelectedChess.Position.y);
                    if (positions.Contains(mousePosition))
                    {// move chess
                        isPlayerTurn = false;
                        logicMap.MoveChess(lastSelectedChess.Position, mousePosition);
                        Board.SelectedPostion    = null;
                        Board.HintedPosition     = null;
                        Board.HighlightedPostion = mousePosition;
                        lastSelectedChess        = null;
                        logicMap.ForceTriggerMapUpdate();
                        var thr = new Thread(new ThreadStart(OnAITurn));
                        thr.Start();
                    }
                    else
                    {// unselect chess
                        Board.SelectedPostion    = null;
                        Board.HintedPosition     = null;
                        lastSelectedChess        = null;
                        Board.HighlightedPostion = null;
                    }
                }
                else
                {
                    //var positions = lastSelectedChess.GetAccessiblePosition();
                    var positions = DecisionTreeDll.GetAccessiblePosition(logicMap.GetDLLMap(), lastSelectedChess.Position.x, lastSelectedChess.Position.y);
                    if (positions.Contains(mousePosition))
                    {
                        if (lastSelectedChess.Country == chess.Country)
                        {// unselect chess
                            Board.SelectedPostion    = null;
                            Board.HintedPosition     = null;
                            Board.HighlightedPostion = null;
                            lastSelectedChess        = null;
                        }
                        else
                        {// capture chess
                            isPlayerTurn = false;
                            logicMap.MoveChess(lastSelectedChess.Position, mousePosition);
                            Board.SelectedPostion    = null;
                            Board.HintedPosition     = null;
                            Board.HighlightedPostion = mousePosition;
                            lastSelectedChess        = null;
                            logicMap.ForceTriggerMapUpdate();
                            Board.UpdateViewCentent(logicMap.ChessMap);
                            var thr = new Thread(new ThreadStart(OnAITurn));
                            thr.Start();
                        }
                    }
                    else
                    {// unselect chess
                        Board.SelectedPostion    = null;
                        Board.HintedPosition     = null;
                        Board.HighlightedPostion = null;
                        lastSelectedChess        = null;
                    }
                }
            }
        }