Esempio n. 1
0
        private BulkSolveDataItem CreateGame()
        {
            if (DataContext is Data data)
            {
                UserDV selectedUser = data.UsersPanelDV.UserListDV.SelectedUser;
                if (selectedUser == null)
                {
                    return(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);
                }


                BulkSolveDataItem bsdi = new BulkSolveDataItem();
                bsdi.DeskData            = new DeskData();
                bsdi.DeskData.SquareSize = 5;
                bsdi.Game = game;
                bsdi.User = selectedUser;

                return(bsdi);
            }
            return(null);
        }
Esempio n. 2
0
 private void CreateGames_Click(object sender, RoutedEventArgs e)
 {
     if (DataContext is Data data)
     {
         for (int i = 0; i < 24; i++)
         {
             BulkSolveDataItem bsdi = CreateGame();
             data.BulkSolveData.Data.Add(bsdi);
         }
     }
 }
Esempio n. 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)
            {
            }
        }