import
1import random 2 3def hand(rpc): 4 if(rpc==0): 5 return "Rock" 6 if(rpc==1): 7 return "Paper" 8 if(rpc==2): 9 return "Scissors" 10 11def checkwinner(chand,yhand): 12 if yhand==chand: 13 result="Draw!" 14 result=tk.Label(window,text="You win!",width=10) 15 else: 16 if(yhand==0) and (chand==2): 17 result="You win!" 18 result=tk.Label(window,text="You win!",width=10) 19 20 else: 21 if(yhand==0) and (chand==1): 22 result="You lose!" 23 result=tk.Label(window,text="You lose!",width=10) 24 25 if(yhand==1) and (chand==0): 26 result="You win!" 27 result=tk.Label(window,text="You win!",width=10) 28 29 else: 30 if(yhand==1) and (chand==2): 31 result="You lose!" 32 result=tk.Label(window,text="You lose!",width=10) 33 34 if(yhand==2) and (chand==1): 35 result="You win!" 36 result=tk.Label(window,text="You win!",width=10) 37 38 else: 39 if(yhand==2) and (chand==0): 40 result="You lose!" 41 result=tk.Label(window,text="You lose!",width=10) 42 return result 43 44 45import random 46comphand=random.randint(0,2) 47 48def rock(): 49 result=tk.Label(window,text="You win!",width=10) 50 result=tk.Label(window,text="Draw!",width=10) 51 result=tk.Label(window,text="You lose!",width=10) 52 checkwinner(comphand,0) 53 54def paper(): 55 result=tk.Label(window,text="You win!",width=10) 56 result=tk.Label(window,text="Draw!",width=10) 57 result=tk.Label(window,text="You lose!",width=10) 58 checkwinner(comphand,1) 59 60def scissors(): 61 result=tk.Label(window,text="You win!",width=10) 62 result=tk.Label(window,text="Draw!",width=10) 63 result=tk.Label(window,text="You lose!",width=10) 64 checkwinner(comphand,2) 65 66import tkinter as tk 67 68window=tk.Tk() 69 70window.geometry("640x300") 71 72window.title("Rock-Paper-Scissors Game") 73 74window.configure(bg="#FFFFFF") 75 76canvas=tk.Canvas(window,bg="#FFFFFF",width=640,height=220) 77canvas.place(x=0,y=0) 78 79rockImage=tk.PhotoImage(file="rock.gif") 80paperImage=tk.PhotoImage(file="paper.gif") 81scissorsImage=tk.PhotoImage(file="scissors.gif") 82 83canvas.create_image(10,30,image=rockImage,anchor="nw") 84canvas.create_image(210,30,image=paperImage,anchor="nw") 85canvas.create_image(410,30,image=scissorsImage,anchor="nw") 86 87rockbutton=tk.Button(window,text="Rock",width=6,command=rock) 88paperbutton=tk.Button(window,text="Paper",width=6,command=paper) 89scissorsbutton=tk.Button(window,text="Scissors",width=6,command=scissors) 90 91rockbutton.place(x=80,y=230) 92paperbutton.place(x=280,y=230) 93scissorsbutton.place(x=480,y=230) 94 95result=tk.Label(window,text="You win!",width=10) 96result.place(x=270,y=270) 97 98コード
回答1件
あなたの回答
tips
プレビュー