U E D R , A S I H C RSS

데블스캠프2005/월요일/Blue Dragon

청룡을 무찔러 보물찾기


~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 '어디로 갈까요?'

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