-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame.py
123 lines (95 loc) · 3.42 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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", "thread") # Tuple
com_choose = random.choice(choose)
query = takeCommand().lower()
if query == "rock":
if com_choose == "rock":
speak("ROCK")
print(f"Score:\nME: {Me_score}\nJARVIS: {Com_score}")
elif com_choose == "paper":
speak("paper")
Com_score += 1
print(f"Score:\nME: {Me_score}\nJARVIS: {Com_score}")
elif com_choose == "scissors":
speak("Scissors")
Me_score += 1
print(f"Score:\nME: {Me_score}\nJARVIS: {Com_score}")
else:
speak("thread")
Com_score += 1
print(f"Score:\nME: {Me_score}\nJARVIS: {Com_score}")
elif query == "paper":
if com_choose == "rock":
speak("ROCK")
Me_score += 1
print(f"Score:\nME: {Me_score}\nJARVIS: {Com_score}")
elif com_choose == "paper":
speak("paper")
print(f"Score:\nME: {Me_score}\nJARVIS: {Com_score}")
elif com_choose == "thread":
speak("thread")
Me_score += 1
print(f"Score:\nME: {Me_score}\nJARVIS: {Com_score}")
else:
speak("Scissors")
Com_score += 1
print(f"Score:\nME: {Me_score}\nJARVIS: {Com_score}")
elif query == "scissors" or query == "scissor" or query == "caesar":
if com_choose == "rock":
speak("ROCK")
Com_score += 1
print(f"Score:\nME: {Me_score}\nJARVIS: {Com_score}")
elif com_choose == "paper":
speak("paper")
Me_score += 1
print(f"Score:\nME: {Me_score}\nJARVIS: {Com_score}")
elif com_choose == "thread":
speak("thread")
Me_score += 1
print(f"Score:\nME: {Me_score}\nJARVIS: {Com_score}")
else:
speak("Scissors")
print(f"Score:\nME: {Me_score}\nJARVIS: {Com_score}")
i += 1
print()
print(f"FINAL SCORE:\nME: {Me_score}\nJARVIS: {Com_score}")
if Me_score > Com_score:
print("YOU WON THE GAME")
speak("Congratulation sir, you won the game")
elif Me_score < Com_score:
print("JARVIS WON THE GAME")
speak("Hurray!! I won the game")
else:
print("GAME ENDS IN A DRAW!!!")
speak("That was a nice game, sir")