Beispiel #1
0
        /// <summary>
        /// Executes Move command and returns appropriate DisplayText to caller
        /// </summary>
        /// <param name="commandClauseString">Term to be matched to Location exits</param>
        /// <returns>a DisplayText object</returns>
        public override DisplayText Move(string commandClauseString)
        {
            var displayText = new DisplayText();

            if (commandClauseString == "")
            {
                return(TextStringManager.GetCommandTextString(CommandTextStrings.CannotMoveToTarget, this));
            }

            var destination = Location.GetExitMatchInLocation(commandClauseString);

            if (destination == null)
            {
                return(TextStringManager.GetCommandTextString(CommandTextStrings.CannotMoveToTarget, this));
            }

            if (IsHostile)
            {
                displayText.Add(TextStringManager.GetErrorTextString(ErrorTextStrings.CannotMoveInCombat));
            }
            else
            {
                displayText.Add(TextStringManager.GetCommandTextString(CommandTextStrings.MoveToTargetLocation, this));
                displayText.Add(destination.Enter(this));
            }

            return(displayText);
        }
Beispiel #2
0
        /// <summary>
        /// Returns a DisplayText object with the text description of the Location
        /// </summary>
        /// <param name="actor">The actor object that is calling this method and to which a DisplayText object is returned</param>
        /// <returns>A DisplayText object</returns>
        public virtual DisplayText Enter(Actor actor)
        {
            //set location of actor entering location
            actor.Location = this;

            //get description of location and add to DisplayText to be returned

            DisplayText enterDisplayText = new DisplayText();


            if (actor is Player)
            {
                enterDisplayText.Add(new DisplayTextLine(Name, ConsoleColor.Red));
                enterDisplayText.Add(TextStringManager.GetGeneralTextString(GeneralTextStrings.ActorEntersLocation, actor, Description));

                //add list of npcs to DisplayText
                enterDisplayText += GetListOfActorsDisplay();

                //add list of items to DisplayText
                enterDisplayText += GetListOfItemsDisplay();
            }
            else
            {
                enterDisplayText = new DisplayText("");
            }

            return(enterDisplayText);
        }
Beispiel #3
0
        /// <summary>
        /// Executes Unequip command and returns appropriate DisplayText to caller
        /// </summary>
        /// <param name="commandClauseString">Term to be matched to items in player Equip Slots</param>
        /// <returns>a DisplayText object</returns>
        public override DisplayText Unequip(string commandClauseString)
        {
            var unequipDisplayText = new DisplayText();

            if (commandClauseString == "")
            {
                return(TextStringManager.GetErrorTextString(ErrorTextStrings.InvalidUnequipTarget));
            }

            //search for item in equipment slots
            var item = GetEquipSlotWithMatch(commandClauseString);

            if (item != null)
            {
                // For now we equip everything to and from Weapon slot -
                // TODO add slot property equipable items that can be tested for to see where it goes
                Inventory.Add(item);
                var equipableItem = item as IEquipable;

                switch (equipableItem.EquipableSlot)
                {
                case EquipmentSlots.Head:
                    EquipSlotHead = null;
                    break;

                case EquipmentSlots.Body:
                    EquipSlotBody = null;
                    break;

                case EquipmentSlots.Hands:
                    EquipSlotHands = null;
                    break;

                case EquipmentSlots.Feet:
                    EquipSlotFeet = null;
                    break;

                case EquipmentSlots.MainWeapon:
                    EquipSlotMainWeapon = null;
                    break;

                default:
                    throw new Exception("Equiped item has no EquipableSlot");
                }

                RemoveItemBonusesFromStats(equipableItem);

                unequipDisplayText.Add(TextStringManager.GetCommandTextString(CommandTextStrings.UnequipItem, this, item.Name));
                return(unequipDisplayText);
            }

            unequipDisplayText.Add(TextStringManager.GetErrorTextString(ErrorTextStrings.CannotUnequipTarget));

            return(unequipDisplayText);
        }
        public void ToStringMethodWorksCorrectly()
        {
            var displayText = new DisplayText();

            //return empty string if it contains nothing
            Assert.Equal("", displayText.ToString());

            //returns single line if it has only one line
            var value = "Hello World!";

            displayText.Add(value);
            Assert.Equal(value, displayText.ToString());

            //returns multiple lines seperated by '/r/n' if it has multiple lines
            displayText.Add(value);
            Assert.Equal(value + "/r/n" + value, displayText.ToString());
        }
Beispiel #5
0
        /// <summary>
        /// Executes Inventory command and returns appropriate DisplayText to caller
        /// </summary>
        /// <returns>a DisplayText object</returns>
        public override DisplayText ShowInventory()
        {
            var inventoryDisplayText     = new DisplayText();
            var inventoryDisplayTextLine = new DisplayTextLine();

            if (Inventory.Count < 1)
            {
                inventoryDisplayTextLine.Add(TextStringManager.GetCommandTextString(CommandTextStrings.InventoryEmpty, this).ToString());
            }
            else if (Inventory.Count == 1)
            {
                inventoryDisplayTextLine.Add(TextStringManager.GetCommandTextString(CommandTextStrings.ShowInventory, this) + Inventory[0].Name + ".");
            }
            else
            {
                inventoryDisplayTextLine.Add(TextStringManager.GetCommandTextString(CommandTextStrings.ShowInventory, this).ToString());

                var index = 0;

                foreach (var item in Inventory)
                {
                    if (index == Inventory.Count - 1)
                    {
                        inventoryDisplayTextLine.Add(item.Name + ".");
                    }
                    else
                    {
                        inventoryDisplayTextLine.Add(item.Name + ", ");
                    }

                    index++;
                }
            }

            inventoryDisplayText.Add(inventoryDisplayTextLine);

            //now show equiped items
            inventoryDisplayText.Add("Your equiped items: (head) " + (EquipSlotHead != null ? EquipSlotHead.Name : "Empty") + ", " +
                                     "(main weapon) " + (EquipSlotMainWeapon != null ? EquipSlotMainWeapon.Name : "Empty") + ", " +
                                     "(body) " + (EquipSlotBody != null ? EquipSlotBody.Name : "Empty") + ", " +
                                     "(hands) " + (EquipSlotHands != null ? EquipSlotHands.Name : "Empty") + ", " +
                                     "(feet) " + (EquipSlotFeet != null ? EquipSlotFeet.Name : "Empty"));

            return(inventoryDisplayText);
        }
        public void CanAddStringAndEnumerateOverValues()
        {
            var value       = "Hello World!";
            var displayText = new DisplayText();

            Assert.Empty(displayText);
            displayText.Add(value);
            foreach (var line in displayText)
            {
                Assert.Equal(value, line.ToString());
            }
        }
Beispiel #7
0
        /// <summary>
        /// Returns a DisplayText object with a list of Items in the Location
        /// </summary>
        /// <returns>a DisplayText object</returns>
        private DisplayText GetListOfItemsDisplay()
        {
            //get list of items in room

            var itemListDisplayText = new DisplayText();

            foreach (var item in Items)
            {
                var itemDisplayTextLine = new DisplayTextLine(item.Name + " is here");
                itemListDisplayText.Add(itemDisplayTextLine);
            }

            return(itemListDisplayText);
        }
Beispiel #8
0
        /// <summary>
        /// Returns a DisplayText object with the text description of the location
        /// </summary>
        /// <param name="viewer">The actor object that is calling this method and to whcih a DisplayText object is returned</param>
        /// <returns>A DisplayText object</returns>
        public virtual DisplayText Viewed(Actor viewer)
        {
            var viewedDisplayText = new DisplayText();

            viewedDisplayText.Add(TextStringManager.GetGeneralTextString(GeneralTextStrings.ActorViewsLocation, viewer, Description));

            //add list of npcs to DisplayText
            viewedDisplayText += GetListOfActorsDisplay();

            //add list of items to DisplayText
            viewedDisplayText += GetListOfItemsDisplay();

            return(viewedDisplayText);
        }
Beispiel #9
0
        /// <summary>
        /// Executes Look command and returns appropriate DisplayText to caller
        /// </summary>
        /// <param name="commandClauseString">Term to be matched to IViewable objects in Location (or just location if empty string)</param>
        /// <returns>a DisplayText object</returns>
        public override DisplayText Look(string commandClauseString)
        {
            var displayText = new DisplayText();

            var viewed = Location.GetViewableMatchInLocation(commandClauseString);

            if (viewed == null)
            {
                displayText.Add(TextStringManager.GetErrorTextString(ErrorTextStrings.InvalidLookTarget));
            }
            else if (viewed is Location)
            {
                displayText.Add(TextStringManager.GetCommandTextString(CommandTextStrings.LookAtLocation, this));
                displayText.Add(viewed.Viewed(this));
            }
            else
            {
                displayText.Add(TextStringManager.GetCommandTextString(CommandTextStrings.LookAt, this, viewed.Name));
                displayText.Add(viewed.Viewed(this));
            }

            return(displayText);
        }
        public void CanAddDisplayTextAndEnumerateOverValues()
        {
            var value             = "Hello World!";
            var displayText       = new DisplayText(value);
            var displayTextSecond = new DisplayText(value);

            displayText.Add(displayTextSecond);
            Assert.Equal(2, displayText.LineCount);

            foreach (var line in displayText)
            {
                Assert.Equal(value, line.ToString());
            }
        }
Beispiel #11
0
        ////////////////////////////////////////////////////////////////////////////////////////
        //   PRIVATE METHODS
        ////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Returns a DisplayText object with a list of Actors in the Location
        /// </summary>
        /// <returns>a DisplayText object</returns>
        private DisplayText GetListOfActorsDisplay()
        {
            //get list of npcs in room
            var npcListDisplayText = new DisplayText();

            foreach (var person in Actors)
            {
                //var personDisplayTextLine = new DisplayTextLine(person.Name + " is here");
                //npcListDisplayText.Add(personDisplayTextLine);
                var personDisplayTextLine = new DisplayTextLine(TextStringManager.GetGeneralTextString(GeneralTextStrings.ActorIsHere, person).ToString());
                npcListDisplayText.Add(personDisplayTextLine);
            }

            return(npcListDisplayText);
        }
        public void CanAddListAndEnumerateOverValues()
        {
            var value               = "Hello World!";
            var displayText         = new DisplayText(value);
            var displayTextLineList = new List <DisplayTextLine>
            {
                new DisplayTextLine(value),
                new DisplayTextLine(value)
            };

            displayText.Add(displayTextLineList);

            Assert.Equal(3, displayText.LineCount);

            foreach (var line in displayText)
            {
                Assert.Equal(value, line.ToString());
            }
        }