Example #1
0
		public void ManageInventory()
		{
			bool runInventory = true;
			//Queue commands = new Queue();
			
			LimitedQueue<string> messageBoard = new LimitedQueue<string>(15);
			List<string> commands = new List<string>();
			
			while (runInventory)
			{
				Console.Clear();
				Console.Write(this.ToString());
				Console.WriteLine();
				Console.WriteLine("To strip item, write 'strip #of_equipment'\n" +
					"To equip item, wrire 'equip #of_equipment'\n" +
					"To drop item from inventory, write 'drop #of_equipment'\n" +
				    "To use the item, write 'use #of_equipment'\n" +
					"To go back to game, press Escape\n");
				
				foreach (string s in messageBoard)
				{
					Console.WriteLine(s);
				}
				
				string response = commands.ListThroughCommands();
				commands.Add(response);
				messageBoard.Enqueue(response);
				string[] words = response.Split(' ');
				int n;
				switch (words[0])
				{
				case "close":
				{
					runInventory = false;
					break;
				}
				case "strip":
				{
					try
					{
						n = int.Parse(words[1]);
						messageBoard.Enqueue(this.StripItem(this.equiped.bag[n-1]));
					}
					catch
					{
						messageBoard.Enqueue("Something wrong with your output");
					}
					break;
				}
				case "equip":
				{
					try
					{
						n = int.Parse(words[1]);
						messageBoard.Enqueue(this.EquipItem(this.bag.bag[n-1], true));
					}
					catch
					{
						messageBoard.Enqueue("Something wrong with your output");
					}
					break;
				}
				case "drop":
				{
					try
					{
						n = int.Parse(words[1]);
						Location loc = ThisGame.dungeon.location[this.X,this.Y];
						if (loc.CanDropItemOnto())
						{
							Item i = this.bag.bag[n-1];
							messageBoard.Enqueue(this.DropItem(i));
							ThisGame.dungeon.location[this.X,this.Y].DropItemOnLocation(i);
							ThisGame.dungeon.location[this.X,this.Y].UpdateSymbol();
						}
					}
					catch
					{
						messageBoard.Enqueue("Something wrong with your output");
					}
					break;
				}
				case "use":
				{
					try
					{
						n = int.Parse(words[1]);
						Item i = this.bag.bag[n-1];
						messageBoard.Enqueue(i.Use());
					}
					catch
					{
						messageBoard.Enqueue("Something wrong with your output");
					}
					break;
				}
				default:
				{
					messageBoard.Enqueue("Can not recognize the command");
					break;
				}
				}
			
			}
			
		}
Example #2
0
        public override void VoluntaryAction(Player p)
        {
            bool lootChest = true;

            LimitedQueue<string> messageBoard = new LimitedQueue<string>(10);
            List<string> commands = new List<string>();

            while (lootChest)
            {
                Console.Clear();
                Console.WriteLine(this.message);
                Console.Write(this.Content.ToString());
                Console.WriteLine();
                Console.WriteLine("YOUR INVENTORY");
                Console.Write(p.bag.ToString());
                Console.WriteLine();

                Console.WriteLine("To pick item, write 'pick #of_equipment' or write 'pick all' to take everything\n" +
                    "To drop item from inventory, write 'drop #of_equipment'\n" +
                    "To go back to game, press Escape\n");

                foreach (string s in messageBoard)
                {
                    Console.WriteLine(s);
                }

                string response = commands.ListThroughCommands();
                commands.Add(response);
                messageBoard.Enqueue(response);
                string[] words = response.Split(' ');
                int n;
                switch (words[0])
                {
                case "close":
                {
                    lootChest = false;
                    break;
                }
                case "pick":
                {
                    try
                    {
                        if (words[1] == "all")
                        {
                            if (p.bag.maxsize - p.bag.Count() - this.Content.Count() < 0)
                            {
                                messageBoard.Enqueue("You don't have enough space to take all items in your bag.");
                                break;
                            }
                            foreach (Item i in this.Content.bag)
                            {
                                p.PickItem(i);
                            }
                            this.Content.RemoveAll();
                            messageBoard.Enqueue("All items has been taken");
                        } else {
                            n = int.Parse(words[1]);
                            if (p.bag.maxsize - p.bag.Count() > 0)
                            {
                                p.PickItem(this.Content.bag[n-1]);
                                messageBoard.Enqueue(this.Content.bag[n-1].Name);
                                this.Content.Remove(this.Content.bag[n-1]);
                            }
                            else
                                messageBoard.Enqueue("You don't have enough space to take all items in your bag.");
                        }
                    }
                    catch
                    {
                        messageBoard.Enqueue("Something wrong with your command");
                    }
                    break;
                }
                case "drop":
                {
                    try
                    {
                        n = int.Parse(words[1]);
                        this.Content.Add(p.bag.GetItem(p.bag.bag[n-1].Name));
                        messageBoard.Enqueue(p.bag.bag[n-1].Name);
                        p.DropItem(p.bag.bag[n-1]);
                    }
                    catch
                    {
                        messageBoard.Enqueue("Something wrong with your command");
                    }
                    break;
                }
                default:
                {
                    messageBoard.Enqueue("Can not recognize the command");
                    break;
                }
                }

            }
        }