#!/usr/bin/env python3
import random
import os
#注册
def zhuce():
print("*******请注册英雄游戏用户*******")
a = input("注册名:")
b = input("密码:")
c = input("确认密码:")
while True:
if b == c:
meiu[a] = b
print("注册成功!\n返回主菜单")
break
else:
print("输入的密码不一致,请重新输入密码")
print("注册名:",a)
b = input("密码:")
c = input("确认密码:")
#登录
def denglu():
print("*******欢迎登录系统*******")
m = input("请输入用户名:")
n = input("请输入密码:")
while True:
if m in meiu:
if n == meiu['admin']:
print("恭喜您,登录成功!您是超级管理员用户")
yxguanli()
elif n == meiu[m]:
print("恭喜您,登录成功!您是普通用户")
print("------------------------------------------")
yxduijue()
else:
print("密码错误!请重新输入!")
print("请输入用户名:",m)
n = input("请输入密码:")
else:
print("用户不存在!请重新输入!")
m = input("请输入用户名:")
n = input("请输入密码:")
#英雄管理系统
def yxguanli():
while True:
print("*******欢迎来到英雄管理系统*******")
print("1.查看英雄")
print("2.添加英雄")
print("3.修改英雄")
print("4.删除英雄")
print("5.返回主菜单")
k = input("请选择:")
if k == '1':
for i in L:
print(i.names(),i.xueliang(),i.fangfa())
elif k == '2':
f1 = input("请输入新英雄名字:")
f2 = input("请输入新英雄血量:")
f3 = input("请输入新英雄技能:")
f1 = yingxiong(f1,f2,f3)
L.append(f1)
elif k == '3':
while True:
w = input("请输入要修改英雄的名字:")
for i in L:
if i.names() == w :
w1 = input("请输入英雄的新血量:")
w2 = input("请输入英雄的新技能:")
i.setxueliang(w1)
i.setfangfa(w2)
print(i.names(),"血量:",i.xueliang(),"技能:",i.fangfa())
print("修改成功")
break
else:
print("输入有误,请重新输入")
break
elif k == '4':
while True:
w = input("请输入要删除英雄的名字:")
for i in L:
if i.names() == w :
L.remove(i)
print("删除成功")
break
else:
print("输入有误,请重新输入")
break
elif k == '5':
yxduijue()
#英雄对决菜单
def yxduijue():
while True:
print("*******欢迎来到英雄对决*******")
print("1.选择英雄")
print("2.开始对决")
print("3.退出游戏")
q = input("请选择:")
if q == '1':
while True:
print("*******英雄列表*******")
for x in range(len(L)):
print(str(x+1)+"."+str(L[x].names()))
i = int(input("请输入英雄:"))
print("您选择的英雄是:",L[i-1].names()," 技能是:",L[i-1].fangfa())
o = random.randint(0,len(L)-1)
print("电脑选择的是:",L[o].names()," 技能是:",L[o].fangfa())
a = input("输入0返回菜单:")
if a == '0':
break
elif q == '2':
print("*******开始游戏*******")
print(" ",L[i-1].names(),"VS",L[o].names())
b2 = int(L[i-1].xueliang())
b1 = int(L[o].xueliang())
while True:
a1 = random.randint(200,500)
print(L[i-1].names(),":",L[i-1].fangfa(),L[o].names()+"掉血",a1)
b1 -= a1
print(L[o].names(),"剩余血量:",b1)
if b1 < 0:
print("结果:",L[o].names()+"战败")
print("你赢了")
break
a2 = random.randint(200,500)
print(L[o].names(),":",L[o].fangfa(),L[i-1].names()+"掉血",a2)
b2 -= a2
print(L[i-1].names(),"剩余血量:",b2)
if b2 < 0:
print("结果:",L[i-1].names()+"战败")
print("你输了")
break
elif q == '3':
os._exit(1)
#创建英雄的类
class yingxiong:
def __init__(self,name,xue,jineng):
self.name = name
self.xue = xue
self.jineng = jineng
def names(self):
return self.name
def xueliang(self):
return self.xue
def setxueliang(self,setx):
self.xue = setx
def setfangfa(self,setf):
self.jineng = setf
def fangfa(self):
return self.jineng
# def __repr__(self):
# return self.names()+self.fangfa()
daji = yingxiong("妲己",'1000',"妖法")
zhouyu = yingxiong("周瑜",'1000',"智力")
zwji = yingxiong("张无忌",'1000',"乾坤大挪移")
lqshui = yingxiong("李秋水",'1000',"冰魄银针")
yanguo = yingxiong("杨过",'1000',"黯然销魂掌")
l = [daji,zhouyu,zwji,lqshui,yanguo]
L = []#存放英雄信息的列表
for i in l:
L.append(i)
#存放注册用户和管理员的信息字典
meiu = {'admin':'123456'}
#主菜单
def main():
while True:
print("*******欢迎来到游戏世界*******")
print(" 1.注册")
print(" 2.登录")
print(" 3.退出")
n = input("请选择:")
if n == '1':
zhuce()
elif n == '2':
denglu()
elif n == '3':
break
if __name__ == "__main__":
main()
接上一条博文,英雄对战小程序,自己写的代码,还没有优化,不喜误喷
最新推荐文章于 2022-05-09 16:53:06 发布