public IActionResult ChangePlayerScore([FromBody] PlayerScoreVM model)
        {
            if (model == null || model.IdPlayerScore <= 0)
            {
                return(Ok(0));
            }
            PlayerScore player = _context.Scores.SingleOrDefault(p => p.IdPlayerScore == model.IdPlayerScore);

            if (player == null)
            {
                return(CreatePlayerScore(model));
            }
            else
            {
                try
                {
                    player.IdPlayerScore           = model.IdPlayerScore;
                    player.CorrectAnswers          = model.CorrectAnswers;
                    player.IncorrectAnswers        = model.IncorrectAnswers;
                    player.SkippedAnswers          = model.SkippedAnswers;
                    player.TotalScore              = model.TotalScore;
                    player.TimeGameInSeconds       = model.TimeGameInSeconds;
                    player.ProgressInGame          = model.ProgressInGame;
                    player.CurrentQuestionNoAnswer = model.CurrentQuestionNoAnswer;
                    player.AnswersSkipped          = model.AnswersSkipped;
                    player.AnswersWrong            = model.AnswersWrong;
                    _context.SaveChanges();
                }
                catch (Exception) { return(Ok(0)); }

                return(Ok(player.IdPlayerScore));
            }
        }
Exemplo n.º 2
0
        private void BtnAdmin_Click(object sender, RoutedEventArgs e)
        {
            if (_isGame)
            {
                MessageBox.Show("At first you must end the game!");
                return;
            }
            this.Hide();
            AdminWindow admin = new AdminWindow(_hostUrl);

            admin.Owner = this;
            admin.ShowDialog();

            if (MainWindow.playerLogin == "none" && MainWindow.playerPassword == "none")
            {
                this.Close();
                return;
            }

            requestUrl     = _hostUrl + $"/api/jsstudygame/login?emailOrLogin={MainWindow.playerLogin}&password={MainWindow.playerPassword}";
            _player        = ServerWorker.GetInfoFromServer <PlayerVM>(requestUrl);
            requestUrl     = _hostUrl + $"/api/jsstudygame/addinfo?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}";
            _playerAddInfo = ServerWorker.GetInfoFromServer <PlayerAdditionalInfoVM>(requestUrl);

            requestUrl   = _hostUrl + $"/api/jsstudygame/score?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}";
            _playerScore = ServerWorker.GetInfoFromServer <PlayerScoreVM>(requestUrl);
            _playerScore.IdPlayerScore = _player.Id;

            this.ShowDialog();
        }
        public IActionResult CreatePlayerScore([FromBody] PlayerScoreVM model)
        {
            if (model == null)
            {
                return(Ok(0));
            }

            PlayerScore player;

            try
            {
                player = new PlayerScore()
                {
                    IdPlayerScore           = model.IdPlayerScore,
                    CorrectAnswers          = model.CorrectAnswers,
                    IncorrectAnswers        = model.IncorrectAnswers,
                    SkippedAnswers          = model.SkippedAnswers,
                    TotalScore              = model.TotalScore,
                    TimeGameInSeconds       = model.TimeGameInSeconds,
                    ProgressInGame          = model.ProgressInGame,
                    CurrentQuestionNoAnswer = model.CurrentQuestionNoAnswer,
                    AnswersSkipped          = model.AnswersSkipped,
                    AnswersWrong            = model.AnswersWrong
                };
                _context.Scores.Add(player);
                _context.SaveChanges();
            }
            catch (Exception) { return(Ok(0)); }

            return(Ok(player.IdPlayerScore));
        }
Exemplo n.º 4
0
 public ProfileWindow(string hostUrl)
 {
     _hostUrl        = hostUrl;
     playerVM        = new PlayerVM();
     playerAddInfoVM = new PlayerAdditionalInfoVM();
     scoreVM         = new PlayerScoreVM();
     InitializeComponent();
 }
Exemplo n.º 5
0
        private void DpScore_Loaded(object sender, RoutedEventArgs e)
        {
            string requestUrl = _hostUrl + $"/api/jsstudygame/score?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}";

            scoreVM = ServerWorker.GetInfoFromServer <PlayerScoreVM>(requestUrl);
            if (scoreVM == null)
            {
                return;
            }
            lblTotal.Content             = scoreVM.TotalScore;
            lblCorrectAnswers.Content    = scoreVM.CorrectAnswers;
            lblIncorrectAnswers.Content  = scoreVM.IncorrectAnswers;
            lblSkippedAnswers.Content    = scoreVM.SkippedAnswers;
            lblTimeGameInSeconds.Content = scoreVM.TimeGameInSeconds;
            lblProgressInGame.Content    = scoreVM.ProgressInGame + " %";
        }
Exemplo n.º 6
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();
 }
        public IActionResult GetPlayerScore(string login, string password)
        {
            PlayerScoreVM scoreVM = new PlayerScoreVM()
            {
                IdPlayerScore           = 0,
                CorrectAnswers          = 0,
                IncorrectAnswers        = 0,
                SkippedAnswers          = 0,
                TotalScore              = 0,
                TimeGameInSeconds       = 0,
                ProgressInGame          = 0,
                CurrentQuestionNoAnswer = 1,
                AnswersSkipped          = "",
                AnswersWrong            = ""
            };

            var playerBasic = _context.Players.SingleOrDefault(p => p.Login == login && p.Password == password);

            if (playerBasic == null)
            {
                return(Ok(scoreVM));
            }

            var score = _context.Scores.SingleOrDefault(p => p.IdPlayerScore == playerBasic.Id);

            if (score == null)
            {
                scoreVM.IdPlayerScore = playerBasic.Id;
                return(Ok(scoreVM));
            }

            scoreVM.IdPlayerScore           = score.IdPlayerScore;
            scoreVM.CorrectAnswers          = score.CorrectAnswers;
            scoreVM.IncorrectAnswers        = score.IncorrectAnswers;
            scoreVM.SkippedAnswers          = score.SkippedAnswers;
            scoreVM.TotalScore              = score.TotalScore;
            scoreVM.TimeGameInSeconds       = score.TimeGameInSeconds;
            scoreVM.ProgressInGame          = score.ProgressInGame;
            scoreVM.CurrentQuestionNoAnswer = score.CurrentQuestionNoAnswer;
            scoreVM.AnswersSkipped          = score.AnswersSkipped;
            scoreVM.AnswersWrong            = score.AnswersWrong;

            return(Ok(scoreVM));
        }
Exemplo n.º 8
0
        public MainWindow(string hostUrl)
        {
            _hostUrl = hostUrl;
            InitializeComponent();

            requestUrl                 = _hostUrl + $"/api/jsstudygame/login?emailOrLogin={MainWindow.playerLogin}&password={MainWindow.playerPassword}";
            _player                    = ServerWorker.GetInfoFromServer <PlayerVM>(requestUrl);
            requestUrl                 = _hostUrl + $"/api/jsstudygame/addinfo?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}";
            _playerAddInfo             = ServerWorker.GetInfoFromServer <PlayerAdditionalInfoVM>(requestUrl);
            requestUrl                 = _hostUrl + $"/api/jsstudygame/score?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}";
            _playerScore               = ServerWorker.GetInfoFromServer <PlayerScoreVM>(requestUrl);
            _playerScore.IdPlayerScore = _player.Id;

            requestUrl     = _hostUrl + $"/api/jsstudygame/amountoftests?login={MainWindow.playerLogin}&password={MainWindow.playerPassword}";
            _amountoftests = ServerWorker.GetInfoFromServer <int>(requestUrl);
            if (_amountoftests == 0)
            {
                _amountoftests = 1;
            }

            if (_player.IsAdmin)
            {
                btnAdmin.Visibility = Visibility.Visible;
            }

            spStartGame.Visibility  = Visibility.Hidden;
            btnReference.Visibility = Visibility.Hidden;

            _skippedAnswer = new List <string>();
            _wrongAnswer   = new List <string>();
            if (!string.IsNullOrWhiteSpace(_playerScore.AnswersSkipped))
            {
                _skippedAnswer = _playerScore.AnswersSkipped.Split(',').ToList();
                if (_skippedAnswer != null)
                {
                    _skippedAnswer.Sort();
                }
                foreach (var item in _skippedAnswer)
                {
                    cbSkipped.Items.Add($"<<  {item}  >>");
                }
            }
            if (!string.IsNullOrWhiteSpace(_playerScore.AnswersWrong))
            {
                _wrongAnswer = _playerScore.AnswersWrong.Split(',').ToList();
                if (_wrongAnswer != null)
                {
                    _wrongAnswer.Sort();
                }

                foreach (var item in _wrongAnswer)
                {
                    cbWrong.Items.Add($"<<  {item}  >>");
                }
            }
            _stopwatch = new Stopwatch();
            Task.Run(() =>
            {
                string imgPathStr = _hostUrl + $"/images/jsImg2.jpg";
                Uri resourceUri   = new Uri(imgPathStr, UriKind.Absolute);
                this.Dispatcher.Invoke(() =>
                {
                    backgroundImg.ImageSource = new BitmapImage(resourceUri);
                });
            });
        }