Ejemplo n.º 1
0
        public int Run(Inventory inventory)
        {
            total        = 0;
            houseScore   = randomizeCards.Next(15, 22);
            userCards[0] = DealCards();
            userCards[1] = DealCards();
            do
            {
                Console.WriteLine("Welcome to 21! To win you must beat the house." +
                                  "\nThe objective is to get as close as possible, or up to, 21 " +
                                  "\npoints. Hit to be dealt more cards or stay to play your hand" +
                                  "\nagainst the house. Note, if you go over 21 you automatically lose!" +
                                  "\nYou have 3 tries to beat the house!");
                Console.WriteLine("\n\n\nPress any key to continue.");
                Console.ReadLine();
                Console.Clear();
                Console.WriteLine("Your cards are " + userCards[0] + " and " + userCards[1] + ". " +
                                  "\nYour total is " + total + ".\nHit or stay?");
                hitOrStay = Console.ReadLine().ToLower();
                while (hitOrStay == "inventory")
                {
                    Console.Clear();
                    IItem itemChoice = inventory.InventoryMenu();
                    if (itemChoice == null)
                    {
                        Console.WriteLine("Your cards are " + userCards[0] + " and " + userCards[1] + ". " +
                                          "\nYour total is " + total + ".\nHit or stay?");
                        hitOrStay = Console.ReadLine().ToLower();
                        break;
                    }
                    if (itemChoice.Type == "Weapon")
                    {
                        if (itemChoice.Name.Contains("Epic"))
                        {
                            hasWon      = true;
                            playerScore = 500;
                            Console.WriteLine("You brandish your weapon, allowing you to slay the monster and advance.");
                            Console.ReadLine();
                            Console.Clear();
                        }
                        else
                        {
                            rematchCount--;
                            Console.WriteLine($"You brandish your weapon, giving you an extra attempt to beat the house. You have {maxTries - rematchCount} tries remaining.");
                            Console.ReadLine();
                            Console.Clear();
                        }
                        inventory.RemoveItem(itemChoice);
                        Console.WriteLine($"{itemChoice.Name} has been removed from your inventory.");
                        Console.ReadLine();
                        Console.Clear();
                    }
                    else
                    {
                        Console.WriteLine("You cannot use that here");
                        Console.ReadLine();
                        Console.Clear();
                    }
                    Console.WriteLine("Your cards are " + userCards[0] + " and " + userCards[1] + ". " +
                                      "\nYour total is " + total + ".\nHit or stay?");
                    hitOrStay = Console.ReadLine().ToLower();
                }
            } while (!hitOrStay.Equals("hit") && !hitOrStay.Equals("stay"));
            HitOrStay();

            if (hasWon)
            {
                if (total == 21)
                {
                    playerScore = 500;
                }
                else if (rematchCount == 1)
                {
                    playerScore = 500;
                }
                else if (rematchCount == 2)
                {
                    playerScore = 350;
                }
                else if (rematchCount == 3)
                {
                    playerScore = 250;
                }
                Console.WriteLine("\n\n" +
                                  "Congratulations! You have beaten the house!");
                Console.WriteLine("Your score was: " + playerScore);
                Console.ReadLine();
                return(playerScore);
            }
            else
            {
                return(25);
            }
        }