随手一做的王者荣耀。。。
沉迷王者两年有余,看到python,便想自己做个。。。。
游戏内容涉及:
1.随机数生成
2.相关模块用法
3.0 1 用法
4.条件判断
5.循环
6.列表
7.单词的记忆
import random
print('*'*40)
print('\t欢迎来到王者荣耀')
print('*'*40)
coins=3000
weapon_list=[]
role1 = [0,"鲁班","后羿","李白","孙尚香","貂蝉","诸葛亮"]#"0"只是用来过下标
while True:role=input('请选择游戏人物:(1.鲁班 2.后羿 3.李白 4.孙尚香 5.貂蝉 6.诸葛亮)')if role == "":print("请输入人物代号")else:print('欢迎!'+str(role1[int(role)])+'来到王者荣耀,当前金币是:{0}'.format(coins))breakwhile True:choice=input('\n请选择:\n 1.购买武器\n 2.打仗\n 3.删除武器\n 4.查看武器\n 5.退出游戏\n')if choice=="1":print('欢迎进入武器库:')weapons=[['暗影战斧',2090],['破军',2950],['破晓',3400],['制裁之刃',1800],['纯净苍穹',2230],['碎星锤',2100]]for weapon in weapons:print(weapon[0],weapon[1],sep=' ')weaponname=input('请输入要购买的武器名称:')if weaponname not in weapon_list:for weapon in weapons:if weaponname == weapon[0]:if coins >= weapon[1]:coins-=weapon[1]weapon_list.append(weapon[0])print('{}购买武器:{}'.format(role,weaponname))breakelse:print('金币不足,赶快挣金币去吧!')breakelse:print('输入武器名称错误')else:print('已经拥有该武器!')elif choice=="2":print('欢迎来到王者荣耀战场')if len(weapon_list)>0:print('{}拥有的武器如下:'.format(role))for weapon in weapon_list:print(weapon)weaponname = input('请选择:')if weaponname in weapon_list:ran1 = random.randint(1,20)ran2 = random.randint(1,20)if ran1>ran2:print('此局对战:张飞胜!!!')elif ran1<ran2:print('此局对战:{}胜'.format(role))coins+=200print('此局对战:{}胜!金币{}'.format(role,coins))else:print('此局平局,可再次对战')else:print('选择的武器不存在,请重新选择')else:print('还没有购买武器,赶快使用金币购买武器去吧')elif choice=="3":print('武器太多啦,快扔掉一点吧.........')if len(weapon_list)>0: print('{}拥有的武器如下:'.format(role))for weapon in weapon_list:print(weapon)while True:weaponname = input('请选择需要删除的武器名称:')if weaponname in weapon_list:weapon_list.remove(weaponname)for weapon in weapons:if weaponname==weapon[0]:coins+=weapon[1]breakbreakelse:print('武器名称输入有误!')else:print('你都没有武器,还干啥......,快购买武器去吧!')elif choice=="4":print('{}拥有的武器如下:'.format(role))for weapon in weapon_list: print(weapon)print('总金币:',coins)elif choice=="5":answer=input('确认要离开王者荣耀游戏吗?(yes/no)')if answer=='yes':print('GAME OVER')breakelif choice=="":print('为什么不选呢?这可是游戏呢!')else:print('输入错误,请重新选择')