Ejemplo n.º 1
0
        /// <summary>
        /// Copies data from logic class to display
        /// </summary>
        /// <param name="isFirstRun">Prevent exceptions resulting from no game being played prior</param>
        private void UpdateDisplay(bool isFirstRun)
        {
            // Show images
            this.UpdatePictureBoxImage(this.picCoin1, TwoUpGame.IsHeads(COIN_1));
            this.UpdatePictureBoxImage(this.picCoin2, TwoUpGame.IsHeads(COIN_2));

            // Show scores
            this.lblScorePlayer.Text   = TwoUpGame.GetPlayersScore().ToString();
            this.lblScoreComputer.Text = TwoUpGame.GetComputersScore().ToString();

            if (!isFirstRun)
            {
                // Show toss outcomes
                this.lblOutcome.Visible = true;

                string tossOutcome = TwoUpGame.TossOutcome();

                this.lblOutcome.Text = tossOutcome;

                if (tossOutcome != "Odds")
                {
                    this.btnThrowCoins.Enabled = false;
                    this.btnPlayAgain.Visible  = true;
                }
            }
        }
Ejemplo n.º 2
0
        public FormGameTwoUp()
        {
            InitializeComponent();

            TwoUpGame.SetUpGame();

            this.UpdateDisplay(true);
        }
Ejemplo n.º 3
0
        private void tmrAnimation_Tick(object sender, EventArgs e)
        {
            // Display true result after one second
            if (animationCounter >= ONE_SECOND)
            {
                tmrAnimation.Stop();

                btnThrowCoins.Enabled = true;

                TwoUpGame.TossCoins();

                this.UpdateDisplay(false);

                return;
            }

            // DateTime.UtcNow.Ticks is a measure of nanoseconds, so values between are different.
            // Makes for slightly more realistic coin flips
            UpdatePictureBoxImage(this.picCoin1, DateTime.UtcNow.Ticks % 2 == 0);
            UpdatePictureBoxImage(this.picCoin2, DateTime.UtcNow.Ticks % 2 == 0);

            // Update animationCounter with how many seconds it has been
            animationCounter += (double)tmrAnimation.Interval / 1000.0f;
        }