文字打怪小游戏
来源:互联网 发布:如何开一家淘宝网店 编辑:程序博客网 时间:2024/04/29 03:09
# 文字打怪小游戏class Villain: object = {} # object{}收集“反派” def __init__(self, name, health, describe): self.name = name self.health, self.full_health = health, health # full_health不变,用来比较动态血量 self.describe = describe Villain.object[self.name] = self @property def check_health(self): # 血量动态 if self.health >= .5 * self.full_health: return '{} health is strong'.format(self.name) if .5 * self.full_health > self.health >= .00000000000001: return '{} is weaker'.format(self.name) if self.health <= 0: return 'You killed {}'.format(self.name) @check_health.setter def check_health(self, value): self.health = value def __call__(self, *args, **kwargs): return '{}, {} who had {} health, now has {} health'.format(self.name, self.describe, self.full_health, round(self.health, 5))class Goblin(Villain): def __init__(self): super().__init__('Goblin', 5, 'the thief')class Orge(Villain): def __init__(self): super().__init__('Orge', 12, '格鲁尔之孙')goblin = Goblin()orge = Orge()class FightSkill: # 十八般武艺 def __init__(self, skill_name, power): self.skill_name = skill_name self.skill_power = power @property def power(self): # 技能杀伤力 return self.skill_power def fight(self, noun): # 战斗动态 if noun in Villain.object: Villain.object[noun].health -= self.power if Villain.object[noun].health > 0: return '{}\'s health is {} {} {}'.format(noun, round(Villain.object[noun].health), '-'*5, Villain.object[noun].check_health) else: Villain.object[noun].health = 0 # 定义血量最低为0 return '{}\'s health is {} {} {}'.format(noun, 0, '-'*5, Villain.object[noun].check_health) else: return '{} wrong'.format(self.skill_name.capitalize())class Hit(FightSkill): # 固定掉血1 def __init__(self): super().__init__('hit', 1)class Kik(FightSkill): # 固定掉血2 def __init__(self): super().__init__('kik', 2)class Combo(FightSkill): # 80%掉血 def __init__(self): super().__init__('combo', 0.8) def fight(self, noun): if noun in Villain.object: Villain.object[noun].health *= self.power if Villain.object[noun].health > 0: return '{}\'s health is {} {} {}'.format(noun, round(Villain.object[noun].health), '-'*5, Villain.object[noun].check_health) else: Villain.object[noun].health = 0 return '{}\'s health is {} {} {}'.format(noun, 0, '-'*5, Villain.object[noun].check_health) else: return '{} wrong'.format(self.skill_name.capitalize())hit = Hit().fightkik = Kik().fightcombo = Combo().fightdef say(noun): return 'You said {}'.format(noun)def examine(noun): if noun.capitalize() in Villain.object: return Villain.object[noun.capitalize()]() else: return 'examine no way of {}'.format(noun)verb_dict = {'say': say, 'examine': examine, 'hit': hit, 'kik': kik, 'combo': combo}def get_input(input_words): command = input_words.split() verb_word = command[0] if verb_word in verb_dict: verb = verb_dict[verb_word] else: print('Unknown verb "{}"'.format(verb_word)) return if len(command) >= 2: noun = command[1] print(verb(noun.capitalize())) else: print(verb("nothing"))flag = 1while True: if flag: # 只在游戏开始时执行一次 print('The game begin') flag = 0 input_word = input("Action:") if input_word in['out', 'exit']: # 设置退出条件 print('The game Stop') break else: get_input(input_word)
阅读全文
0 0
- 文字打怪小游戏
- Java打怪小游戏
- html5 canvas 英雄打怪小游戏
- 制作打怪小游戏Kill Bill
- 打蜜蜂小游戏
- Unity打飞机小游戏
- Java打地鼠小游戏
- 打地鼠小游戏展示
- 打字母小游戏
- 猎人打怪兽小游戏
- 打砖块小游戏1.0
- 打地鼠小游戏
- 小游戏 打地鼠
- 打地鼠小游戏
- 破解小游戏<打飞机>
- java打飞机小游戏
- 用C++语言写游戏——打怪小游戏
- JAVA打蜜蜂小游戏源码
- Fiddler接口健壮性测试
- HTML5(十五)
- 疯狂Spring Cloud连载(26)消息代理RabbitMQ框架
- Redis服务停止报错解决方案[NOAUTH Authentication required]
- SpringMVC“Ambiguous mapping found. Cannot map 'XXXController' bean method”解决方法
- 文字打怪小游戏
- 代码片段----重载操作符
- 基础练习 字母图形
- scikit-learn 中文文档-成对的矩阵, 类别和核函数-用户指南|ApacheCN
- 速算+记忆经历
- Makefile 编译动态库文件及链接动态库
- JavaScript基础知识——apply、call、bind
- div的要应用
- 《认知与设计:理解UI设计准则》【PDF】下载