Exemple #1
0
        public ObservableCollection<Content> Get_lvl_1_Country()
        {
            ObservableCollection<Content> countries = new ObservableCollection<Content>();
            using (var statement = con.Prepare("SELECT country, capital, img_source_url, level, test FROM Content WHERE length(capital) < 17 AND length(country) < 19 AND length(img_source_url) > 2 AND level = 1"))
            {
                while (statement.Step() == SQLiteResult.ROW)
                {
                    Content Record = new Content();
                    Record.Country = (string)statement[0];
                    Record.Capital = (string)statement[1];
                    Record.PathSourceImage = (string)statement[2];
                    Record.Level = Convert.ToInt16(statement[3]);
                    countries.Add(Record);
                }
            }


            return countries;
        }
        private void GameWork(ObservableCollection<Content> lvlCountries)
        {
            Random rnd = new Random();
            CurrentCountries = lvlCountries;
            int elem_id = rnd.Next(0, lvlCountries.Count);
            CurrentCountry = lvlCountries.ElementAt(elem_id);

            string namecountry = CurrentCountry.Country;
            NameCountryText.Text = namecountry;
            nameCapital = CurrentCountry.Capital.ToLower();


            var mixedCapital = CurrentCountry.ConvertCapitalName(CurrentCountry.Capital);

            //countryLeftText.Text = App.AllCountries.Count.ToString() + " / " + App.LeftCounter.ToString();
           // textBlock.Text = lvlCountries.Count.ToString();
            ImageBrush brush = new ImageBrush();
            string path = "ms-appx:///img/" + CurrentCountry.PathSourceImage + ".jpg";
            brush.ImageSource = new BitmapImage(new Uri(path, UriKind.Absolute));
            MainImage.Background = brush;


            if (App.SettingsGame.HintButton == true)
            {
                hintbutton.Opacity = 100;
                hintbutton.IsEnabled = true;

            }
            else
            {
                hintbutton.Opacity = 0;
                hintbutton.IsEnabled = false;
            }


            for (int i = 0; i < gridLetters.Children.Count; i++)
            {
                if (gridLetters.Children[i].GetType() == textBlock1.GetType())
                {
                    textBlocks.Add((TextBlock)gridLetters.Children[i]);
                }
            }

            for (int i = 0; i < gridCap.Children.Count; i++)
            {
                if (gridLetters.Children[i].GetType() == textBlock1.GetType())
                {
                    textBlocksCapital.Add((TextBlock)gridCap.Children[i]);
                }
            }


            start = (textBlocksCapital.Count - mixedCapital.Length) / 2;


            for (int i = 0; i < mixedCapital.Length; i++)
            {
                rand = rnd.Next(0, textBlocks.Count);
                while (textBlocks[rand].Text != "")
                {
                    rand = rnd.Next(0, textBlocks.Count);
                }

                textBlocks[rand].Text = mixedCapital[i].ToString();
                textBlocksCapital[start + i].Text = ".";
            }

            foreach (TextBlock txtBlock in textBlocks)
            {
                if (txtBlock.Text == "") textBlocksTrash.Add(txtBlock);
            }

            foreach (TextBlock trashBlock in textBlocksTrash)
            {
                rand = rnd.Next(0, textBlocksTrash.Count);
                trashBlock.Text = trashLetters[rand].ToString();
            }


        }
        private void updCountries(int lvl, Content deathCountry)
        {
            switch(lvl)
            {
                case 1: 
                    App.lvl_1_Countries.Remove(deathCountry);
                    if(App.lvl_1_Countries.Count == 0)
                    {
                        App.pgsBarValue_lvl_1 = 100;
                    }
                    else App.pgsBarValue_lvl_1 = ((App.LeftCounter_lvl_1 - App.lvl_1_Countries.Count) / App.LeftCounter_lvl_1) * 100;
                    LevelProgressBar.Value = App.pgsBarValue_lvl_1;
                     

                    break;

                case 2:
                    App.lvl_2_Countries.Remove(deathCountry);
                    if (App.lvl_2_Countries.Count == 0)
                    {
                        App.pgsBarValue_lvl_2 = 100;
                    }
                    else
                        App.pgsBarValue_lvl_2 = ((App.LeftCounter_lvl_2 - App.lvl_2_Countries.Count) / App.LeftCounter_lvl_2 ) * 100;
                    LevelProgressBar.Value = App.pgsBarValue_lvl_2;
                     

                    break;

                case 3:
                    App.lvl_3_Countries.Remove(deathCountry);
                    if (App.lvl_3_Countries.Count == 0)
                    {
                        App.pgsBarValue_lvl_3 = 100;
                    }
                    else
                        App.pgsBarValue_lvl_3 = ((App.LeftCounter_lvl_3 - App.lvl_3_Countries.Count) / App.LeftCounter_lvl_3) * 100;
                    LevelProgressBar.Value = App.pgsBarValue_lvl_3;
                    break;

                case 4:
                    App.AllCountries.Remove(deathCountry);
                    if (App.AllCountries.Count == 0)
                    {
                        App.pgsBarValue_All = 100;
                    }
                    else
                        App.pgsBarValue_All = (App.AllCountries.Count / App.LeftCounterAll) * 100;
                    LevelProgressBar.Value = App.pgsBarValue_All;
                     
                    break;
            }

        }