コード例 #1
0
        private void CbIsAdmin_Checked(object sender, RoutedEventArgs e)
        {
            if (!(dgShow.SelectedItem is PlayerFullInfo))
            {
                dgShow.SelectedItem = null;
                return;
            }

            PlayerFullInfo playerFull = dgShow.SelectedItem as PlayerFullInfo;
            PlayerVM       player     = new PlayerVM()
            {
                Id       = playerFull.Id,
                Login    = playerFull.Login,
                Email    = playerFull.Email,
                Password = playerFull.Password,
                IsAdmin  = ((CheckBox)sender).IsChecked == true ? true : false
            };

            string url     = _hostUrl + "/api/jsstudygame/player";
            int    mistake = ServerWorker.ChangePlayerToServer(player, url);

            if (mistake <= 0)
            {
                MessageBox.Show("Adding error! Try again!");
                return;
            }
        }
コード例 #2
0
        private void SaveScore()
        {
            _playerScore.AnswersSkipped = "";
            _playerScore.AnswersWrong   = "";

            _playerScore.ProgressInGame = _playerScore.CorrectAnswers * 100 / _amountoftests;

            foreach (var item in _skippedAnswer)
            {
                if (string.IsNullOrWhiteSpace(_playerScore.AnswersSkipped))
                {
                    _playerScore.AnswersSkipped += item;
                }
                else
                {
                    _playerScore.AnswersSkipped += $",{item}";
                }
            }
            foreach (var item in _wrongAnswer)
            {
                if (string.IsNullOrWhiteSpace(_playerScore.AnswersWrong))
                {
                    _playerScore.AnswersWrong += item;
                }
                else
                {
                    _playerScore.AnswersWrong += $",{item}";
                }
            }

            requestUrl = _hostUrl + $"/api/jsstudygame/score";
            int result = ServerWorker.ChangePlayerToServer(_playerScore, requestUrl);
        }
コード例 #3
0
        private void BtmStartGame_Click(object sender, RoutedEventArgs e)
        {
            cbWrong.SelectedItem   = cbWrong.Items[0];
            cbSkipped.SelectedItem = cbSkipped.Items[0];

            int index = cbWrong.Items.Count;

            for (int i = index - 1; i > 0; i--)
            {
                if (i != 0)
                {
                    cbWrong.Items.RemoveAt(i);
                }
            }
            index = cbSkipped.Items.Count;
            for (int i = index - 1; i > 0; i--)
            {
                if (i != 0)
                {
                    cbSkipped.Items.RemoveAt(i);
                }
            }

            _playerScore.IdPlayerScore           = _player.Id;
            _playerScore.TotalScore              = 0;
            _playerScore.TimeGameInSeconds       = 0;
            _playerScore.SkippedAnswers          = 0;
            _playerScore.ProgressInGame          = 0;
            _playerScore.IncorrectAnswers        = 0;
            _playerScore.CurrentQuestionNoAnswer = 1;
            _playerScore.CorrectAnswers          = 0;
            _playerScore.AnswersWrong            = "";
            _playerScore.AnswersSkipped          = "";

            requestUrl = _hostUrl + $"/api/jsstudygame/score";
            if (ServerWorker.ChangePlayerToServer(_playerScore, requestUrl) <= 0)
            {
                BtmEndGame_Click(sender, e);
            }

            if (_stopwatch.IsRunning)
            {
                _stopwatch.Restart();
            }
            else
            {
                _stopwatch.Start();
            }

            spStartGame.Visibility     = Visibility.Visible;
            btnReference.Visibility    = Visibility.Visible;
            btnNextQuestion.Visibility = Visibility.Visible;

            _isGame = true;
            if (!UpdateQuestion(_playerScore.CurrentQuestionNoAnswer))
            {
                BtmEndGame_Click(sender, e);
            }
        }
コード例 #4
0
 private void BtnLogout_Click(object sender, RoutedEventArgs e)
 {
     if (_isGame)
     {
         MessageBox.Show("At first you must end the game!");
         return;
     }
     MainWindow.playerLogin    = "******";
     MainWindow.playerPassword = "******";
     _isGame        = false;
     _player        = null;
     _playerAddInfo = null;
     _playerScore   = null;
     _isAnswer      = false;
     requestUrl     = _hostUrl + $"/api/jsstudygame/score";
     ServerWorker.ChangePlayerToServer(_playerScore, requestUrl);
     this.Close();
 }
コード例 #5
0
        private void BtnDeleteScore_Click(object sender, RoutedEventArgs e)
        {
            scoreVM.IdPlayerScore           = playerVM.Id;
            scoreVM.TotalScore              = 0;
            scoreVM.TimeGameInSeconds       = 0;
            scoreVM.SkippedAnswers          = 0;
            scoreVM.ProgressInGame          = 0;
            scoreVM.IncorrectAnswers        = 0;
            scoreVM.CurrentQuestionNoAnswer = 1;
            scoreVM.CorrectAnswers          = 0;
            scoreVM.AnswersWrong            = "";
            scoreVM.AnswersSkipped          = "";

            string requestUrl = _hostUrl + $"/api/jsstudygame/score";

            if (ServerWorker.ChangePlayerToServer(scoreVM, requestUrl) > 0)
            {
                DpScore_Loaded(sender, e);
            }
        }
コード例 #6
0
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            if (txtPasswordOne.IsVisible)
            {
                txtPasswordOneTxt.Text = txtPasswordOne.Password;
            }
            else
            {
                txtPasswordOne.Password = txtPasswordOneTxt.Text;
            }

            if (txtPasswordTwo.IsVisible)
            {
                txtPasswordTwoTxt.Text = txtPasswordTwo.Password;
            }
            else
            {
                txtPasswordTwo.Password = txtPasswordTwoTxt.Text;
            }

            if (!CheckIfAllCorrect())
            {
                return;
            }

            playerVM.Login    = txtLogin.Text;
            playerVM.Email    = txtEmail.Text;
            playerVM.Password = txtPasswordOne.Password;

            string url     = _hostUrl + "/api/jsstudygame/player";
            int    mistake = ServerWorker.ChangePlayerToServer(playerVM, url);

            if (mistake == 0)
            {
                MessageBox.Show("Adding error! Try again!");
                this.Close();
            }

            if (mistake == -1 || mistake == -3)
            {
                lblLoginError.Content = "Sorry! This login is already in use!";
                txtLogin.IsReadOnly   = false;
            }

            if (mistake == -2 || mistake == -3)
            {
                lblEmailError.Content = "Sorry! This email is already in use!";
                txtEmail.IsReadOnly   = false;
            }

            if (mistake < 0)
            {
                return;
            }

            MainWindow.playerLogin    = playerVM.Login;
            MainWindow.playerPassword = playerVM.Password;

            playerAddInfoVM.IdPlayerAdditionalInfo = playerVM.Id;
            playerAddInfoVM.Name    = txtName.Text;
            playerAddInfoVM.Surname = txtSurname.Text;

            playerAddInfoVM.Photo     = photoUser.ToBase64String();
            playerAddInfoVM.BirthDate = dateChoose.SelectedDate.Value;

            url     = _hostUrl + "/api/jsstudygame/playeraddinfo";
            mistake = ServerWorker.ChangePlayerToServer(playerAddInfoVM, url);

            if (mistake == 0)
            {
                MessageBox.Show("Changing Additional Information error! Try again!");
                this.Close();
            }
            else
            {
                wpPasswordTwo.Visibility      = Visibility.Collapsed;
                wpPasswordTwoTitle.Visibility = Visibility.Collapsed;
                btnChange.Visibility          = Visibility.Visible;
                btnDelete.Visibility          = Visibility.Visible;
                btnChangePhoto.Visibility     = Visibility.Hidden;
                btnSave.Visibility            = Visibility.Hidden;
                Window_Loaded(sender, e);
                MessageBox.Show("Account was successfully changed!\nWe sent you mail!");
            }
        }