Ejemplo n.º 1
0
        static void GetPlayerMovement(Player myPlayer, Mob currentMob, Potion currentPotion)
        {
            currentMob    = Combat.GetCurrentMob(currentMob, Combat.CurrentMobs);
            currentPotion = Combat.GetPotion(currentPotion, GameAttributes.potions);
            bool exit  = false;
            bool fight = false;

            do
            {
                // Display the player's current location
                Console.WriteLine($"Current Location: {Player.CurrentRoom.Name}");

                // Consume the next line for appearance
                Console.WriteLine("");

                // Prompt the player's movement
                Console.Write("Which direction do you want to move? ");
                string userInput = Console.ReadLine();
                PlayerMovement.GetMovement(userInput);
                //Console.ReadLine();

                int mobCoinToss    = RandomNumber.NumberBetween(1, 2);
                int potionCoinToss = RandomNumber.NumberBetween(1, 2);
                switch (mobCoinToss)
                {
                case 1:
                    fight = true;
                    // Prevent dead Mobs from being reused; remove when you find a better way
                    if (currentMob.HP <= 0)
                    {
                        currentMob = Combat.GetCurrentMob(currentMob, Combat.CurrentMobs);
                        fight      = false;
                        Console.WriteLine("There are no enemies here.");
                        switch (potionCoinToss)
                        {
                        case 1:
                            myPlayer      = GetPlayerPotion(myPlayer, currentPotion);
                            currentPotion = Combat.GetPotion(currentPotion, GameAttributes.potions);
                            break;

                        case 2:
                            Console.WriteLine("There are no potions here.");
                            break;
                        }

                        // Toss the coin again to alternate chances of finding a potion
                        potionCoinToss = RandomNumber.NumberBetween(1, 2);
                    }
                    else
                    {
                        Console.WriteLine($"You must fight a {currentMob.Name}!");
                        Console.WriteLine($"{currentMob.Name}'s HP is {currentMob.HP}.");

                        do
                        {
                            int fightCoinToss = RandomNumber.NumberBetween(1, 2);
                            switch (fightCoinToss)
                            {
                            case 1:
                                Combat.PerformPlayerAttack(myPlayer, currentMob);
                                break;

                            case 2:
                                Combat.PerformMobAttack(myPlayer, currentMob);
                                break;
                            }

                            // Toss the coin again to alternate chances of attacking
                            fightCoinToss = RandomNumber.NumberBetween(1, 2);

                            if (myPlayer.HP <= 0)
                            {
                                if (myPlayer.HP < 0)
                                {
                                    myPlayer.HP = 0;
                                }

                                // Add color for dramatic effect
                                Console.ForegroundColor = ConsoleColor.Red;

                                Console.WriteLine("You are defeated. GAME OVER");
                                fight = false;
                                exit  = true;

                                // Return color to normal
                                Console.ForegroundColor = ConsoleColor.White;
                            }

                            if (currentMob.HP <= 0)
                            {
                                if (currentMob.HP < 0)
                                {
                                    currentMob.HP = 0;
                                }

                                // Add color for dramatic effect
                                Console.ForegroundColor = ConsoleColor.Green;

                                Console.WriteLine($"{currentMob.Name} is defeated. YOU WIN!");
                                myPlayer.XP += currentMob.XP;
                                Console.WriteLine($"{myPlayer.Name}'s XP: {myPlayer.XP}");
                                fight      = false;
                                currentMob = Combat.GetCurrentMob(currentMob, Combat.CurrentMobs);

                                // Return color to normal
                                Console.ForegroundColor = ConsoleColor.White;

                                switch (potionCoinToss)
                                {
                                case 1:
                                    myPlayer      = GetPlayerPotion(myPlayer, currentPotion);
                                    currentPotion = Combat.GetPotion(currentPotion, GameAttributes.potions);
                                    break;

                                case 2:
                                    Console.WriteLine("There are no potions here.");
                                    break;
                                }

                                // Toss the coin again to alternate chances of finding a potion
                                potionCoinToss = RandomNumber.NumberBetween(1, 2);
                            }
                        } while (fight == true);
                    }
                    break;

                case 2:
                    fight = false;
                    Console.WriteLine("There are no enemies here.");
                    switch (potionCoinToss)
                    {
                    case 1:
                        myPlayer      = GetPlayerPotion(myPlayer, currentPotion);
                        currentPotion = Combat.GetPotion(currentPotion, GameAttributes.potions);
                        break;

                    case 2:
                        Console.WriteLine("There are no potions here.");
                        break;
                    }

                    // Toss the coin again to alternate chances of finding a potion
                    potionCoinToss = RandomNumber.NumberBetween(1, 2);
                    break;
                }

                // Toss the coin again to alternate chances of a fight
                mobCoinToss = RandomNumber.NumberBetween(1, 2);
            } while (exit == false);

            //Console.ReadLine();
        }