示例#1
0
        private void ShowSelectedGame()
        {
            try
            {
                if (DataContext is Data data)
                {
                    UserListDV ul = data.UsersPanelDV.UserListDV;
                    if (ul.SelectedUser != null)
                    {
                        if (ul.SelectedUser.Games.Count > 0)
                        {
                            UserDV selectedUser = ul.SelectedUser;
                            GameDV game         = ul.SelectedUser.SelectedGame;

                            if (game == null)
                            {
                                return;
                            }

                            JsonCheckStatusRequest checkStatusRequest = new JsonCheckStatusRequest();
                            checkStatusRequest.userToken = selectedUser.Token;
                            checkStatusRequest.gameToken = game.GameToken;

                            JsonCheckStatusResponse response = JsonCommunication.CheckStatus(checkStatusRequest);

                            if (response.winnerId != null)
                            {
                                ul.SelectedUser.SelectedGame = null;
                                ul.SelectedUser.Games.Remove(game);
                            }
                            else
                            {
                                DeskData dd       = new DeskData();
                                bool     isMyTurn = selectedUser.Id == response.actualPlayerId;
                                ESymbol  mySymbol;
                                if (isMyTurn)
                                {
                                    mySymbol = response.actualPlayerId == response.playerCircleId ? ESymbol.Circle : ESymbol.Cross;
                                }
                                else
                                {
                                    mySymbol = response.actualPlayerId == response.playerCircleId ? ESymbol.Cross : ESymbol.Circle;
                                }

                                dd.Fill(response, mySymbol, isMyTurn);
                                data.DeskData = dd;

                                if (isMyTurn && data.AutomaticMode)
                                {
                                    AIEngine.StartAIEngine(game, selectedUser, dd);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
示例#2
0
        private void ShowSelectedGame()
        {
            try
            {
                if (DataContext is Data data)
                {
                    foreach (var bsdi in data.BulkSolveData.Data)
                    {
                        Task.Run(() =>
                        {
                            UserDV user = bsdi.User;
                            GameDV game = bsdi.Game;

                            if (game == null)
                            {
                                return;
                            }

                            JsonCheckStatusRequest checkStatusRequest = new JsonCheckStatusRequest();
                            checkStatusRequest.userToken = user.Token;
                            checkStatusRequest.gameToken = game.GameToken;

                            JsonCheckStatusResponse response = JsonCommunication.CheckStatus(checkStatusRequest);

                            if (response.winnerId != null)
                            {
                                DeskData dd = bsdi.DeskData.Copy();
                                if (response.winnerId == user.Id)
                                {
                                    dd.Winner = user.Nickname;
                                }
                                else
                                {
                                    dd.Winner = "Opponent";
                                }
                                bsdi.DeskData = dd;
                            }
                            else
                            {
                                DeskData dd   = new DeskData();
                                bool isMyTurn = user.Id == response.actualPlayerId;
                                ESymbol mySymbol;
                                if (isMyTurn)
                                {
                                    mySymbol = response.actualPlayerId == response.playerCircleId ? ESymbol.Circle : ESymbol.Cross;
                                }
                                else
                                {
                                    mySymbol = response.actualPlayerId == response.playerCircleId ? ESymbol.Cross : ESymbol.Circle;
                                }

                                dd.SquareSize = 5;
                                dd.Fill(response, mySymbol, isMyTurn);
                                bsdi.DeskData = dd;

                                if (isMyTurn)
                                {
                                    AIEngine.StartAIEngine(game, user, dd);
                                }
                            }
                        });
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
示例#3
0
        private void Play()
        {
            try
            {
                if (DataContext is Data data)
                {
                    foreach (var d in data.BulkSolveData.Data)
                    {
                        if (d.DeskData.Winner != null)
                        {
                            if (RemoveCounter.ContainsKey(d))
                            {
                                RemoveCounter[d]++;
                            }
                            else
                            {
                                RemoveCounter.Add(d, 0);
                            }

                            if (RemoveCounter[d] >= 5)
                            {
                                data.BulkSolveData.Data.Remove(d);
                                RemoveCounter.Remove(d);
                            }
                        }
                    }

                    if (!stop)
                    {
                        while (data.BulkSolveData.Data.Count < 24)
                        {
                            BulkSolveDataItem bsdi = CreateGame();
                            data.BulkSolveData.Data.Add(bsdi);
                        }
                    }


                    foreach (var item in data.BulkSolveData.Data)
                    {
                        Task.Run(() =>
                        {
                            try
                            {
                                UserDV user = item.User;
                                GameDV game = item.Game;

                                if (game == null)
                                {
                                    return;
                                }

                                JsonCheckStatusRequest checkStatusRequest = new JsonCheckStatusRequest();
                                checkStatusRequest.userToken = user.Token;
                                checkStatusRequest.gameToken = game.GameToken;

                                JsonCheckStatusResponse response = JsonCommunication.CheckStatus(checkStatusRequest);

                                if (response.winnerId != null)
                                {
                                    DeskData dd = item.DeskData.Copy();
                                    if (response.winnerId == user.Id)
                                    {
                                        dd.Winner = user.Nickname;
                                    }
                                    else
                                    {
                                        dd.Winner = "Opponent";
                                    }
                                    item.DeskData = dd;
                                }
                                else
                                {
                                    DeskData dd   = new DeskData();
                                    bool isMyTurn = user.Id == response.actualPlayerId;
                                    ESymbol mySymbol;
                                    if (isMyTurn)
                                    {
                                        mySymbol = response.actualPlayerId == response.playerCircleId ? ESymbol.Circle : ESymbol.Cross;
                                    }
                                    else
                                    {
                                        mySymbol = response.actualPlayerId == response.playerCircleId ? ESymbol.Cross : ESymbol.Circle;
                                    }

                                    dd.SquareSize = 5;
                                    dd.Fill(response, mySymbol, isMyTurn);
                                    item.DeskData = dd;

                                    if (isMyTurn)
                                    {
                                        AIEngine.StartAIEngine(game, user, dd);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                        });
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }