之前讲过:基于pygame用python做接小球游戏的小游戏设计但是相比pygame,easygui是python自带的库,无需额外安装
这里将简单制作一个猜拳小游戏
import easygui
# 1.电脑出拳
import random
computer = random.randint(1,3) # 随机整数
# 2.我们出拳
say = easygui.enterbox("你要出啥?")
easygui.msgbox("战斗正在处理中,请稍后---")
try:
say = int(say)
# 3.判断
result = computer - say
# print(result)
if 1 <= say <= 3:
if result == 2 or result == -1:
q = '我们赢了!\n'
elif result == 0:
q = '平局!\n'
elif result == -2 or result == 1:
q = '我们输了!\n'
else:
easygui.msgbox('请不要瞎出!')
if computer ==1:
q = q + "电脑出了石头!\n"
elif computer ==2:
q = q + "电脑出了布!\n"
elif computer == 3:
q = q + "电脑出了剪刀!\n"
if say==1:
q = q + "我们出了石头!\n"
elif say ==2:
q = q + "我们出了布!\n"
elif say == 3:
q = q + "我们出了剪刀!\n"
easygui.msgbox(q)
except:
easygui.msgbox("你在破坏我们的游戏,已报警!")
更多精彩内容