Exemple #1
0
        private async void timer1_Tick(object sender, EventArgs e)
        {
            timeTimer   = timeTimer.AddSeconds(-1);
            totalTime   = totalTime.AddSeconds(1);
            label3.Text = timeTimer.ToString("m:ss");
            if (timeTimer.Minute == 0 && timeTimer.Second == 0)
            {
                timer1.Stop();
                this.TimeOver = true;
                MessageBox.Show("Время вышло");
                await gameSessionService.CompleteGameSessionForUser(gameSession.Id, UserProfile.Id, totalTime.ToString("m:s"), totalUserPoints);

                await gameSessionService.AddResultToGameSessionUser(gameSession.Id, UserProfile.Id, "Time is over");

                var rivalGameSessionUser = gameSessionService.GetGameSessionUser(gameSession.Id, UserProfile.RivalName);
                if (!rivalGameSessionUser.Finished)
                {
                    MessageBox.Show("Пожалуйста подождите пока ваш соперник не закончит игру.\nВы автоматичски будете переброшенны на страницу результатов!", "Игра окончена", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    pictureBox3.Image   = Image.FromFile(@"Resources/99px_ru_animacii_20594_kot_krutitsja_kak_kolesiko_zagruzki.gif");
                    pictureBox3.Dock    = DockStyle.Fill;
                    pictureBox3.Visible = true;
                }
                else
                {
                    dispose = false;
                    await gameSessionService.CompleteGameSession(gameSession.Id);

                    HubService.RivalFinishedRequest(UserProfile.RivalName);
                    ResultForm resultForm = new ResultForm(totalTime.ToString("m:s"), totalUserPoints, rivalGameSessionUser.TotalTime, rivalGameSessionUser.Points, timeOver: TimeOver);
                    resultForm.Show();
                    this.Close();
                }
            }
        }
Exemple #2
0
 public void AddResultToGameSessionUser([FromBody] string result, int gameSessionId, int userId)
 {
     try
     {
         gameSessionService.AddResultToGameSessionUser(gameSessionId, userId, result);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemple #3
0
        private async void ResultForm_Load(object sender, EventArgs e)
        {
            pictureBox2.Visible = false;
            label1.MaximumSize  = new Size(this.Width - leftIndent, this.Height);
            label2.MaximumSize  = new Size(this.Width - leftIndent, this.Height);
            label3.MaximumSize  = new Size(this.Width - leftIndent, this.Height);
            var result = String.Empty;

            if (Surrender.HasValue && Surrender.Value)
            {
                label3.Text    = string.Format(WinMessage, UserProfile.RivalName);
                label1.Visible = false;
                label2.Text    = SurrenderMassage;
                result         = "Won";
            }
            else if (RivalExited.HasValue && RivalExited.Value)
            {
                label3.Text    = string.Format(WinMessage, UserProfile.RivalName);
                label1.Visible = false;
                label2.Text    = RivalExitedMessage;
                result         = "Won";
            }
            else if (TimeOver.HasValue && TimeOver.Value == true)
            {
                label3.Text    = TimeOverMessage;
                label2.Visible = false;
                label1.Visible = false;
            }
            else
            {
                var userTime         = TotalTime.Split(':');
                var userMinutes      = Convert.ToInt32(userTime[0]);
                var userSeconds      = Convert.ToInt32(userTime[1]);
                var userTotalSeconds = userMinutes * 60 + userSeconds;

                var rivalTime         = RivalTotalTime.Split(':');
                var rivalMinutes      = Convert.ToInt32(rivalTime[0]);
                var rivalSeconds      = Convert.ToInt32(rivalTime[1]);
                var rivalTotalSeconds = rivalMinutes * 60 + rivalSeconds;

                label1.Text = string.Format(UserTemplateMessage, TotalTime, TotalPoints);
                label2.Text = string.Format(RivalTemplateMessage, RivalTotalTime, RivalTotalPoints);

                if (TotalPoints > RivalTotalPoints || (TotalPoints == RivalTotalPoints && userTotalSeconds < rivalTotalSeconds))
                {
                    label3.Text = string.Format(WinMessage, UserProfile.RivalName);
                    result      = "Won";
                }
                else if (TotalPoints == RivalTotalPoints && userTotalSeconds == rivalTotalSeconds)
                {
                    label3.Text = string.Format(DrawMessage, UserProfile.RivalName);
                    result      = "Draw";
                }
                else
                {
                    label3.Text = string.Format(LoseMessage, UserProfile.RivalName);
                    result      = "Lost";
                }
            }

            await gameSessionService.AddResultToGameSessionUser(UserProfile.GamaSessionId, UserProfile.Id, result);
        }