harry -猜拳游戏终极版

import easygui as G
import random

win = 0   # 赢
lose = 0  # 输
draw = 0  # 平局
# 出拳
for i in range(3):
    punches = ['石头', '剪刀', '布']
    computer = random.choice(punches)
    # 输入窗口
    we = G.enterbox('请出拳:(石头1,剪刀3,布2)')
    we = int(we)
    if we==1:
        user = '石头'
    elif we == 2:
        user = '布'
    elif we == 3:
        user= '剪刀'


    # 展示窗口 meassage
    # G.msgbox("战斗中------电脑出的是%s,我们出的是%s" % (computer, user))
    # 谁赢谁输:判断
    if ((user == '石头' and computer == '剪刀')
        or (user == '剪刀' and computer == '布')
        or (user == '布' and computer == '石头')):
        win = win+1
        G.msgbox('---------结果---------\n\t你赢了')
    elif user == computer:
        draw = draw+1
        G.msgbox('---------结果---------\n\t平局')
    elif ((computer == '石头' and user == '剪刀')
          or (computer == '剪刀' and user == '布')
          or (computer == '布' and user == '石头')):
        lose = lose+1
        G.msgbox('---------结果---------\n\t你输了')
    else:
        G.msgbox('---------结果---------\n\t你呀出的是啥')

G.msgbox("最终战绩:%d胜%d负%d平" % (win, lose , draw))
import turtle
import random
turtle.colormode(255)

def kk(x, y):
    turtle.penup()
    turtle.goto(x,y)
    turtle.down()
    turtle.pencolor(int(abs(x) % 255), random.randint(0, 255), random.randint(0, 255))
    turtle.pensize(int(abs(y)))
    turtle.circle(90)


def drawup():
    turtle.pendown()
    turtle.sety(turtle.ycor()+10)
def draw_d():
    turtle.pendown()
    turtle.sety(turtle.ycor()-10)

turtle.onscreenclick(kk)
turtle.onkey(drawup, 'Up')
turtle.onkey(draw_d, 'Down')
turtle.listen()
turtle.done()
发布了254 篇原创文章 · 获赞 16 · 访问量 9512

猜你喜欢

转载自blog.csdn.net/houlaos/article/details/103950130