public static void Move(string direction)
        {
            Room room = Player.GetCurrentRoom();

            if (!room.CanExit(direction))
            {
                TextBuffer.Add("Invalid Direction");
                return;
            }
            Player.moves++;

            switch (direction)
            {
            case Direction.North:
                posY--;
                break;

            case Direction.South:
                posY++;
                break;

            case Direction.West:
                posX--;
                break;

            case Direction.East:
                posX++;
                break;
            }
            Player.GetCurrentRoom().Describe();
        }
Exemplo n.º 2
0
 public void Describe()
 {
     TextBuffer.Add("Coordonates: " + this.GetCoordonates() + "\n" + this.description);
     TextBuffer.Add(this.GetItemList());
     TextBuffer.Add(this.GetExitList());
     Console.ForegroundColor = Color;
 }
        public static void ProcessCommand(string line)
        {
            var command   = TextUtils.ExtractCommand(line.Trim()).Trim().ToLower();
            var arguments = TextUtils.ExtractArgument(line.Trim()).Trim().ToLower();

            if (Direction.IsValidDirection(command))
            {
                Player.Move(command);
            }
            else
            {
                switch (command)
                {
                case "exit":
                    Program.quit = true;
                    return;

                case "help":
                    ShowHelp();
                    break;

                case "move":
                    Player.Move(arguments);
                    break;

                case "look":
                    Player.GetCurrentRoom().Describe();
                    break;

                case "pickup":
                    Player.PickupItem(arguments);
                    break;

                case "drop":
                    Player.DropItem(arguments);
                    break;

                case "inventory":
                    Player.DisplayInventory();
                    break;

                case "whereami":
                    Player.GetCurrentRoom().ShowTitle();
                    break;

                default:
                    TextBuffer.Add("Input not understood.");
                    break;
                }
            }
            GameManager.ApplyRules();
            TextBuffer.Display();
        }
 public static void ShowHelp()
 {
     TextBuffer.Add("Available commands:");
     TextBuffer.Add("+-------------------------------------------------------+");
     TextBuffer.Add("Help");
     TextBuffer.Add("Exit");
     TextBuffer.Add("Move [North, East, South, West]");
     TextBuffer.Add("Look");
     TextBuffer.Add("Pickup");
     TextBuffer.Add("Drop");
     TextBuffer.Add("Inventory");
     TextBuffer.Add("WhereAmI");
     TextBuffer.Add("+-------------------------------------------------------+");
 }
        public static void DropItem(string itemName)
        {
            Room room = Player.GetCurrentRoom();
            Item item = GetInventoryItem(itemName);

            if (item != null)
            {
                Player.inventoryItems.Remove(item);
                room.Items.Add(item);
                TextBuffer.Add("The " + itemName + " has been dropped into " + room.Title + " room.");
            }
            else
            {
                TextBuffer.Add("There is no " + itemName + " in your Inventory.");
            }
        }
        public static void PickupItem(string itemName)
        {
            Room room = Player.GetCurrentRoom();
            Item item = room.GetItem(itemName);

            if (item != null)
            {
                if (Player.InventoryWeight + item.Weight > Player.weightCapacity)
                {
                    TextBuffer.Add("You must first drop some weight before you can pickup that item.");
                    return;
                }
                room.Items.Remove(item);
                Player.inventoryItems.Add(item);
                TextBuffer.Add(item.PickupText);
            }
            else
            {
                TextBuffer.Add("There is no " + itemName + " in this room.");
            }
        }
        public static void DisplayInventory()
        {
            var message   = "Your inventory contains:";
            var items     = "";
            var underline = "";

            underline = underline.PadLeft(message.Length, '-');
            if (inventoryItems.Count > 0)
            {
                foreach (Item item in inventoryItems)
                {
                    items += "\n[" + item.Title + "][" + item.Weight.ToString() + "]";
                }
            }
            else
            {
                items = "\n<no items>";
            }
            items += "\n Total weight: [" + Player.InventoryWeight + "/" + Player.WeightCapacity + "]";
            TextBuffer.Add(message + "\n" + underline + items);
        }
 public void ShowTitle()
 {
     TextBuffer.Add(this.title);
 }
 public void Describe()
 {
     TextBuffer.Add("Coordonates: " + this.GetCoordonates() + "\n" + this.description);
     TextBuffer.Add(this.GetItemList());
     TextBuffer.Add(this.GetExitList());
 }