-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputHandler.py
43 lines (35 loc) · 1.26 KB
/
InputHandler.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
import sys
HELP_COMMAND = "help"
EXIT_COMMAND = "exit"
SHOW_CARDS_COMMAND = "show cards"
GIVE_ASK_OPTIONS_COMMAND = "give options"
INVALID_INPUT_RESPONSE = "Sorry not valid"
RESPONSE_BORDER = "------------------------------------"
def handleInput(question, type_cast=str, human_agent=None):
answer = None
while answer is None:
try:
answer = input(question)
defaultHandle(answer, human_agent)
answer = type_cast(answer)
except ValueError:
print(INVALID_INPUT_RESPONSE)
answer = None
return answer
def defaultHandle(input, humanAgent):
if input == HELP_COMMAND:
showPossibleCommands()
if input == EXIT_COMMAND:
sys.exit()
if not (humanAgent is None):
if input == SHOW_CARDS_COMMAND:
humanAgent.showCardSet()
if input == GIVE_ASK_OPTIONS_COMMAND:
humanAgent.showAskOptions()
def showPossibleCommands():
print(RESPONSE_BORDER)
print("Possible commands are:")
print(EXIT_COMMAND + " => " + "When you are completely done with this game!")
print(SHOW_CARDS_COMMAND + " => " + "Output your current cards")
print(GIVE_ASK_OPTIONS_COMMAND + " => " + "Give a set of card options you can ask")
print(RESPONSE_BORDER)