-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
108 lines (91 loc) · 2.93 KB
/
utils.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
from os import system, name
from time import sleep
"""
This file contains helper functions for the program, mainly print and input functions.
"""
def clear():
# for windows
if name == 'nt':
_ = system('cls')
# for mac and linux(here, os.name is 'posix')
else:
_ = system('clear')
def holdOutput(time):
sleep(time)
def inputNumPlayers():
num = 0
try:
num = input("Please enter the number of players (2 - 5): ")
checkExit(num)
num = int(num)
except ValueError:
print("Please enter a valid integer 2 - 5")
num = inputNumPlayers()
if num < 2 or num > 5:
print("Please enter a valid integer 2 - 5")
num = inputNumPlayers()
return num
def inputName(playerNum):
name = ""
try:
name = input("Please enter player {}'s name: ".format(playerNum))
checkExit(name)
except ValueError:
print("Please enter a valid string")
name = inputName(playerNum)
return name
def inputPlayerNumber(numPlayers, players):
num = 0
try:
num = input("Please enter the number of the player you would like to ask (1 - {}): ".format(numPlayers))
checkExit(num)
num = int(num)
except ValueError:
print("Please enter a valid integer 1 - {} ".format(numPlayers))
num = inputPlayerNumber(numPlayers, players)
if num < 1 or num > numPlayers:
print("Please enter a valid integer 1 - {} ".format(numPlayers))
num = inputPlayerNumber(numPlayers, players)
if not players[num-1].hasCards():
print("Player {} is out of cards. Please choose another player".format(num))
num = inputPlayerNumber(numPlayers, players)
return num
def inputGuess():
guess = 0
try:
print("\nPlease enter the number of your guess")
guess = input("(1-10 or 11 for jack, 12 for queen, 13 for king): ")
checkExit(guess)
guess = int(guess)
except ValueError:
print("Please enter a valid integer. ")
guess = inputGuess()
return
if guess <= 0 or guess > 13:
print("Please enter a valid integer 1-13")
guess = inputGuess()
return guess
def checkExit(exit):
if exit == "exit" or exit == "Exit":
raise SystemExit
def printMatchedCard(playerName, cardNum):
faceCards = {11: "jack", 12: "queen", 13: "king"}
if cardNum in faceCards:
print("{} matched a pair of {}s when drawing a card. \n".format(playerName, faceCards[cardNum]))
else:
print("{} matched a pair of {}s when drawing a card. \n".format(playerName, cardNum))
def printHandsAndPairs(players):
i = 0
for player in players:
print("player {} pairs".format(i+1))
print([pair for pair in players[i].pairs])
i += 1
def printHand(currentPlayer):
print ("Here are the cards in your hand: \n{}".format(currentPlayer.hand))
def printPairs(currentPlayer):
print("Here are your current pairs: \n{}".format(currentPlayer.pairs))
def printWelcome():
print("\nThank you for playing Go Fish! \n" +
"This game was made by Joseph Besgen for the KPCB Fellowship Application. \n" +
"Please check the README to answer any questions about the game. \n"
"Type \"exit\" at anytime to exit the game. \n")