示例#1
0
 // This will allow you to eat if you have food.
 public static void Eat(ref Player player)
 {
     for (int i = 0; i < player.storage.Length; i++)
     {
         if (player.storage[i] != null)
         {
             if (player.storage[i].itemType == ItemType.FOOD)
             {
                 if (player.hunger < 100)
                 {
                     if (player.storage[i].itemStack > 1)
                     {
                         Food tempFood = (Food)player.storage[i];
                         player.Eat(ref tempFood);
                         player.storage[i].itemStack--;
                         Console.WriteLine($"You are eating. You now have {player.hunger} hunger left.");
                         FileSetup.PlayerFileWrite(ref player, Game.playerFile);
                     }
                     else
                     {
                         Food tempFood = (Food)player.storage[i];
                         player.Eat(ref tempFood);
                         player.storage[i] = null;
                         Console.WriteLine($"You are eating. You now have {player.hunger} hunger left.");
                         FileSetup.PlayerFileWrite(ref player, Game.playerFile);
                     }
                 }
             }
         }
     }
 }
 // Sells the item to the npc
 public static void Sell(ref Player player, ref NPC npc)
 {
     while (true)
     {
         Console.Clear();
         bool exitLoop = false;
         Console.Clear();
         Tools.Shuffle(ref player.storage);
         Tools.ShuffleDamage(ref player);
         Console.Write("Please type the item you wish to sell. ");
         string message = Console.ReadLine().ToLower();
         // This is a forloop that checks if the item name you put is valid and if it is valid it will add your coins to the worth of that item.
         for (int i = 0; i < npc.storage.Length; i++)
         {
             if (npc.storage[i] != null)
             {
                 for (int x = 0; x < player.storage.Length; x++)
                 {
                     if (!exitLoop)
                     {
                         if (player.storage[x] != null)
                         {
                             try
                             {
                                 if (player.storage[x].name.ToLower() == message)
                                 {
                                     if (player.storage[x].itemStack > 1)
                                     {
                                         player.storage[x].itemStack--;
                                         exitLoop = true;
                                         Console.WriteLine($"You have sold {player.storage[x].name} for ${player.storage[x].cost}.");
                                         FileSetup.PlayerFileWrite(ref player, Game.playerFile);
                                         Thread.Sleep(2500);
                                     }
                                     else
                                     {
                                         Console.WriteLine($"You have sold {player.storage[x].name} for ${player.storage[x].cost}.");
                                         player.storage[x] = null;
                                         exitLoop          = true;
                                         FileSetup.PlayerFileWrite(ref player, Game.playerFile);
                                         Thread.Sleep(2500);
                                     }
                                 }
                             }
                             catch (NullReferenceException e) { }
                         }
                     }
                 }
             }
         }
         if (message == "exit")
         {
             break;
         }
     }
 }
示例#3
0
        // This will be the scene that will happen for a fight
        public static string FightScene(ref Monster monster, ref Player player)
        {
            Console.Clear();
            while (monster.health > 0)
            {
                Console.WriteLine($"Hello, {player.name} you have been caught by {monster.name} now you must fight to make it out alive.\n\n");
                Console.Write($"Actions:\nStrike - you will strike your weapon at {monster.name}.\nStatus - shows yours and {monster.name} stats.\nHeal - this will be used to heal yourself.\n" +
                              $"Eat - this will allow you to eat.\n\n\nWhat action you like to take? ");
                string message = Console.ReadLine().ToLower();
                Console.WriteLine();
                switch (message)
                {
                case "strike":
                    Strike(ref player, ref monster);
                    break;

                case "status":
                    Status(ref player, ref monster);
                    break;

                case "heal":
                    Heal(ref player);
                    break;

                case "eat":
                    Eat(ref player);
                    break;

                default:
                    Console.WriteLine("You typed an invalid action try again.");
                    break;
                }
                if (player.health <= 0)
                {
                    return("failed");
                }
                Thread.Sleep(1500);
                Console.Clear();
            }
            monster = null;
            player.level++;
            player.coins++;
            FileSetup.CoinWrite(Game.coinFile, ref player);
            FileSetup.LevelWrite(Game.levelFile, ref player);
            FileSetup.PlayerFileWrite(ref player, Game.playerFile);
            return("success");
        }
示例#4
0
 // This will heal the player if you have potions
 public static void Heal(ref Player player)
 {
     for (int i = 0; i < player.storage.Length; i++)
     {
         if (player.storage[i] != null)
         {
             if (player.storage[i].itemType == ItemType.POTION)
             {
                 if (player.health < 100)
                 {
                     Console.Write($"\nWhat potion would you like to use? ");
                     string message = Console.ReadLine();
                     if (player.storage[i].name == message)
                     {
                         if (player.storage[i].itemStack > 1)
                         {
                             Potion tempPotion = (Potion)player.storage[i];
                             player.Heal(ref tempPotion);
                             player.storage[i].itemStack--;
                             Console.WriteLine($"You have healed. You now have {player.health} health left.");
                             FileSetup.PlayerFileWrite(ref player, Game.playerFile);
                         }
                         else
                         {
                             Potion tempPotion = (Potion)player.storage[i];
                             player.Heal(ref tempPotion);
                             player.storage[i] = null;
                             Console.WriteLine($"You have healed. You now have {player.health} health left.");
                             FileSetup.PlayerFileWrite(ref player, Game.playerFile);
                         }
                     }
                 }
             }
         }
     }
 }
 // Buys the item from the npc
 public static void Buy(ref Player player, ref NPC npc)
 {
     while (true)
     {
         Console.Clear();
         bool exitLoop = false;
         Console.Clear();
         Tools.Shuffle(ref player.storage);
         Tools.ShuffleDamage(ref player);
         Console.Write("Please type the item you wish to buy.");
         string message = Console.ReadLine().ToLower();
         // This is a forloop will alow you to buy a item.
         for (int i = 0; i < npc.storage.Length; i++)
         {
             if (npc.storage[i] != null)
             {
                 for (int x = 0; x < player.storage.Length; x++)
                 {
                     if (!exitLoop)
                     {
                         if (player.storage[x] != null)
                         {
                             try
                             {
                                 if (player.storage[x].name.ToLower() == message)
                                 {
                                     if (player.coins >= npc.storage[x].cost)
                                     {
                                         player.storage[x].itemStack++;
                                         exitLoop = true;
                                         Console.WriteLine($"You have bought {player.storage[x].name} for ${player.storage[x].cost}.");
                                         FileSetup.PlayerFileWrite(ref player, Game.playerFile);
                                         Thread.Sleep(2500);
                                     }
                                 }
                             }
                             catch (NullReferenceException e)
                             {
                             }
                         }
                         else if (player.storage[x] == null)
                         {
                             if (npc.storage[i].name.ToLower() == message)
                             {
                                 if (player.coins >= npc.storage[x].cost)
                                 {
                                     player.storage[x] = npc.storage[x];
                                     exitLoop          = true;
                                     Console.WriteLine($"You have bought {player.storage[x].name} for ${player.storage[x].cost}.");
                                     FileSetup.PlayerFileWrite(ref player, Game.playerFile);
                                     Thread.Sleep(2500);
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (message == "exit")
         {
             break;
         }
     }
 }