Higher Level Language ¶
{{|
from bun import *
from bun import *
# 빌딩
bobst = Building("대", 7)
bobst.floors(("1","2","3","4","5","6","7"))
bobst.floor(1).buildRooms((("","복","1-2"),
bobst.floor(1).room(2,2).connectRoom(bobst.floor(2).room(2,2),"up") #
bobst.floor(2).room(2,2).connectRoom(bobst.floor(1).room(2,2),"down") #
bobst = Building("대", 7)
bobst.floors(("1","2","3","4","5","6","7"))
bobst.floor(1).buildRooms((("","복","1-2"),
("1-1","복","1-3"),
("","","복"))
# 방 방 ("","","복"))
bobst.floor(1).room(2,2).connectRoom(bobst.floor(2).room(2,2),"up") #
bobst.floor(2).room(2,2).connectRoom(bobst.floor(1).room(2,2),"down") #
# 물 물
playground = Building("동", 1)
playground.connectBuilding("north", bobst)
bobst.connectBuilding("south", playground)
playground.connectBuilding("north", bobst)
bobst.connectBuilding("south", playground)
# Character
bok = Character("",playground)
bok.move("north", 2)
bok.move("up", 3)
bok.position() # tell current position
bok = Character("",playground)
bok.move("north", 2)
bok.move("up", 3)
bok.position() # tell current position
|}}
Code (with dynamic typing, w/o string parsing ) ¶
~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