示例#1
0
        //user eats
        public static void Eat(Player_Stats player)
        {
            string foodInput = "";

            TextWriter.Write("Would you like to consume apple(A), bread(B), or cake(C)");
            foodInput = Console.ReadLine();
            if (foodInput == "a" || foodInput == "A")
            {
                if (player.RemoveItem("Apple"))
                {
                    player.hunger += 5;
                }
            }
            else if (foodInput == "b" || foodInput == "B")
            {
                if (player.RemoveItem("Bread"))
                {
                    player.hunger += 20;
                }
            }
            else if (foodInput == "c" || foodInput == "C")
            {
                if (player.RemoveItem("Cake"))
                {
                    player.hunger += 50;
                }
            }
        }
示例#2
0
        //Gets enemy attack damage and announces attack
        private int AnnounceEnemyAttack(Player_Stats ps, Random random, ref int enemyhealth)
        {
            int enemyDamage = 0;
            int enemyAttack = Convert.ToInt32(random.Next(attackProbabilities.Sum() + abilityProbabilities.Sum()));
            int attIndex    = GetIndexFromProbability(enemyAttack);

            if (attIndex != -1)
            {
                if (attIndex >= attackProbabilities.Length)
                {
                    attIndex -= attackProbabilities.Length;
                    UseAbility(abilityNames[attIndex], abilityModifiers[attIndex], ps, ref enemyhealth, ref rewardGold);
                }
                else
                {
                    enemyDamage = Convert.ToInt32(attackBaseDamages[attIndex] + (random.Next(7) - 3));

                    if (enemyDamage < 0)
                    {
                        enemyDamage = 0;
                    }

                    TextWriter.Write($"%5{enemyName}%0 %4{attackNames[attIndex]}%0 for %5{enemyDamage - ps.defense}%0 point{(enemyDamage > 1 ? "s" : "")} of damage!");
                }
            }

            return(enemyDamage);
        }
示例#3
0
 //gets player stats
 public static void CheckInventory(Player_Stats player)
 {
     for (int x = 0; x < player.inv.Count; x++)
     {
         TextWriter.Write(player.inv[x].name);
     }
 }
示例#4
0
        public void UseAbility(string abilityName, string abilityModifier, Player_Stats ps, ref int health, ref int gold)
        {
            string mod  = abilityModifier.Substring(0, 1);
            int    amnt = Convert.ToInt32(abilityModifier.Substring(1));

            switch (mod)
            {
            case "h":
                health += amnt;
                TextWriter.Write($"%5{enemyName}%0 %4{abilityName}%0 and recovers {amnt} health. %4{enemyName}%0's health is now %3{health}%0!");
                break;

            case "g":
                gold += amnt;
                TextWriter.Write($"%5{enemyName}%0 %4{abilityName}%0 and {(amnt < 0 ? "gives you" : "takes")} {amnt} gold! %4{enemyName}%0 you now have %5{ps.Money} gold%0.");
                break;

            case "s":
                TextWriter.Write($"%5{enemyName}%0 %4{abilityName}%0 and swaps your health with theirs! %5{enemyName}%0 now has %3{ps.Health}%0 health and you now have %3{enemyHealth}%0 health.");
                int healthswap = ps.Health;
                ps.Health   = enemyHealth;
                enemyHealth = healthswap;
                break;
            }
        }
示例#5
0
        public static void DoRandomRoll(Player_Stats player)
        {
            Random random = new Random();

            if (random.Next(4) == 0)
            {
                TextWriter.Write("%4You found a hidden chest in this room! Inside you find...%0");

                int goldamnt         = random.Next(20);
                int healthpotionamnt = random.Next(player.strength / 3);

                if (goldamnt > 0)
                {
                    TextWriter.Write($"%5{goldamnt} gold!%0");
                }

                if (healthpotionamnt > 0)
                {
                    TextWriter.Write($"%3{healthpotionamnt} health potion{(healthpotionamnt > 1 || healthpotionamnt == 0 ? "s" : "")}!%0");
                }
            }
            else
            {
                TextWriter.Write("%4You look around, but don't find anything particularly interesting.%0");
            }
        }
示例#6
0
 private static void PurchaseItem(Player_Stats ps, Item item, int cost)
 {
     if (ps.money >= cost)
     {
         ps.money -= cost;
         ps.inv.Add(item);
         TextWriter.Write($"%5{cost}%0 gold removed.");
         TextWriter.Write($"You got the %4{item.name}%0!`");
     }
 }
示例#7
0
 //gets player stats
 public static void DisplayMap(Player_Stats player)
 {
     if (player.GetItemCount("Map") != 0)
     {
         //TODO: map code
     }
     else
     {
         TextWriter.Write("You do not have a map. To get one buy one from the shop");
     }
 }
示例#8
0
        public bool GetCanProgress(Player_Stats ps, Directions direction)
        {
            foreach (Item i in ps.inv)
            {
                if (i.type == ItemTypes.KEY && i.metadata == keyTable[(int)direction])
                {
                    return(true);
                }
            }

            return(true);
        }
示例#9
0
        //opens the user shop
        public static void Buy(Player_Stats ps, Game game)
        {
            TextWriter.Write(
                "What would you like to buy?\n\n" +
                "%1Item Name\tCost\tEffects%0\n" +
                "1\\.Wood Sword\t %5$15%0\t%2+5atk%0\n" +
                "2\\.Iron Sword\t %5$30%0\t%2+10atk%0\n" +
                "3\\.Master Sword\t %5$60%0\t%2+15atk%0\n" +
                "4\\.Necreant Blade %5$100%0\t%2+25atk%0\n" +
                "5\\.Health Potion\t %5$15%0\t%4+20 Health on Use%0\n" +
                "6\\.Magic Armor\t %5$100%0\t%4+5 Defense%0\n" +
                "7\\.Area Map\t %5$100%0\t%4View the area map with 'M'%0\n" +
                "Type '%5exit%0' to exit the shop.\n", 10);

            int input = Convert.ToInt32(char.GetNumericValue(Console.ReadKey().KeyChar));

            Console.CursorLeft--;
            Console.Write(" ");
            Console.CursorLeft--;

            switch (input)
            {
            case 1:
                PurchaseItem(ps, game.GetItemFromName("wooden sword"), 15);
                break;

            case 2:
                PurchaseItem(ps, game.GetItemFromName("iron sword"), 30);
                break;

            case 3:
                PurchaseItem(ps, game.GetItemFromName("master sword"), 60);
                break;

            case 4:
                PurchaseItem(ps, game.GetItemFromName("necreant blade"), 100);
                break;

            case 5:
                PurchaseItem(ps, game.GetItemFromName("health potion"), 15);
                break;

            case 6:
                //TODO: just increase player defense
                break;

            case 7:
                //TODO: enable player map
                break;
            }
        }
示例#10
0
 private void WritePlayerOptions(Player_Stats ps, bool canDrinkPotion = true, bool canRun = true)
 {
     TextWriter.Write(
         $"\n%1------------------%0\n\n" +
         $"Player Health: %3{ps.health}%0\n" +
         $"Player Strength: %3{ps.strength}%0\n" +
         $"Player Weapon Attack: %4{ps.EquippedWeapon.metadata}%0\n" +
         $"Total Attack Power: %4{GetDamage(ps)}%0\n" +
         $"\nWhat will you do\\?\n" +
         $"'%3A%0' - Attack\\! ({ps.EquippedWeapon.name})\n" +
         $"{(canDrinkPotion ? $"'%3H%0' - Drink Health Potion (You have {ps.GetItemCount("health potion")}" : "")})" +
         $"{(canRun ? "\n'%3R%0' - Run Away (Lose a random amount of gold\\!)" : "")}" +
         "\n%1>>>%0 ", 10);
 }
示例#11
0
        //user eats
        public static void Heal(Player_Stats player)
        {
            string Healinput = "";

            TextWriter.Write("Would you like to use a health potion? y for yes");
            Healinput = Console.ReadLine();
            if (Healinput.ToLower() == "y" || Healinput.ToLower() == "yes")
            {
                if (player.RemoveItem("HealthPotion"))
                {
                    player.health += 20;
                }
            }
        }
示例#12
0
        //gets player stats
        public static void Stats(Player_Stats player)
        {
            int strength = player.strength;
            int money    = player.money;
            int hunger   = player.hunger;
            int health   = player.health;
            int defense  = player.defense;

            TextWriter.Write("Health:%3\t" + health + "%0\n" +
                             "Strength:%3\t" + strength + "%0\n" +
                             "Hunger:%3\t" + hunger + "%0\n" +
                             "Money:%3\t" + money + "%0\n" +
                             "Defense:%3\t" + defense + "%0\n");
        }
示例#13
0
        //Calculates player attack damage and announces attack
        private int AnnouncePlayerAttack(Player_Stats ps, Random random, int enemyhealth)
        {
            int playerDamage = Convert.ToInt32(GetDamage(ps) + (random.Next(7) - 3));

            if (playerDamage <= 0)
            {
                playerDamage = random.Next(3);
            }

            if (playerDamage < 0)
            {
                playerDamage = 0;
            }

            TextWriter.Write($"You attack %5{enemyName}%0 for %3{playerDamage}%0 point{(playerDamage > 1 ? "s" : "")} of damage!");

            return(playerDamage);
        }
示例#14
0
        private void PerformEnemyAttack(Player_Stats ps, Random random, ref int enemyhealth)
        {
            Console.WriteLine();
            int enemydamage = AnnounceEnemyAttack(ps, random, ref enemyhealth);

            ps.Health -= enemydamage;

            if (ps.Health <= 0)
            {
                ps.Health = 0;
                TextWriter.Write($"You have no health left!", 25);
                return;
            }

            if (enemydamage > 0)
            {
                TextWriter.Write($"Your health is now %3{ps.Health}%0.");
            }
        }
示例#15
0
        private void PerformPlayerAttack(Player_Stats ps, Random random, ref int enemyhealth)
        {
            Console.WriteLine();
            int damage = AnnouncePlayerAttack(ps, random, enemyhealth);

            enemyhealth -= damage;

            if (enemyhealth <= 0)
            {
                enemyhealth = 0;
                TextWriter.Write($"%5{enemyName}%0 has %30%0 health!", 25);
                return;
            }

            if (damage > 0)
            {
                TextWriter.Write($"%5{enemyName}%0's health is now %3{enemyhealth}%0!");
            }
        }
示例#16
0
        //Does the encounter
        public void PerformEncounter(Player_Stats ps, Game game)
        {
            if (!completed)
            {
                Random random          = new Random();
                int    currEnemyHealth = enemyHealth;
                TextWriter.Write(announcement);
                bool playerRan = false;

                //While nobody is dead
                while (currEnemyHealth > 0 && ps.Health > 0 && !playerRan)
                {
                    bool doneWithInput = false;
                    char input         = ' ';

                    WritePlayerOptions(ps, true, enemyName.ToLower() != "trap");

                    while (!doneWithInput)
                    {
                        doneWithInput = true;
                        input         = Console.ReadKey().KeyChar;

                        switch (input)
                        {
                        case 'a':
                            Console.Clear();
                            TextWriter.Write("En garde!");
                            break;

                        case 'h':
                            if (ps.RemoveItem("health potion"))
                            {
                                int potionHealth = game.GetItemFromName("health potion").metadata;
                                ps.health += potionHealth;
                                Console.Clear();
                                TextWriter.Write($"You chug a health potion. %3+{potionHealth} health%0!`\nYour health is now %3{ps.health}%0!");
                            }
                            else
                            {
                                Console.Clear();
                                TextWriter.Write($"%2You have no health potions!%0");
                            }
                            break;

                        case 'r':
                            if (ps.money <= 0)
                            {
                                TextWriter.Write($"\nYou have no gold! %4{enemyName}%0 attacks you for %5{random.Next(10)}%0 damage as you run!````");
                                Console.Clear();
                            }
                            else
                            {
                                int moneyloss = random.Next(15);
                                if (ps.money < moneyloss)
                                {
                                    moneyloss = ps.money;
                                    ps.money  = 0;
                                }
                                else
                                {
                                    ps.money -= moneyloss;
                                }

                                TextWriter.Write($"\nYou lost %5{moneyloss} gold%0 as you run away...` You now have %5{ps.money} gold%0.````");
                                playerRan = true;
                                Console.Clear();
                            }
                            break;

                        default:
                            Console.CursorLeft--;
                            Console.Write(" ");
                            Console.CursorLeft--;
                            doneWithInput = false;
                            break;
                        }
                    }

                    if (playerRan)
                    {
                        break;
                    }

                    //Randomly make the player or enemy attack first
                    if (random.Next(2) == 0)
                    {
                        PerformPlayerAttack(ps, random, ref currEnemyHealth);
                        if (currEnemyHealth > 0)
                        {
                            PerformEnemyAttack(ps, random, ref currEnemyHealth);
                        }
                    }
                    else
                    {
                        PerformEnemyAttack(ps, random, ref currEnemyHealth);
                        if (ps.health > 0)
                        {
                            PerformPlayerAttack(ps, random, ref currEnemyHealth);
                        }
                    }

                    if (currEnemyHealth <= 0)
                    {
                        TextWriter.Write($"\n%5YOU WIN!%0\n%4{win}%0\n");

                        ps.strength += 1;
                        ps.money    += rewardGold;

                        TextWriter.Write($"Your strength increases to %3{ps.strength}%0!");
                        TextWriter.Write($"You gain %5{rewardGold} gold%0!");
                        foreach (int i in itemrewards)
                        {
                            string itemname = game.items[i].name.ToLower();
                            bool   useAn    = itemname[0] == 'a' || itemname[0] == 'e' || itemname[0] == 'i' || itemname[0] == 'o' || itemname[0] == 'u';
                            TextWriter.Write($"You got a{(useAn ? "n" : "")} %2{game.items[i].name}%0!");
                            ps.inv.Add(game.items[i]);
                        }
                        completed = true;
                    }
                    else if (ps.Health <= 0)
                    {
                        TextWriter.Write($"\n%2{lose}%0\n");
                    }
                }
            }
            else //if previously completed
            {
                TextWriter.Write($"You've already defeated %5{enemyName}%0.");
            }
        }
示例#17
0
        //gets the user
        public static void Input(Player_Stats player)
        {
            int x = 0;

            while (x == 0)
            {
                TextWriter.Write("");
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    TextWriter.Write("Error, What you entered is not acceptable. You haven't entered anything. Try again.\n");
                }
                else
                {
                    input = input.ToUpper();
                    switch (input)
                    {
                    case "?":
                    case "HELP":
                        Help();
                        break;

                    case "SOUTH":
                    case "S":
                        move = "south";
                        break;

                    case "E":
                    case "EAST":
                        move = "east";
                        break;

                    case "WEST":
                    case "W":
                        move = "west";
                        break;

                    case "N":
                    case "NORTH":
                        move = "north";
                        break;

                    case "BUY":
                    case "B":
                        Buy(player, Program.game);
                        break;

                    case "CONSUME":
                    case "C":
                        Eat(player);
                        break;

                    case "R":
                    case "RUN":
                        move = "back";
                        break;

                    case "Exit":
                    case "Stop":
                        TextWriter.Write("Are you sure you wish to quit? y for yes or any key for no");
                        string quit = Console.ReadLine();
                        if ((quit.ToLower() == "yes") || (quit.ToLower() == "y"))
                        {
                            Environment.Exit(0);
                        }
                        break;

                    case "PS":
                    case "STATS":
                    case "PLAYERSTATS":
                        Stats(player);
                        break;

                    case "INVENTORY":
                    case "I":
                        CheckInventory(player);
                        break;

                    case "LOCATION":
                    case "L":
                        GetLocation();
                        break;

                    case "HEAL":
                    case "H":
                        Heal(player);
                        break;

                    case "M":
                    case "Map":
                        DisplayMap(player);
                        break;

                    default:
                        TextWriter.Write("Your code is broken");
                        break;
                    }
                }
            }
        }
示例#18
0
 //Gets the player's damage value
 //
 //  weapondmg^2 + strength
 //  ---------------------- = damage
 //          strength
 //
 //
 public int GetDamage(Player_Stats ps)
 {
     return(Convert.ToInt32(ps.EquippedWeapon.metadata + ps.strength));
 }