示例#1
0
        } //End TwoUpForm

        /// <summary>
        /// Throws the two coins and shows the results on the screen.
        /// Pre: The user has thrown the coins and an output is yet to be placed
        /// onto the GUI.
        /// Post: The label of both coin combination is updated with the correct
        /// value. The animation is continuing for it's total of 1000ms.
        /// </summary>
        private void ShowResultsOfThrow()
        {
            TwoUp.ThrowCoins();
            btnThrowCoins.Enabled = false;
            tmrFlip.Start();              //Start animation timer.
            switch (TwoUp.OutputWinner()) //Output the correct roll and winner.
            {
            case 0:
                lblCoinsTossed.Text = "Tails";
                Trace.WriteLine(TAILS);
                break;

            case 1:
                lblCoinsTossed.Text = "Odds";
                Trace.WriteLine(ODDS);
                Trace.WriteLine("Click Throw Coins");
                return;

            case 2:
                lblCoinsTossed.Text = "Heads";
                Trace.WriteLine(HEADS);
                break;
            }
            btnPlayAgain.Visible = true;
            Trace.WriteLine("\nYou have " + TwoUp.SCORES[PLAYER_ID] + " points and I have "
                            + TwoUp.SCORES[COMPUTER_ID] + " points.\n");
        } //End ShowResultsOfThrow
示例#2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="form"></param>
 public TwoUpForm()
 {
     InitializeComponent();
     Trace.Listeners.Add(new ListBoxTraceListener(twoUpListBox));
     TwoUp.SetUpCoins();
     TwoUp.ResetGlobals();
 } //End TwoUpForm
示例#3
0
        } //End ShowResultsOfThrow

        /// <summary>
        /// Makes the tossed coins appear to be animated by
        /// alternating between the two sides of the coin (images)
        /// until finally reaching the side it landed on.
        /// Pre: The coins require a form of animation and have held values
        /// (i.e. odds, tails or heads)
        /// Post: The coin picture box images are replaced with the correct
        /// landing of the coins.
        /// </summary>
        private void AnimateCoins()
        {
            //Set both images to Heads if this is an even loop of the animation.
            SetPictureBox(1, tickCount % 2 == 0 ? true : false);
            SetPictureBox(2, tickCount % 2 == 0 ? true : false);
            tickCount++;

            //Once the animation is complete (after 10 loops/1000ms of time)
            //we will set both picture boxes to the real faces of the coins
            //whilst revealing the labels to show which face it landed on.
            if (tickCount >= 10)
            {
                SetPictureBox(1, TwoUp.IsHeads(1));
                SetPictureBox(2, TwoUp.IsHeads(2));
                lblCoinsTossed.Visible = true;
                if (lblCoinsTossed.Text == "Odds")
                {
                    btnThrowCoins.Enabled = true;
                }
                tmrFlip.Stop();
                tickCount = 0;  //Reset the timer for next toss.
            }
        } //End AnimateCoins
示例#4
0
        static void Main(string[] args)
        {
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
            Trace.AutoFlush = true;

            do
            {
                DisplayMenu(mainMenu);
                menuOption = GetMenuOption(EXIT, HIGHEST_MENU_NUMBER);
                switch (menuOption)
                {
                case SIMPLE_TWO_UP:
                    TwoUp.PlayConsole();
                    break;

                case TWENTY_ONE:
                    TwentyOne.PlayConsole();
                    break;

                case CRAZY_EIGHTS:
                    CrazyEights.PlayConsole();
                    break;

                case PIG:
                    Pig.PlayConsole();
                    break;

                case EXIT:
                    DisplayEndMessage();
                    break;

                default:
                    Trace.WriteLine("Major Logical error - this message should not appear!");
                    break;
                } // end switch
            } while (menuOption != EXIT);
        }         //end Main