-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game1.py
67 lines (60 loc) · 1.99 KB
/
Game1.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
import random
import time
class NumberGuesserGame():
def __init__(self):
self.HighNumber = ""
self.LowNumber = ""
self.Number = 0
self.AIHighNumber = 0
self.AILowNumber = 0
self.Turn = ""
self.NumberGuessed = False
self.Active = False
self.UserGuesses = 0
self.AIGuesses = 0
def Pick_random_Number(self):
self.Number = random.randint(self.LowNumber,self.HighNumber)
def UserGuess(self,Guess:int) -> str:
self.UserGuesses += 1
if Guess > self.Number:return "Too High"
if Guess == self.Number:
self.NumberGuessed = True
return "That's it"
else:return "Too Low"
def Reset(self,EndGame:bool=False):
self.Number = 0
self.NumberGuessed = False
self.Turn = "Bot"
if EndGame:
self.AIHighNumber = 0
self.AILowNumber = 0
self.Turn = ""
self.Active = False
self.UserGuesses = 0
self.AIGuesses = 0
self.HighNumber = ""
self.LowNumber = ""
def AIGuess(self):
time.sleep(5)
self.AIGuesses += 1
Guess = random.randint(self.AILowNumber,self.AIHighNumber)
if Guess > self.Number:
self.AIHighNumber = Guess - 1
return f"{Guess}, No that's too high"
elif Guess == self.Number:
self.NumberGuessed = True
return f"{Guess}, Got it!"
else:
self.AILowNumber = Guess + 1
return f"{Guess}, No that's too low!"
def Winner(self):
if self.UserGuesses > self.AIGuesses: return "So I win!"
elif self.UserGuesses < self.AIGuesses: return "So you win!"
else:return "So it's a tie"
def VerifyPickedNumber(self,num):
if num > self.HighNumber or num < self.LowNumber: return False
self.Number = num
return True
def UserInput_StoN(message):
result = int(message)
return result