Exemplo n.º 1
0
        private void SendResult()                  // send all relevant statistics to database
        {
            LocalDataStorage.RefreshSaveFileXML(); // insure we have last progress in local storage
            Guid gamerGuid = LocalDataStorage.GetGamerGuid();

            if (gamerGuid == Guid.Empty) // completely new gamer
            {
                gamerGuid = Guid.NewGuid();
                ResultDO.SendGamerToDatabase(gamerGuid, GamerNameTextBox.Text); // send new gamer to database
            }
            else if (!ResultDO.IsGuidInDatabase(gamerGuid))                     // wrong Guid of gamer, which isn't in database
            {
                gamerGuid = Guid.NewGuid();
                ResultDO.SendGamerToDatabase(gamerGuid, GamerNameTextBox.Text); // send new gamer to database
            }

            ResultDO.SendResultToDatabaseAsync(
                gamerGuid,
                LocalDataStorage.GetLastCurrentScore(),
                GameBoard.GetBiggestTile()
                );
            this.Visibility = Visibility.Collapsed;
            LocalDataStorage.SetGamerGuid(gamerGuid); // insure, that program will recognize gamer next time

            LocalDataStorage.ClearSaveFileBeforeNewGame();
        }
Exemplo n.º 2
0
 private async void GameOverUserControl_Loaded(object sender, RoutedEventArgs e)
 {
     if (await ResultDO.TestConnectionAsync()) // test of connection
     {
         await PrepareGamerNameTextBox();
     }
     else
     {
         GamerNameTextBox.IsEnabled = true;
         this.Resources["GamerNamePlaceholderText"] = "Your name...";
         ErrorMessageLabel.Visibility = Visibility.Visible;
     }
 }
Exemplo n.º 3
0
 private async void SendResultButton_Click(object sender, RoutedEventArgs e)
 {
     ErrorMessageLabel.Visibility = Visibility.Collapsed;
     LoadingLabel.Visibility      = Visibility.Visible;
     SendResultButton.IsEnabled   = false;
     if (await ResultDO.TestConnectionAsync())
     {
         SendResult();
     }
     else
     {
         LoadingLabel.Visibility      = Visibility.Collapsed;
         ErrorMessageLabel.Visibility = Visibility.Visible;
         SendResultButton.IsEnabled   = true;
     }
 }
Exemplo n.º 4
0
        private async Task PrepareGamerNameTextBox() // handling of gamer name textbox
        {
            Guid gamerGuid = LocalDataStorage.GetGamerGuid();

            if (await ResultDO.IsGuidInDatabaseAsync(gamerGuid))
            {
                GamerNameTextBox.Text = await ResultDO.GetGamerNameByGuidAsync(gamerGuid); // get gamer name from database using Guid

                GamerNameTextBox.IsEnabled = false;
            }
            else // allow gamer to add new name in text box
            {
                GamerNameTextBox.IsEnabled = true;
                this.Resources["GamerNamePlaceholderText"] = "Your name...";
            }
        }
Exemplo n.º 5
0
        private async Task PrepareStatisticsTable()
        {
            Grid statisticsTable = GetStatisticsPageInstance().StatisticsTable;

            // label used for user informing about actual state
            Label messageText = new Label();

            messageText.Content             = "Loading, please wait...";
            messageText.HorizontalAlignment = HorizontalAlignment.Center;
            statisticsTable.Children.Add(messageText);
            Grid.SetRow(messageText, 1);
            Grid.SetColumnSpan(messageText, 4);
            try
            {
                List <ResultDO> scoresList = await ResultDO.GetBestResultsAsync();

                if (scoresList.Count > 0)
                {
                    statisticsTable.Children.Remove(messageText);
                    Label gamerLabel;
                    Label scoreLabel;
                    Tile  bgstTile;
                    statisticsTable.Children.OfType <Ellipse>().ToList().ForEach(x => { x.Visibility = Visibility.Visible; }); // show up all medals
                    scoresList.ForEach(scoreRow =>
                    {
                        int currentIndex = scoresList.FindIndex(x => x == scoreRow) + 1; //current row + header
                        if (statisticsTable.RowDefinitions.Count <= currentIndex)
                        {
                            statisticsTable.RowDefinitions.Add(new RowDefinition());
                        }

                        // prepare game name column content
                        gamerLabel                     = new Label();
                        gamerLabel.Content             = scoreRow.GamerName + (scoreRow.GamerGuid == LocalDataStorage.GetGamerGuid() ? " (you)" : "");
                        gamerLabel.HorizontalAlignment = HorizontalAlignment.Left;
                        gamerLabel.VerticalAlignment   = VerticalAlignment.Center;
                        statisticsTable.Children.Add(gamerLabel);
                        Grid.SetRow(gamerLabel, currentIndex);
                        Grid.SetColumn(gamerLabel, 0);

                        // prepare score column content
                        scoreLabel                     = new Label();
                        scoreLabel.Content             = scoreRow.GamerScores;
                        scoreLabel.HorizontalAlignment = HorizontalAlignment.Center;
                        scoreLabel.VerticalAlignment   = VerticalAlignment.Center;
                        statisticsTable.Children.Add(scoreLabel);
                        Grid.SetRow(scoreLabel, currentIndex);
                        Grid.SetColumn(scoreLabel, 2);

                        // prepare biggest tile column content
                        bgstTile         = new Tile();
                        bgstTile.Content = scoreRow.GamerBiggestTile;
                        GamePage.SetTileStyleByNumber(bgstTile, bgstTile.GetNumber());
                        bgstTile.HorizontalAlignment = HorizontalAlignment.Right;
                        bgstTile.VerticalAlignment   = VerticalAlignment.Center;
                        statisticsTable.Children.Add(bgstTile);
                        Grid.SetRow(bgstTile, currentIndex);
                        Grid.SetColumn(bgstTile, 3);
                        bgstTile.Height = 50;
                        bgstTile.Width  = 50;
                    });
                }
                else
                {
                    messageText.Content = "No relevant data to display.";
                }
            }
            catch
            {
                messageText.Content = "No connection to server, please try again later...";
            }
        }