Ejemplo n.º 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);
        }
Ejemplo n.º 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 exception that will occur when the maze ends (goes out of bounds)
            catch
            {
                mazeEnds = true;
            }

            return(mazeEnds);
        }