コード例 #1
0
ファイル: TrepiPlayer.cs プロジェクト: intrepid249/JamToast
        public void LevelUp(int pointsAvailable)
        {
            Level++;

            Console.WriteLine();
            TrepiGame.WriteTitle("LEVEL UP");
            Console.WriteLine();

            Console.WriteLine("Level: " + (Level - 1) + " -> " + Level);
            TrepiGame.WaitToContinue();
            Console.Clear();

            int[] stats = QueryStatAllocation(pointsAvailable);
            ApplyStatChanges(stats[0], stats[1], stats[2]);
            CalculateStats();

            Console.Clear();
            Console.WriteLine("Your stats are now:");
            PreviewStatChanges(0, 0, 0);
            Console.WriteLine();
            DisplayCombatStats();

            Console.WriteLine();
            TrepiGame.WaitToContinue();
            Console.Clear();
        }
コード例 #2
0
        public int GetAndDisplayOptionsChoice()
        {
            // Make sure the choices are on a new line
            Console.WriteLine();

            // Display the choices to the console
            for (int i = 0; i < Options.Count; i++)
            {
                Console.WriteLine((i + 1) + ". " + Options[i]);
            }

            bool validResult = false;
            int  choiceIndex = -1;

            // Hang the input in a while loop to check for valid input
            while (!validResult)
            {
                Console.WriteLine("Type the number corresponding to the choice:");

                // Check to make sure the input in a number, and the number corresponds to an index of an option in the list
                if (int.TryParse(Console.ReadLine(), out choiceIndex) && choiceIndex > 0 && choiceIndex <= Options.Count)
                {
                    validResult = true;
                }
            }

            TrepiGame.WriteSeparator();
            // Return the index of the option chosen
            return(choiceIndex - 1);
        }
コード例 #3
0
        private void StartNewEncounter(int previousEntityIdx)
        {
            Console.WriteLine("Setting PreviousEntity to currentEntityIdx: " + previousEntityIdx);
            PreviousEntityIdx = previousEntityIdx;

            TrepiGame.WaitToContinue();

            RunEncounter();
        }
コード例 #4
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);
            }
        }