Exemple #1
0
        private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
        {
            if (IfWorking == false && GameViewModel.IsGameOver == false)
            {
                IfWorking = true;
                var   ArenaCell = (SKCanvasView)sender;
                int[] index     = new int[2] {
                    int.Parse(ArenaCell.StyleId[0].ToString()), int.Parse(ArenaCell.StyleId[1].ToString())
                };
                if (GameViewModel.ArenaMatrix[index[0], index[1]] != ' ')
                {
                    IfWorking = false;
                    return;
                }
                ArenaCell.AnchorX   = 0;
                ArenaCell.RotationY = 0;
                ArenaCell.RotateYTo(360, 500, Easing.Linear);
                ArenaCell.AnchorX             = 0.5;
                TurnButtonLayout.TranslationY = 0;
                GameViewModel.UpdateGameArena(index);
                ArenaCell.InvalidateSurface();

                if (GameViewModel.IsGameOver)
                {
                    if (GameViewModel.GameResult == 'P')
                    {
                        GameViewModel.PlayerWins++;
                        GameViewModel.OpponentLoses++;
                        Application.Current.Properties["temp1"] = GameViewModel.PlayerWins.ToString();
                        DisplayAlert("Game Over", GameViewModel.PlayerName + " won!!", "Okay");
                    }
                    else if (GameViewModel.GameResult == 'O')
                    {
                        GameViewModel.PlayerLoses++;
                        GameViewModel.OpponentWins++;
                        Application.Current.Properties["temp2"] = GameViewModel.PlayerLoses.ToString();
                        DisplayAlert("Game Over", GameViewModel.OpponentName + " won!!", "Okay");
                    }
                    else
                    {
                        GameViewModel.PlayerTies++;
                        GameViewModel.OpponentTies++;
                        Application.Current.Properties["temp3"] = GameViewModel.PlayerTies.ToString();
                        DisplayAlert("Game Over", " It's a tie!!", "Okay");
                    }
                }

                IfWorking = false;
            }
        }
 private async Task PrintArenaAsync(SKCanvasView ArenaCell)
 {
     int[] index = new int[2] {
         int.Parse(ArenaCell.StyleId[0].ToString()), int.Parse(ArenaCell.StyleId[1].ToString())
     };
     if (GameViewModel.ArenaMatrix[index[0], index[1]] != ' ')
     {
         IfFailure = true;
         IfWorking = false;
         GameViewModel.Filled--;
         return;
     }
     ArenaCell.AnchorX   = 0;
     ArenaCell.RotationY = 0;
     ArenaCell.RotateYTo(360, 500, Easing.Linear);
     ArenaCell.AnchorX             = 0.5;
     TurnButtonLayout.TranslationY = 0;
     GameViewModel.UpdateGameArena(index);
     ArenaCell.InvalidateSurface();
     if (GameViewModel.IsGameOver)
     {
         if (GameViewModel.GameResult == 'P')
         {
             GameViewModel.PlayerWins++;
             GameViewModel.OpponentLoses++;
             Application.Current.Properties["SingleHardWinsCount"] = ((long.Parse(Application.Current.Properties["SingleHardWinsCount"] as string)) + 1).ToString();
             Application.Current.Properties["SingleHardWins"]      = ((long.Parse(Application.Current.Properties["SingleHardWins"] as string)) + 1).ToString();
             DisplayAlert("Game Over", GameViewModel.PlayerName + " won!!", "Okay");
         }
         else if (GameViewModel.GameResult == 'O')
         {
             GameViewModel.OpponentWins++;
             GameViewModel.PlayerLoses++;
             Application.Current.Properties["SingleHardLosesCount"] = ((long.Parse(Application.Current.Properties["SingleHardLosesCount"] as string)) + 1).ToString();
             Application.Current.Properties["SingleHardLoses"]      = ((long.Parse(Application.Current.Properties["SingleHardLoses"] as string)) + 1).ToString();
             DisplayAlert("Game Over", GameViewModel.OpponentName + " won!!", "Okay");
         }
         else
         {
             GameViewModel.PlayerTies++;
             GameViewModel.OpponentTies++;
             Application.Current.Properties["SingleHardTiesCount"] = ((long.Parse(Application.Current.Properties["SingleHardTiesCount"] as string)) + 1).ToString();
             Application.Current.Properties["SingleHardTies"]      = ((long.Parse(Application.Current.Properties["SingleHardTies"] as string)) + 1).ToString();
             DisplayAlert("Game Over", " It's a tie!!", "Okay");
         }
         await Task.Run(async() =>
         {
             string url     = "http://tictactoe.sudeshkumar.me/Android/UpdateStatsMob";
             HttpContent q1 = new FormUrlEncodedContent(new List <KeyValuePair <string, string> >()
             {
                 new KeyValuePair <string, string>("UserName", Application.Current.Properties["UserName"] as string), new KeyValuePair <string, string>("Password", Application.Current.Properties["Password"] as string), new KeyValuePair <string, string>("SingleEasyWinsCount", Application.Current.Properties["SingleEasyWinsCount"] as string), new KeyValuePair <string, string>("SingleEasyLosesCount", Application.Current.Properties["SingleEasyLosesCount"] as string), new KeyValuePair <string, string>("SingleEasyTiesCount", Application.Current.Properties["SingleEasyTiesCount"] as string), new KeyValuePair <string, string>("SingleHardWinsCount", Application.Current.Properties["SingleHardWinsCount"] as string), new KeyValuePair <string, string>("SingleHardLosesCount", Application.Current.Properties["SingleHardLosesCount"] as string), new KeyValuePair <string, string>("SingleHardTiesCount", Application.Current.Properties["SingleHardTiesCount"] as string), new KeyValuePair <string, string>("DoubleWinsCount", Application.Current.Properties["DoubleWinsCount"] as string), new KeyValuePair <string, string>("DoubleLosesCount", Application.Current.Properties["DoubleLosesCount"] as string), new KeyValuePair <string, string>("DoubleTiesCount", Application.Current.Properties["DoubleTiesCount"] as string)
             });
             using (var httpClient = new HttpClient())
             {
                 try
                 {
                     Task <HttpResponseMessage> getResponse = httpClient.PostAsync(url, q1);
                     HttpResponseMessage response           = await getResponse;
                     if (response.IsSuccessStatusCode)
                     {
                         Application.Current.Properties["SingleHardWinsCount"]  = "0";
                         Application.Current.Properties["SingleHardLosesCount"] = "0";
                         Application.Current.Properties["SingleHardTiesCount"]  = "0";
                     }
                 }
                 catch (Exception)
                 {
                 }
             }
         });
     }
 }