コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter number N to roll a N-sided dice.");
            int sides = String2Int.String2Int.Transform(Console.ReadLine());

            switch (sides)
            {
            case (25):
                D25.D25 d25 = new D25.D25();
                Console.WriteLine($"Rolling a d{sides}: {d25.Roll()}");
                break;

            case (6):
                D6.D6 d6 = new D6.D6();
                Console.WriteLine($"Rolling a d{sides}: {d6.Roll()}");
                break;

            case (5):
                D5.D5 d5 = new D5.D5();
                Console.WriteLine($"Rolling a d{sides}: {d5.Roll()}");
                break;

            default:
                UniversalDice universalDice = new UniversalDice();
                Console.WriteLine($"Sorry, d{sides} dice not implemented (yet?).");
                break;
            }
        }
コード例 #2
0
        public void Test(int numberOfTests)
        {
            D6 dice = new D6();

            int[] results = new int[6];
            for (int rollNumber = 1; rollNumber <= numberOfTests; ++rollNumber)
            {
                ++(results[dice.Roll() - 1]);
            }
            string[] numberNames = { "ones", "twos", "threes", "fours", "fives", "sixes" };
            Console.WriteLine($"Rolled {numberOfTests} times. Results:");
            int numberOfFaces = 6;

            for (int face = 1; face <= numberOfFaces; ++face)
            {
                Console.WriteLine($"{results[face - 1]} {numberNames[face - 1]}");
            }
        }