예제 #1
0
        public ObservableCollection <Passwordclass> LoadDataFromXml()
        {
            document = LoadXml();
            nodelist = document.SelectNodes("/" + Root + "/" + Branch);

            ObservableCollection <Passwordclass> PasswordCollection = new ObservableCollection <Passwordclass>();

            try
            {
                foreach (XmlNode node in nodelist)
                {
                    if (node != null)
                    {
                        Passwordclass PasswordList = new Passwordclass();
                        PasswordList.Id       = Convert.ToInt32(node["id"].InnerText);
                        PasswordList.Name     = node["nazwa"].InnerText;
                        PasswordList.Category = node["kategoria"].InnerText;
                        PasswordList.Level    = node["poziom"].InnerText;
                        PasswordCollection.Add(PasswordList);
                    }
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            document.Save(@XmlName);

            return(PasswordCollection);
        }
예제 #2
0
        public ObservableCollection <Passwordclass> LookForDataInXml(string Data1, string Data1Key, string Data2, string Data2Key, string Data3, string Data3Key)
        {
            ObservableCollection <Passwordclass> PasswordCollection = new ObservableCollection <Passwordclass>();

            document = LoadXml();

            try
            {
                XmlNodeList nodeList = document.DocumentElement.SelectNodes("//" + Branch + "[" + Data1Key + "=" + "'" + Data1 + "'"
                                                                            + " and " + Data2Key + "=" + "'" + Data2 + "'"
                                                                            + " and " + Data3Key + "=" + "'" + Data3 + "'" + "]");

                foreach (XmlNode node in nodeList)
                {
                    Passwordclass PasswordList = new Passwordclass();
                    PasswordList.Id       = Convert.ToInt32(node["id"].InnerText);
                    PasswordList.Name     = node["nazwa"].InnerText;
                    PasswordList.Category = node["kategoria"].InnerText;
                    PasswordList.Level    = node["poziom"].InnerText;
                    PasswordCollection.Add(PasswordList);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            document.Save(@XmlName);

            return(PasswordCollection);
        }
예제 #3
0
        private void PlayerReadyButton(object sender, RoutedEventArgs e)
        {
            Random rnd          = new Random();
            int    passwordTake = (int)((PasswordAmount)this.PasswordsComboBox.SelectedItem);

            for (int i = 0; i < passwordTake; i++)
            {
                int elementIndex = rnd.Next(0, PasswordCollection.Count - 1);
                PasswordGameCollection.Add(PasswordCollection.ElementAt(elementIndex));
                PasswordCollection.RemoveAt(elementIndex);
            }

            Passwordclass PasswordList = new Passwordclass();

            PasswordList = PasswordGameCollection.ElementAt(0);
            PasswordGameCollection.RemoveAt(0);
            PasswordLabelContent = PasswordList.Name;
            CategoryLabelContent = PasswordList.Category;

            PasswordAmountToQuess = passwordTake;

            playerReady = true;

            StackReadyPanel.Visibility = Visibility.Hidden;
            TimerTextBlock.Visibility  = Visibility.Visible;
            TimeForClock = TimeChoosen;
            Timer.Start();
        }
예제 #4
0
        private void Sort(object sender, RoutedEventArgs e)
        {
            Passwordclass PasswordObject = new Passwordclass();

            PasswordCollection = PasswordObject.SortCollection(PasswordCollection, this.ValueSortTypeComboBox.SelectedItem.ToString(), _TypeOfSort);

            UpdateListView(PasswordCollection);
        }
예제 #5
0
        private void RemoveSelected(object sender, RoutedEventArgs e)
        {
            while (PasswordListWiev.SelectedItems.Count > 0)

            {
                Passwordclass item = (Passwordclass)PasswordListWiev.SelectedItem;

                PasswordCollection.Remove(PasswordCollection.Single(x => x.Id == item.Id));

                int id = 1;

                foreach (var Password in PasswordCollection)
                {
                    Password.Id = id;
                    id++;
                }

                Passworded.UpdateXmlData(PasswordCollection);
            }
        }
예제 #6
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            var NewPasswordCollection = new ObservableCollection <Passwordclass>();
            var PasswordModel         = new Passwordclass();
            var PasswordXml           = new PasswordsXml();

            NewPasswordCollection = PasswordXml.LoadDataFromXml();

            if (this.newName.Text.ToString() == String.Empty || this.newCategory.Text.ToString() == String.Empty)
            {
                MessageBox.Show("Żadne pole nie może być puste!...");
            }
            else
            {
                bool IfExist = PasswordModel.SearchDataInCollection(NewPasswordCollection, this.newName.Text.ToString(), this.newCategory.Text.ToString());

                if (IfExist == true)
                {
                    MessageBox.Show("Przykro mi, takie hasło jest już w bazie...");
                }
                else
                {
                    int lastId = PasswordModel.GetLastIdIndexValue(NewPasswordCollection) + 1;
                    PasswordXml.AddDataToXml(lastId, this.newName.Text.ToString(), this.newCategory.Text.ToString(), this.newLevel.Text.ToString());
                    PasswordModel.Id       = lastId;
                    PasswordModel.Category = this.newCategory.Text.ToString();
                    PasswordModel.Name     = this.newName.Text.ToString();
                    PasswordModel.Level    = this.newLevel.Text.ToString();

                    NewPasswordCollection.Add(PasswordModel);
                    MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                    mainWindow.PasswordCollection = NewPasswordCollection;
                    mainWindow.UpdateListView(mainWindow.PasswordCollection);
                    // this.Close();
                    //MessageBox.Show("Dodano nowe hasło!"); - optionally
                }
            }
        }
예제 #7
0
        private void PasswordGuessed(object sender, RoutedEventArgs e)
        {
            if (playerReady)
            {
                StackReadyPanel.Visibility = Visibility.Visible;

                // here is some problem (only in full screen mode) with refreshing points in label graphic structure

                if (TeamToPLay && PasswordAmountToQuess > 0)
                {
                    Team2Score       += 1;
                    Team2ScoreContent = Team2Score.ToString() + " pkt";
                    Team2ScoreLabel.Refresh();
                }
                else if (!TeamToPLay && PasswordAmountToQuess > 0)
                {
                    Team1Score       += 1;
                    Team1ScoreContent = Team1Score.ToString() + " pkt";
                    Team1ScoreLabel.Refresh();
                }

                Task.Factory.StartNew(() =>
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() => { Team1ScoreLabel.UpdateLayout(); }));
                });

                Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() => { Team2ScoreLabel.UpdateLayout(); }));

                PasswordAmountToQuess--;

                GameIterations--;

                try
                {
                    if (PasswordAmountToQuess == 0 && GameIterations > 0)
                    {
                        Timer.Stop();
                        TimeForClock = TimeChoosen;

                        if (TeamToPLay)
                        {
                            TeamLabelContent   = Team1List.ElementAt(0);
                            PlayerLabelContent = Team1List.ElementAt(1);
                            Team1List.RemoveRange(0, 2);

                            TeamToPLay = team1;
                        }
                        else
                        {
                            TeamLabelContent   = Team2List.ElementAt(0);
                            PlayerLabelContent = Team2List.ElementAt(1);
                            Team2List.RemoveRange(0, 2);
                            TeamToPLay = team2;
                        }

                        TimerTextBlock.Visibility = Visibility.Hidden;
                        PasswordAmountToQuess     = (int)((PasswordAmount)this.PasswordsComboBox.SelectedItem);
                        MessageBox.Show("Następny gracz!");
                        playerReady = false;
                    }
                    else if (GameIterations > 0)
                    {
                        Passwordclass PasswordList = new Passwordclass();
                        PasswordList = PasswordGameCollection.ElementAt(0);
                        PasswordGameCollection.RemoveAt(0);
                        PasswordLabelContent = PasswordList.Name;
                        CategoryLabelContent = PasswordList.Category;
                    }

                    playerReady = false;

                    if (GameIterations <= 0)
                    {
                        int result = Team2Score - Team1Score;
                        if (result > 0)
                        {
                            MessageBox.Show("Koniec gry!\n Wygrała drużyna: " + Team2Name);
                        }
                        else if (result == 0)
                        {
                            MessageBox.Show("Koniec gry!\n REMIS!");
                        }
                        else
                        {
                            MessageBox.Show("Koniec gry!\n Wygrała drużyna: " + Team1Name);
                        }

                        SetParametersDefault();
                    }
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }