예제 #1
0
파일: Room.cs 프로젝트: JvJ/CotWM
        /// <summary>
        /// 
        /// </summary>
        /// <param name="m">
        /// A <see cref="Maze"/>
        /// </param>
        /// <param name="rand">
        /// A <see cref="System.Random"/>
        /// </param>
        /// <returns>
        /// A <see cref="Room"/>
        /// </returns>
        public static Room ChambersFromMaze(Maze m, ChamberMap cm, System.Random rand, coords StartPosition, coords EndPosition)
        {
            // LEFTOFF: Here!
            Room ret = new Room(m.Width * Chambers.CHAMBER_WIDTH, m.Height  * Chambers.CHAMBER_HEIGHT);

            for (int x = 0; x < m.Width; x++){
                for (int y = 0; y < m.Height; y++){

                    // Select a random chamber type
                    ChamberType ct;

                    if (new coords(x,y) == EndPosition){
                        ct = ChamberType.TYPE_BOSS;
                    }
                    else{
                        ct = (ChamberType)(rand.Next() % (int)ChamberType.NumElements);
                        if (ct == ChamberType.TYPE_BOSS){
                            ct = ChamberType.TYPE_5;
                        }
                    }

                    cm[x,y] = ct;

                    Room r = Chambers.Rooms(ct).Clone() as Room;

                    switch(m[x,y]){
                    case MazeTileType.SPACE:

                        // Handle the door carving
                        // Left and Right
                        if (x > 0){
                            if (m[x-1,y] == MazeTileType.SPACE){
                                Chambers.LeftDoor(r, TileType.SNOW);
                            }
                        }
                        if (x < m.Width-1){
                            if (m[x+1,y] == MazeTileType.SPACE){
                                Chambers.RightDoor(r, TileType.SNOW);
                            }
                        }
                        // Bottom and Top
                        if (y > 0){
                            if (m[x,y-1] == MazeTileType.SPACE){
                                Chambers.BottomDoor(r, TileType.SNOW);
                            }
                        }
                        if (y < m.Height-1){
                            if (m[x,y+1] == MazeTileType.SPACE){
                                Chambers.TopDoor(r, TileType.SNOW);
                            }
                        }

                        ret.CopyRoom(r, x * Chambers.CHAMBER_WIDTH, y * Chambers.CHAMBER_HEIGHT);
                        break;
                    }

                }
            }

            return ret;
        }
예제 #2
0
파일: Room.cs 프로젝트: JvJ/CotWM
        /// <summary>
        /// Crappy, naive random generation algorithm. 
        /// </summary>
        /// <param name="width">
        /// A <see cref="System.Int32"/>
        /// </param>
        /// <param name="height">
        /// A <see cref="System.Int32"/>
        /// </param>
        /// <param name="numRooms">
        /// A <see cref="System.Int32"/>
        /// </param>
        /// <returns>
        /// A <see cref="Room"/>
        /// </returns>
        public static Room ChambersGen0(int width, int height, int numRooms)
        {
            Room ret = new Room(width, height);
            for (int x = 0; x < width; x++){
                for (int y = 0; y < width; y++){
                    ret.tiles[x,y] = new Tile(TileType.SNOW);
                }
            }

            System.Random r = new System.Random();

            for (int i = 0; i < numRooms; i++){

                // Randomly select the index
                ChamberType cIdx = (ChamberType)(r.Next() % (int)ChamberType.NumElements);

                Room rm = Chambers.Rooms(cIdx);

                int x = r.Next() % width;
                int y = r.Next() % height;

                ret.CopyRoom(rm, x, y);
            }

            return ret;
        }