Ejemplo n.º 1
0
        private Control addAdditionalCase()
        {
            Control additionalTextBox = GetAdditionalTextBox();

            ControlThreadingHelper.InvokeControlAction(this, () =>
            {
                this.Width += additionalWidthPerAdditionalBox;
                this.Controls.Add(additionalTextBox);
                //vertical align with other boxes
                additionalTextBox.Top  = firstShotResultTextBox.Top;
                additionalTextBox.Left = this.Width - additionalWidthPerAdditionalBox + 5;
            });

            return(additionalTextBox);
        }
Ejemplo n.º 2
0
        private void Frame_BonusChanges(object sender, Tuple <int, int> e)
        {
            if (e.Item2 != 0)
            {
                if (additionalTextBoxesTofill.Count == 0)
                {
                    throw new Exception("No boxes is provided to receive the bonus value");
                }
                ControlThreadingHelper.InvokeControlAction(additionalTextBoxesTofill[0], () =>
                {
                    additionalTextBoxesTofill[0].Text = (e.Item2 - e.Item1).ToString();
                });

                additionalTextBoxesFilled.Add(additionalTextBoxesTofill[0]);
                additionalTextBoxesTofill.RemoveAt(0);
            }
        }
Ejemplo n.º 3
0
 private void GameControl_PlayerSubscription(object sender, Tuple <Player, bool> playerAndSubscribed)
 {
     System.Action <int> action = score =>
     {
         ControlThreadingHelper.InvokeControlAction(followedPlayersScores, () =>
         {
             followedPlayersScores.Items.Add(playerAndSubscribed.Item1.Name + " score now is " + score);
         });
     };
     if (playerAndSubscribed.Item2)
     {
         BowlingService.Instance.Subscribe(playerAndSubscribed.Item1.Id, action);
     }
     else
     {
         BowlingService.Instance.Unsubscribe(playerAndSubscribed.Item1.Id);
     }
 }
Ejemplo n.º 4
0
 private void Game_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (e.PropertyName.Equals("Over"))
     {
         ControlThreadingHelper.InvokeControlAction(knockedDownPinsTextBox, () =>
         {
             knockedDownPinsTextBox.Visible = !game.Over;
         });
         ControlThreadingHelper.InvokeControlAction(rollBtn, () =>
         {
             rollBtn.Visible = !game.Over;
         });
         ControlThreadingHelper.InvokeControlAction(gameOverLabel, () =>
         {
             gameOverLabel.Visible = game.Over;
         });
     }
 }
Ejemplo n.º 5
0
        private void Frame_ScoreChanged(object sender, int e)
        {
            //if it's the last frame whose score is updated and if we have not already provided the additional textboxes
            if (e == frame.Position && (!needAdditionalShots || frame.FirstOpportunityResult == null))
            {
                int nbCasesToAdd = 0;
                if (frame.Spare)
                {
                    nbCasesToAdd = 1;
                }
                else if (frame.Strike)
                {
                    nbCasesToAdd = 2;
                }

                if (nbCasesToAdd == 0)
                {
                    foreach (Control additionalBox in additionalTextBoxesFilled)
                    {
                        ControlThreadingHelper.InvokeControlAction(this, () =>
                        {
                            Controls.Remove(additionalBox);
                            Width -= additionalWidthPerAdditionalBox;
                        });
                    }
                    additionalTextBoxesFilled.Clear();
                    needAdditionalShots = false;
                }

                else
                {
                    for (int i = 1; i <= nbCasesToAdd; i++)
                    {
                        additionalTextBoxesTofill.Add(addAdditionalCase());
                    }
                    if (nbCasesToAdd > 0)
                    {
                        needAdditionalShots = true;
                    }
                }
            }
        }
Ejemplo n.º 6
0
 //Binding is now different, I integrated the ControlThreadingHelper that avoid cross-thread exception
 private void Frame_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName.Equals("FirstOpportunityResult"))
     {
         ControlThreadingHelper.InvokeControlAction(firstShotResultTextBox, () =>
         {
             firstShotResultTextBox.Text = frame.FirstOpportunityResult.ToString();
         });
         ControlThreadingHelper.InvokeControlAction(firstShotResultTextBox, () =>
         {
             firstShotResultTextBox.Visible = !frame.Strike;
         });
         ControlThreadingHelper.InvokeControlAction(strikePictureBox, () =>
         {
             strikePictureBox.Visible = frame.Strike;
         });
     }
     else if (e.PropertyName.Equals("SecondOpportunityResult"))
     {
         ControlThreadingHelper.InvokeControlAction(secondShotResultTextBox, () =>
         {
             secondShotResultTextBox.Text = frame.SecondOpportunityResult.ToString();
         });
         ControlThreadingHelper.InvokeControlAction(sparePictureBox, () =>
         {
             sparePictureBox.Visible = frame.Spare;
         });
         ControlThreadingHelper.InvokeControlAction(secondShotResultTextBox, () =>
         {
             secondShotResultTextBox.Visible = !frame.Spare;
         });
     }
     else if (e.PropertyName.Equals("AggregatedAmount"))
     {
         ControlThreadingHelper.InvokeControlAction(totalAmountTextBox, () =>
         {
             totalAmountTextBox.Text = frame.AggregatedAmount.ToString();
         });
     }
 }