Exemplo n.º 1
0
        /// <summary>
        /// Copies data from the logic class to the form
        /// </summary>
        /// <param name="firstRun">Prevent exceptions as a result of the game not being played prior</param>
        private void UpdateDisplay(bool firstRun)
        {
            // Update images
            this.imgDie1.Image = Images.GetDieImage(SnakeEyesGame.GetDiceFaceValue(0));
            this.imgDie2.Image = Images.GetDieImage(SnakeEyesGame.GetDiceFaceValue(1));

            // Update scores
            this.lblPlayerScore.Text = SnakeEyesGame.GetPlayersPoints().ToString();
            this.lblHouseScore.Text  = SnakeEyesGame.GetHousePoints().ToString();

            if (!firstRun)
            {
                // Show roll outcome
                string rollOutcome = SnakeEyesGame.GetRollOutcome();

                this.lblRoll.Text = rollOutcome;

                this.lblResult.Visible = true;

                int points = SnakeEyesGame.GetPossiblePoints();

                // Create user friendly, gramatically correct text.
                if (rollOutcome == SnakeEyesGame.PLAYER_WIN)
                {
                    this.lblResult.Text = "You get " + points.ToString() + " point" + (points == 1 ? "" : "s") + ".";
                }
                else if (rollOutcome == SnakeEyesGame.HOUSE_WIN)
                {
                    this.lblResult.Text = "House gets " + points.ToString() + " point" + (points == 1 ? "" : "s") + ".";
                }
                else if (!this.firstRoll)
                {
                    bool anNeeded = false;

                    // Only the numbers 8 and 11 need "an" instead of "a"
                    if (points == 8 || points == 11)
                    {
                        anNeeded = true;
                    }

                    this.lblResult.Text = "You need to roll a" + (anNeeded ? "n " : " ") + points.ToString();
                }
            }

            // Aesthetics
            this.CenterControlHorizontally(this.lblRoll);
            this.CenterControlHorizontally(this.lblResult);
        }