Пример #1
0
        public void TakeItem(string itemName)
        {
            int itemIndex = CurrentRoom.IndexOfItemByName(itemName);

            if (itemIndex == -1)
            {
                Console.WriteLine($"You must be hallucinating. That item isn't in this room");
                return;
            }

            // change colors + print name and description of item
            ConsoleColor background = Console.BackgroundColor;
            ConsoleColor foreground = Console.ForegroundColor;

            Console.BackgroundColor = ConsoleColor.Green;
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine($" {CurrentRoom.Items[itemIndex].Name} ");
            Console.BackgroundColor = background;
            Console.ForegroundColor = foreground;
            Console.WriteLine(CurrentRoom.Items[itemIndex].Description);

            if (CurrentRoom.Items[itemIndex].KillsPlayer)
            {
                GameLost = true;
                Console.WriteLine($"You died when you picked up the {itemName}. R.I.P.");
                return;
            }

            CurrentPlayer.Inventory.Add(CurrentRoom.Items[itemIndex]);
            CurrentRoom.RemoveItem(itemIndex);
        }