Esempio n. 1
0
 //Allows you to trade your item with the npc.
 public static void Trade(ref UserInput userInput, ref Player player, ref NPC npc)
 {
     Console.Clear();
     while (true)
     {
         userInput.Message(@"Please type the item you wish to trade. If you wish to exit type exit.");
         string message = Console.ReadLine();
         // Loops to check if you can buy the item and if the item is valid.
         for (int i = 0; i < player.storage.Length; i++)
         {
             if (player.storage[i] != null)
             {
                 if (player.storage[i].name == message)
                 {
                     Console.WriteLine("Please put the item you wish to receive. ");
                     message = Console.ReadLine();
                     for (int j = 0; i < npc.storage.Length; j++)
                     {
                         try
                         {
                             if (npc.storage[j] != null)
                             {
                                 if (npc.storage[j].name == message)
                                 {
                                     if (player.storage[i].worth >= npc.storage[j].worth)
                                     {
                                         Console.WriteLine($"The {player.storage[i].name} was traded with {npc.storage[j].name}.");
                                         Items tmp = player.storage[i];
                                         player.storage[i] = npc.storage[j];
                                         npc.storage[j]    = tmp;
                                         RPG.WritePlayerData();
                                         Thread.Sleep(1500);
                                         break;
                                     }
                                     else
                                     {
                                         Console.WriteLine("Sorry, but it's just not worth enough to trade.");
                                         Thread.Sleep(1500);
                                         Console.Clear();
                                         break;
                                     }
                                 }
                             }
                         }catch (IndexOutOfRangeException e)
                         {
                         }
                     }
                 }
             }
         }
         if (message == "exit")
         {
             Console.Clear();
             break;
         }
         Console.Clear();
     }
 }
Esempio n. 2
0
 // This will sell your items for you.
 public static void Sell(ref UserInput userInput, ref Player player, ref NPC npc)
 {
     Console.Clear();
     while (true)
     {
         userInput.Message(@"Please type the item you wish to sell. If you wish to exit type exit.");
         string message = Console.ReadLine();
         // Loops and check if you are able to sell that item and if the item exists.
         for (int i = 0; i < player.storage.Length; i++)
         {
             if (player.storage[i] != null)
             {
                 if (player.storage[i].name == message)
                 {
                     if (npc.balance >= player.storage[i].worth)
                     {
                         npc.storage[i]  = player.storage[i];
                         npc.balance    -= player.storage[i].worth;
                         player.balance += npc.storage[i].worth;
                         Console.WriteLine($"You just sold yourself {player.storage[i].name} for ${player.storage[i].worth}.");
                         RPG.WritePlayerData();
                         player.storage[i] = null;
                         Thread.Sleep(1500);
                         Console.Clear();
                         break;
                     }
                     else
                     {
                         Console.WriteLine("The npc does not have enough money to buy this.");
                         Thread.Sleep(1500);
                         Console.Clear();
                     }
                 }
             }
         }
         if (message == "exit")
         {
             Console.Clear();
             break;
         }
         Console.Clear();
     }
 }
Esempio n. 3
0
 //Allows you to buy the item from the npc
 public static void Buy(ref UserInput userInput, ref Player player, ref NPC npc)
 {
     Console.Clear();
     while (true)
     {
         userInput.Message(@"Please type the item you wish to buy. If you wish to exit type exit.");
         string message = Console.ReadLine();
         // Loops through to check if the item is buyable and if it's a valid item also if you have enough of a balance to buy it.
         for (int i = 0; i < npc.storage.Length; i++)
         {
             if (npc.storage[i] != null)
             {
                 if (npc.storage[i].name == message)
                 {
                     if (player.balance >= npc.storage[i].worth)
                     {
                         player.balance   -= npc.storage[i].worth;
                         npc.balance      += npc.storage[i].worth;
                         player.storage[i] = npc.storage[i];
                         Console.WriteLine($"You just bought yourself {npc.storage[i].name} for ${npc.storage[i].worth}.");
                         RPG.WritePlayerData();
                         npc.storage[i] = null;
                         Thread.Sleep(1500);
                         Console.Clear();
                         break;
                     }
                     else
                     {
                         Console.WriteLine("You don't have enough money to buy this.");
                         Thread.Sleep(1500);
                         Console.Clear();
                     }
                 }
             }
         }
         if (message == "exit")
         {
             Console.Clear();
             break;
         }
         Console.Clear();
     }
 }
Esempio n. 4
0
 // Main function that will start the game.
 static void Main(string[] args)
 {
     RPG.Start();
 }