U E D R , A S I H C RSS

데블스캠프2005/월요일/번지점프를했다

Higher Level Language

{{|
from bun import *

# 빌딩의 건설
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)

# Character
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



 
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:00
Processing time 0.0100 sec