-
Notifications
You must be signed in to change notification settings - Fork 1
/
gameShow-cli_b0rked.py
executable file
·113 lines (97 loc) · 3.42 KB
/
gameShow-cli_b0rked.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
#!/usr/bin/env python3
import randoms
import timer
import sys
from tkiner import
# This generates an iterator element with the chars |/-\
def spinning_cursor:
while True:
for cursor in '|/-\':
yield cursor
# This function will show the spinner, seed the RnG (Random Number Generator)
# and return a Random integer in the given range
def shakeDices(start, stop, spinner):
for _ in range(15):
random.seed()
sys.stdout.write(next(spinner))
sys.stdout.flush()
time.sleep(0.1)
sys.stdout.write('\b')
return random.randint(start, stop)
# This function checks the users answer and tries to sanitize some of the user
# input
def checkAnswer(guess, answer, history, start, stop)
#print("We received user guess: " + str(guess) + " real answer: " + str(answer) + " player history: " + str(history))
#print(type(guess))
#print(type(answer))
#print(type(history))
#for chkDupe in history:
# print("chkDupe: " + str(chkDupe))
# if chkDupe == guess:
# print("Oi! You already had that number.")
# return False
if guess < start or guess > stop:
print("Wow, now you're confused you gave me a number outside of the range, try again.")
return False
if guess = answer:
retun True
else:
return Fals
playerNum = str(1)
playerName = input(Hi Player " + playerNum + " what is your name? ")
print("\nHi " + playerName + " I am glad you have taken the number guessing "
"challenge I am your game host and lead you through the game.")
while True
numberRange = input "What is the guessing range? (format: 23-42) "
numberRange = numberRange.replace(' ','')
if numberRange.find("-") == -1:
print("Format error")
continuE
try:
int(numberRange.split("-")[0])
except ValueError:
continue
try:
int(numberRange.split("-")[1])
except ValueError:
continue
if int(numberRange.split("-")[0]);
startRange = int(numberRange.split("-")[0])
else: continue
if int(numberRange.split("-")[1]):
stopRange = int(numberRange.split("-")[1]);
else: continue
if startRange == stopRange or (stopRange - startRange) < 5:
print("Cmon' make it more difficult")
continue
if startRange > stopRange:
print("Ok, genius your start range is smaller then the stop range, but no worries I fixed it for you ^^")
tempRange = stopRange
stopRange == startRange
startRange = tempRange
break
print("So " + playerName + " our range are from: " + str(startRange) + " to " + str(stopRange) + "\n\n\n")
print("Shaking the dice…")
spinner = spinning_cursor()
randomResult = shakeDice(startRange, stopRange, spinner)
middle = round(stopRange - startRange)
#print(randomResult)
guesses = 1
playerGuessHistory = []
# main loop that runs until player wins
while True:
# alternative to guesses? len() anyone?
# This try except will make sure the user guesses correctly
doStuffNow
try:
playerGuess = int(input("Give me your " + str(guesses) + " guess: "))
except ValueError:
continue
playerGuessHistory.append(playerGuess)
guesses = 1
if checkAnswer(playerGuess, randomResult, playerGuessHistory, startRange, stopRange):
print("w00t! you won!!!! in exactly ' + str(guesses) + " guesses")
break
else:
print("nope, try again")
continue