コード例 #1
0
        /*
         * Welcome message
         * Directions
         * Choose a machine
         * Place a bet
         * Pull lever
         * Randomly rolls around and gives you
         * Machine tells you if you won or not
         */
        static void Main(string[] args)
        {
            SlotMachine myMachine = new SlotMachine(); // 3 slots, 5 icons per slot

            Console.WriteLine("Welcome to slots!");

            Console.WriteLine("Directions");

            while (true)
            {
                // place a bet
                Console.WriteLine("Type in how many pennies to bet");

                // You could get this using:
                // int userBet = Convert.ToInt32(Console.ReadLine());
                // myMachine.CurrentBet = userBet;
                myMachine.CurrentBet = Convert.ToInt32(Console.ReadLine());

                // pull the lever
                Console.WriteLine("Press enter to pull the lever");
                Console.ReadKey(); // TODO Later: make this actually look for ENTER
                myMachine.PullLever();

                // display the results
                int[] tempResults = myMachine.GetResults();
                for (int i = 0; i < tempResults.Length; i++)
                {
                    Console.Write(tempResults[i] + " ");
                }

                // payout
                Console.WriteLine("You won {0} pennies!", myMachine.GetPayout());
            }
        }
コード例 #2
0
        /*
         * Welcome message
         * Directions
         * Choose a machine
         * Place a bet
         * Pull lever
         * Randomly rolls around and gives you
         * Machine tells you if you won or not
         */
        static void Main(string[] args)
        {
            SlotMachine myMachine = new SlotMachine(); // 3 slots, 5 icons per slot

            Console.WriteLine("\n\nWelcome to ¢heapE slots!\n");

            Console.WriteLine("This is a simple penny slot machine. Place your wager and win BIG!!!\n\n");

            while (true)
            {
                // place a bet
                Console.WriteLine("Please enter your wager in pennies.");

                // You could get this using:
                // int userBet = Convert.ToInt32(Console.ReadLine());
                // myMachine.CurrentBet = userBet;
                myMachine.CurrentBet = Convert.ToInt32(Console.ReadLine());

                // pull the lever
                Console.WriteLine("Press enter to pull the lever");
                Console.ReadKey(); // TODO Later: make this actually look for ENTER
                myMachine.PullLever();

                // display the results
                int[] tempResults = myMachine.GetResults();
                for (int i = 0; i < tempResults.Length; i++)
                {
                    Console.Write(tempResults[i] + " ");
                }

                // payout
                Console.WriteLine("You won {0} pennies!", myMachine.GetPayout());
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: OlayG/slot-machine
        /*
         * Welcome message
         * Directions
         * Choose a machine
         * Place a bet
         * Pull lever
         * Randomly rolls around and gives you
         * Machine tells you if you won or not
         */
        static void Main(string[] args)
        {
            double      GameCounter = 0, WinCounter = 0;
            SlotMachine myMachine = new SlotMachine(); // 3 slots, 5 icons per slot

            Console.WriteLine("Welcome to slots!");

            Console.WriteLine("Directions");

            while (true)
            {
                GameCounter++;
                // place a bet
                Console.WriteLine("Type in how many pennies to bet");

                // You could get this using:
                // int userBet = Convert.ToInt32(Console.ReadLine());
                // myMachine.CurrentBet = userBet;
                myMachine.CurrentBet = Convert.ToInt32(Console.ReadLine());

                // pull the lever
                Console.WriteLine("Press enter to pull the lever");
                Console.ReadKey(); // TODO Later: make this actually look for ENTER
                myMachine.PullLever();

                // display the results
                int[] tempResults = myMachine.GetResults();
                for (int i = 0; i < tempResults.Length; i++)
                {
                    Console.Write(tempResults[i] + " ");
                }

                // payout
                if (myMachine.GetPayout() > 0)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("You won {0} pennies!", myMachine.GetPayout());
                    Console.ResetColor();
                    WinCounter++;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("You won {0} pennies!", myMachine.GetPayout());
                    Console.ResetColor();
                }

                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Your win percentage: {0}/{1} = {2:P2}", WinCounter, GameCounter, myMachine.GetWinPrecentage(WinCounter, GameCounter));
                Console.ResetColor();
            }
        }
コード例 #4
0
        /*
         * Welcome message
         * Directions
         * Choose a machine
         * Place a bet
         * Pull lever
         * Randomly rolls around and gives you
         * Machine tells you if you won or not
         */
        static void Main(string[] args)
        {
            SlotMachine myMachine = new SlotMachine(); // 3 slots, 5 icons per slot

            Console.WriteLine("Welcome to slots!");

            Console.WriteLine("Directions");

            while (true)
            {
                // place a bet
                Console.WriteLine("Type in how many pennies to bet or enter 0 to exit: ");

                // You could get this using:
                // int userBet = Convert.ToInt32(Console.ReadLine());
                // myMachine.CurrentBet = userBet;
                myMachine.CurrentBet = Convert.ToInt32(Console.ReadLine());

                // if zero pennies then leave the program
                if (myMachine.CurrentBet == 0)
                {
                    break;
                }

                // pull the lever
                Console.WriteLine("Press enter to pull the lever");
                Console.ReadKey(); // TODO Later: make this actually look for ENTER
                myMachine.PullLever();

                // display the results
                int[] tempResults = myMachine.GetResults();
                Console.ForegroundColor = ConsoleColor.Red;
                for (int i = 0; i < tempResults.Length; i++)
                {
                    Console.Write(tempResults[i] + " ");
                }
                Console.ForegroundColor = ConsoleColor.White;

                // payout
                Console.WriteLine();
                if (myMachine.GetPayout() == 0)
                {
                    Console.WriteLine("Sorry you did not win, try again!", myMachine.GetPayout());
                }
                else
                {
                    decimal penniesInDollars = myMachine.GetPayout() / 100;
                    Console.WriteLine("You won $ {0} ", penniesInDollars);
                }
            }
        }