예제 #1
0
        /// <summary>
        /// Generates the random maze.
        /// </summary>
        /// <param name='length'>
        /// How long should the maze be?
        /// </param>
        public void GenerateRandomMaze(int length)
        {
            // initialize the grid
            rooms = new MazeRoom[length, length];

            // for now just make a straight line and start on the left
            for (int i=0; i<length; i++)
            {
                rooms[i,0] = new MazeRoom();
                rooms[i,0].position.x = i;
                rooms[i,0].position.y = 0;
            }

            // for now just connect all adjacent rooms
            for (int c=0; c<=rooms.GetUpperBound(0); c++)
            {
                for (int r=0; r<=rooms.GetUpperBound(1); r++)
                {
                    if (rooms[c,r] == null) continue;
                    if (c>0)
                        rooms[c,r].SetNeighbor(rooms[c-1,r], Cube.Side.LEFT, MazeRoom.EntryState.Open);
                    if (c<rooms.GetUpperBound(0))
                        rooms[c,r].SetNeighbor(rooms[c+1,r], Cube.Side.RIGHT, MazeRoom.EntryState.Open);
                    if (r>0)
                        rooms[c,r].SetNeighbor(rooms[c,r-1], Cube.Side.BOTTOM, MazeRoom.EntryState.Open);
                    if (r<=rooms.GetUpperBound(1))
                        rooms[c,r].SetNeighbor(rooms[c,r+1], Cube.Side.TOP, MazeRoom.EntryState.Open);
                }
            }
        }
예제 #2
0
 public void MakeMaze(int height, int width)
 {
     //			Log.Debug("making maze");
     rooms = new MazeRoom[height, width];
     for(int y = 0; y<height; y++){
         for(int x = 0; x<width; x++){
             rooms[x,y] = new MazeRoom();
             rooms[x,y].position.x = x;
             rooms[x,y].position.y = y;
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Occupies the specified room.
 /// </summary>
 /// <param name='room'>
 /// Room.
 /// </param>
 public void OccupyRoom(MazeRoom room)
 {
     _currentRoom = room;
     room.occupant = this;
 }
예제 #4
0
 /// <summary>
 /// Sets the neighbor to another room on the specified side.
 /// </summary>
 /// <param name='otherRoom'>
 /// The neighbor room.
 /// </param>
 /// <param name='side'>
 /// The side to which the neighbor room should be attached.
 /// </param>
 /// <param name='connectionState'>
 /// Specifies whether the neighboring room should be open or closed for access.
 /// </param>
 public void SetNeighbor(MazeRoom otherRoom, Cube.Side side, EntryState connectionState)
 {
     this.neighbors[(int)side] = otherRoom;
     this.entryStates[(int)side] = (otherRoom==null)?EntryState.Closed:connectionState;
 }
예제 #5
0
 /// <summary>
 /// Determines whether this instance is neighbor of the specified other.
 /// </summary>
 /// <returns>
 /// <c>true</c> if this instance is neighbor of the specified other; otherwise, <c>false</c>.
 /// </returns>
 /// <param name='other'>
 /// If set to <c>true</c> other.
 /// </param>
 public bool IsNeighborOf(MazeRoom other)
 {
     bool ret = false;
     foreach (MazeRoom room in neighbors)
     {
         if (room == other) ret = true;
     }
     return ret;
 }
예제 #6
0
 /// <summary>
 /// Determines whether this instance is accessible neighbor of the specified other.
 /// </summary>
 /// <returns>
 /// <c>true</c> if this instance is accessible neighbor of the specified other; otherwise, <c>false</c>.
 /// </returns>
 /// <param name='other'>
 /// If set to <c>true</c> other.
 /// </param>
 public bool IsAccessibleNeighborOf(MazeRoom other)
 {
     bool ret = false;
     for (int i=0; i<neighbors.Length; i++)
     {
         if (neighbors[i] == other && entryStates[i] == EntryState.Open) ret = true;
     }
     return ret;
 }
예제 #7
0
파일: Entity.cs 프로젝트: amechtley/Reunion
        /// <summary>
        /// Occupies the specified room.
        /// </summary>
        /// <param name='room'>
        /// Room.
        /// </param>
        public void OccupyRoom(MazeRoom room)
        {
            // leave the current room
            if (currentRoom != null) currentRoom.occupant = null;

            // move into the new room
            currentRoom = room;

            // perform more actions if the new room is not null
            if (room != null)
            {
                // TODO: handle a collision with another entity
                if (room.occupant != null)
                {
                    room.occupant.OccupyRoom(null);
                }

                // set the room's occupant to this entity, if it is not null
                room.occupant = this;
            }
        }