Пример #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 Save(JsonNewUserResponse jsonUser, string nickname, string email)
 {
     if (DataContext is Data data)
     {
         UserDV user = new UserDV();
         user.Id       = jsonUser.userId;
         user.Token    = jsonUser.userToken;
         user.Email    = email;
         user.Nickname = nickname;
         data.UsersPanelDV.UserListDV.Users.Add(user);
     }
     else
     {
         MessageBox.Show("Invalid Data Context - user registration");
     }
 }
Пример #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (DataContext is Data data)
            {
                UserDV selectedUser = data.UsersPanelDV.UserListDV.SelectedUser;
                if (selectedUser != null)
                {
                    JsonConnectRequest request = new JsonConnectRequest();
                    request.userToken = selectedUser.Token;
                    JsonConnectResponse response = JsonCommunication.Connect(request);

                    GameDV game = new GameDV();
                    game.GameId    = response.gameId;
                    game.GameToken = response.gameToken;
                    if (!selectedUser.Games.Any(x => x.GameId == game.GameId))
                    {
                        selectedUser.Games.Add(game);
                    }
                }
            }
        }