python 猜拳游戏easygui

"""
author:魏振东
data:2019.09.27
func:猜拳游戏
"""
import easygui as g
import random
import sys

p_score = 0
c_score = 0

while 1:
    computer = random.choice('石剪布')

    msg = "请选择你要做的手势?"
    title = "猜拳游戏"
    choices = ["石", "剪", "布"]

    choices = g.buttonbox(msg, title,choices)

    if choices == "石" and computer == '剪' or choices == "剪" and computer == '布' or choices == "布" and computer == "石":
        g.msgbox('你赢了!\n'+'你出的是:'+choices+" 电脑出的是:"+computer)
        p_score+=1
    elif choices == computer:
        g.msgbox('平局!')
    elif choices == "石" or choices == "剪" or choices == "布":
        g.msgbox('电脑赢了!\n' + '你出的是:' + choices + " 电脑出的是:" + computer)
        c_score += 1

    msg = "你希望重新开始小游戏吗?"
    if g.ccbox(msg, title):
        pass
    else:
        g.msgbox('游戏退出!\n你的得分为:'+str(p_score)+'分\n电脑得分:'+str(c_score)+'分')
        sys.exit(0)
发布了39 篇原创文章 · 获赞 41 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/wei_zhen_dong/article/details/102650475