Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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");
        }
Пример #4
0
        public void AreYouTest()
        {
            Location TestLocation = new Location (new string[] { "potato", "farm" }, "potato farm", "a potato farm");

            Assert.IsTrue (TestLocation.AreYou ("potato"));
            Assert.IsTrue (TestLocation.AreYou ("farm"));
        }
Пример #5
0
        public void LocateTest()
        {
            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");

            TestLocation.Inventory.PutItem (TestItem);

            Assert.IsTrue (TestLocation.Locate ("gem") == TestItem);
        }
Пример #6
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);
        }
Пример #7
0
        public Player(string name, string desc)
            : base(new string[] { "me", "inventory"} , name, desc)
        {
            this.Name = name;
            this.LongDesc = desc;

            _inventory = new Inventory ();

            _location = null;
            _lastlocation = null;
        }
Пример #8
0
        public Path(string[] ids)
        {
            _north = null;
            _south = null;
            _east = null;
            _west = null;
            _north_east = null;
            _north_west = null;
            _south_east = null;
            _south_west = null;

            foreach(string id in ids)
            {
                this.AddIdentifier (id);
            }
        }
        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);
        }
Пример #10
0
 public void LeaveLocation()
 {
     _location = _lastlocation;
 }
Пример #11
0
        public static void Main(string[] args)
        {
            //Get the player's name and description from the user, and use these details to create a
            //Player object.
            //■ Create two items and add them to the the player's inventory
            //■ Create a bag and add it to the player's inventory
            //■ Create another item and add it to the bag
            //■ Loop reading commands from the user, and getting the look command to execute them.
            Console.WriteLine("Enter Player Name:");
            string Name = Console.ReadLine();
            Console.WriteLine ("Describe yourself:");
            string Desc = Console.ReadLine();

            Player GamePlayer = new Player (Name, Desc);
            Item Sword = new Item (new string[] { "Sword", "broadsword" }, "sword", "a broadsword");
            Item Potato = new Item (new string[] { "potato", "baked" }, "baked potato", "a baked potato");

            GamePlayer.Inventory.PutItem (Sword);
            GamePlayer.Inventory.PutItem (Potato);

            Bag Bag1 = new Bag (new string[] { "Test", "Bag" }, "Test Bag", "A Testing Bag");

            GamePlayer.Inventory.PutItem (Bag1);

            Item Gem = new Item (new string[] { "gem", "Shiny" }, "Gem", "A Shiny Gem");
            Bag1.Inventory.PutItem (Gem);

            Location PotatoFarm = new Location (new string[] { "potato", "farm" }, "potato farm", "a potato farm");
            Location MelonFarm = new Location (new string[] { "melon", "farm" }, "melon farm", "a melon farm");
            Location TomatoFarm = new Location (new string[] { "tomato", "farm" }, "tomato farm", "a tomato farm");

            Path PotatoPath = new Path(new string[] { "potato", "path" });
            Path MelonPath = new Path(new string[] { "melon", "path" });
            Path TomatoPath = new Path(new string[] { "tomato", "path" });

            PotatoFarm.Path = PotatoPath;
            PotatoPath.SetLocation('w', MelonFarm);
            PotatoPath.SetLocation('n', TomatoFarm);

            MelonFarm.Path = MelonPath;
            MelonPath.SetLocation('e', PotatoFarm);
            MelonPath.SetLocation('a', TomatoFarm);

            TomatoFarm.Path = TomatoPath;
            TomatoPath.SetLocation('s', PotatoFarm);
            TomatoPath.SetLocation('d', MelonFarm);

            GamePlayer.Location = PotatoFarm;

            CommandProcessor MainCommandProcessor = new CommandProcessor();
            LookCommand Look = new LookCommand ();
            MoveCommand Move = new MoveCommand ();

            MainCommandProcessor.AddCommand (Look);
            MainCommandProcessor.AddCommand (Move);

            do
            {
                Console.WriteLine("Enter Command:");
                string UserInput = Console.ReadLine();
                String[] Command = UserInput.Split(' ');

                Console.WriteLine(MainCommandProcessor.Execute(GamePlayer,Command));

            }while(true);
        }
Пример #12
0
 public void SetLocation(char direction, Location location)
 {
     if (location == null)
     {
         return;
     }
     switch(direction)
     {
     case 'n':
         _north = location;
         break;
     case 's':
         _south = location;
         break;
     case 'e':
         _east = location;
         break;
     case 'w':
         _west = location;
         break;
     case 'a':
         _north_east = location;
         break;
     case 'b':
         _north_west = location;
         break;
     case 'c':
         _south_east = location;
         break;
     case 'd':
         _south_west = location;
         break;
     }
 }