本文整理汇总了Python中room.Room类的典型用法代码示例。如果您正苦于以下问题:Python Room类的具体用法?Python Room怎么用?Python Room使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Room类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MyFactory
class MyFactory(ServerFactory):
protocol = Echo
def __init__(self, clients_max=10):
self.clients_max = clients_max
self.clients = []
self.room = Room()
def startSpeaking(self, client):
# 某个客户端开始说话
log.msg("Client start speaking: %s"%hex(id(client)))
self.room.startSpeaking(client)
def speaking(self, content):
log.msg("Client speaking: %d"%len(content))
self.room.speaking(content)
def stopSpeaking(self, client):
# 某个客户端开始说话
log.msg("Client stop speaking: %s"%hex(id(client)))
self.room.stopSpeaking(client)
def addClient(self, client):
self.clients.append(client)
self.room.addClient(client)
def removeClient(self, client):
self.clients.remove(client)
self.room.removeClient(client)
示例2: dig
def dig(self, direction):
room = self.current_room
direction = direction_abbreviations.get(direction, direction)
if direction in room.exits:
print "There is already an exit in that direction"
return
cur_pos = room.pos
vector = direction_vectors[direction]
new_pos = cur_pos+vector
print "Digging %s" % (direction,)
# Find the room in that direction, if any
new_room = self.world.rooms.get(new_pos, None)
if new_room is None:
new_room = Room(underground_terrain, new_pos)
self.world.rooms[new_pos] = room
# Link the two rooms together.
room.exits[direction] = new_room
new_room.exits[opposite_directions[direction]] = room
print "You dig into a new room."
self.current_room = new_room
示例3: loadRooms
def loadRooms(self):
import copy
rooms = self.db.rooms.find()
for i in range(0, rooms.count()): # default is zero
newRoom = Room(self, rooms[i])
print newRoom
print rooms[i]
newRoom.id = rooms[i]['id']
if 'items' in rooms[i]:
for item in rooms[i]['items']:#
newRoom.items.append(copy.deepcopy(self.items[item]))
if 'npcs' in rooms[i]:
for mobile in rooms[i]['npcs']:
m = Mobile(self.mobile_list[mobile]['name'], self, self.mobile_list[mobile])
m.room = newRoom
self.mobiles.append(m)
self.rooms.append(newRoom)
# have to load all the rooms BEFORE loading the exits
for i in range(0, rooms.count()):
exits = rooms[i]['exits']
for e in exits:
exit = exits[e]
target_room = next(room for room in self.rooms if room.id == exit['target'])
direction = exit['direction']
self.rooms[i].exits.append(Exit(direction.lower(), target_room))
示例4: room_create
def room_create(sock, data):
user = User.find_user_by_sock(sock)
target_name = data['details']['new_user']
echo = None
if "echo" in data:
echo = data['echo']
target_resource = user.resource
target_online = User.find_user_by_name(target_name, user.resource) # sock de outro usuario conectado
target_offline = None
if not target_online:
api_mongo.insert_user(target_name, target_resource)
target_offline = target_name
if user == target_online:
info = {"type": "chat", "payload": {"command": "error", "details": "choose_another_less_you"}}
send(user, info)
else:
second_user = None
if target_online:
second_user = target_online.username
if not second_user:
second_user = target_offline
if second_user:
if not Room.check_exist_room([user.username, second_user], user.resource): # se sala nao existe
user_temp = []
for username in [user.username, second_user]:
user_temp.append({"username": username, "seen": None, "received": None})
room_name = Room.open(user_temp, target_resource) # cria a sala e recebe nome unico a sala
new_room = Room.find_room_by_name(room_name) # sock para o nova sala criada
new_room.users_name = user_temp # insert two news name users
new_room.alias = 'DEFAULT' # insert alias
alias = new_room.alias
api_mongo.insert_room(user_temp, room_name, alias, target_resource, False, None)
info = {"type": "chat", "payload": {"command": "room_id",
"alias": new_room.alias,
"room_id": room_name,
"users": user_temp,
"echo": echo,
"is_group": False}}
send(user, info)
else: # se sala ja existe
user_temp = []
for username in [user.username, second_user]:
user_temp.append({"username": username, "seen": None, "received": None})
room_to_append = Room.find_room_by_users([user.username, second_user], user.resource)
room_restore(room_to_append)
new_room = Room.find_room_by_name(room_to_append) # sock para o nova sala criada
info = {"type": "chat", "payload": {"command": "room_id",
"alias": new_room.alias,
"room_id": room_to_append,
"users": user_temp,
"is_group": new_room.is_group}}
send(user, info)
示例5: test_room_paths
def test_room_paths():
center = Room("Center", "Test room in the center.")
north = Room("North", "Test room in the north.")
south = Room("South", "Test room in the south.")
center.add_paths({'north': north, 'south': south})
assert_equal(center.go('north'), north)
assert_equal(center.go('south'), south)
示例6: test_player_move_out_of_bounds
def test_player_move_out_of_bounds(self):
room = Room(game=None, square_size=GRID_SIZE)
room.load_from_file(os.path.join("test-files", "boundaries-test.map"))
self.assertEqual(room.width, 10)
self.assertEqual(room.height, 6)
self.assertFalse(room.player.can_move_to(-1, 0))
self.assertFalse(room.player.can_move_to(10, 0))
self.assertFalse(room.player.can_move_to(0, -1))
self.assertFalse(room.player.can_move_to(0, 6))
示例7: room_rename
def room_rename(sock, data=None):
u = User.find_user_by_sock(sock)
r = Room.find_room_by_name(data['destination'])
r.alias = data['room_rename']
api_mongo.rename_room(data['destination'], data['room_rename'])
list_user = Room.find_users_by_room(data['destination'])
info = {"type": "chat",
"payload": {"command": "room_rename",
"room_id": data['destination'],
"alias": data['room_rename']}}
send_broadcast(list_user, info, u.resource)
示例8: addRoom
def addRoom(self, adjRoom, type, direction=NO_DIR):
# print "Add Room Called"
# assign the room new coords relative to the adjacent room
gridCoord = [0, 0]
# if the new room is to the west of adjRoom
if direction == WEST:
gridCoord[x] = adjRoom.gridCoord[x] - 1
gridCoord[y] = adjRoom.gridCoord[y]
# if the new room is to the north of adjRoom
elif direction == NORTH:
gridCoord[x] = adjRoom.gridCoord[x]
gridCoord[y] = adjRoom.gridCoord[y] - 1
# if the new room is to the east of adjRoom
elif direction == EAST:
gridCoord[x] = adjRoom.gridCoord[x] + 1
gridCoord[y] = adjRoom.gridCoord[y]
# if the new room is to the south of adjRoom
elif direction == SOUTH:
gridCoord[x] = adjRoom.gridCoord[x]
gridCoord[y] = adjRoom.gridCoord[y] + 1
alreadyExists = False
for room in self.rooms:
if room.gridCoord == gridCoord:
alreadyExists = True
if not alreadyExists:
# make the room
newRoom = Room(direction, type, [None, None, None, None], gridCoord)
newRoom.doors[opposite(direction)] = Door(opposite(direction))
adjRoom.doors[direction] = Door(direction)
# update pointers
if direction != NO_DIR:
adjRoom.adjRooms[direction] = newRoom
newRoom.adjRooms[opposite(direction)] = adjRoom
newRoom.roomId = len(Dungeon.floorKeys)
room = r.randint(0, len(self.rooms) - 1)
xPos = r.randint(Room.currentRoom.boundingBox[WEST] + Key.keyImg.width/2,
Room.currentRoom.boundingBox[EAST] - Key.keyImg.width/2)
yPos = r.randint(Room.currentRoom.boundingBox[NORTH] + Key.keyImg.width/2,
Room.currentRoom.boundingBox[SOUTH] - Key.keyImg.width/2)
newKey = Key(xPos, yPos, self.rooms[room])
newRoom.rightKey = newKey
Dungeon.floorKeys.append(newKey)
self.rooms.append(newRoom)
self.linkRooms(newRoom)
return True if not alreadyExists else False
示例9: __init__
def __init__(self):
self.model = Room()
self.view = PrintView()
self.model.attach(self.view)
self.network_listen()
print('Listening to port {}...'.format(self.port))
reactor.run()
示例10: monitor
def monitor(sock, data):
u = User.find_user_by_sock(sock)
print 'command from:', u.username
command = data['command']
room_name = data['destination']
if command == 'users':
li = []
for el in User.users:
if el.username:
li.append([el.username, el.network])
print 'Number users on:', len(li), '---', len(User.users)
for el in li:
print el
if command == 'rooms':
r = Room.find_room_by_name(room_name)
try:
print 'room alias:', r.alias
print 'room users_name:', adapter(r.users_name)
except:
print 'no room'
if command == 'message':
u = User.find_user_by_name('[email protected]', 'dev-socialbase')
info = {"type": "chat", "payload": {"command": "test_user",
"details": str(u)}}
u.connection.write_message(info)
print 'B.sended to ', u.username, info
示例11: __init__
def __init__(self):
cmd.Cmd.__init__(self)
self.loc = Room.get_room(1)
self.loc.print_room()
self.dbfile = tempfile.mktemp()
shutil.copyfile("game.db", self.dbfile)
示例12: move
def move(self, direction):
newroom = self.loc.get_neighbor(direction)
if newroom is None:
print("you can't go this way")
else:
self.loc = Room.get_room(newroom)
self.loc.print_room()
示例13: roomFromShapes
def roomFromShapes(handler):
"""
here's where we actually do the work.
"""
rm = Room()
rm.eggs = []
rm.food = []
rm.ball = False
ff = food.FoodFactory()
#print rects
for r in handler.rects:
r.toGeom(rm)
for a in handler.arcs:
a.toGeom(rm, ff)
if not rm.ball:
rm.ball = ball.Ball(rm)
return rm
示例14: reconnect_rooms
def reconnect_rooms(sock, user):
li = room_list_by_user(sock=None, data={'sender': user}, call=False)
for el in li:
r = Room.find_room_by_name(el['room'])
for u in adapter(r.users_name):
if u == user:
s = User.find_user_by_sock(sock)
s.connection = sock
示例15: __init__
def __init__(self):
Room.__init__(self)
# make the walls (x_pos, y_pos, width, height)
# This is a list of walls. Each is in the form [x, y, width, height]
walls = [[0, 0, 20, 250, WHT],
[0, 350, 20, 250, WHT],
[780, 0, 20, 250, WHT],
[780, 350, 20, 250, WHT],
[20, 0, 760, 20, WHT],
[20, 580, 760, 20, WHT],
[390, 50, 20, 500, BLU]
]
# loop through walls list
for item in walls:
wall = Wall(item[0], item[1], item[2], item[3], item[4])
self.wall_list.add(wall)