示例#1
0
        public ActionResult DeleteConfirmed(int id)
        {
            cRoom cRoom = db.cRooms.Find(id);

            db.cRooms.Remove(cRoom);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#2
0
 public ActionResult Edit([Bind(Include = "cRoomID,roomName,studentName,studentEmail,studentPhone,cRoomDate,cRoomDateTo")] cRoom cRoom)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cRoom).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(cRoom));
 }
示例#3
0
        public ActionResult Create([Bind(Include = "cRoomID,roomName,studentName,studentEmail,studentPhone,cRoomDate,cRoomDateTo")] cRoom cRoom)
        {
            if (ModelState.IsValid)
            {
                db.cRooms.Add(cRoom);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cRoom));
        }
示例#4
0
        // GET: cRooms/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            cRoom cRoom = db.cRooms.Find(id);

            if (cRoom == null)
            {
                return(HttpNotFound());
            }
            return(View(cRoom));
        }
    bool CreateCorridorRecursivly(cRoom room)
    {
        ////randomly choose a room
        //cRoom room = roomList[Random.Range(0, roomList.Count - 1)];

        int deltaX, deltaZ;
        int wallX, wallZ;//target wall pos
        switch (Random.Range(1,4)) {
        //randomly choose a direction (for corridor)
        case 1:
            //up
            deltaX = 0;
            deltaZ = 1;
            wallX = Random.Range (room.x + 1, room.x + room.xWidth - 2);
            wallZ = room.z + room.zLength - 1;
            if (_mapInfo[wallX,wallZ] != -1 || _mapInfo[wallX-1,wallZ] != -1 || _mapInfo[wallX+1,wallZ] != -1) {
                return false;
            }
            break;
        case 2:
            //down
            deltaX = 0;
            deltaZ = -1;
            wallX = Random.Range (room.x + 1, room.x + room.xWidth - 2);
            wallZ = room.z;
            if (_mapInfo[wallX,wallZ] != -1 || _mapInfo[wallX-1,wallZ] != -1 || _mapInfo[wallX+1,wallZ] != -1) {
                return false;
            }
            break;
        case 3:
            //left
            deltaX = -1;
            deltaZ = 0;
            wallX = room.x;
            wallZ = Random.Range (room.z + 1, room.z + room.zLength - 2);
            if (_mapInfo[wallX,wallZ] != -1 || _mapInfo[wallX,wallZ-1] != -1 || _mapInfo[wallX,wallZ+1] != -1) {
                return false;
            }
            break;
        case 4:
            //right
            deltaX = 1;
            deltaZ = 0;
            wallX = room.x+room.xWidth-1;
            wallZ = Random.Range (room.z + 1, room.z + room.zLength - 2);
            if (_mapInfo[wallX,wallZ] != -1 || _mapInfo[wallX,wallZ-1] != -1 || _mapInfo[wallX,wallZ+1] != -1) {
                return false;
            }
            break;
        default:
            deltaX = 0;
            deltaZ = 0;
            wallX = 0;
            wallZ = 0;
            Debug.LogError ("Invalid Direction!");
            break;
        }
        int corridorLength = Random.Range (_corridorMinLength, _corridorMaxLength);
        if (!CheckCorridorSpace(
            wallX + deltaX,
            wallZ + deltaZ,
            deltaX,
            deltaZ,
            corridorLength
        )) {
            return false;
        }
        currentMapElemId++;
        currentCorridor = new cCorridor (
            currentMapElemId,
            wallX + deltaX,
            wallZ + deltaZ,
            deltaX,
            deltaZ,
            corridorLength
        );
        _mapInfo [wallX, wallZ] = room.id;//remove wall
        UpdateMapInfo (currentCorridor);
        corridorList.Add (currentCorridor);
        return true;
    }
 void UpdateMapInfo(cRoom room)
 {
     for (int i=room.x; i<room.x+room.xWidth; i++) {
         for (int j=room.z; j<room.z+room.zLength; j++) {
             if (i == room.x ||
                 i == room.x+room.xWidth - 1 ||
                 j == room.z ||
                 j == room.z+room.zLength - 1)
             {
                 _mapInfo[i, j] = -1;
             }
             else
             {
                 _mapInfo[i, j] = room.id;
             }
         }
     }
 }
    void GenerateMap()
    {
        currentMapElemId = 1;
        roomList = new List<cRoom>();
        corridorList = new List<cCorridor> ();

        currentRoom = new cRoom(
            currentMapElemId,
            Random.Range(_mapX / 3, _mapX / 3 * 2),
            Random.Range(_mapZ / 3, _mapZ / 3 * 2),
            Random.Range(_roomMinRange, _roomMaxRange),
            Random.Range(_roomMinRange, _roomMaxRange)
        );

        UpdateMapInfo(currentRoom);
        roomList.Add(currentRoom);
        CreateCorridorRecursivly (currentRoom);

        CreateCorridorRecursivly (currentRoom);
        CreateCorridorRecursivly (currentCorridor);

        for (int n=_expectRoomNum; n>0; n--) {
            cCorridor tmpCorridor = corridorList [Random.Range (0, corridorList.Count - 1)];
            if (tmpCorridor.exitList.Count>0) {
                CreateRoomRecursivly (tmpCorridor);
            }
        }
    }
 bool CreateRoomRecursivly(cCorridor corridor)
 {
     int jointX = corridor.x + corridor.deltaX * (corridor.length+1);//wall length add 1 for wall
     int jointZ = corridor.z + corridor.deltaZ * (corridor.length+1);
     int roomX, roomZ;
     int widthX = Random.Range (_roomMinRange, _roomMaxRange);
     int lengthZ = Random.Range (_roomMinRange, _roomMaxRange);
     if (corridor.deltaX == 0) {
         if (corridor.deltaZ == 1) {
             //joint on room down
             roomX = jointX - Random.Range(1, widthX-2);
             roomZ = jointZ;
         } else {
             //joint on room up
             roomX = jointX - Random.Range(1, widthX-2);
             roomZ = jointZ - lengthZ + 1;
         }
     } else {
         if (corridor.deltaX == 1) {
             //joint on room left
             roomX = jointX;
             roomZ = jointZ - Random.Range (1, lengthZ-2);
         } else {
             //joint on room right
             roomX = jointX - widthX + 1;
             roomZ = jointZ - Random.Range (1, lengthZ-2);
         }
     }
     if (!CheckRoomSpace(
         roomX,
         roomZ,
         widthX,
         lengthZ
     )) {
         return false;
     }
     currentMapElemId++;
     currentRoom = new cRoom(
         currentMapElemId,
         roomX,
         roomZ,
         widthX,
         lengthZ
     );
     UpdateMapInfo(currentRoom);
     roomList.Add(currentRoom);
     _mapInfo [corridor.x + corridor.deltaX * corridor.length, corridor.z + corridor.deltaZ * corridor.length] = corridor.id;
     _mapInfo [jointX, jointZ] = currentRoom.id;
     corridor.exitList.Clear ();
     return true;
 }