|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import random as r
class Maps:
def __init__(self,name = 'x'):
self.shuxing = r.randint(1,2)
self.name = name
self.hp = 1
def get(self):
self.shuxing = r.randint(1,10)
return self.shuxing
class Player:
def __init__(self):
self.hp = 100 #当前生命值
self.maxhp = 100 #最大生命值
self.point = 3 #行动力
self.maxpoint = 3
self.gongjili = 10 #攻击力
self.morengongjili = 10
self.fangyu = 0 #护甲
def attack(self):
self.point -= 1
if self.point <= 0:
self.point = 0
return self.gongjili
def GetPoint(self):
return self.point
def injured(self,value):
if value > self.fangyu :
value = value - self.fangyu
self.fangyu = 0
self.hp = self.hp - value
elif value <= self.fangyu:
self.fangyu = self.fangyu - value
print('你受到了%d点伤害,护甲点剩余%d,生命值剩余%d\n' % (value,self.fangyu,self.hp))
def defense(self):
self.fangyu = self.fangyu + r.randint(self.gongjili - 5,self.gongjili + 5)
self.point -= 1
print('当前防御点数为',self.fangyu)
def shuxing(self):
a = ("当前人物生命值%d,攻击力%d,防御点%d,行动点%d"%(self.hp,self.gongjili,self.fangyu,self.point))
return a
def injured_jineng(self,type_value,value):
if type_value == 1:
self.point -= value
elif type_value == 2:
self.gongjili -= value
def round(self,value = 0):
self.point = self.maxpoint - value
def round_new(self):
self.gongjili = self.morengongjili
self.fangyu = 0
class Monster:
def __init__(self):
self.hp = 100 + r.randint(-20,30)
self.gongjili = 10 +r.randint(-3,10)
self.fangyu = r.randint(0,21)
self.maxhp = 100
def name(self,name):
self.name = name
def attack(self):
return self.gongjili
def injured(self,value):
if value > self.fangyu :
value = value - self.fangyu
self.fangyu = 0
self.hp = self.hp - value
elif value <= self.fangyu:
self.fangyu = self.fangyu - value
if self.hp <0:
self.hp =0
print('怪物被打死了')
print('名字是',self.name,'的怪物受到了 %d 点伤害,护甲剩余 %d 点,生命值剩余 %d ' % (value,self.fangyu,self.hp))
def shuxing(self):
a = ('名字是'+self.name+"的怪物,生命值 %d ,攻击力 %d ,护甲点 %d " % (self.hp,self.gongjili,self.fangyu))
return a
class Boss(Monster):
def jineng(self):
chaos_value = r.randint(1,3)
weak_value = r.randint(2,5)
type_value = r.randint(1,3)
qianghua_value = r.randint(5,10)
if type_value == 1:
print('Boss使用了混乱,你的行动力发生了变化。')
return 1,chaos_value
elif type_value ==2:
print('Boss使用了虚弱,你的攻击力下降了')
return 2,weak_value
elif type_value == 3:
print('Boss使用了强化,他的攻击力提升了!')
self.gongjili += qianghua_value
return 3,3
class Box:
def __init__(self):
self.hp = 1
def open(self):
while self.hp ==1:
choice = input('你遇见了一个宝箱,你可选择:\n1、恢复30%生命值\n2、提升攻击力(随机)\n3、提升最大生命值\n4、提升每回合的行动力\n:')
if choice == '1':
print('恢复了生命值')
self.hp = 0
return 1,0.3
elif choice == '2':
print('提升了攻击力')
self.hp = 0
return 2,r.randint(3,8)
elif choice == '3':
print('提升了最大生命值')
self.hp = 0
return 3,r.randint(5.15)
elif choice == '4':
print('提升了每回合的行动力')
self.hp = 0
return 4,1
else:
print("输入错误,请重新输入")
def name():
lista_z = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
list0_9 = ['1','2','3','4','5','6','7','8','9','0']
random_time = r.randint(5,10)
name_list = []
while random_time >0:
aornum = r.randint(0,1)
if aornum == 0:
name_list.append(r.choice(lista_z))
else:
name_list.append(r.choice(list0_9))
random_time -= 1
rname = ''.join(name_list)
return rname
#初始化,创建人物、生成怪物,生成地图、创造boss。
input('按回车开始游戏')
p =Player()
jishashu = 0
baoxiangshu = 0
shanghailiang = 0
#对象生成
while 1:#创建面对的对象
monsterType = r.randint(1,10)
if 2 < monsterType <= 9:
guaiwu = Monster()
guaiwu.name(name())
elif monsterType > 9 :
guaiwu = Boss()
guaiwu.name(name()+'的Boss级别')
elif monsterType <= 2:
guaiwu = Box()
if type(guaiwu) == Box:
xiaoguo = guaiwu.open()
if xiaoguo[0] == 1:
p.hp = p.hp + int(p.maxhp * xiaoguo[1])
elif xiaoguo[0] == 2:
p.gongjili += xiaoguo[1]
p.morengongjili += xiaoguo[1]
elif xiaoguo[0] == 3:
p.maxhp += xiaoguo[1]
p.hp += xiaoguo[1]
elif xiaoguo[0] == 4:
p.maxpoint += 1
elif type(guaiwu) != Box:
print('你遇见了怪物!',guaiwu.shuxing(),p.shuxing(),sep = '\n')
while p.hp >0 and guaiwu.hp >0 : #先判断主角和怪物是否活着,活着就循环下面的内容
while p.point >0 and p.hp>0 and guaiwu.hp>0 : #再判断现在是主角的行动还是怪物的行动,利用主角的行动力(.point)点数来判断
print('\n请做出选择:\n1、攻击 \n2、防御\n3、查询当前属性值')
xuanze = input('请输入选择:')
if xuanze == '1' :#攻击
guaiwu.injured(p.attack())
print('主角剩余行动力为:',p.GetPoint(),'当行动力为0时怪物会采取行动\n')
shanghailiang += p.gongjili
elif xuanze == '2':#防御
p.defense()
elif xuanze == '3':#查看属性
print(p.shuxing(),guaiwu.shuxing(),sep = '\n')
else:
print('输入错误,请重新输入')
if guaiwu.hp > 0:
print('\n你的行动力用完了!到怪物的回合了!')
if type(guaiwu) == Monster:#判断怪物是不是BOSS
print('怪物攻击了你')
p.injured(guaiwu.attack())
p.round()
input('按回车继续')
elif type(guaiwu) == Boss:
input("怪物正在思考如何对付你。请按回车继续")
input('怪物有想法了,请按回车继续')
a = r.randint(1,2)
if a == 1:
print('\n怪物决定直接攻击你')
p.injured(guaiwu.attack())
p.round()
elif a == 2:
print('\n怪物使用了技能')
type_jineng = guaiwu.jineng()
if type_jineng[0] == 1: #混乱,行动力下降
p.round(type_jineng[1])
elif type_jineng[0] == 2:#虚弱,攻击力下降
p.gongjili -= type_jineng[1]
if p.gongjili <=1:
p.gongjili = 1
print('你的攻击力已经被下降到1点,无法继续降低,慢慢磨吧')
p.round()
elif type_jineng[0] ==3:#提升自身攻击力
p.round()
if p.hp <=0:
print('you died\n你一共杀死了%d个怪物,打开了%d个宝箱,造成了%d点伤害'%(jishashu,baoxiangshu,shanghailiang))
elif guaiwu.hp <= 0 and type(guaiwu) != Box:
print('怪物死了')
jishashu += 1
else:
baoxiangshu += 1
input("按回车继续脸探草丛")
p.round()
希望小甲鱼能玩一下? |
评分
-
查看全部评分
|