Exemple #1
0
 def branchTile(self, generalmap, room):
     (xpos, ypos) = room.getPos()
     (xdim, ydim) = room.getDimensions()
     candidateList = [ ]
     #room.printGrid()
     for i in range(1,xdim-1):
         #print generalmap.getEntry(i+xpos,ypos), room.getGrid(i,0).getFG()
         if generalmap.getEntry(i+xpos,ypos) == const.EWWALL:
             candidateList += [(i+xpos,ypos)]
         #print generalmap.getEntry(i+xpos,ypos+ydim-1), room.getGrid(i,ydim-1).getFG()
         if generalmap.getEntry(i+xpos,ypos+ydim-1) == const.EWWALL:
             candidateList += [(i+xpos,ypos+ydim-1)]
     for i in range(1,ydim-1):
         #print generalmap.getEntry(xpos,i+ypos), room.getGrid(0,i).getFG()
         if generalmap.getEntry(xpos,i+ypos) == const.NSWALL:
             candidateList += [(xpos,i+ypos)]
         #print generalmap.getEntry(xpos+xdim-1,i+ypos), room.getGrid(xdim-1,i).getFG()
         if generalmap.getEntry(xpos+xdim-1,i+ypos) == const.NSWALL:
             candidateList += [(xpos+xdim-1,i+ypos)]
     
     #print candidateList
     cand = choice(candidateList)
     if cand[0] == xpos:
         return (cand, 'w')
     elif cand[0] == xpos+xdim-1:
         return (cand, 'e')
     elif cand[1] == ypos:
         return (cand, 'n')
     elif cand[1] == ypos+ydim-1:
         return (cand, 's')
Exemple #2
0
 def checkNewRoom(self, generalmap, newRoom, tile, dir):
     print tile
     (xpos, ypos) = tile
     (xdim, ydim) = newRoom.getDimensions()
     if xpos + xdim + 1 >= generalmap.DIM or ypos + ydim + 1 >= generalmap.DIM:
         return False
     if xpos - xdim - 1 < 0 or ypos - ydim - 1 < 0:
         return False
     if dir == 'n':
         newRoomPos = ( xpos - xdim/2, (ypos - ydim) )
     elif dir == 's':
         newRoomPos = ( xpos - xdim/2, ypos + 1 )
     elif dir == 'w':
         newRoomPos = ( (xpos - xdim), ypos - ydim/2 )
     elif dir == 'e':
         newRoomPos = ( xpos + 1, ypos - ydim/2 )
     for i in range(newRoomPos[0], newRoomPos[0]+xdim):
         for j in range(newRoomPos[1], newRoomPos[1]+ydim):
             if generalmap.getEntry(i, j) != const.VOID:
                 return False
     newRoom.setPos(newRoomPos)
     return True