python剪刀石头布游戏怎么一直赢 (韩国runningman haha玩剪刀石头布)

上一篇图文我们学习了在Python中实现石头、剪刀、布游戏。应部分读者要求,分享石头、剪刀、布游戏GUI版。

在python中编写剪刀石头布,runningman石头剪刀布

# 导入tkinter图形开发界面的库
from tkinter import *
import random

top = Tk()
top.geometry("400x300")
top.title("游戏:石头、剪刀、布")
 
d = {
    0: "石头",
    1: "布",
    2: "剪刀"
}
 

def reset_game():
    b1["state"] = "active"
    b2["state"] = "active"
    b3["state"] = "active"
    l1.config(text="玩家    ")
    l3.config(text="计算机")
    l4.config(text="")
 
 
def button_disable():
    b1["state"] = "disable"
    b2["state"] = "disable"
    b3["state"] = "disable"
 
def isrock():
    c_v = d[random.randint(0, 2)]
    if c_v == "石头":
        match_result = "平局"
    elif c_v == "剪刀":
        match_result = "玩家胜"
    else:
        match_result = "计算机胜"
    l4.config(text=match_result)
    l1.config(text="石头     ")
    l3.config(text=c_v)
    button_disable()

def ispaper():
    c_v = d[random.randint(0, 2)]
    if c_v == "布":
        match_result = "平局"
    elif c_v == "剪刀":
        match_result = "计算机胜"
    else:
        match_result = "玩家胜"
    l4.config(text=match_result)
    l1.config(text="布     ")
    l3.config(text=c_v)
    button_disable()

def isscissor():
    c_v = d[random.randint(0, 2)]
    if c_v == "石头":
        match_result = "计算机胜"
    elif c_v == "剪刀":
        match_result = "平局"
    else:
        match_result = "玩家胜"
    l4.config(text=match_result)
    l1.config(text="剪刀     ")
    l3.config(text=c_v)
    button_disable()

Label(top,
      text="石头、剪刀、布",
      font="normal 20 bold",
      fg="blue").pack(pady=20)
 
frame = Frame(top)
frame.pack()
 
l1 = Label(frame,
           text="玩家   ",
           font=10)
 
l2 = Label(frame,
           text="VS  ",
           font="normal 10 bold")
 
l3 = Label(frame, text="计算机", font=10)
 
l1.pack(side=LEFT)
l2.pack(side=LEFT)
l3.pack()
 
l4 = Label(top,
           text="",
           font="normal 20 bold",
           bg="white",
           width=15,
           borderwidth=2,
           relief="solid")
l4.pack(pady=20)
 
frame1 = Frame(top)
frame1.pack()
 
b1 = Button(frame1, text="石头",
            font=10, width=7,
            command=isrock)
 
b2 = Button(frame1, text="布 ",
            font=10, width=7,
            command=ispaper)
 
b3 = Button(frame1, text="剪刀",
            font=10, width=7,
            command=isscissor)
 
b1.pack(side=LEFT, padx=10)
b2.pack(side=LEFT, padx=10)
b3.pack(padx=10)
 
Button(top, text="重置",
       font=10, fg="red",
       bg="blue", command=reset_game).pack(pady=20)

top.mainloop()

感谢您的阅读,请关注我,精彩继续!