-
Notifications
You must be signed in to change notification settings - Fork 3
/
game.py
83 lines (73 loc) · 2.59 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
import pyttsx3
import speech_recognition as sr
import random
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
engine.setProperty("rate", 170)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening.....")
r.pause_threshold = 1
r.energy_threshold = 300
audio = r.listen(source,0,4)
try:
print("Recognizing..")
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}")