Exemplo n.º 1
0
        void InitConsumables()
        {
            TrepiConsumable HealthPot = new TrepiConsumable("Health Potion", 15);

            HealthPot.AddDiscoveredFlairText("A strange vial holding bright red liquid rolls out from under a bush...\nWhat do you want to do?");
            HealthPot.AddDiscoveredFlairText("Something glints in the leaves at the corner of your eyes. Upon investigation it is a small round bottle holding a bright red liquid");
            HealthPot.AddConsumedFlairText("You feel a strange tingle as the liquid enters your body, soothing your aches and pains");
            HealthPot.AddConsumedFlairText("As you drink the liquid, it feels as though life is entering your body, empowering you and revitalising your wounds");
            HealthPot.AddDeclinedFlairText("The crimson liquid makes you feel somewhat unsettled. You don't feel good about consuming the strange bubbling liquid");
            HealthPot.AddDeclinedFlairText("Science was never your strong suit, neither was your curiosity. Better to let sleeping cats lie");
            Consumables.Add(HealthPot);
        }
Exemplo n.º 2
0
        public void RunEncounter()
        {
            // Choose a random entity from the list of spawnable entities for the Encounter
            int currentEntityIdx = GetRandomIndex(Spawnables.Count);

            Console.WriteLine("currentEntityIdx: " + currentEntityIdx + " PreviousEntity: " + PreviousEntityIdx);
            TrepiSpawnable entity = Spawnables[currentEntityIdx];

            // If the previous entity index is not invalid (If there is a previously generated entity)
            if (PreviousEntityIdx != -1)
            {
                Console.WriteLine("Checking for the same generated entity...");
                int newIdx = -1;

                // While the previous entity is the same as the currently selected entity index...
                while (PreviousEntityIdx == currentEntityIdx)
                {
                    // Choose a new index from the list
                    newIdx = GetRandomIndex(Spawnables.Count);
                    Console.WriteLine("newIdx: " + newIdx);
                    // Select the entity at the index
                    entity = Spawnables[newIdx];

                    // Set the previous entity index to the new selected index
                    Console.WriteLine("Setting PreviousEntity to newIdx: " + newIdx);
                    PreviousEntityIdx = newIdx;
                }

                // Update the currently selected index to the new duplicate free index that was generated
                currentEntityIdx = (newIdx != -1) ? newIdx : currentEntityIdx;
            }

            // Check for the entity type and set appropriate options and results
            if (entity is TrepiEnemy)
            {
                TrepiEnemy enemy = (TrepiEnemy)entity;
                TypeOfEncounter = TrepiEncounterType.Enemy;

                Console.WriteLine("A " + entity.Name + " charges at you from the shadows, smashing branches out of its path!");

                Console.WriteLine();
                Console.WriteLine(Player.Name + ": " + Player.Health);
                Console.WriteLine();

                SetOptions("Fight", "Flee");
                SetResults(
                    // Fight
                    () => { Console.WriteLine("You raise your fist in anger and declare war!"); },
                    // Flee
                    () => { Console.WriteLine("You run away, crying like a baby..."); });

                int resultIndex = GetAndDisplayOptionsChoice();
                Results[resultIndex]();
                Console.WriteLine();
                if (resultIndex == 0)
                {
                    // If we choose to fight
                    SetOptions("Attack", "Block", "Flee");

                    SetResults(
                        // Attack
                        () =>
                    {
                        List <string> hitResults = new List <string>();
                        hitResults.Add("You swing a fist at the " + entity.Name + " and hit them square in the face!");
                        hitResults.Add("Poking a finger in their general direction, the " + entity.Name + " impales themself on your finger!");
                        hitResults.Add("Didn't anyone tell you pointing was rude? " + entity.Name + " just stabbed themself with your finger!");

                        List <string> missResults = new List <string>();
                        missResults.Add("You fix " + entity.Name + " with a deathly stare... Too bad you're crosseyed...");
                        missResults.Add("You trip over a leaf trying to throw a punch... Nice work =)");

                        if (Player.MakeAttack() && !enemy.BlockAttack())
                        {
                            Console.WriteLine(hitResults[GetRandomIndex(hitResults.Count)]);
                            Console.WriteLine();
                            enemy.TakeDamage(Player.AtkDamage);
                        }
                        else
                        {
                            Console.WriteLine(missResults[GetRandomIndex(missResults.Count)]);
                            Console.WriteLine();
                        }
                    },
                        // Block
                        () =>
                    {
                        Player.isBlocking = true;
                        Player.RechargeStamina();     // TODO: Add this function to let the player recharge stamina
                        // Since the stamina wouldn't regenerate if the BlockAttack returns false in the if conditions

                        Console.WriteLine("You brace yourself for an attack!");
                        Console.WriteLine();
                    },
                        // Flee
                        () =>
                    {
                        Console.WriteLine("You run away, crying like a baby...");
                        HasEnded = true;
                        StartNewEncounter(currentEntityIdx);
                    }

                        );

                    while (!HasEnded)
                    {
                        if (Player.Health > 0)
                        {
                            if (enemy.Health > 0)
                            {
                                Console.Clear();
                                TrepiGame.WriteTitle("BATTLE");

                                Console.WriteLine(Player.Name + " VS " + entity.Name);
                                TrepiGame.WriteSeparator();

                                Console.WriteLine();
                                Console.WriteLine(Player.Name + ":");
                                Player.DisplayCombatStats();
                                TrepiGame.WriteSeparator();

                                int combatChoice = GetAndDisplayOptionsChoice();
                                Results[combatChoice]();

                                TrepiGame.WaitToContinue();

                                if (enemy.MakeAttack())
                                {
                                    List <string> hitResults = new List <string>();
                                    hitResults.Add("The " + entity.Name + " swings a fist at you and hits you square in the face!");
                                    hitResults.Add("The " + entity.Name + " pokes a finger in your general direction, and you impale yourself on their finger!");
                                    hitResults.Add("Didn't anyone tell the " + entity.Name + " pointing was rude? You just stabbed yourself with their finger!");

                                    if (Player.isBlocking)
                                    {
                                        if (Player.BlockAttack())
                                        {
                                            // If the monsters attack is blocked by the player
                                            Console.WriteLine("You successfully block the attack, taking no damage");
                                            Console.WriteLine();
                                        }
                                        else
                                        {
                                            // If the monster hits the player while they are blocking
                                            Console.WriteLine("You try to block the attack, but alas!");
                                            Console.WriteLine(hitResults[GetRandomIndex(hitResults.Count)]);
                                            Console.WriteLine();
                                            Player.TakeDamage(enemy.AtkDamage);
                                        }
                                        Player.isBlocking = false;
                                    }
                                    else
                                    {
                                        // if the monster hits the player
                                        Console.WriteLine(hitResults[GetRandomIndex(hitResults.Count)]);
                                        Console.WriteLine();
                                        Player.TakeDamage(enemy.AtkDamage);
                                    }
                                }
                                else
                                {
                                    // If the monster misses the player
                                    List <string> missResults = new List <string>();
                                    missResults.Add("The " + entity.Name + " fixes you with a deathly stare... Too bad they're crosseyed...");
                                    missResults.Add("The " + entity.Name + " trips over a leaf trying to throw a punch... Nice work =)");

                                    Console.WriteLine(missResults[GetRandomIndex(missResults.Count)]);
                                    Console.WriteLine();
                                }

                                TrepiGame.WaitToContinue();
                            }
                            else
                            {
                                // If the player kills the monster
                                List <string> victories = new List <string>();
                                victories.Add("You have slain the " + entity.Name + "!");

                                Console.WriteLine(victories[GetRandomIndex(victories.Count)]);
                                StartNewEncounter(currentEntityIdx);
                            }
                        }
                        else
                        {
                            // If the player gets killed
                            Console.WriteLine();
                            Console.WriteLine(Player.Name + ": 0");
                            Console.WriteLine();

                            List <string> defeats = new List <string>();
                            defeats.Add("You have been killed by a " + entity.Name + ". I knew I should've chosen somebody else...");

                            Console.WriteLine(defeats[GetRandomIndex(defeats.Count)]);

                            TrepiGame.WaitToContinue();

                            HasEnded = true;
                            TrepiGame.EndGame();
                        }
                    }
                }
                else if (resultIndex == 1)
                {
                    // If we choose to flee
                    HasEnded = true;
                    StartNewEncounter(currentEntityIdx);
                }
            }

            if (entity is TrepiConsumable)
            {
                TrepiConsumable item = (TrepiConsumable)entity;
                TypeOfEncounter = TrepiEncounterType.Consumable;

                Console.WriteLine(item.GetRandomDiscoveredFlair());

                SetOptions("Consume", "Leave Alone");
                SetResults(
                    // Consume
                    () =>
                {
                    Console.WriteLine(item.GetRandomConsumedFlair());
                    if (item is ITrepiHealthItem)
                    {
                        Console.WriteLine("[You gain " + item.NutritionValue + "health]");
                        item.Heal(Player);
                    }

                    StartNewEncounter(currentEntityIdx);
                },
                    // Leave Alone
                    () =>
                {
                    Console.WriteLine(item.GetRandomDeclinedFlair());
                    StartNewEncounter(currentEntityIdx);
                }
                    );

                int resultIndex = GetAndDisplayOptionsChoice();
                Results[resultIndex]();
            }

            if (entity is TrepiLoreEntity)
            {
                ((TrepiLoreEntity)entity).ShowLore();
                TypeOfEncounter = TrepiEncounterType.Lore;
                StartNewEncounter(currentEntityIdx);
            }
        }