面向对象写的小游戏,欢迎玩耍
程序员文章站
2022-03-26 12:30:22
面向对象写的小游戏 欢迎玩耍 ......
面向对象写的小游戏
欢迎玩耍
class omnicience: camp = 'omniscience' def __init__(self, name, atk=100, hp=1000, mp=500, power=500, lever=1, atk_growth=2.0, hp_growth=1.9, mp_growth=1.2, power_growth=1.3, money=1000 ): self.name = name self.atk = atk * atk_growth ** lever self.hp = hp * hp_growth ** lever self.mp = mp * mp_growth ** lever self.power = power * power_growth ** lever self.lever = lever self.money = money def attack(self, enemy): # 普通攻击技能,enemy是敌人; damage_value = self.atk - enemy.power*0.05 # 根据自己的攻击力,攻击敌人就减掉敌人的生命值。 enemy.hp -= damage_value def sword(self, enemy): self.mp -= 200 enemy.hp -= 300 * self.lever class offscum: camp = 'offscum' def __init__(self, name, atk=100, hp=1000, mp=500, power=500, lever=1, atk_growth=1.3, hp_growth=1.6, mp_growth=1.2, power_growth=2.0, money=1000 ): self.name = name self.atk = atk * atk_growth ** lever self.hp = hp * hp_growth ** lever self.mp = mp * mp_growth ** lever self.power = power * power_growth ** lever self.lever = lever self.money = money def attack(self, enemy): # 普通攻击技能,enemy是敌人; damage_value = self.atk - enemy.power*0.05 # 根据自己的攻击力,攻击敌人就减掉敌人的生命值。 enemy.hp -= damage_value def xianglong_zhang(self, enemy): self.mp -= 200 enemy.hp -= 200 * self.lever class critters: camp = 'critters' def __init__(self, name, atk=10, hp=100, mp=50, power=50, lever=1, atk_growth=1.3, hp_growth=1.6, mp_growth=1.2, power_growth=2.0, money=100): self.name = name self.atk = atk * atk_growth ** lever self.hp = hp * hp_growth ** lever self.mp = mp * mp_growth ** lever self.power = power * power_growth ** lever self.lever = lever self.money = money def attack(self, enemy): # 普通攻击技能,enemy是敌人; damage_value = self.atk - enemy.power # 根据自己的攻击力,攻击敌人就减掉敌人的生命值。 enemy.hp -= damage_value def xianglong_zhang(self, enemy): self.mp -= 20 enemy.hp -= 20 * self.lever class dagger: def __init__(self, name='dagger', price=475, atk=9, hp=100, lever=10): self.name = name self.price = price self.atk = atk self.hp = hp self.lever = lever def update(self, obj): if obj.lever >= self.lever and obj.money >= self.price: obj.money -= self.price # 减钱 obj.atk += self.atk # 加攻击 obj.hp += self.hp # 加生命值 import random import time p_1 = omnicience('ywy') boos = offscum('wq',lever=random.randint(1,10)) npc = critters('nick') equipment = dagger() while true: print(f'name:{p_1.name}') print(f'lever:{p_1.lever}') print(f'money:{p_1.money}') print(f'hp:{p_1.hp}') print(f'mp:{p_1.mp}') print(f'atk:{p_1.atk}') print(f'power:{p_1.power}') print('旅行中..........') time.sleep(random.random()*10) meet = random.choice(('boos', 'npc', 'equipment')) if meet == 'boos': print('boos出现了') print(f'name:{boos.name}') print(f'lever:{boos.lever}') print(f'money:{boos.money}') print(f'hp:{boos.hp}') print(f'mp:{boos.mp}') print(f'atk:{boos.atk}') print(f'power:{boos.power}') while boos.hp > 0 and p_1.hp > 0: print('请选择') p_1_chiose = input('普通攻击,六脉神剑\n') if p_1_chiose == '普通攻击': p_1.attack(boos) print(f'{p_1.name}使用了{p_1_chiose}攻击了boos') print(f'boos剩余{boos.hp}hp') boos_chiose = random.choice(('普通攻击','降龙十八掌')) print(boos_chiose) if boos.hp <= 0: print('boos临死也不放过你') if boos_chiose == '普通攻击': boos.attack(p_1) print(f'{boos.name}使用了{boos_chiose}攻击了{p_1.name}') print(f'你剩余{p_1.hp}hp') elif boos_chiose == '降龙十八掌': if boos.mp >= 200: boos.xianglong_zhang(p_1) print(f'{boos.name}使用了{boos_chiose}攻击了{p_1.name}') print(f'你剩余{p_1.hp}hp') else: print(f'*boos{boos.name}没有蓝没法使用{boos_chiose}你躲过一劫') print(f'你剩余{p_1.hp}hp') elif p_1_chiose == '六脉神剑': if p_1.mp >= 200: p_1.sword(boos) print(f'boos剩余{boos.hp}hp') if boos.hp <= 0: print('boos临死也不放过你') boos_chiose = random.choice(('普通攻击','降龙十八掌')) if boos_chiose == '普通攻击': boos.attack(p_1) print(f'{boos.name}使用了{boos_chiose}攻击了{p_1.name}') print(f'你剩余{p_1.hp}hp') elif boos_chiose == '降龙十八掌': if boos.mp >= 200: boos.xianglong_zhang(p_1) print(f'{boos.name}使用了{boos_chiose}攻击了{p_1.name}') print(f'你剩余{p_1.hp}hp') else: print(f'*boos{boos.name}没有蓝没法使用{boos_chiose}你躲过一劫') print(f'你剩余{p_1.hp}hp') else: print('蓝不够') continue if p_1.hp <= 0 and boos.hp <= 0: print('你和boos同归于尽了') break elif p_1.hp <= 0: print('你死了boos赢了') break elif boos.hp <= 0: print('恭喜你通过了') break if meet == 'npc': print('npc出现了') print(f'name:{npc.name}') print(f'lever:{npc.lever}') print(f'money:{npc.money}') print(f'hp:{npc.hp}') print(f'mp:{npc.mp}') print(f'atk:{npc.atk}') print(f'power:{npc.power}') while npc.hp > 0 and p_1.hp > 0: print('请选择') p_1_chiose = input('普通攻击,六脉神剑\n') if p_1_chiose == '普通攻击': p_1.attack(npc) print(f'{p_1.name}使用了{p_1_chiose}攻击了npc') print(f'npc剩余{npc.hp}hp') if npc.hp <=0: print('nike临死也不放过你') npc_chiose = random.choice(('普通攻击','鲤鱼打滚')) if npc_chiose == '普通攻击': npc.attack(p_1) print(f'{npc.name}使用了{npc_chiose}攻击了{p_1.name}') print(f'你剩余{p_1.hp}hp') elif npc_chiose == '鲤鱼打滚': if npc.mp >= 200: npc.xianglong_zhang(p_1) print(f'{npc.name}使用了{npc_chiose}攻击了{p_1.name}') print(f'你剩余{p_1.hp}hp') else: print(f'*npc{npc.name}没有蓝没法使用{npc_chiose}你躲过一劫') print(f'你剩余{p_1.hp}hp') elif p_1_chiose == '六脉神剑': if p_1.mp >= 200: p_1.sword(npc) print(f'npc剩余{npc.hp}hp') if npc.hp <= 0: print('nike临死也不放过你') npc_chiose = random.choice(('普通攻击','鲤鱼打滚')) if npc_chiose == '普通攻击': npc.attack(p_1) print(f'{npc}使用了{npc_chiose}攻击了{p_1.name}') print(f'你剩余{p_1.hp}hp') if npc_chiose == '鲤鱼打滚': if npc.mp >= 200: npc.xianglong_zhang(p_1) print(f'{npc}使用了{npc_chiose}攻击了{p_1.name}') print(f'你剩余{p_1.hp}hp') else: print(f'*npc{npc.name}没有蓝没法使用{npc_chiose}你躲过一劫') print(f'你剩余{p_1.hp}hp') else: print('蓝不够') continue if p_1.hp <= 0 and npc.hp <= 0: print('你和npc同归于尽了') break elif p_1.hp <= 0: print('你死了npc赢了') break elif npc.hp <= 0: print('你打死了npc') print('升级1级') p_1.lever += 1 npc.lever = random.randint(1,100) p_1 = omnicience('ywy',lever=p_1.lever) npc = critters('nick',lever=npc.lever) elif meet == 'equipment': if p_1.lever >= equipment.lever and p_1.money >= equipment.price: print('碰到装备装备成功') else: print('等级不够或者钱不够你与装备有缘无分')
推荐阅读
-
用面向对象的方法写选项卡功能
-
用面向对象的方法写选项卡功能
-
面向对象写的小游戏,欢迎玩耍
-
超级玛丽 Super Mario java基础小游戏:基于JAVA面向对象实现的超级马里奥(Super Mario)游戏(简单小游戏,仅仅使用Java面向对象基础实现(附上源码))
-
基于面向对象实现:猫抓老鼠小游戏 有一只猫和一只老鼠,当猫的体重是小于老鼠体重的5倍时,猫可以抓到老鼠。
-
面向对象实现简单版的超级马里奥小游戏
-
写自已的js类库需要的核心代码_js面向对象
-
写自已的js类库需要的核心代码_js面向对象
-
手把手教你自己写一个js表单验证框架的方法_js面向对象
-
AppBaseJs 类库 网上常用的javascript函数及其他js类库写的_js面向对象