Beispiel #1
0
        }//end of main program eom

        public static void SetDiceSides(Die player1dice, Die player2dice)  //local variable are lower case
        {
            string indicesize = "";
            int    dicesize   = 6;

            Console.WriteLine("Set dice face count of 6 -20");
            Console.WriteLine("An invalid entry will default to 6");
            Console.Write("Enter number of sides: ");
            indicesize = Console.ReadLine();

            //VAlidation
            //a) did the user enter a number
            if (!int.TryParse(indicesize, out dicesize))
            {
                Console.WriteLine("Die size is invalid. Die size will be set to 6.");
                dicesize = 6;
            }
            else
            {
                //b) is integer between 6 and 20
                if (dicesize < 6 || dicesize > 20)
                {
                    Console.WriteLine("Die size is invalid. Die size will be set to 6.");
                    dicesize = 6;
                }
                else  //this else statement is actually not needed
                {
                    Console.WriteLine("Die size will be set to {0}.", dicesize);
                }
            }
            player1dice.SetSides(dicesize);
            player2dice.SetSides(dicesize);
        }
Beispiel #2
0
        }//eom

        public static void SetDiceSides(Die player1dice, Die player2dice)
        {
            string indicesize = "";
            int    dicesize   = 6;

            Console.WriteLine("Set dice face count of 6 to 20");
            Console.WriteLine("An invalid entry will default to 6");
            Console.Write("Enter number of sides: ");
            indicesize = Console.ReadLine();

            //Validation
            //a) did the user enter a number
            if (!int.TryParse(indicesize, out dicesize))
            {
                Console.WriteLine("Die size is invalid. Die size will be set to 6.");
                dicesize = 6;
            }
            else
            {
                //b) is integer between 6 and 20
                if (dicesize < 6 || dicesize > 20)
                {
                    Console.WriteLine("Die size is invalid. Die size will be set to 6.");
                    dicesize = 6;
                }
                else
                {
                    Console.WriteLine("Die size will be set to {0}.", dicesize);
                }
            }
            player1dice.SetSides(dicesize);
            player2dice.SetSides(dicesize);
        }//eom
Beispiel #3
0
        } // end of main

        public static void SetDiceSides(Die player1dice, Die player2dice)
        {
            // Don's coding best practice is to code local variables in all lower case
            string idicesize = ""; // using in represents integer, maybe just use i since that's what I'm used to
            int    dicesize  = 6;

            Console.WriteLine("Set dice face count of 6 to 20");
            Console.WriteLine("An invalid entry will default to 6");
            Console.WriteLine("Enter number of sides: ");
            idicesize = Console.ReadLine();

            //////////////
            // Validation
            //////////////

            // a. did the user enter a number?
            if (!int.TryParse(idicesize, out dicesize)) // FIGURE OUT HOW THIS SHIT WORKS TOO
            {
                Console.WriteLine("Die size is invalid and will be set to 6.");
                dicesize = 6;
            }

            else
            {
                // b. is integer between 6 an 20?
                if (dicesize < 6 || dicesize > 20)
                {
                    Console.WriteLine("Die size is invalid and will be set to 6.");
                    dicesize = 6;
                }

                else
                {
                    Console.WriteLine("Die size will be set to {0}", dicesize);
                }
            }
            player1dice.SetSides(dicesize); // FIGURE OUT HOW THIS WORKS TOO, COMPARE TO CONSOLE.WRITELINE
            player2dice.SetSides(dicesize);
        } // closes SetDiceSides method