~cpp # -*- coding: UTF-8 -*- class Building: def __init__(self, name, numFloors): self.name = name self.numFloors = numFloors self.connectedComponent = {} def floors(self, floorNames): self.floors = [] for name in floorNames : self.floors.append(Floor(name, buildingName)) def __str__(self): return self.name def connectBuilding(self, direction, building): self.connectedComponent[direction] = building def floor(self, roomID): return self.floors[roomID] class Floor: def __init__(self, floorName, buildingName): self.name = floorName self.buildingName = buildingName def buildRooms(self, roomNames): self.roomGrid = [] for roomTup in roomNames: rooms = [] for name in roomTup: rooms.append(Room(name)) self.roomGrid.append(rooms) def __str__(self): return self.name class Room: def __init__(self, roomName, floorName): self.roomName = roomName self.floorName = floorName self.connectedComponent = {} def connectRoom(self, room, direction): self.connectedComponent[direction] = room class Character: def __init__(self, name, currentPosition): self.currentPosition = currentPosition self.name = name self.tellPosition() def __str__(self): return self.name def move(self, direction, step): for i in range(0, step): if self.currentPosition.connectedComponent.has_key(direction) : self.currentPosition = self.currentPosition.connectedComponent[direction] else: return '갈 수 없습니다' self.tellPosition() def tellPosition(self): print '현재 당신의 위치는 %s 입니다' % self.currentPosition