示例#1
0
        public string MoveTo(Player p, string id)
        {
            Location _location;
            if (id == "leave")
            {
                p.LeaveLocation ();
                return p.Location.LongDesc;

            }

            _location = p.Location;

            Path _path = _location.Path;

            if (_path == null)
            {
                return "location has no path";
            }

            _location = _path.GetLocation (id);

            if(_location ==null)
            {
                return "path not found";
            }

            p.Location = _location;
            return p.Location.LongDesc;
        }
示例#2
0
 public void TestLocatesItem()
 {
     Player test = new Player ("Player 1", "a funny wizard");
     Item item1 = new Item( new String[] {"shovel", "spade" }, "a shovel", "This is a might fine ..." );
     test.Inventory.Put (item1);
     Assert.AreEqual(test.Locate ("shovel"),item1);
 }
        public void TestInvalidLook()
        {
            Player TestPlayer = new Player ("TestPlayer", "For testing");
            LookCommand TestLook = new LookCommand ();

            Assert.IsTrue (TestLook.Execute (TestPlayer, new string[1] {"hello"}) == "i don't know how to look like that");
        }
示例#4
0
        public override string Execute(Player p, string[] text)
        {
            if (text.Length == 1 && text [0] != "leave" || text.Length > 3)
            {
                return "i don't know how to move like that";
            }

            if (text [0] != "move" && text [0] != "go" && text [0] != "head" && text [0] != "leave")
            {
                return "error in move input";
            }

            if (text[0] != "leave")
            {
                if (text[1] != "to" || text.Length < 3)
                {
                    return "where do you want to go?";
                }
                else
                {
                    return MoveTo(p, text[2]);
                }
            }
            else
            {
                return MoveTo(p, "leave");
            }
        }
示例#5
0
        public void GetPathTest()
        {
            Player TestPlayer = new Player ("TestPlayer", "For testing");
            Location TestLocation = new Location (new string[] { "potato", "farm" }, "potato farm", "a potato farm");
            Location TestLocation2 = new Location (new string[] { "melon", "farm" }, "melon farm", "a melon farm");
            Location TestLocation3 = new Location (new string[] { "tomato", "farm" }, "tomato farm", "a tomato farm");

            Path TestPath = new Path(new string[] { "potato", "path" });
            Path TestPath2 = new Path(new string[] { "melon", "path" });
            Path TestPath3 = new Path(new string[] { "tomato", "path" });

            TestLocation.Path = TestPath;
            TestPath.SetLocation('w', TestLocation2);
            TestPath.SetLocation('n', TestLocation3);

            TestLocation2.Path = TestPath2;
            TestPath2.SetLocation('e', TestLocation);
            TestPath2.SetLocation('a', TestLocation3);

            TestLocation3.Path = TestPath3;
            TestPath3.SetLocation('s', TestLocation);
            TestPath3.SetLocation('d', TestLocation2);

            TestPlayer.Location = TestLocation;
            Assert.IsTrue (TestLocation.Path == TestPath);
        }
示例#6
0
        public override string Execute(Player p, string[] text)
        {
            if (text.Length  != 3 && text.Length != 5)
            {
                return "i don't know how to look like that";
            }

            if (text [0] != "look")
            {
                return "error in look input";
            }

            if (text [1] != "at")
            {
                return "what do you want to look at?";
            }

            if (text.Length == 5 && text [3] != "in")
            {
                return "what do you want to look in?";
            }
            else if (text.Length == 5)
            {
                return this.LookAtIn (p, text [2], text [4]);
            }
            else
            {
                return this.LookAtIn (p, text [2], "");
            }
        }
示例#7
0
 public void TestLookAtGem()
 {
     LookCommand test = new LookCommand ();
     Player testPlayer = new Player ("Player 1", "a funny wizard");
     testPlayer.Inventory.Put (new Item( new String[] {"gun", "rifle" }, "a gun", "This is a a long spirally grooved ..." ));
     Assert.AreEqual (test.Execute(testPlayer, new String[]{"look", "at", "gun", "in", "inventory"}),"This is a a long spirally grooved ...");
 }
示例#8
0
        public void LeaveFailTest()
        {
            Player TestPlayer = new Player ("TestPlayer", "For testing");
            Location TestLocation = new Location (new string[] { "potato", "farm" }, "potato farm", "a potato farm");
            Location TestLocation2 = new Location (new string[] { "melon", "farm" }, "melon farm", "a melon farm");
            Location TestLocation3 = new Location (new string[] { "tomato", "farm" }, "tomato farm", "a tomato farm");

            Path TestPath = new Path(new string[] { "potato", "path" });
            Path TestPath2 = new Path(new string[] { "melon", "path" });
            Path TestPath3 = new Path(new string[] { "tomato", "path" });

            TestLocation.Path = TestPath;
            TestPath.SetLocation('w', TestLocation2);
            TestPath.SetLocation('n', TestLocation3);

            TestLocation2.Path = TestPath2;
            TestPath2.SetLocation('e', TestLocation);
            TestPath2.SetLocation('a', TestLocation3);

            TestLocation3.Path = TestPath3;
            TestPath3.SetLocation('s', TestLocation);
            TestPath3.SetLocation('d', TestLocation2);

            TestPlayer.Location = TestLocation;

            MoveCommand TestMove = new  MoveCommand ();

            Assert.IsTrue (TestMove.Execute (TestPlayer, new string[3] {"move", "to","heaven"}) == "path not found");
            Assert.IsTrue (TestMove.Execute (TestPlayer, new string[1] {"should fail"}) == "i don't know how to move like that");
        }
示例#9
0
 public void TestFullDescription()
 {
     Player test = new Player ("Player 1", "a funny wizard");
     Item item1 = new Item( new String[] {"shovel", "spadxze" }, "a shovel", "This is a might fine ..." );
     test.Inventory.Put (item1);
     Assert.AreEqual (test.FullDescription, "You are carrying:\r\na shovel (shovel)\r\n");
 }
示例#10
0
        public void LeaveTest()
        {
            Player TestPlayer = new Player ("TestPlayer", "For testing");
            Location TestLocation = new Location (new string[] { "potato", "farm" }, "potato farm", "a potato farm");
            Location TestLocation2 = new Location (new string[] { "melon", "farm" }, "melon farm", "a melon farm");
            Location TestLocation3 = new Location (new string[] { "tomato", "farm" }, "tomato farm", "a tomato farm");

            Path TestPath = new Path(new string[] { "potato", "path" });
            Path TestPath2 = new Path(new string[] { "melon", "path" });
            Path TestPath3 = new Path(new string[] { "tomato", "path" });

            TestLocation.Path = TestPath;
            TestPath.SetLocation('w', TestLocation2);
            TestPath.SetLocation('n', TestLocation3);

            TestLocation2.Path = TestPath2;
            TestPath2.SetLocation('e', TestLocation);
            TestPath2.SetLocation('a', TestLocation3);

            TestLocation3.Path = TestPath3;
            TestPath3.SetLocation('s', TestLocation);
            TestPath3.SetLocation('d', TestLocation2);

            TestPlayer.Location = TestLocation;

            MoveCommand TestMove = new  MoveCommand ();

            Assert.IsTrue (TestMove.Execute (TestPlayer, new string[3] {"move", "to","west"}) == TestLocation2.LongDesc);
            Assert.IsTrue (TestMove.Execute (TestPlayer, new string[1] {"leave"}) == TestLocation.LongDesc);
        }
示例#11
0
 public void TestLookAtNoGemInBag()
 {
     LookCommand test = new LookCommand ();
     Player testPlayer = new Player ("Player 1", "a funny wizard");
     Bag testBag = new Bag (new string[]{ "Bag", "Backpack" }, "a bag", "This is a bag for....");
     testPlayer.Inventory.Put (testBag);
     Assert.AreEqual (test.Execute(testPlayer, new String[]{"look", "at", "shovel", "in", "bag"}),"I cannot find the shovel in the bag");
 }
示例#12
0
        public void IdentifyPlayerTest()
        {
            Player TestPlayer = new Player ("TestPlayer", "For testing");

            //Assert.IsTrue (TestPlayer.Locate ("TestPlayer")== TestPlayer);

            Assert.IsTrue (TestPlayer.AreYou ("me"));
        }
示例#13
0
        public void LocateNothingTest()
        {
            Player TestPlayer = new Player ("TestPlayer", "For testing");

            //Assert.IsTrue (TestPlayer.Locate ("TestPlayer")== TestPlayer);

            Assert.IsTrue (TestPlayer.Locate ("potato") == null);
        }
示例#14
0
        public void LocatePlayerTest()
        {
            Player TestPlayer = new Player ("TestPlayer", "For testing");

            //Assert.IsTrue (TestPlayer.Locate ("TestPlayer")== TestPlayer);

            Assert.IsTrue (TestPlayer.Locate ("me") == TestPlayer);
        }
示例#15
0
 public void TestInvalidLook()
 {
     LookCommand test = new LookCommand ();
     Player testPlayer = new Player ("Player 1", "a funny wizard");
     Assert.AreEqual (test.Execute(testPlayer, new String[]{"look", "around"}),"I don’t know how to look like that");
     Assert.AreEqual (test.Execute(testPlayer, new String[]{"Hello", "man", "there"}),"Error in look input");
     Assert.AreEqual (test.Execute(testPlayer, new String[]{"look", "at", "sth", "about", "me"}),"What do you want to look in?");
     Assert.AreEqual (test.Execute(testPlayer, new String[]{"look", "over", "that"}),"What do you want to look at?");
 }
示例#16
0
 public void TestPlayerLocateinLocation()
 {
     Player test = new Player ("Player 1", "a funny wizard");
     Locations testLocation = new Locations("park","a nice park which is ...");
     Item item1 = new Item( new String[] {"shovel", "spade" }, "a shovel", "This is a might fine ..." );
     testLocation.Inventory.Put (item1);
     test.Location = testLocation;
     Assert.AreEqual (test.Location,testLocation);
     Assert.AreEqual (test.Locate("shovel"),item1);
 }
        public void TestLookAtGemFail()
        {
            Player TestPlayer = new Player ("TestPlayer", "For testing");
            Item TestItem = new Item (new string[] { "baked", "potato" }, "Gem", "A Shiny Gem");

            TestPlayer.Inventory.PutItem (TestItem);

            LookCommand TestLook = new LookCommand ();

            Assert.IsFalse (TestLook.Execute (TestPlayer, new string[5] {"look", "at", "gem", "in", "TestPlayer"}) == TestItem.LongDesc);
        }
示例#18
0
        public void PlayerLocateTest()
        {
            Player TestPlayer = new Player ("TestPlayer", "For testing");
            Location TestLocation = new Location (new string[] { "potato", "farm" }, "potato farm", "a potato farm");
            Item TestItem = new Item (new string[] { "gem", "shiny" }, "shiny gem", "a shiny gem");

            TestPlayer.Location = TestLocation;
            TestLocation.Inventory.PutItem (TestItem);

            Assert.IsTrue (TestPlayer.Location.Locate ("gem") == TestItem);
        }
        public override string Execute(Player p, string[] text)
        {
            foreach (Command command in _Commands)
            {
                if (command.AreYou (text [0]))
                {
                    return command.Execute (p, text);
                }
            }

            return "no such command";
        }
示例#20
0
        public void LocateItemsTest()
        {
            Player TestPlayer = new Player ("TestPlayer", "For testing");
            Item TestItem = new Item (new string[] { "potato", "baked" }, "baked potato", "a baked potato");

            TestPlayer.Inventory.PutItem (TestItem);

            //Assert.IsTrue (TestPlayer.Locate ("TestPlayer")== TestPlayer);

            Assert.IsTrue (TestPlayer.Locate ("potato") == TestItem);
            Assert.IsTrue (TestPlayer.Locate ("potato") == TestItem);
        }
        public void TestLookAtGem()
        {
            Player TestPlayer = new Player ("TestPlayer", "For testing");
            Item TestItem = new Item (new string[] { "gem", "Shiny" }, "Gem", "A Shiny Gem");

            TestPlayer.Inventory.PutItem (TestItem);

            LookCommand TestLook = new LookCommand ();

            Console.WriteLine (TestLook.Execute (TestPlayer, new string[3] {"look", "at", "gem"}));

            Assert.IsTrue (TestLook.Execute (TestPlayer, new string[3] {"look", "at", "gem"}) == TestItem.LongDesc);
        }
        public void TestLookAtGemInBagFail()
        {
            Player TestPlayer = new Player ("TestPlayer", "For testing");
            Item TestItem = new Item (new string[] { "gem", "Shiny" }, "Gem", "A Shiny Gem");
            Bag TestBag = new Bag (new string[] { "bag", "test" }, "Test Bag", "A Testing Bag");

            TestBag.Inventory.PutItem (TestItem);
            TestPlayer.Inventory.PutItem (TestBag);

            LookCommand TestLook = new LookCommand ();

            Assert.IsTrue (TestLook.Execute (TestPlayer, new string[5] {"look", "at", "gem", "in", "nobag"}) == "i cannot find the nobag");
        }
示例#23
0
        public void PlayerFullDescTest()
        {
            Player TestPlayer = new Player ("TestPlayer", "For testing");
            Item TestItem = new Item (new string[] { "potato", "baked" }, "baked potato", "a baked potato");

            TestPlayer.Inventory.PutItem (TestItem);
            //Assert.IsTrue (TestPlayer.Locate ("TestPlayer")== TestPlayer);

            //Assert.IsTrue (TestInventory.ItemList ().Contains("baked potato" + "\t" + "A baked potato potato." + "\n"));
            //Assert.IsTrue (TestInventory.ItemList ().Contains("baked chicken" + "\t" + "A baked chicken chicken." + "\n"));

            Assert.IsTrue (TestPlayer.FullDescription().Contains("You are Carrying: \n" + "baked potato" + "\t" + "A baked potato potato." + "\n" ));
            Console.WriteLine (TestPlayer.FullDescription ());
        }
        public void LookTest()
        {
            Player TestPlayer = new Player ("TestPlayer", "For testing");

            LookCommand TestLook = new LookCommand ();

            CommandProcessor TestProcessor = new CommandProcessor ();

            TestProcessor.AddCommand (TestLook);

            Console.WriteLine(TestProcessor.Execute(TestPlayer, new string[3] {"look", "at", "me"}) );

            Assert.IsTrue (TestProcessor.Execute (TestPlayer, new string[3] {"look", "at", "me"}) == TestPlayer.LongDesc);
        }
示例#25
0
        /// <summary>
        /// Looks at in.
        /// </summary>
        private string LookAtIn(Player p, string thingId, string containerId)
        {
            string output = "";
            GameObject obj= p.Locate (containerId);

            if (obj != null) {
                IHaveInventory container = obj as IHaveInventory;
                if (container.Locate (thingId) != null) {
                    output = container.Locate (thingId).FullDescription;
                } else {
                    if (containerId == "inventory") {
                        output = "I cannot find the " + thingId;
                    } else {
                        output = "I cannot find the " + thingId + " in the " + containerId;
                    }
                }
            } else {
                output = "I cannot find the " + containerId;
            }
            return output;
        }
示例#26
0
        public static void Main(string[] args)
        {
            string _playerName;
            string _playerDesc;
            LookCommand _lookCommand = new LookCommand ();

            Console.WriteLine ("Welcome to Swin-Adventure");
            Console.WriteLine ("+―++―++―++―++―++―++―+\r\n");
            Console.WriteLine ("Please enter your name:");
            _playerName = Console.ReadLine();
            Console.WriteLine ("Please enter your description:");
            _playerDesc = Console.ReadLine();

            Player _player = new Player (_playerName, _playerDesc);
            _player.Inventory.Put(new Item( new String[] {"map" }, "an incomplete map", "This is an incomplete map of......" ));
            _player.Inventory.Put(new Item( new String[] {"gun", "rifle" }, "a gun", "This is a a long spirally grooved ..." ));
            Bag _bag = new Bag (new string[]{"Bag", "Backpack"}, "a bag", "This is a bag for....");
            Item item1 = new Item( new String[] {"shovel", "spade" }, "a shovel", "This is a might fine ..." );
            _bag.Inventory.Put (item1);
            _player.Inventory.Put (_bag);

            string _command;
            string _output;
            String[] _commandArr;

            do {
                Console.WriteLine ("Enter a command or enter 'exit' to exit the game");
                _command = Console.ReadLine ();
                if (_command.ToLower () == "exit") {
                    Console.WriteLine ("Press enter to exit");
                    Console.ReadLine ();
                    break;
                } else {

                    _commandArr = ToStringArray (_command);
                    _output = _lookCommand.Execute (_player, _commandArr);
                    Console.WriteLine (_output);
                }
            } while (_command.ToLower () != "exit");
        }
示例#27
0
        /// <summary>
        /// Execute the look command.
        /// </summary>
        /// <param name="p">P.</param>
        /// <param name="text">Text.</param>
        public override string Execute(Player p, string[] text)
        {
            string output = "";
            if (text.Length == 3 || text.Length == 5) {
                if (text [0].ToLower () != "look") {
                    output = "Error in look input";
                } else if (text [1].ToLower () != "at") {
                    output = "What do you want to look at?";
                } else if (text.Length == 3) {
                    output = LookAtIn (p, text [2], "inventory");
                } else if (text.Length == 5) {
                    if (text [3].ToLower () != "in") {
                        output = "What do you want to look in?";
                    } else {
                        output= LookAtIn (p, text [2], text [4]);
                    }
                }
            }else{
                output= "I don’t know how to look like that";
            }

            return output;
        }
示例#28
0
        public string LookAtIn(Player p, string thingId, string containerId)
        {
            if (p.AreYou(thingId))
            {
                return p.LongDesc;
            }

            GameObject wantedItem = null;
            IHaveInventory wantedInventory = p.Locate(containerId) as IHaveInventory;

            if (p.AreYou (containerId) || containerId == "")
            {
                wantedInventory = (IHaveInventory)p;
                //return p.LongDesc;
            }

            if (wantedInventory == null)
            {
                return "i cannot find the " + containerId;
            }

            wantedItem = wantedInventory.Locate (thingId);

            if (wantedItem == null)
            {
                if (containerId == "")
                {
                    return "i cannot find the " + thingId;
                }
                else
                {
                    return "i cannot find the " + thingId + " in " + containerId;
                }
            }

            return wantedItem.LongDesc;
        }
        public void MultipleCommandTest()
        {
            Player TestPlayer = new Player ("TestPlayer", "For testing");
            Location TestLocation = new Location (new string[] { "potato", "farm" }, "potato farm", "a potato farm");
            Location TestLocation2 = new Location (new string[] { "melon", "farm" }, "melon farm", "a melon farm");
            Location TestLocation3 = new Location (new string[] { "tomato", "farm" }, "tomato farm", "a tomato farm");

            Path TestPath = new Path(new string[] { "potato", "path" });
            Path TestPath2 = new Path(new string[] { "melon", "path" });
            Path TestPath3 = new Path(new string[] { "tomato", "path" });

            TestLocation.Path = TestPath;
            TestPath.SetLocation('w', TestLocation2);
            TestPath.SetLocation('n', TestLocation3);

            TestLocation2.Path = TestPath2;
            TestPath2.SetLocation('e', TestLocation);
            TestPath2.SetLocation('a', TestLocation3);

            TestLocation3.Path = TestPath3;
            TestPath3.SetLocation('s', TestLocation);
            TestPath3.SetLocation('d', TestLocation2);

            TestPlayer.Location = TestLocation;

            MoveCommand TestMove = new  MoveCommand ();
            LookCommand TestLook = new LookCommand ();
            CommandProcessor TestProcessor = new CommandProcessor ();

            TestProcessor.AddCommand (TestMove);

            TestProcessor.AddCommand (TestLook);

            Assert.IsTrue (TestProcessor.Execute (TestPlayer, new string[3] {"look", "at", "me"}) == TestPlayer.LongDesc);
            Assert.IsTrue (TestProcessor.Execute (TestPlayer, new string[3] {"move", "to","west"}) == TestLocation2.LongDesc);
            Assert.IsTrue (TestProcessor.Execute (TestPlayer, new string[3] {"move", "to","north_east"}) == TestLocation3.LongDesc);
        }
示例#30
0
 public abstract string Execute(Player p, string[ ] text);