一个关于小甲鱼的游戏
这个游戏需要easygui模块哈游戏中,你就是小甲鱼,你可以睡觉,吃东西,工作,玩游戏,学Python
但如果你没钱了,很累了,没吃的了,就会。。。
不知道能不能过审嘿嘿嘿
上代码:
# 曲速飞跃作
# 开始前请先设置小甲鱼!
from tkinter import *
import random
import easygui as g
# 加载tkinter模块,easygui模块和random。
fen = []# 分数为0
food = # 食物为3
lei = # 疲惫值是2
xing =
money =
time =
def sleep():
fen.append(1)
lei.remove(1)
time.remove(1)
time.remove(1)
var.set("困了困了,睡了。。。疲惫值为" + str(len(lei)) + ",现在分数为:" + str(len(fen)))
if len(lei) == 5:
g.msgbox("小甲鱼被累死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
elif len(money) <= 1:
g.msgbox("小甲鱼被穷死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
elif len(food) <= 1:
g.msgbox("小甲鱼被饿死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
elif len(time) <= 1:
g.msgbox("小甲鱼被老死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
def eat():
fen.append(1)
if len(food) >= 1:
food.remove(1)
else:
money.remove(1)
var.set("吃货的梦想就是天天吃(*^▽^*),食物有" + str(len(food)) + " 还有" + str(len(money)) + "元。现在分数为:" + str(len(fen)))
if len(lei) == 5:
g.msgbox("小甲鱼被累死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
elif len(money) <= 1:
g.msgbox("小甲鱼被穷死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
elif len(food) <= 1:
g.msgbox("小甲鱼被饿死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
elif len(time) <= 1:
g.msgbox("小甲鱼被老死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
def work():
fen.append(1)
lei.append(1)
food.remove(1)
l = random.randint(0, 2)
if l == 0:
var.set("走,搬砖去喽!哎呀,老板心情不好,才给0元。气死我啦!现在分数为:" + str(len(fen)))
elif l == 1:
money.append(1)
var.set("走,搬砖去喽!555,居然才给1元。真抠门!现在分数为:" + str(len(fen)) + " ,还有" + str(len(money)) + "元")
elif l == 2:
money.append(1)
money.append(1)
var.set("走,搬砖去喽!给了我2元?……还行。现在分数为:" + str(len(fen)) + " ,还有" + str(len(money)) + "元")
elif len(lei) == 5:
g.msgbox("小甲鱼被累死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
elif len(money) <= 1:
g.msgbox("小甲鱼被穷死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
elif len(food) <= 1:
g.msgbox("小甲鱼被饿死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
elif len(time) <= 1:
g.msgbox("小甲鱼被老死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
def study():
lei.append(1)
fen.append(1)
fen.append(1)
money.remove(1)
var.set("互谅的广大盆友们,大家好!我是小甲鱼。欢迎大家和我一起入门学习拍森……现在分数为:" + str(len(fen)) + " ,还有" + str(len(money)) + "元")
if len(lei) == 5:
g.msgbox("小甲鱼被累死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
elif len(money) <= 1:
g.msgbox("小甲鱼被穷死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
elif len(food) <= 1:
g.msgbox("小甲鱼被饿死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
elif len(time) <= 1:
g.msgbox("小甲鱼被老死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
def play():
xing.append(1)
var.set("好开森好开森!我居然是小甲鱼心里的蛔虫!不就是8这个数嘛,嘿嘿嘿……")
if len(lei) == 5:
g.msgbox("小甲鱼被累死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
elif len(money) <= 1:
g.msgbox("小甲鱼被穷死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
elif len(food) <= 1:
g.msgbox("小甲鱼被饿死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
elif len(time) <= 1:
g.msgbox("小甲鱼被老死了。。。")
with open('fen.txt', 'a+') as f:
f.write(str(len(fen)))
f.write('\r\n')
exit(0)
while True:# 主循环
msg = "小甲鱼游戏1.0"
title = "little turtle"
choices = ["开始游戏", "游戏规则", "历史成绩", "设置小甲鱼", "退出"]
choices = g.choicebox(msg, title, choices)
if choices == "开始游戏":
root = Tk()
zhuye = Frame(root)
go = Frame(root)
var = StringVar()
var.set("我是小甲鱼!你要干嘛?现在我好饱,有3点食物,疲惫值为2,只有3块钱,能活5岁。。。现在分数为:0")
textLabel = Label(zhuye, textvariable=var)
textLabel.pack(side=LEFT)
a = open("UI.txt")
b = a.read()
c = int(b)
if c == 1:
photo = PhotoImage(file="小甲鱼.GIF")
imgLabel = Label(root, image=photo)
imgLabel.pack(side=RIGHT)
else:
photo = PhotoImage(file="小甲鱼2.GIF")
imgLabel = Label(root, image=photo)
imgLabel.pack(side=RIGHT)
sleep = Button(zhuye, text="睡觉", command=sleep)
sleep.pack()
eat = Button(zhuye, text="吃饭", command=eat)
eat.pack()
work = Button(zhuye, text="上班", command=work)
work.pack()
study = Button(zhuye, text="学习Python", command=study)
study.pack()
play = Button(zhuye, text="玩游戏", command=play)
play.pack()
zhuye.pack(padx=200, pady=170)
go.pack(padx=10, pady=10)
mainloop()
elif choices == "游戏规则":
msg = "游戏规则"
title = "小甲鱼"
choices = ["游戏设定", "主页功能"]
c = g.choicebox(msg, title, choices)
if c == "游戏设定":
g.msgbox("小甲鱼现在由你来控制。设定如下:\n1.点击按钮来控制小甲鱼做什么\n2.如果寿命、疲惫、食物、金钱其一达到了最低值或最高值,游戏结束。")
else:
g.msgbox("点击“开始游戏”即可开始,点击“历史记录”查看历史记录,您还可以设置小甲鱼。")
elif choices == "历史成绩":
a = open('fen.txt')
b = a.read()
g.msgbox(b)
elif choices == "设置小甲鱼":
msg = "小甲鱼?"
title = "设置"
choices = ["1号", "2号"]
choices = g.choicebox(msg, title, choices)
if choices == "1号":
with open('UI.txt', 'w') as f:
f.write("1")
g.msgbox("设置成功!")
else:
with open('UI.txt', 'w') as f:
f.write("2")
g.msgbox("设置成功!")
elif choices == "退出":
exit(0)
特别说明:
开始游戏之前请先点击设置小甲鱼
然后请保存:
https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=%E5%B0%8F%E7%94%B2%E9%B1%BC&step_word=&hs=0&pn=69&spn=0&di=84370&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&istype=0&ie=utf-8&oe=utf-8&in=&cl=2&lm=-1&st=undefined&cs=731205992%2C529052797&os=929990285%2C1618266389&simid=3479428112%2C181971222&adpicid=0&lpn=0&ln=1867&fr=&fmq=1596355992973_R&fm=&ic=undefined&s=undefined&hd=undefined&latest=undefined©right=undefined&se=&sme=&tab=0&width=undefined&height=undefined&face=undefined&ist=&jit=&cg=&bdtype=0&oriquery=&objurl=http%3A%2F%2Fimg.jf258.com%2Fi%2F5a1473050153x251796984b27.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3B3udcb_z%26e3Bv54AzdH3Fpw2AzdH3F%25E0%25b8%25bF%25Ec%25BF%25lc%25Em%25lc%25Bn%25Em%25Ac%25Bb%25E0%25B9%25b8ypi5g%25E0%25l8%25ll%25Ec%25l0%25lB%25EE%25lc%25BmAzdH3F&gsm=46&rpstart=0&rpnum=0&islist=&querylist=&force=undefined
https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=%E5%B0%8F%E7%94%B2%E9%B1%BC&step_word=&hs=0&pn=58&spn=0&di=123090&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&istype=0&ie=utf-8&oe=utf-8&in=&cl=2&lm=-1&st=undefined&cs=1160374487%2C2705784626&os=3016038988%2C3457842539&simid=4237201171%2C408656084&adpicid=0&lpn=0&ln=1867&fr=&fmq=1596355992973_R&fm=&ic=undefined&s=undefined&hd=undefined&latest=undefined©right=undefined&se=&sme=&tab=0&width=undefined&height=undefined&face=undefined&ist=&jit=&cg=&bdtype=0&oriquery=&objurl=http%3A%2F%2Fpic3.zhimg.com%2Fv2-fe6c647bc28799b7a99b83666ba89ae9_b.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fzi7wgswg_z%26e3Bziti7_z%26e3Bv54AzdH3FrAzdH3Fn8ac8dd8&gsm=3b&rpstart=0&rpnum=0&islist=&querylist=&force=undefined
命名为小甲鱼.GIF和小甲鱼2.GIF
谢谢! Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\Try_1\甲鱼\甲鱼.py", line 208, in <module>
photo = PhotoImage(file="小甲鱼2.GIF")
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 4061, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\tkinter\__init__.py", line 4006, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file "小甲鱼2.GIF" @曲速飞跃 靳子轩 发表于 2020-8-2 17:50
@曲速飞跃
你好,请确保你保存了我发的图片,且命名为小甲鱼.GIF和小甲鱼2.GIF,并保存在保存代码的位置,谢谢 本帖最后由 靳子轩 于 2020-8-3 19:05 编辑
曲速飞跃 发表于 2020-8-2 19:13
你好,请确保你保存了我发的图片,且命名为小甲鱼.GIF和小甲鱼2.GIF,并保存在保存代码的位置,谢谢
靳子轩 发表于 2020-8-3 19:04
好了吗? 曲速飞跃 发表于 2020-8-4 19:00
好了吗?
没,你都不给我解决方法。
要不把照片和程序以附件的形式发送出来
靳子轩 发表于 2020-8-5 15:06
没,你都不给我解决方法。
要不把照片和程序以附件的形式发送出来
直接改文件后缀没用
你把文件转换成gif就OK了 本帖最后由 xiao-wugui 于 2020-8-29 18:30 编辑
@曲速飞跃
我的也出现了同样的问题Traceback (most recent call last):
File "D:\2345Downloads\g.py", line 208, in <module>
photo = PhotoImage(file="小甲鱼2.GIF")
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 4061, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 4006, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "小甲鱼2.GIF": no such file or directory
冒个泡{:10_280:} @曲速飞跃 曲速飞跃 发表于 2020-8-4 19:00
好了吗?
Hello?
页:
[1]