예제 #1
0
        public void CloseDoor(int x, int y, Directions.Direction direction)
        {
            string dir = direction.ToString().Substring(0, 1);
            string key = Rooms[x, y].ToString();

            key         = key.Replace(dir, "");
            Rooms[x, y] = RoomDictionary.GetRoom(key);
        }
예제 #2
0
        public bool OpenDoor(int x, int y, Directions.Direction direction)
        {
            bool mazeEnds = false;

            string dir = "";

            switch (direction)
            {
            case Directions.Direction.North:
                dir = "N";
                break;

            case Directions.Direction.East:
                dir = "E";
                break;

            case Directions.Direction.South:
                dir = "S";
                break;

            case Directions.Direction.West:
                dir = "W";
                break;
            }
            //string dir = direction.ToString().Substring(0, 1);
            Rooms[x, y] = RoomDictionary.GetRoom(Rooms[x, y].ToString() + dir);

            try
            {
                switch (direction)
                {
                case Directions.Direction.North:
                    y = y - 1;
                    if (y < 0)
                    {
                        mazeEnds = true;
                        break;
                    }
                    if (Rooms[x, y] == null)
                    {
                        Rooms[x, y] = RoomDictionary.GetRoom("");
                        OpenDoor(x, y, Directions.Direction.South);
                    }
                    break;

                case Directions.Direction.South:
                    y = y + 1;
                    if (y >= Rooms.GetLength(1))
                    {
                        mazeEnds = true;
                        break;
                    }
                    if (Rooms[x, y] == null)
                    {
                        Rooms[x, y] = RoomDictionary.GetRoom("");
                        OpenDoor(x, y, Directions.Direction.North);
                    }

                    break;

                case Directions.Direction.East:
                    x = x + 1;
                    if (x >= Rooms.GetLength(0))
                    {
                        mazeEnds = true;
                        break;
                    }
                    if (Rooms[x, y] == null)
                    {
                        Rooms[x, y] = RoomDictionary.GetRoom("");
                        OpenDoor(x, y, Directions.Direction.West);
                    }
                    break;

                case Directions.Direction.West:
                    x = x - 1;
                    if (x < 0)
                    {
                        mazeEnds = true;
                        break;
                    }

                    if (Rooms[x, y] == null)
                    {
                        Rooms[x, y] = RoomDictionary.GetRoom("");
                        OpenDoor(x, y, Directions.Direction.East);
                    }
                    break;
                }
            }
            //catch the expection that will occur when the maze ends (goes out of bounds)
            catch (Exception ex)
            {
                mazeEnds = true;
            }

            return(mazeEnds);
        }