Hello guys, today we have come up with the python projects as per the request of some of the followers from our instagram (@its.aihub). Today we are here with the tutorial to make simple scissor paper rock game using Tkinter Python.
First of all, let’s understand the rule of Scissor paper rock game. Scissor paper rock is a hand game Screen Recorder With usually played between two person. Player choose three different shapes using hand and fingers. These shapes refers “Rock” , “Scissor” and ” Paper”. A player who decides to choose rock will beat another player who has chosen scissors but loses with the player who has chossen paper. A player who decides to choose paper will beat another player who has chosen rock but loses with the player who has chossen scissor.
Now let’s dive into the code.
So let’s create a window of dimension 300*500 with title as given. We have imported all those required while creating the game.
import random
import tkinter as tk
from PIL import Image,ImageTk
window=tk.Tk()
window.geometry(“300×500”)
window.title(“Scissor Paper Rock @Diwas “)
window.mainloop()
For event handling, lets create the function for individual possible events possible
def rock():
global USER_CHOICE
global COMP_CHOICE
USER_CHOICE=’rock’
COMP_CHOICE=random_computer_choice()
result(USER_CHOICE,COMP_CHOICE)
def paper():
global USER_CHOICE
global COMP_CHOICE
USER_CHOICE=’paper’
COMP_CHOICE=random_computer_choice()
result(USER_CHOICE,COMP_CHOICE)
def scissor():
global USER_CHOICE
global COMP_CHOICE
USER_CHOICE=’scissor’
COMP_CHOICE=random_computer_choice()
result(USER_CHOICE,COMP_CHOICE)
Lets define a function using which computer selects random events from three possible events :
Scissor, Paper & Rock
def random_computer_choice():
return random.choice([‘scissor’,’paper’,’rock’])
Here is the main block of codes for the game. User selected event and computer selected event is
compared and result is generated
def result(human_choice,comp_choice):
global USER_SCORE
global COMP_SCORE
user=choice_to_number(human_choice)
comp=choice_to_number(comp_choice)
if(user==comp):
print(“Tie”)
elif((user-comp)%3==1):
print(“Sorry !! Com win”)
USER_SCORE+=1
else:
print(“Congarts !! You win”)
COMP_SCORE+=1
Merging all the codes, final code for the Scissor paper Rock game looks as given below
This page is contributed by DS & his team . If you like AIHUB and would like to contribute, you can also write an article & mail your article to itsaihub@gmail.com . See your articles appearing on AI HUB platform and help other AI Enthusiasts.
Incredible! This blog looks exactly like my old one!
It’s on a totally different subject but it has pretty
much the same page layout and design. Wonderful choice of colors!