ì²ë£¡ì�„ 무찔러 보물찾기
~cpp
# -*- coding: cp949 -*-
import random
class Room:
def __init__(self):
self.place = ['루ì�´ìФ', 'ì²ë£¡íƒ•', '공대', 'í• ë§¤ë�™ì‚°', 'ì •ë¬¸']
class User:
def __init__(self):
self.aRoom = Room()
self.place = 'ì •ë¬¸'
self.hasKey = False
self.name = '�명'
self.hp = 100
self.aDragon = BlueDragon(self)
self.aTrasure = Trasure()
def setName(self, name):
self.name = name
def checkPlace(self):
if self.place == 'ì²ë£¡íƒ•' and not self.aDragon.die:
self.aDragon.attack()
if self.place == 'í• ë§¤ë�™ì‚°':
print '보물��를 발견했습니다.'
if not self.aTrasure.open:
if self.hasKey:
print '보물ìƒ�ìž�를 ì—´ì‡ ë¡œ 엽니다.'
self.aTrasure.open = True
print '축하합니다. 보물� 발견했습니다.'
print '게임� �냅니다.'
else:
print 'ì—´ì‡ ë¥¼ 찾아오세요/'
def move(self):
print self.name, '�',
for room in self.aRoom.place:
if room != self.place:
print room,',',
print '� 갈 수 있습니다.'
place = raw_input("어디로 갈까요?")
self.place = place
print self.name, self.place , '� 들어왔습니다.'
self.checkPlace()
def attack(self):
if self.place != 'ì²ë£¡íƒ•':
return
print 'ì²ë£¡ì�„ 공격합니다.'
self.aDragon.hp -= random.randrange(100)
print 'ì²ë£¡ì�˜ hp는 ', self.aDragon.hp, '입니다.'
if self.aDragon.hp <= 0:
self.aDragon.die = True
print 'ì²ë£¡ì�„ ë¬´ì°”ë €ìŠµë‹ˆë‹¤.'
print 'ì—´ì‡ ë¥¼ ì·¨ë“�했습니다.'
self.hasKey = True
else:
self.aDragon.attack()
class BlueDragon:
def __init__(self, user):
self.name = 'ì²ë£¡'
self.die = False
self.aUser = user
self.hp = 100
def attack(self):
print 'ë‹¹ì‹ ì�„ 물어뜯습니다.'
self.aUser.hp -= random.randrange(100)
print 'ë‹¹ì‹ ì�˜ hp는 ', self.aUser.hp, '입니다.'
if self.aUser.hp <= 0:
print 'ë‹¹ì‹ ì�€ 죽었습니다.'
print 'Game Over'
class Trasure:
def __init__(self):
self.name = '보물��'
self.open = False
if __name__ == '__main__':
print 'ë‹¹ì‹ ì�€ 중앙대 ì •ë¬¸ì—� 서 있습니다.'
print '차가 ì§€ë‚˜ê°€ê³ , 사람ë�„ 지나다닙니다.'
print '어디로 갈까요?'










