示例#1
0
        public void Move()
        {
            if (myLocation is RoomWithDoor)
            {
                if (random.Next(2) == 1) // go through door?
                {
                    RoomWithDoor nextLocation = myLocation as RoomWithDoor;
                    myLocation = nextLocation.DoorLocation;
                }
            }

            do
            {
                myLocation = myLocation.Exits[random.Next(myLocation.Exits.Length)]; // go through a random exit
            } while (!(myLocation is IHidingPlace));                                 // repeat if no hiding place
        }
示例#2
0
        private void createObjects()
        {
            livingRoom = new RoomWithDoor("Living Room", "an antique carpet", "an oak door with a brass knob", "behind the coat rack");
            kitchen = new RoomWithDoor("Kitchen", "a wood cook stove", "a screen door", "inside the refrigerator");
            diningRoom = new Room("Dining Room", "a cherry dining table with high-back chairs");
            frontYard = new OutsideWithDoor("Front Yard", "an oak door with a brass knob", true);
            backYard = new OutsideWithDoor("Back Yard", "a screen door", false);
            garden = new OutsideWithHidingPlace("Garden", false, "inside the shed");
            stairway = new Room("Stairway", "a wooden banister");
            upstairsHallway = new RoomWithHidingPlace("Upstairs Hallway", "a picture of a dog", "inside the closet");
            masterBedroom = new RoomWithHidingPlace("Master Bedroom", "a large bed", "under the bed");
            secondBedroom = new RoomWithHidingPlace("Second Bedroom", "a small bed", "under the bed");
            bathroom = new RoomWithHidingPlace("Bathroom", "a sink and a smelly unflushed toilet", "in the shower");
            driveway = new OutsideWithHidingPlace("Driveway", true, "inside the garage");

            // Set outside doors
            livingRoom.DoorLocation = frontYard;
            kitchen.DoorLocation = backYard;
            backYard.DoorLocation = kitchen;
            frontYard.DoorLocation = livingRoom;

            // set exits -- attaches rooms together
            livingRoom.Exits = new Location[] { frontYard, diningRoom, stairway };
            kitchen.Exits = new Location[] { backYard, diningRoom };
            diningRoom.Exits = new Location[] { livingRoom, kitchen };
            frontYard.Exits = new Location[] { livingRoom, backYard, garden, driveway };
            backYard.Exits = new Location[] { kitchen, frontYard, garden, driveway };
            garden.Exits = new Location[] { frontYard, backYard };
            stairway.Exits = new Location[] { livingRoom, upstairsHallway };
            upstairsHallway.Exits = new Location[] { stairway, masterBedroom, secondBedroom, bathroom };
            masterBedroom.Exits = new Location[] { upstairsHallway };
            secondBedroom.Exits = new Location[] { upstairsHallway };
            bathroom.Exits = new Location[] { upstairsHallway };
            driveway.Exits = new Location[] { frontYard, backYard };


            //moveToANewLocation(frontYard);  // start in front yard
        }
示例#3
0
        private void createObjects()
        {
            livingRoom      = new RoomWithDoor("Living Room", "an antique carpet", "an oak door with a brass knob", "behind the coat rack");
            kitchen         = new RoomWithDoor("Kitchen", "a wood cook stove", "a screen door", "inside the refrigerator");
            diningRoom      = new Room("Dining Room", "a cherry dining table with high-back chairs");
            frontYard       = new OutsideWithDoor("Front Yard", "an oak door with a brass knob", true);
            backYard        = new OutsideWithDoor("Back Yard", "a screen door", false);
            garden          = new OutsideWithHidingPlace("Garden", false, "inside the shed");
            stairway        = new Room("Stairway", "a wooden banister");
            upstairsHallway = new RoomWithHidingPlace("Upstairs Hallway", "a picture of a dog", "inside the closet");
            masterBedroom   = new RoomWithHidingPlace("Master Bedroom", "a large bed", "under the bed");
            secondBedroom   = new RoomWithHidingPlace("Second Bedroom", "a small bed", "under the bed");
            bathroom        = new RoomWithHidingPlace("Bathroom", "a sink and a smelly unflushed toilet", "in the shower");
            driveway        = new OutsideWithHidingPlace("Driveway", true, "inside the garage");

            // Set outside doors
            livingRoom.DoorLocation = frontYard;
            kitchen.DoorLocation    = backYard;
            backYard.DoorLocation   = kitchen;
            frontYard.DoorLocation  = livingRoom;

            // set exits -- attaches rooms together
            livingRoom.Exits      = new Location[] { frontYard, diningRoom, stairway };
            kitchen.Exits         = new Location[] { backYard, diningRoom };
            diningRoom.Exits      = new Location[] { livingRoom, kitchen };
            frontYard.Exits       = new Location[] { livingRoom, backYard, garden, driveway };
            backYard.Exits        = new Location[] { kitchen, frontYard, garden, driveway };
            garden.Exits          = new Location[] { frontYard, backYard };
            stairway.Exits        = new Location[] { livingRoom, upstairsHallway };
            upstairsHallway.Exits = new Location[] { stairway, masterBedroom, secondBedroom, bathroom };
            masterBedroom.Exits   = new Location[] { upstairsHallway };
            secondBedroom.Exits   = new Location[] { upstairsHallway };
            bathroom.Exits        = new Location[] { upstairsHallway };
            driveway.Exits        = new Location[] { frontYard, backYard };


            //moveToANewLocation(frontYard);  // start in front yard
        }