Beispiel #1
0
        public void TestMovePeggyToRoomWhichRequiresAnItemAndPeggyHasTheItem()
        {
            Room r1           = _r1;
            Room r2           = _r2;
            Item requiredItem = _requiredItem;

            r1.AddAdjoiningRoom("north", r2.Id, requiredItem.Id);
            GameWorld gw = new GameWorld();

            gw.AddRoom(r1.Id, r1);
            gw.AddRoom(r2.Id, r2);

            gw.Peggy.AddItemToInventory(requiredItem);
            gw.MovePeggyToRoom(r1);

            // If Peggy tries moving a room which requires an item (eg. a key), and
            // Peggy _does_ have that item, 4 things should happen...
            string res = gw.MovePeggy("north");

            // 1. Peggy moves to the new room.
            Assert.Equal(r2.Id, gw.Peggy.CurrentRoom.Id);

            // 2. The item has been 'used', ie. Peggy no longer has the item.
            Assert.True(!gw.Peggy.InventoryHasItems());

            // 3. The the adjoining room is now 'open', ie. no longer requires an item
            //    to move into it.
            Assert.Equal("", r1.GetAdjoiningRoom(Direction.North).RequiresId);

            // 4. MovePeggy() returns a string stating success.
            Assert.Equal($"Moved to the {r2.FriendlyName}.\r\n", res);
        }
Beispiel #2
0
        public void TestMovePeggyToRoomWhichRequiresItemAndPeggyDoesntHaveTheItem()
        {
            Room r1           = _r1;
            Room r2           = _r2;
            Item requiredItem = _requiredItem;

            r1.AddAdjoiningRoom("north", r2.Id, requiredItem.Id);
            GameWorld gw = new GameWorld();

            gw.AddRoom(r1.Id, r1);
            gw.AddRoom(r2.Id, r2);

            gw.Peggy.AddItemToInventory(_randomItem);
            gw.MovePeggyToRoom(r1);

            // If Peggy tries moving a room which requires an item (eg. a key), and
            // Peggy _does not_ have that item, 4 things should happen...
            string res = gw.MovePeggy("north");

            // 1. Peggy stays in the original room.
            Assert.Equal(r1.Id, gw.Peggy.CurrentRoom.Id);

            // 2. Any items in Peggy's inventory are still there.
            Assert.True(gw.Peggy.InventoryHasItems());

            // 3. The adjoining room still has the required item.
            Assert.Equal(requiredItem.Id, r1.GetAdjoiningRoom(Direction.North).RequiresId);

            // 4. MovePeggy() returns a failure message.
            // (TODO: this needs to be updated when we use the requiredItem friendly name).
            Assert.Equal($"The {requiredItem.Id} is required to get into the {r2.FriendlyName}.\r\n", res);
        }
Beispiel #3
0
        public void TestAdjoiningRoomNoRequiredItem()
        {
            Room r = new Room("a", "b", "c");

            r.AddAdjoiningRoom("west", "room-with-requirement");
            AdjoiningRoom ar = r.GetAdjoiningRoom(Direction.West);

            Assert.Equal("", ar.RequiresId);
        }
Beispiel #4
0
        public void TestAddAdjoiningRoom(string direction, Direction directionEnum, string id)
        {
            Room r = new Room("a", "b", "c");

            r.AddAdjoiningRoom(direction, id);
            AdjoiningRoom ar = r.GetAdjoiningRoom(directionEnum);

            Assert.Equal(id, ar.Id);
        }
Beispiel #5
0
        public void TestMovePeggyWithNoRequiredItem()
        {
            Room r1 = _r1;
            Room r2 = _r2;

            r1.AddAdjoiningRoom("north", r2.Id);
            GameWorld gw = new GameWorld();

            gw.AddRoom(r1.Id, r1);
            gw.AddRoom(r2.Id, r2);

            gw.MovePeggyToRoom(r1);
            Assert.Equal(r1.Id, gw.Peggy.CurrentRoom.Id);

            string res = gw.MovePeggy("north");

            Assert.Equal(r2.Id, gw.Peggy.CurrentRoom.Id);
            Assert.Equal($"Moved to the {r2.FriendlyName}.\r\n", res);
        }