public void MoveTest()
        {
            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 ();
            CommandProcessor TestProcessor = new CommandProcessor ();

            TestProcessor.AddCommand (TestMove);

            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);
        }
        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);
        }
Example #3
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);
        }
Example #4
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);
        }
        public static void Main(string[] args)
        {
            // Create List of Locations
            List <Location> _locations = new List <Location>();
            List <Path>     _paths     = new List <Path>();
            List <Item>     _items     = new List <Item>();

            //Item _sword = new Item(new string[] { "sword", "bronze sword" }, "a Sword", "A mighty fine Sword");
            //Location _bathroom = new Location("Bathroom", "Room in a house");
            //Location _study = new Location("Study", "Study nook");
            //Path Hallway = new Path(new string[] { "north", "Hallway in house" }, _bathroom);
            //Path Corridor = new Path(new string[] { "south", "Corridor leading south" }, _study);
            //_locations.Add(_bathroom);
            //_locations.Add(_study);

            // Create list of Items

            //Item _shovel = new Item(new string[] { "shovel", "spade" }, "a Shovel", "A Mighty fine Shovel");

            // Place Items in locations
            //_bathroom.Inventory.Put(_sword);
            //_study.Inventory.Put(_shovel);


            // Populate Maze
            PopulateMaze(_locations, _paths, _items);


            // Print Introduction
            Console.WriteLine("\n\nWelcome to the C# Adventure Game!");
            Console.WriteLine("What is your name?");

            // Save the User's input into the string variable called 'name':
            string _name = Console.ReadLine();

            // Print Dialog
            Console.WriteLine("\nWelcome {0}!", _name);
            Console.WriteLine("How would you describe yourself?");

            // Save the User's input into
            string _description = Console.ReadLine();

            // Create Player
            Player _player = new Player(_name, _description);

            _player.Location = _locations[0];



            // Create bag and new item, put bag in Player's inventory, put item in bag
            Bag bag = new Bag(new string[] { "bag", "container" }, "a Bag", "A Container for items");

            _player.Inventory.Put(bag);
            Item computer = new Item(new string[] { "computer", "PC" }, "a Computer", "Small PC for Hacking");

            bag.Inventory.Put(computer);

            Console.WriteLine("\nThere are doors to your left and right.");

            // Set Variables
            string command;

            string[] commandArray = { "Look", "at", "room" };
            //LookCommand look = new LookCommand();

            CommandProcessor commandProcessor = new CommandProcessor(_locations);

            // Game Loop
            while (true)
            {
                Console.WriteLine("What would you like to do?");
                Console.Write("\nCommand --> ");
                command = Console.ReadLine();

                if (command == "quit")
                {
                    break;
                }

                //commandArray = command.Split();
                Console.WriteLine("{0}", commandProcessor.Execute(_player, command));
            }
        }