Ejemplo n.º 1
0
 // 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;
         }
     }
 }