python 面向对象编程 - 小游戏

面向对象写的小游戏

欢迎玩耍

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('等级不够或者钱不够你与装备有缘无分')
上一篇:Dev_GridView:使用PopupContainerControl实现下拉树形列表


下一篇:CentOS 7 关闭防火墙和SELinux