# -*- coding:utf-8 -*-

# 植物大战僵尸 英雄列表   
#植物方:
 #    英雄名                  属性           原型               专属超级能量                     超级能量效果                           
#5绿影侠Green Shadow       猛长 聪明      豌豆射手        精准轰击 Precision Blast         攻击中线,造成 5 点伤害。
#4玫瑰 Rose                智慧 光能      玫瑰            变羊术Goatify                    把力量最高的一只僵尸变为1/1的山羊。
#3土豆仔Spudow             爆花 守卫      土豆地雷      扔土豆Tater Toss                 召唤一株“烫大头”(对自己线上的一只僵尸造成6点伤害)
#2坚果骑士Wall-Knight      守卫 光能      坚果            坚不可摧 Uncrackable              你的英雄在本回合无法受到伤害。抽一张牌。
#1暗夜菇Night Cap          爆花 聪明      大喷菇        膨胀蘑菇膨胀蘑菇Toadstool Takedown 召唤一株毒蘑菇。在它线上对一只僵尸造成2点伤害

#僵尸方:
#     英雄名                     属性         原型             专属超级能量                     超级能量效果                           
#5超尸Super Brainz            有脑 狡猾    普通僵尸     移动攻击(carried away)     效果:指定一个僵尸移动位置,并且进行一次额外攻击。
#4摔跤狂The Smash            健壮猛兽    巨人         震地猛击Slammin'Smackdown  消灭一株4攻以下的植物。
#3不死女巫Immorticia        有脑 猛兽    蝙蝠女巫     魔宠Witch's Familiar       召唤一只僵尸蝙蝠(2/1,两栖,这张牌对植物造成伤害时,抽一张牌)
#2霹雳舞王Electric Boogaloo 猛兽 疯狂   迪斯科僵尸   活力四射Stayin' Alive      对一株植物造成 3 点伤害。为你的英雄治疗 3 点血量。
#1无穷小子Impfinity            狡猾 疯狂    小鬼         三重威胁Triple Threat      在任意两行生成2攻击1生命的分身小鬼克隆体。能力:两栖。

from random import randint
from sys import exit

class Sence(object):
    def __init__(self):
        pass
    #    self.location = location     ,location, zombie
    #    self.zombie = zombie     
        
    def Greeting(self,location,zombie):
        #self.location = location
        #self.zombie = zombie
        #location = 'discotheque'
        #zombie = 'Electric Boogaloo'
        
        print "Welcome to %s! You all will be eatten by %s and burried here! Haw-haw!" % (location, zombie)
        print "What's the exclusive energy of the %s?" % zombie
        print "A: 'Super Brainz', B: 'Stayin' Alive', C: 'Witch's Familiar', D: 'Slammin'Smackdown' and E: 'carried away'."      
        zombie_energy = raw_input("-->")
        print "Which hero will you choose to destroy the %s?" % zombie
        print "No.1 Night Cap, No.2 Wall-Knight, No.3 Spudow, N0.4 Rose and No.5 Green Shadow."
        hero_no = raw_input("-->")       
        print "Which super power will you choost to match your hero?"
        print "#1 'Toadstool Takedown', #2 'Uncrackable', #3 'Tater Toss', #4 'Goatify', #5 'Precision Blast'."
        plant_power = raw_input("-->")
        
        #print "\n"      #怎么会输出两行回车???待解答
        return zombie_energy, hero_no, plant_power    #此行作用是返回变量值,可在其它Sence类中使用(否则需在Scene类中定义,且与此处值无关)

class Engine(object):     
    def __init__(self,the_room):
        self.the_room = the_room
        
    def play(self):
    
        #print "Welcome to %s! You all will be eatten by %s and burried here! Haw-haw!" % (location, zombie)
        print "You are the plant family: Night Cap, Wall-Knight, Spudow, Rose and Green Shadow."
        print "Your super power are 'Toadstool Takedown', 'Uncrackable', 'Tater Toss', 'Goatify', 'Precision Blast'."
        print "Your opponents are the zombie family: Impfinity, Electric Boogaloo, Immorticia, The Smash and Super Brainz."
        print "They have the exclusive energy of 'Super Brainz', 'Stayin' Alive', 'Witch's Familiar', 'Slammin'Smackdown' and 'carried away'."                    
        print "Your plant family will have a war with the zombie family. Now you are under the castle wall of zombie.\n"
        
        while True:
            current_room = the_map.this_scene(self.the_room)          #返回当前场景 类名
            self.the_room = current_room.enter()                      #返回下一场景 名
            #next_room = self.this_scene(current_room)

class Cemetery(Sence):
    #location =  'cemetery'
    #zombie = 'Impfinity'
    #Location1.Greeting()      NameError: name 'Location1' is not defined   不能在类名称后引用函数/方法,只能在实例(变量)后引用
    #aa = Sence('cemetery','Impfinity')
    #aa.Greeting()
    
    def enter(self):   
        password = '%s%s%s'  % (randint(1,9), randint(1,9), randint(1,9))       #变量为3位字符串组成的数字,而非整数
        ## password = '%s%s%s'  % randint(1,9)*3    ----> TypeError: not enough arguments for format string
        #如果写成整形变量  password = randint(1,9)+10*randint(1,9)+100*randint(1,9) 则必须输入整数,
                #     否则会报错--->ValueError: invalid literal for int() with base 10: ''     
        print password        #为了验证程序,print出口令
        
        i = 0
        while i<10:
            cc = raw_input("please input the password to enter the zombie realm!-->")     #字符串变量        
           #如果password直接写成整形变量,则对应的 cc = int(raw_input(……))    此时必须输入整数,输入空字符串(>>   )时会报错
            if cc == password:               #将字符串转变为整形变量
                print "Oh! You are so smart!\n"
                break                                
            i = i+1

if i == 10 and cc != password:
            print "Oh! You have chosen the wrong password! You die!\n"       #\n 不要写成/n       
            exit(1)                  #此处写exit()或 exit(1) 有何区别??-----------返回值不同,如何查看??待学习
        
        #zombie_energy = ''       #line48 Engine类的3个变量已传入此处,否则这3个变量值都为'',if语句永远无法正确执行
        #hero_no = ''
        #plant_power = ''     
        
        aa = Sence()      
        zombie_energy, hero_no, plant_power = aa.Greeting('Cemetery','Impfinity')    #此行很重要,否则3个变量不会被传递Scene()中输入的值
        ###aa.Greeting('cemetery','Impfinity')           NameError: global name 'zombie_energy' is not defined
                
        if zombie_energy == 'A' and hero_no == 'No.1' and plant_power == '#1':
        #if zombie_energy == '' and hero_no == '' and plant_power == '':       
            print "The Impfinity moves rapidly then uses 'Triple Threat' and turns into 3 bodies to attack the Night Cap, "
            print "but the Night Cap summons 'Toadstool Takedown' and become a expansion rapidly to against and defect it."
            print "The Impfinity converts back one body then drop dead and become a skull on the Cemetery!\n"
            print "^-^  "*10,  "\n \n"
            return 'discotheque'
        else:
            return 'death'

class Discotheque(Sence):
    #def __init__(self):
        #Sence.__init__(self)
    #location =  'discotheque'
    #zombie = 'Electric Boogaloo'
   #Location1.Greeting()      NameError: name 'Location1' is not defined   不能在类名称后引用函数/方法,只能在实例(变量)后引用
    def enter(self):   
            
        #aa = Sence('discotheque','Electric Boogaloo')
        aa = Sence()
        #location = 'discotheque'
        #zombie = 'Electric Boogaloo'
        zombie_energy, hero_no, plant_power = aa.Greeting('Discotheque','Electric Boogaloo')
        
        if zombie_energy == 'B' and hero_no == 'No.2' and plant_power == '#2':        
            print "The Electric Boogaloo becomes crazy with earsplitting disco music and uses 'Stayin' Alive' to attack the Wall-Knight, "
            print "but the Wall-Knight exerts 'Uncrackable' and get a golden shinging body armor to against and defect it."
            print "The Electric Boogaloo dances slower and slower then drops dead and become a pile of bone ash on the Discotheque!\n"
            print "^-^  "*10,  "\n \n"
            return 'bat_cave'
        else:
            return 'death'
        
        
        
        
#pp = Discotheque()  
#pp.enter()
     
   
class BatCave(Sence):
    def enter(self):

aa = Sence()      
        zombie_energy, hero_no, plant_power = aa.Greeting('Bat-cave','Immorticia')
        
        if zombie_energy == 'C' and hero_no == 'No.3' and plant_power == '#3':
            print "The Immorticia bawls and squals then uses 'Witch's Familiar' to summon a zombie bats to attack the Spudow, "
            print "but the Spudow exerts 'Tater Toss' and throw out a large formidable landmines to against and defect it."
            print "The Immorticia let out an ear-piercing scream then drop dead and become a huge black bat on the Bat-cave!\n"   
            print "^-^  "*10,  "\n \n"             
            return 'rifter'
        else:
            return 'death'

class Rifter(Sence):
    def enter(self):    
            
        aa = Sence()      
        zombie_energy, hero_no, plant_power = aa.Greeting('Rifter','The Smash')
        
        if zombie_energy == 'D' and hero_no == 'No.4' and plant_power == '#4':
            print "The Smash appears with tremendous steps and uses 'Slammin'Smackdown' to attack the Rose, "
            print "but the Rose summon 'Goatify' and emits boundless sunshine to against and defect it."
            print "The Smash stops step and becomes a hyaline ice goat as the same size as it before on the Rifter!\n"  
            print "^-^  "*10,  "\n \n"          
            return 'ruins'
        else:
            return 'death'    
    
class Ruins(Sence):
    def enter(self):

aa = Sence()      
        zombie_energy, hero_no, plant_power = aa.Greeting('Ruins','Super Brainz')
        
        if zombie_energy == 'E' and hero_no == 'No.5' and plant_power == '#5':
            #continue           ###SyntaxError: 'continue' not properly in loop  只能用在循环里面
            print "The Super Brainz uses 'carried away' to combine a stream of zombies and itself to a huge Skeleton to attack the Green Shadow, "
            print "but the Green Shadow exerts 'Precision Blast' and fire repeating magic pea bullets to against and defect it."
            print "The huge Skeleton cannot move and summon more zombies again, it become a puff of dark smoke then fade from the Ruins!\n"
            print "^-^  "*10,  "\n \n"             
        else:
            return 'death'    
        
        keyword = randint(1,9)                                                #整形变量
        print keyword                           #为了验证程序,print出口令keyword
        cc = int(raw_input("please input the password that to escape the zombie realm!-->") )   ##必须输入整数
        if cc == keyword:                   
            print "Oh! I believe you are smart enough!\n"
            return 'win'
        else:            
            return 'death'   
            
            
class Death(Sence):
    def enter(self):
        print "What a pity! Your hero plant have not enough powerful to defeat the zombie family! You die!\n"
        print "~"*20
        exit(1)
    
class Win(Sence):
    def enter(self):
        print "Wow! Your hero plant are so powerful that you win the game! You are the SUPER HERO!\n"
        print "----------************----------\n"
        exit(1)

class Map(object):
    dict = {'cemetery': Cemetery(),
            'discotheque': Discotheque(),
            'bat_cave': BatCave(),    
            'rifter': Rifter(),
            'ruins': Ruins(),
            'death': Death(),
            'win': Win()
            }
        
    #def Opening_scene(self):    
        #return Map().next_scene(self.start_scene)
        
    def this_scene(self,scene_name):           #
        #dd = Current_scene.enter()
        return Map.dict.get(scene_name)        #返回传入字符串对应的场景 类名
 
the_map = Map()
the_engine = Engine('cemetery')
the_engine.play()

Learn Python The Hard Way (python 2.7) ex45.py 你来制作一个游戏相关推荐

  1. linux打包运行python文件_Linux下安装pyinstaller用于将py文件打包生成一个可执行文件...

    安装使用流程 1. 首先给系统装个easy_install, 如果装了的可以跳过这步 到pypi官方网址 https://pypi.python.org/pypi/setuptools 去downlo ...

  2. python 如果没有该key值置为空_如何制作一个python字典,为字典中缺少的键返回键,而不是引发KeyError?...

    恭喜你 您也已经发现了标准dict类型. 如果那可执行的中间代码有气味像您一样冒犯了您的敏感,这是您的幸运StackOverflow日. 多亏了3参数的禁忌奇迹dict的变体内置的,精心设计的无用默认 ...

  3. 怎样制作一个 Python Egg

    from:http://liluo.org/blog/2012/08/how-to-create-python-egg/ 制作打包一个 Python Egg 并部署整个过程还蛮有意思的,下面小教程(这 ...

  4. python计算器教程,用Python程序制作一个简单的计算器

    用Python程序制作一个简单的计算器 在此示例中,您将学习创建一个简单的计算器,该计算器可以根据用户的输入进行加,减,乘或除. 要理解此示例,您应该了解以下Python编程主题: 通过函数创建简单计 ...

  5. python中文怎么读-python的读法

    广告关闭 2017年12月,云+社区对外发布,从最开始的技术博客到现在拥有多个社区产品.未来,我们一起乘风破浪,创造无限可能. 程序员,在其他人眼中往往都是高冷的存在,在他们的眼中能用代码解决的问题绝 ...

  6. python制作小游戏教程_12岁的少年教你用Python做小游戏

    你有没有想过电脑游戏是怎样制作出来的?其实它没有你想象的那样复杂! 在这个教程里,你要学做一个叫<兔子和獾>的塔防游戏,兔子作为英雄,需要在城堡里抵御獾的进攻. 为了写这个游戏的代码,你将 ...

  7. java python算法_用Python,Java和C ++示例解释的排序算法

    java python算法 什么是排序算法? (What is a Sorting Algorithm?) Sorting algorithms are a set of instructions t ...

  8. python第三方库排行-Python常用第三方库总结

    网络爬虫 网络请求 requests: Requests allows you to send HTTP/1.1 requests extremely easily. 一个处理http请求的客户端库, ...

  9. python可以制作网站吗_小白如何入门Python? 制作一个网站为例

    首先最重要的问题是为什么要学习python?这个问题这个将指导你如何学习Python和学习的方式. 以你最终想制作一个网站为例.从一个通用的学习资源列表开始不仅会消磨你的激情,而且你获得的知识很难应用 ...

  10. python程序生成exe_使用Python程序生成QR代码的Python程序

    python程序生成exe QR code is a short form of the quick response code. It is a type of matrix barcode tha ...

最新文章

  1. 空的宏定义作用及常见用法
  2. 倒数日怎么设置起始日_起始价131亿!杭州江河汇流区85万方综合体招标延期
  3. Linux解决find /run/user/1000/gvfs
  4. preparedStatement问号的深入理解
  5. python中exp_python中的exp是什么
  6. 车纷享:基于阿里云HBase构建车联网平台实践
  7. C# 替换桌面背景图片
  8. linux下内存调试工具——valgrind
  9. Tomcat安装与配置教程(图文教学)
  10. 从SHAttered事件谈安全
  11. USRP X310 Windows烧录
  12. 人工智能初识,百度AI
  13. 造梦无双服务器维护12月17日,《造梦无双》12月31日V0.82版本更新公告:迎战北王,寻斗天君...
  14. 最好的java代码编辑器_推荐 5 款牛逼的代码编辑器
  15. wim工具扫描linux磁盘,[V1.30.2011.501版]WimTool -- Wim文件的图形视窗处理工具[无忧首发]...
  16. Android 微信h5支付
  17. 便签文档储存位置在哪?便签保存在哪个文件夹,怎么在文件管理找到
  18. oracle 用Sqlplus连接的时候中文出现乱码“?胧淙胗没?”的解决方案
  19. 关于信息论中熵、相对熵、条件熵、互信息、典型集的一些思考
  20. 数据不平衡问题解决方法——欠采样

热门文章

  1. 【Go实战基础】程序里面数据是如何显示到浏览器当中的
  2. 计算机服务器加载失败,win10系统打开windows Media player听歌提示“服务器运行失败”的详细步骤...
  3. 听说掌握这些利器,运维就能运筹帷幄
  4. 小程序实现保存图片到手机
  5. cs1.6一直连接服务器,CS1.6连接不上服务器解决办法
  6. 央行发布2020年规章制定计划 涉及个人金融信息保护、征信业务
  7. 服务器主板重装系统,简单几步教你如何重新安装系统
  8. 考勤统计表sql 某个项目在某个月的考勤统计
  9. 冉宝的每日一题-8月15日-- 拓扑排序。
  10. [HR面试] 65个最常见的面试问题与技巧性答复