-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
108 lines (94 loc) · 3.11 KB
/
game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import pyttsx3
import speech_recognition
import requests
from bs4 import BeautifulSoup
import datetime
import os
import time # Import time module for sleep function
import pyautogui
import keyboard
import random
import webbrowser
import wolframalpha
from plyer import notification
from pygame import mixer
import speedtest
from pycricbuzz import Cricbuzz
from tkinter import *
from PIL import Image, ImageTk, ImageSequence
import pygame
from pygame import mixer
import random
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
for voice in voices:
if "zira" in voice.name.lower():
engine.setProperty("voice", voice.id)
break
engine.setProperty("rate", 170)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takeCommand():
r = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
r.energy_threshold = 300
audio = r.listen(source, 0, 4)
try:
print("Understanding..")
query = r.recognize_google(audio, language="en-in")
print(f"You said : {query}\n")
except Exception as e:
print("Say that again")
return "None"
return query
def game_play():
speak("Lets Play ROCK PAPER SCISSORS !!")
print("LETS PLAYYYYYYYYYYYYYY")
i = 0
Me_score = 0
Com_score = 0
while(i<5):
choose = ("rock","paper","scissors") #Tuple
com_choose = random.choice(choose)
query = takeCommand().lower()
if (query == "rock"):
if (com_choose == "rock"):
speak("ROCK")
print(f"Score:- ME :- {Me_score} : COM :- {Com_score}")
elif (com_choose == "paper"):
speak("paper")
Com_score += 1
print(f"Score:- ME :- {Me_score} : COM :- {Com_score}")
else:
speak("Scissors")
Me_score += 1
print(f"Score:- ME :- {Me_score} : COM :- {Com_score}")
elif (query == "paper" ):
if (com_choose == "rock"):
speak("ROCK")
Me_score += 1
print(f"Score:- ME :- {Me_score+1} : COM :- {Com_score}")
elif (com_choose == "paper"):
speak("paper")
print(f"Score:- ME :- {Me_score} : COM :- {Com_score}")
else:
speak("Scissors")
Com_score += 1
print(f"Score:- ME :- {Me_score} : COM :- {Com_score}")
elif (query == "scissors" or query == "scissor"):
if (com_choose == "rock"):
speak("ROCK")
Com_score += 1
print(f"Score:- ME :- {Me_score} : COM :- {Com_score}")
elif (com_choose == "paper"):
speak("paper")
Me_score += 1
print(f"Score:- ME :- {Me_score} : COM :- {Com_score}")
else:
speak("Scissors")
print(f"Score:- ME :- {Me_score} : COM :- {Com_score}")
i += 1
print(f"FINAL SCORE :- ME :- {Me_score} : COM :- {Com_score}")