交作业,lsp体验青春版
本帖最后由 新人求上岸 于 2021-8-2 16:47 编辑import easygui as eg
import pickle
import random
#登录
def register():
def go():
global start,instant_1
while 1:
msg = "登录中,请输入用户名和密码"
title ="galgame"
choices = ["用户名","密码"]
des_1=eg.multpasswordbox(msg,title,choices)
try:
if user_account_password] != des_1:
des_2=eg.buttonbox("用户名或密码错误","galgame",["注册","返回"])
if des_2=="注册":
eg.msgbox("加载中....")
wait()
break
else:
continue
else:
instant_1 =des_1
start = True
break
except KeyError:
des_2=eg.buttonbox("用户名不存在","galgame",["注册","返回"])
if des_2=="注册":
eg.msgbox("加载中....")
wait()
else:
continue
def wait():
while 1:
msg = "注册中,请输入用户名和密码"
title ="galgame"
choices = ["用户名","密码"]
des_1=eg.multpasswordbox(msg,title,choices)
if des_1 in user_account_password:
des_2=eg.buttonbox("用户名已存在","galgame",["登录","返回"])
if des_2=="登录":
go()
break
else:
continue
else:
user_account_password]=des_1
break
def cancel():
while 1:
msg = "请输入需要注销的用户名和密码"
title ="galgame"
choices = ["用户名","密码"]
des_1=eg.multpasswordbox(msg,title,choices)
try:
if des_1==des_1:
user_account_password.pop(des_1)
break
else:
eg.msgbox("输入的用户名或密码错误","galgame",ok_button="返回")
continue
except KeyError:
eg.msgbox("用户名不存在","galgame",ok_button="返回")
continue
def save():
with open("user_account_password.pkl","wb") as pickle_file:
pickle.dump(user_account_password,pickle_file)
try:
with open("user_account_password.pkl","rb") as pickle_file:
user_account_password = pickle.load(pickle_file)
except FileNotFoundError:
with open("user_account_password.pkl","wb") as pickle_file:
my_list ={}
pickle.dump(my_list,pickle_file)
with open("user_account_password.pkl","rb") as pickle_file:
user_account_password = pickle.load(pickle_file)
global start
start =False
while 1:
msg="欢迎体验小游戏"
title="galgame"
choices = ["登录","注册","注销","退出"]
decision = eg.buttonbox(msg,title,choices)
if decision=="登录":
go()
save()
break
elif decision=="注册":
wait()
save()
continue
elif decision=="注销":
cancel()
save()
continue
else:
print("感谢游玩")
break
#=================================================
#存档
def cundang():
while 1:
global P,Protagonist_name
try:
with open("name-instant_1.pkl","rb") as file:
my_list=pickle.load(file)
Protagonist_name =my_list
with open(Protagonist_name+".pkl","rb") as file:
P =Protagonist()
P.data =pickle.load(file)
break
except (FileNotFoundError,KeyError):
Protagonist_name=eg.enterbox("初次登录,请输入昵称","galgame")
try:
with open("name-instant_1.pkl","rb") as file:
my_list =pickle.load(file)
my_list.setdefault(instant_1,name)
with open("name-instant_1.pkl","wb") as file:
pickle.dump(my_list,file)
except FileNotFoundError:
with open("name-instant_1.pkl","wb") as file:
my_list ={}
my_list=Protagonist_name
pickle.dump(my_list,file)
with open(Protagonist_name+".pkl","wb") as file:
P =Protagonist()
pickle.dump(P.data,file)
#基本定义
class Women:
patience=0
def look_at_her(self):
print("看着我干嘛,我脸上有什么东西吗?")
def hand(self):
print("QAQ,嘻嘻~~")
self.patience+=1
def ass(self):
print("变态,哼,不理你了")
self.patience-=1
def legs(self):
print("0_0 ,你想干嘛?")
class Protagonist:
data={"背包":{},"技能":{},"money":1000,"属性":{"HP":100,"Endurance":200,"IQ":105,"EQ":100,"strenth":15},"技能树":{}}
def sleep(self):
self.data["属性"]["HP"]=100
self.data["属性"]["Endurance"]=100
#============================================
#人物内容
class Yangyan(Women):
patience=10
def __init__(self):
print("佯妍:啦啦啦啦啦,QAQ,老公,你终于来找我了")
def hug(self):
print("佯妍:不行...除非..你亲我一下")
self.des_1=eg.buttonbox("亲..还是不亲呢?","galgame",["亲",'不亲'])
if self.des_1=="亲":
print("佯妍:嗯~ o* ̄▽ ̄*o")
print("佯妍:芜湖,起飞")
self.patience +=1
else:
print("佯妍:还嫌弃我?哼!!!")
self.patience -=1
def face(self):
print("佯妍:不要,疼死了(推开你的手),哼~~(嘟起嘴)")
self.patience +=1
def make_love(self):
if self.patience >=20:
print("佯妍:好..好吧,我..我(脸红),能..不能")
eg.msgbox("这时,你主动上前,抱住她,然后.....")
else:
print("佯妍:这样不好吧,姐姐们都在看着呢")
def ass(self):
if self.patience >= 15:
print("佯妍:讨厌,你..你不许再这样做,不然..我叫晓瑜来打你!")
else:
super().ass()
self.patience +=1
def legs(self):
if self.patience >=15:
print("佯妍:不许摸!!!(脸红)")
else:
super().legs()
self.patience +=1
def play(self):
print("佯妍:好呀好呀,要玩什么呢?")
self.game_name=["猜拳","接诗词","不玩了"]
des_1=eg.choicebox("玩什么呢?","galgame",self.game_name)
if des_1=="猜拳":
print("佯妍:石头剪刀...")
while 1:
secret=random.choice()#1为石头,2为剪刀,3为布
des_2=eg.buttonbox("要出什么呢?","galgame",["石头","剪刀","布","不玩了"])
if des_2=="石头":
self.patience +=1
if secret ==2:
print("佯妍:呜呜,你赢了")
elif secret ==3:
print("佯妍:哈哈哈,虽然你很优秀,但猜拳我可是王者!")
else:
print("佯妍:emmm,你运气好而已,再来")
elif des_2=="剪刀":
self.patience +=1
if secret ==3:
print("佯妍:呜呜,你赢了")
elif secret ==1:
print("佯妍:哈哈哈,虽然你很优秀,但猜拳我可是王者!")
else:
print("佯妍:emmm,你运气好而已,再来")
elif des_2=="布":
self.patience +=1
if secret ==1:
print("佯妍:呜呜,你赢了")
elif secret ==2:
print("佯妍:哈哈哈,虽然你很优秀,但猜拳我可是王者!")
else:
print("佯妍:emmm,你运气好而已,再来")
else:
print("佯妍:~好吧~")
break
elif des_1=="接诗词":
print("嗯~~,小心一点哦")
poem_dict={"桃李不言":"下自成蹊","慎终如始":"则无败事","善者不辨,辩者不善":"知者不博,博者不知","心若没有栖息的地方":"到哪里都是在流浪","既然钟情于玫瑰":"就勇敢地吐露真诚","既然选择了远方":"便只顾风雨兼程","艰难方显勇毅":"磨砺始得玉成","人生若只如初见":"何事悲风秋画扇","肠断月明红豆寇":"月似当时,人似当时否","真人之心如珍在渊":"常人之心如瓢在水","凡是过往":"皆为序章","志之所趋,无远勿届,穷山距海,不能限也":"志之所向,无坚不入,锐兵精甲,不能御也"}
while 1:
choice =random.choice(list(poem_dict.keys()))
print("佯妍:"+choice)
your_answer=input("你思考了一下,回答(退出请输入\'不玩了\'):")
if choice=="既然钟情于玫瑰" and poem_dict==your_answer:
print("佯妍:是真的吗?")
eg.msgbox("她的眼睛像天山白雪一样清澈,注视着你","galgame",ok_button="")
eg.msgbox("你知道心中有什么东西正在融化","galgame",ok_button="")
eg.enterbox("于是你说:","galgame")
print("她对你的回答笑而不语,只是脸上已升起了一朵红晕")
elif choice=="肠断月明红豆寇" and poem_dict==your_answer:
print("佯妍:我们会像纳兰容若那样么...")
eg.msgbox("她望向窗外,弱柳扶风,细雨沥沥")
eg.enterbox("于是你说:","galgame")
eg.msgbox("她梨花带雨,与你相拥",ok_button="嗯,别怕")
elif poem_dict==your_answer:
self.patience +=1
print("佯妍:Bingo,答对了!")
print("佯妍:不要骄傲哦")
else:
self.patience +=1
print("佯妍:哈哈,你错了")
print("佯妍:正确答案是:"+poem_dict)
if your_answer =="不玩了":
print("佯妍:~好吧~")
break
else:
print("佯妍:QAQ,我还想玩")
#================================================
#场景
def gym():
eg.msgbox("正在赶往健身房....","galgame",ok_button="")
P.data["属性"]["Endurance"]-=5
eg.msgbox("健身房终于到了...","galgame",ok_button="")
luck =random.randint(1,1024)
if luck == 159:
des_1=eg.buttonbox("一只宽大的手掌拍了拍你的后背\n\'兄弟兄弟,办卡不(现在办卡可享受6折优惠)\'","galgame",["办它","当我伞兵?"])
if des_1=="办它":
P.data["money"] -=18
try:
P.data['背包']["健身卡"]+=12
except KeyError:
P.data["背包"].setdefault("健身卡",12)
else:
pass
while 1:
des_2=eg.choicebox("要做什么呢?","galgame",["前台","健身","离开"])
if des_2=="前台":
print("前台小姐姐:欢迎光临,有什么可以帮你的?")
while 1:
des_3=eg.buttonbox("(要做什么呢?)","galgame",["办卡","买饮料","没事,我随便逛逛.."])
if des_3=="办卡":
P.data["money"] -=30
print("前台小姐姐:办理成功!(money-30)")
try:
P.data['背包']["健身卡"]+=12
except KeyError:
P.data["背包"].setdefault("健身卡",12)
elif des_3=="买饮料":
print("前台小姐姐:我们的饮料应有尽有,随便挑")
des_4=eg.choicebox(title="galgame",choices=["可口可乐","果粒橙","安慕希","蒙牛","伊利","椰子汁","雪碧","农夫山泉"])
if des_4 in ["可口可乐","雪碧","果粒橙","椰子汁"]:
P.data["属性"]["Endurance"]+=20
P.data["money"]-=10
eg.msgbox("一股清凉顺颈而入,你感觉你又行了(体力+20,钱包-10)","galgame")
elif des_4 in ["安慕希","伊利","蒙牛"]:
P.data["属性"]["Endurance"]+=30
P.data["money"]-=15
eg.msgbox("好喝,但又不完全好喝,只能加加体力(体力+30,钱包-15)","galgame")
else:
P.data["属性"]["Endurance"]+=10
P.data["money"]-=5
eg.msgbox("喝起来没什么感觉,就是心疼而已(体力+10,钱包-5)","galgame")
else:
break
elif des_2=="健身":
if "健身卡" in P.data['背包'] and P.data['背包']["健身卡"] >0:
print("功能未完善(我不知道健身房里有什么...........)")
else:
print("某比你强壮的工作人员:想白嫖?我看你是想请刘关张在你口里结义")
else:
break
des_5=eg.choicebox("接下来要去哪呢?","galgame",["回家","关外","武器店"])
if des_5=="回家":
home()
elif des_5=="关外":#
pass
else:
pass
def feild():#想设置成打怪场所的,但是我太懒了哈哈哈哈
eg.msgbox("正在赶往关外...","galgame")
eg.msgbox("")
def home():
while 1:
eg.msgbox("你回家了","galgame")
choices=["佯妍","出门","睡觉","退出(自动保存)"]
des_1=eg.choicebox("要做什么呢?","galgame",choices)
if des_1=="佯妍":
interaction_1()
elif des_1=="出门":
places =["健身房","武器店","关外","返回"]
des_2=eg.choicebox("要去哪里呢?","galgame",places)
if des_2=="健身房":
gym()
elif des_2=="关外":
feild()
elif des_1=="睡觉":
print("一只羊,两只羊....慢慢地,你进入了梦乡")
P.sleep()
print(P.data)
elif des_1=="退出(自动保存)":#目前只有这里可以保存
with open(Protagonist_name+".pkl","wb") as file:
pickle.dump(P.data,file)
break
#互动
def interaction_1():
H = Yangyan()
while 1:
des_2=eg.choicebox("","galgame",["交谈","看着她","牵手","摸屁股","摸腿","抱抱","掐脸","玩","做爱","结束"])
if des_2=="交谈":
conversation =["杏花春雨江南,琴棋书画问雅,炊烟流水人家,渔樵耕种烟火。无论阳春白雪,抑或下里巴人,诗词都有所概括,不会拒人于千里之外","常将有日思无日,莫待无时思有时","带我出去玩出去玩出去玩!!!","你是无意穿堂风,偏偏孤倨引山洪","莫听穿林打叶声,何妨吟啸且徐行"]
print("佯妍:"+random.choice(conversation))
elif des_2=="看着她":
H.look_at_her()
elif des_2=="牵手":
H.hand()
elif des_2=="摸屁股":
H.ass()
elif des_2=="摸腿":
H.legs()
elif des_2=="抱抱":
H.hug()
elif des_2=="掐脸":
H.face()
elif des_2=="玩":
H.play()
elif des_2=="做爱":
H.make_love()
else:
print("佯妍:再见了,老公^_^")
break
#==================================================
register()
if start:
eg.msgbox("登录成功","galgame")
cundang()
home()
cancel键不要点哦,不知道怎么去掉 0.0 ,有没有大佬指点一下 这是什么问题? xxm8023 发表于 2021-8-2 15:54
这是什么问题?
try:
with open("user_account_password.pkl","rb") as pickle_file:
user_account_password = pickle.load(pickle_file)
except FileNotFoundError:
with open("user_account_password.pkl","wb") as pickle_file:#就是这一行出了问题
my_list ={}
pickle.dump(my_list,pickle_file)
with open("user_account_password.pkl","rb") as pickle_file:
user_account_password = pickle.load(pickle_file)while 1:
global P,Protagonist_name
try:
with open("name-instant_1.pkl","rb") as file:
my_list=pickle.load(file)
Protagonist_name =my_list
with open(Protagonist_name+".pkl","rb") as file:
P =Protagonist()
P.data =pickle.load(file)
break
except (FileNotFoundError,KeyError):
Protagonist_name=eg.enterbox("初次登录,请输入昵称","galgame")
try:
with open("name-instant_1.pkl","rb") as file:
my_list =pickle.load(file)
my_list.setdefault(instant_1,name)
with open("name-instant_1.pkl","wb") as file:
pickle.dump(my_list,file)
except FileNotFoundError:
with open("name-instant_1.pkl","wb") as file:
my_list ={}
my_list=Protagonist_name#还有这行也出了问题
pickle.dump(my_list,file)
with open(Protagonist_name+".pkl","wb") as file:
P =Protagonist()
pickle.dump(P.data,file) xxm8023 发表于 2021-8-2 15:54
这是什么问题?
兄弟,抱歉哈,没注意,还不行就把这个Python文件当前目录的user_account_password.pkl,instant_1-name.pkl删一下 {:10_256:}简单看了一遍程序
然后。。。
我被变量名逗乐了 wuqramy 发表于 2021-8-2 23:12
简单看了一遍程序
然后。。。
我被变量名逗乐了
0.0 哈哈,玩了玩,有小甲鱼那味儿了,嘿嘿嘿
厉害 ???
页:
[1]